def _on_change_upgrade_permissions(self, message): production = self._upgrade_production if production is not None: if production.is_paused() == self.upgrade_allowed: ToggleActive(self.get_component(Producer), production).execute(self.session, True)
def refresh(self): """This function is called by the TabWidget to redraw the widget.""" self._refresh_utilization() # remove old production line data parent_container = self.widget.child_finder('production_lines') while parent_container.children: child = parent_container.children[-1] if hasattr(child, "anim"): child.anim.stop() del child.anim parent_container.removeChild(child) # create a container for each production # sort by production line id to have a consistent (basically arbitrary) order for production in self.get_displayed_productions(): # we need to be notified of small production changes # that aren't passed through the instance production.add_change_listener(self._schedule_refresh, no_duplicates=True) gui = load_uh_widget(self.production_line_gui_xml) # fill in values to gui reflecting the current game state container = gui.findChild(name="production_line_container") centered_container = container.findChild( name='centered_production_icons') center_y = self._center_production_line(container, production) centered_container.position = (centered_container.position[0], center_y) self._set_resource_amounts(container, production) if production.is_paused(): centered_container.removeChild( centered_container.findChild(name="toggle_active_active")) toggle_icon = centered_container.findChild( name="toggle_active_inactive") toggle_icon.name = "toggle_active" else: centered_container.removeChild( centered_container.findChild( name="toggle_active_inactive")) toggle_icon = centered_container.findChild( name="toggle_active_active") toggle_icon.name = "toggle_active" if production.get_state() == PRODUCTION.STATES.producing: bg = Icon(image=self.__class__.BUTTON_BACKGROUND) bg.position = toggle_icon.position centered_container.addChild(bg) centered_container.removeChild( toggle_icon) # fix z-ordering centered_container.addChild(toggle_icon) anim = PychanAnimation( toggle_icon, self.__class__.ACTIVE_PRODUCTION_ANIM_DIR) centered_container.anim = anim anim.start(1.0 / 12, -1) # always start anew, people won't notice self._animations.append(weakref.ref(anim)) # fill it with input and output resources in_res_container = container.findChild(name="input_res") self._add_resource_icons(in_res_container, production.get_consumed_resources(), marker=True) out_res_container = container.findChild(name="output_res") self._add_resource_icons(out_res_container, production.get_produced_resources()) # active toggle_active button toggle_active = ToggleActive(self.instance.get_component(Producer), production) centered_container.mapEvents({ 'toggle_active': Callback(toggle_active.execute, self.instance.session) }) # NOTE: this command causes a refresh, so we needn't change the toggle_active-button-image parent_container.addChild(container) super(ProductionOverviewTab, self).refresh()
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()