class Statechart(Context): def __init__(self, param): Context.__init__(self, None, None, None, None) self.param = param def start(self): self.runtime = RuntimeData() self.runtime.reset() self.runtime.activate(self) self.runtime.activate(self.start_state) self.dispatch(None) def dispatch(self, event): current_state = self.runtime.active_states[self].current_state return current_state.dispatch(self.runtime, event, self.param) def add_transition(self, transition): assert False, "Cannot add transition to a statechart" def shutdown(self): pass
def start(self): self.runtime = RuntimeData() self.runtime.reset() self.runtime.activate(self) self.runtime.activate(self.start_state) self.dispatch(None)