def __init__(self, instance):
        super(ProductionOverviewTab,
              self).__init__(widget='overview_productionbuilding.xml',
                             instance=instance)
        self.tooltip = _("Production overview")

        self.destruct_button = DeleteButton(name="destruct_button", \
                                            tooltip=_("Destroy building"), \
                                            position=(190,330) )
        self.widget.addChild(self.destruct_button)
        self.widget.mapEvents({'destruct_button': self.destruct_building})
	def  __init__(self, instance):
		super(ProductionOverviewTab, self).__init__(
			widget = 'overview_productionbuilding.xml',
			instance = instance
		)
		self.tooltip = _("Production overview")

		self.destruct_button = DeleteButton(name="destruct_button", \
		                                    tooltip=_("Destroy building"), \
		                                    position=(190,330) )
		self.widget.addChild(self.destruct_button)
		self.widget.mapEvents( { 'destruct_button' : self.destruct_building } )
class ProductionOverviewTab(OverviewTab):
	production_line_gui_xml = "overview_productionline.xml"

	def  __init__(self, instance):
		super(ProductionOverviewTab, self).__init__(
			widget = 'overview_productionbuilding.xml',
			instance = instance
		)
		self.tooltip = _("Production overview")

		self.destruct_button = DeleteButton(name="destruct_button", \
		                                    tooltip=_("Destroy building"), \
		                                    position=(190,330) )
		self.widget.addChild(self.destruct_button)
		self.widget.mapEvents( { 'destruct_button' : self.destruct_building } )

	def refresh(self):
		"""This function is called by the TabWidget to redraw the widget."""
		cap_util = 0
		if hasattr(self.instance, 'capacity_utilisation'):
			cap_util = int(round( self.instance.capacity_utilisation * 100))
		self.widget.child_finder('capacity_utilisation').text = unicode(cap_util) + u'%'

		# remove old production line data
		parent_container = self.widget.child_finder('production_lines')
		while len(parent_container.children) > 0:
			parent_container.removeChild(parent_container.children[0])

		# create a container for each production
		# sort by production line id to have a consistent (basically arbitrary) order
		for production in sorted(self.instance._get_productions(), \
								             key=(lambda x: x.get_production_line_id())):
			gui = load_xml_translated(self.production_line_gui_xml)
			# fill in values to gui reflecting the current game state
			container = gui.findChild(name="production_line_container")
			if production.is_paused():
				container.removeChild( container.findChild(name="toggle_active_active") )
				container.findChild(name="toggle_active_inactive").name = "toggle_active"
			else:
				container.removeChild( container.findChild(name="toggle_active_inactive") )
				container.findChild(name="toggle_active_active").name = "toggle_active"

			# fill it with input and output resources
			in_res_container = container.findChild(name="input_res")
			for in_res in production.get_consumed_resources():
				filled = float(self.instance.inventory[in_res]) * 100 / \
				       self.instance.inventory.get_limit(in_res)
				in_res_container.addChild( \
				  ImageFillStatusButton.init_for_res(self.instance.session.db,\
				                                     in_res, \
				                                     self.instance.inventory[in_res], \
				                                     filled, \
				                                     use_inactive_icon=False, \
				                                     uncached=True) \
				)
			out_res_container = container.findChild(name="output_res")
			for out_res in production.get_produced_res():
				filled = float(self.instance.inventory[out_res]) * 100 /  \
				       self.instance.inventory.get_limit(out_res)
				out_res_container.addChild( \
				  ImageFillStatusButton.init_for_res(self.instance.session.db, \
				                                     out_res, \
				                                     self.instance.inventory[out_res], \
				                                     filled, \
				                                     use_inactive_icon=False, \
				                                     uncached=True) \
				)


			# fix pychans lack of dynamic container sizing
			# the container in the xml must provide a height attribute, that is valid for
			# one resource.
			max_res_in_one_line = max(len(production.get_produced_res()), \
			                          len(production.get_consumed_resources()))
			container.height = max_res_in_one_line * container.height


			# active toggle_active button
			container.mapEvents( \
			  { 'toggle_active': \
			    Callback(ToggleActive(self.instance, production).execute, self.instance.session) \
			    } )
			# NOTE: this command causes a refresh, so we needn't change the toggle_active-button-image
			container.stylize('menu_black')
			parent_container.addChild(container)
		super(ProductionOverviewTab, self).refresh()

	def destruct_building(self):
		self.instance.session.ingame_gui.hide_menu()
		if self.destruct_button.gui.isVisible():
			self.destruct_button.hide_tooltip()
		Tear(self.instance).execute(self.instance.session)
class ProductionOverviewTab(OverviewTab):
	production_line_gui_xml = "overview_productionline.xml"

	def  __init__(self, instance):
		super(ProductionOverviewTab, self).__init__(
			widget = 'overview_productionbuilding.xml',
			instance = instance
		)
		self.tooltip = _("Production overview")

		self.destruct_button = DeleteButton(name="destruct_button", \
		                                    tooltip=_("Destroy building"), \
		                                    position=(190,330) )
		self.widget.addChild(self.destruct_button)
		self.widget.mapEvents( { 'destruct_button' : self.destruct_building } )

	def refresh(self):
		"""This function is called by the TabWidget to redraw the widget."""
		cap_util = 0
		if hasattr(self.instance, 'capacity_utilisation'):
			cap_util = int(round( self.instance.capacity_utilisation * 100))
		self.widget.child_finder('capacity_utilisation').text = unicode(cap_util) + u'%'

		# remove old production line data
		parent_container = self.widget.child_finder('production_lines')
		while len(parent_container.children) > 0:
			parent_container.removeChild(parent_container.children[0])

		# create a container for each production
		# sort by production line id to have a consistent (basically arbitrary) order
		for production in sorted(self.instance._get_productions(), \
								             key=(lambda x: x.get_production_line_id())):
			gui = load_xml_translated(self.production_line_gui_xml)
			# fill in values to gui reflecting the current game state
			container = gui.findChild(name="production_line_container")
			if production.is_paused():
				container.removeChild( container.findChild(name="toggle_active_active") )
				container.findChild(name="toggle_active_inactive").name = "toggle_active"
			else:
				container.removeChild( container.findChild(name="toggle_active_inactive") )
				container.findChild(name="toggle_active_active").name = "toggle_active"

			# fill it with input and output resources
			in_res_container = container.findChild(name="input_res")
			for in_res in production.get_consumed_resources():
				filled = float(self.instance.inventory[in_res]) * 100 / \
				       self.instance.inventory.get_limit(in_res)
				in_res_container.addChild( \
				  ImageFillStatusButton.init_for_res(self.instance.session.db,\
				                                     in_res, \
				                                     self.instance.inventory[in_res], \
				                                     filled, \
				                                     use_inactive_icon=False) \
				)
			out_res_container = container.findChild(name="output_res")
			for out_res in production.get_produced_res():
				filled = float(self.instance.inventory[out_res]) * 100 /  \
				       self.instance.inventory.get_limit(out_res)
				out_res_container.addChild( \
				  ImageFillStatusButton.init_for_res(self.instance.session.db, \
				                                     out_res, \
				                                     self.instance.inventory[out_res], \
				                                     filled, \
				                                     use_inactive_icon=False) \
				)


			# fix pychans lack of dynamic container sizing
			# the container in the xml must provide a height attribute, that is valid for
			# one resource.
			max_res_in_one_line = max(len(production.get_produced_res()), \
			                          len(production.get_consumed_resources()))
			container.height = max_res_in_one_line * container.height


			# active toggle_active button
			container.mapEvents( \
			  { 'toggle_active': \
			    Callback(ToggleActive(self.instance, production).execute, self.instance.session) \
			    } )
			# NOTE: this command causes a refresh, so we needn't change the toggle_active-button-image
			container.stylize('menu_black')
			parent_container.addChild(container)
		super(ProductionOverviewTab, self).refresh()

	def destruct_building(self):
		self.instance.session.ingame_gui.hide_menu()
		if self.destruct_button.gui.isVisible():
			self.destruct_button.hide_tooltip()
		Tear(self.instance).execute(self.instance.session)