def __init__(self, mp): self.mainPres = mp #This is a slightly convoluted way to avoid importing StartState self.currentState = State().next(State.EVENTS.START)() self.currentState.run(self.mainPres) #Set the StateMachine based on the dataModel of the mainPres self.changeState(self.mainPres.getModeTransition())
class StateMachine(object): def __init__(self, mp): self.mainPres = mp #This is a slightly convoluted way to avoid importing StartState self.currentState = State().next(State.EVENTS.START)() self.currentState.run(self.mainPres) #Set the StateMachine based on the dataModel of the mainPres self.changeState(self.mainPres.getModeTransition()) def changeState(self, event): while True: nextState = self.currentState.next(event) if nextState == type(self.currentState): break self.currentState = nextState() self.currentState.run(self.mainPres) def getStateName(self): return self.currentState.name