class Controller: def __init__(self): self.timerResetValue = 5 self.model = Model() #set up the first frame which displays the current Model value self.view1 = View() self.view1.setTimerView(self.model.timerValue) #set up the second frame which allows the user to modify the Model's value self.view2 = ChangerWidget() self.view2.setTimerButtonText(self.timerResetValue) self.view1.Show() self.view2.Show() # Notify MODEL and persist data ... pub.subscribe(self.model.startTimer, 'timer_starting') # when a timer is started pub.subscribe(self.model.stopTimer, 'timer_stopping') # when a timer is stopped pub.subscribe(self.model.changeTimer, 'timer_changing') # when a timer changes it's value # self.timerThread(amount=99) # Notify VIEW ... # pub.subscribe(self.timerThread, 'timer_counting') # when a timer changes it's value pub.subscribe(self.timerThread, 'timer_starting') # when a timer starts def timerThread(self, amount): print "Controller: timerThread being initialized" rt = mythread.MyThread(self.timerResetValue, 1, self.model.changeTimer, 1) # it auto-starts, no need of rt.start() #rt = mythread.MyThread(5, 1, self.doNothing(), 1) def doNothing(self): print "Controller: I'm doing nothing"
def __init__(self): self.model = Model() self.view1 = View() self.view1.setMoney(self.model.myMoney) self.view2 = ChangerWidget() self.view1.Show() self.view2.Show() pub.subscribe(self.changeMoney, "money_changing")
def __init__(self): self.model = Model() #set up the first frame which displays the current Model value self.view1 = View() self.view1.setMoney(self.model.myMoney) #set up the second frame which allows the user to modify the Model's value self.view2 = ChangerWidget() self.view1.Show() self.view2.Show() pub.subscribe(self.changeMoney, 'money_changing')
def __init__(self): self.timerResetValue = 5 self.model = Model() #set up the first frame which displays the current Model value self.view1 = View() self.view1.setTimerView(self.model.timerValue) #set up the second frame which allows the user to modify the Model's value self.view2 = ChangerWidget() self.view2.setTimerButtonText(self.timerResetValue) self.view1.Show() self.view2.Show() # Notify MODEL and persist data ... pub.subscribe(self.model.startTimer, 'timer_starting') # when a timer is started pub.subscribe(self.model.stopTimer, 'timer_stopping') # when a timer is stopped pub.subscribe(self.model.changeTimer, 'timer_changing') # when a timer changes it's value # self.timerThread(amount=99) # Notify VIEW ... # pub.subscribe(self.timerThread, 'timer_counting') # when a timer changes it's value pub.subscribe(self.timerThread, 'timer_starting') # when a timer starts
class Controller: def __init__(self): self.model = Model() self.view1 = View() self.view1.setMoney(self.model.myMoney) self.view2 = ChangerWidget() self.view1.Show() self.view2.Show() pub.subscribe(self.changeMoney, "money_changing") def changeMoney(self, amount): if amount > 0: self.model.addMoney(amount) else: self.model.removeMoney(-amount)
class Controller: def __init__(self): self.model = Model() #set up the first frame which displays the current Model value self.view1 = View() self.view1.setMoney(self.model.myMoney) #set up the second frame which allows the user to modify the Model's value self.view2 = ChangerWidget() self.view1.Show() self.view2.Show() pub.subscribe(self.changeMoney, 'money_changing') def changeMoney(self, amount): if amount >= 0: self.model.addMoney(amount) else: self.model.removeMoney(-amount)