class TheatreController(object): '''Control widgets in TheatreView class''' def __init__(self, parent, theatre): self.parent = parent self.theatre = theatre self.checked = IntVar() self.view = TheatreView(parent) def run(self): '''Create elements in this frame''' self.view.createWidgets(self.theatre.name, self.theatre.seats.seats, self.theatre.seats.priceGroups, self) def theatreState(self): self.theatre.mayCalculate(self.checked.get()) def isOkay(self, action, val, i): '''Check if entered value in EntryBox is valid''' try: # Action code 0 equals deletion, reset seats if the potential value equals emptry string in Entry if action == "0" and len(val) == 0: seats = 0 else: seats = int(val) # Accepted value -> update seat model self.updateSeatModel(seats, i) self.updateTheatreModel() return True except Exception as e: return False def updateTheatreModel(self): '''Set revenue and percentage for theatre''' self.theatre.calculatePercentage() self.theatre.calculateRevenue() def updateSeatModel(self, seats, i): '''Set bought tickets in PriceGroup and set free seats in SeatsModel''' self.theatre.seats.priceGroups[int(i)].setBought(seats) free = self.theatre.seats.updateFree() self.updateSeatView(free) self.updateCheckButton(free) def updateSeatView(self, free): '''Update SeatLabel text''' self.view.updateSeatLabel(free) def updateCheckButton(self, free): '''Set checkbutton state to normal or depending on the theatre's free seats''' if free != self.theatre.seats.seats and free >= 0: #Checkbutton may be activated self.view.updateCb(True) else: self.view.updateCb(False) #Toggle theatre calculate self.theatreState()
def __init__(self, parent, theatre): self.parent = parent self.theatre = theatre self.checked = IntVar() self.view = TheatreView(parent)