Exemplo n.º 1
0
class ButtonsController(object):
	'''Controls events in ButtonView class'''
	def __init__(self, parent, theatres):
		self.view = ButtonView(parent, theatres)
		self.parent = parent
		self.theatres = theatres

	def run(self):
		'''Create elements in this frame'''
		self.view.createWidgets(self)

	def pressedQuit(self):
		'''User pressed quit-button'''
		ans = messagebox.askokcancel(title="Quit?", message="Are you sure you want to quit?")
		if ans: self.parent.quit()
	
	def pressedPermutations(self):
		sorted = self.sortedTheatres()
		if len(sorted) > 0: self.view.showPermutations(sorted)

	def pressedSales(self):
		'''User pressed calculate sales-button'''	
		sorted = self.sortedTheatres()
		if len(sorted) > 0: self.view.showSales(sorted)


	def sortedTheatres(self):
		'''Sorted list theatres is descending order by percentage'''
		def getCheckedTheatres():
			return [theatre for theatre in self.theatres if theatre.calculate]

		checked = getCheckedTheatres()
		return sorted(checked, key=lambda theatre: theatre.percentage, reverse=True)
Exemplo n.º 2
0
	def __init__(self, parent, theatres):
		self.view = ButtonView(parent, theatres)
		self.parent = parent
		self.theatres = theatres