class X(mvc.Model): def method(self): calls.append("during") control = mvc.Control("method", before=_control_before, after=_control_after)
class X(mvc.Model): def method(self): pass control = mvc.Control("method").before("before").after("after") def before(self, call, notify): calls.append("before") def after(self, answer, notify): calls.append("after")
class X(mvc.Model): def method(self): calls.append("during") control = mvc.Control("method") @control.before def control(self, call, notify): calls.append("before") @control.after def control(self, call, notify): calls.append("after")
class Container(mvc.Structure): def __init__(self, name): self.name = name self.value = None def set(self, value): self.value = value _control_changes = mvc.Control("set", before="_before_change", after="_after_change") def _before_change(self, call, notify): return self.value def _after_change(self, answer, notify): notify(old=answer.before, new=self.value) def __repr__(self): return "Container(%r)" % self.name
class Counter(mvc.Model): def __init__(self): self.value = 0 def increment(self, amount): self.value += amount def decrement(self, amount): self.value -= amount _control_change = ( mvc.Control("increment", "decrement") .before("_control_before_change") .after("_control_after_change") ) def _control_before_change(self, call, notify): return self.value def _control_after_change(self, answer, notify): notify(old=answer.before, new=self.value)
class Counter(mvc.Model): def __init__(self): self.value = 0 def increment(self, amount): self.value += amount def decrement(self, amount): self.value -= amount _control_change = mvc.Control( ["increment", "decrement"], before="_control_before_change", after="_control_after_change", ) def _control_before_change(self, call, notify): return self.value def _control_after_change(self, answer, notify): notify(old=answer["before"], new=self.value)
class X: _control = mvc.Control()
class MyCounter(Counter): _added_control = mvc.Control("increment").before("_added_before") def _added_before(self, call, notify): notify(message="before")
class X: _control = mvc.Control("something")