def update_queue(self, container_active): """ Update the queue display""" queue = self.producer.get_unit_production_queue() queue_container = container_active.findChild(name="queue_container") queue_container.removeAllChildren() for place_in_queue, unit_type in enumerate(queue): image = self.__class__.UNIT_THUMBNAIL.format(type_id=unit_type) helptext = T("{ship} (place in queue: {place})").format( ship=self.instance.session.db.get_unit_type_name(unit_type), place=place_in_queue + 1 ) # people don't count properly, always starting at 1.. icon_name = "queue_elem_" + str(place_in_queue) try: icon = Icon(name=icon_name, image=image, helptext=helptext) except RuntimeError, e: # It's possible that this error was raised from a missing thumbnail asset, # so we check against that now and use a fallback thumbnail instead # TODO string matching for runtime errors is nightmare fuel # Better: Replace RuntimeError in fife with a more precise error class if possible # and only catch that class here if e.message.startswith( "_[NotFound]_ , Something was searched, but not found :: content/gui/icons/thumbnails/" ): # actually load the fallback unit image image = self.__class__.UNIT_THUMBNAIL.format(type_id="unknown_unit") icon = Icon(name=icon_name, image=image, helptext=helptext) else: raise rm_from_queue_cb = Callback(RemoveFromQueue(self.producer, place_in_queue).execute, self.instance.session) icon.capture(rm_from_queue_cb, event_name="mouseClicked") queue_container.addChild(icon)
def update_queue(self, container_active): """ Update the queue display""" queue = self.producer.get_unit_production_queue() queue_container = container_active.findChild(name="queue_container") queue_container.removeAllChildren() for place_in_queue, unit_type in enumerate(queue): image = self.__class__.UNIT_THUMBNAIL.format(type_id=unit_type) helptext = T("{ship} (place in queue: {place})").format( ship=self.instance.session.db.get_unit_type_name(unit_type), place=place_in_queue + 1) # people don't count properly, always starting at 1.. icon_name = "queue_elem_" + str(place_in_queue) try: icon = Icon(name=icon_name, image=image, helptext=helptext) except fife.NotFound as e: # It's possible that this error was raised from a missing thumbnail asset, # so we check against that now and use a fallback thumbnail instead if 'content/gui/icons/thumbnails/' in e.what(): # actually load the fallback unit image image = self.__class__.UNIT_THUMBNAIL.format( type_id="unknown_unit") icon = Icon(name=icon_name, image=image, helptext=helptext) else: raise rm_from_queue_cb = Callback( RemoveFromQueue(self.producer, place_in_queue).execute, self.instance.session) icon.capture(rm_from_queue_cb, event_name="mouseClicked") queue_container.addChild(icon)
def update_queue(self, container_active): """ Update the queue display""" queue = self.producer.get_unit_production_queue() queue_container = container_active.findChild(name="queue_container") queue_container.removeAllChildren() for place_in_queue, unit_type in enumerate(queue): image = self.__class__.UNIT_THUMBNAIL.format(type_id=unit_type) helptext = T("{ship} (place in queue: {place})").format( ship=self.instance.session.db.get_unit_type_name(unit_type), place=place_in_queue + 1) # people don't count properly, always starting at 1.. icon_name = "queue_elem_" + str(place_in_queue) try: icon = Icon(name=icon_name, image=image, helptext=helptext) except fife.NotFound as e: # It's possible that this error was raised from a missing thumbnail asset, # so we check against that now and use a fallback thumbnail instead if 'content/gui/icons/thumbnails/' in e.what(): # actually load the fallback unit image image = self.__class__.UNIT_THUMBNAIL.format(type_id="unknown_unit") icon = Icon(name=icon_name, image=image, helptext=helptext) else: raise rm_from_queue_cb = Callback(RemoveFromQueue(self.producer, place_in_queue).execute, self.instance.session) icon.capture(rm_from_queue_cb, event_name="mouseClicked") queue_container.addChild(icon)
def update_queue(self, container_active): """ Update the queue display""" queue = self.producer.get_unit_production_queue() queue_container = container_active.findChild(name="queue_container") queue_container.removeAllChildren() for place_in_queue, unit_type in enumerate(queue): image = self.__class__.UNIT_THUMBNAIL.format(type_id=unit_type) helptext = _("{ship} (place in queue: {place})").format( ship=self.instance.session.db.get_unit_type_name(unit_type), place=place_in_queue + 1 ) # people don't count properly, always starting at 1.. icon_name = "queue_elem_" + str(place_in_queue) icon = Icon(name=icon_name, image=image, helptext=helptext) rm_from_queue_cb = Callback(RemoveFromQueue(self.producer, place_in_queue).execute, self.instance.session) icon.capture(rm_from_queue_cb, event_name="mouseClicked") queue_container.addChild(icon)
def update_queue(self, container_active): """ Update the queue display""" queue = self.producer.get_unit_production_queue() queue_container = container_active.findChild(name="queue_container") queue_container.removeAllChildren() for place_in_queue, unit_type in enumerate(queue): image = self.__class__.UNIT_THUMBNAIL.format(type_id=unit_type) helptext = _("{ship} (place in queue: {place})").format( ship=self.instance.session.db.get_unit_type_name(unit_type), place=place_in_queue + 1) # people don't count properly, always starting at 1.. icon_name = "queue_elem_" + str(place_in_queue) icon = Icon(name=icon_name, image=image, helptext=helptext) rm_from_queue_cb = Callback( RemoveFromQueue(self.producer, place_in_queue).execute, self.instance.session) icon.capture(rm_from_queue_cb, event_name="mouseClicked") queue_container.addChild(icon)
def update_queue(self, container_active): """ Update the queue display""" queue = self.producer.get_unit_production_queue() queue_container = container_active.findChild(name="queue_container") queue_container.removeAllChildren() for place_in_queue, unit_type in enumerate(queue): image = self.__class__.UNIT_THUMBNAIL.format(type_id=unit_type) helptext = T("{ship} (place in queue: {place})").format( ship=self.instance.session.db.get_unit_type_name(unit_type), place=place_in_queue + 1) # people don't count properly, always starting at 1.. icon_name = "queue_elem_" + str(place_in_queue) try: icon = Icon(name=icon_name, image=image, helptext=helptext) except RuntimeError, e: # It's possible that this error was raised from a missing thumbnail asset, # so we check against that now and use a fallback thumbnail instead # TODO string matching for runtime errors is nightmare fuel # Better: Replace RuntimeError in fife with a more precise error class if possible # and only catch that class here if e.message.startswith( '_[NotFound]_ , Something was searched, but not found :: content/gui/icons/thumbnails/' ): # actually load the fallback unit image image = self.__class__.UNIT_THUMBNAIL.format( type_id="unknown_unit") icon = Icon(name=icon_name, image=image, helptext=helptext) else: raise rm_from_queue_cb = Callback( RemoveFromQueue(self.producer, place_in_queue).execute, self.instance.session) icon.capture(rm_from_queue_cb, event_name="mouseClicked") queue_container.addChild(icon)
def refresh(self): """This function is called by the TabWidget to redraw the widget.""" super(BoatbuilderTab, self).refresh() main_container = self.widget.findChild(name="BB_main_tab") container_active = main_container.findChild(name="container_active") container_inactive = main_container.findChild( name="container_inactive") progress_container = main_container.findChild( name="BB_progress_container") cancel_container = main_container.findChild(name="BB_cancel_container") needed_res_container = self.widget.findChild( name="BB_needed_resources_container") # a boatbuilder is considered active here if it builds sth, no matter if it's paused production_lines = self.producer.get_production_lines() if production_lines: cancel_container.parent.showChild(cancel_container) # Set progress progress_container.parent.showChild(progress_container) progress = math.floor(self.producer.get_production_progress() * 100) self.widget.findChild(name='progress').progress = progress progress_perc = self.widget.findChild(name='BB_progress_perc') progress_perc.text = u'{progress}%'.format(progress=progress) container_active.parent.showChild(container_active) if (Fife.getVersion() >= (0, 4, 0)): container_inactive.parent.hideChild(container_inactive) else: if not container_inactive in container_inactive.parent.hidden_children: container_inactive.parent.hideChild(container_inactive) # Update boatbuilder queue queue = self.producer.get_unit_production_queue() queue_container = container_active.findChild( name="queue_container") queue_container.removeAllChildren() for place_in_queue, unit_type in enumerate(queue): image = self.__class__.SHIP_THUMBNAIL.format(type_id=unit_type) helptext = _("{ship} (place in queue: {place})").format( ship=self.instance.session.db.get_unit_type_name( unit_type), place=place_in_queue + 1) # people don't count properly, always starting at 1.. icon_name = "queue_elem_" + str(place_in_queue) icon = Icon(name=icon_name, image=image, helptext=helptext) rm_from_queue_cb = Callback( RemoveFromQueue(self.producer, place_in_queue).execute, self.instance.session) icon.capture(rm_from_queue_cb, event_name="mouseClicked") queue_container.addChild(icon) # Set built ship info production_line = self.producer._get_production( production_lines[0]) produced_unit_id = production_line.get_produced_units().keys()[0] name = self.instance.session.db.get_unit_type_name( produced_unit_id) container_active.findChild( name="headline_BB_builtship_label").text = _(name) ship_icon = container_active.findChild(name="BB_cur_ship_icon") ship_icon.helptext = self.instance.session.db.get_ship_tooltip( produced_unit_id) ship_icon.image = self.__class__.SHIP_PREVIEW_IMG.format( type_id=produced_unit_id) button_active = container_active.findChild( name="toggle_active_active") button_inactive = container_active.findChild( name="toggle_active_inactive") to_active = not self.producer.is_active() if not to_active: # swap what we want to show and hide button_active, button_inactive = button_inactive, button_active if (Fife.getVersion() >= (0, 4, 0)): button_active.parent.hideChild(button_active) else: if not button_active in button_active.parent.hidden_children: button_active.parent.hideChild(button_active) button_inactive.parent.showChild(button_inactive) set_active_cb = Callback(self.producer.set_active, active=to_active) button_inactive.capture(set_active_cb, event_name="mouseClicked") upgrades_box = container_active.findChild(name="BB_upgrades_box") upgrades_box.removeAllChildren() # Update needed resources production = self.producer.get_productions()[0] needed_res = production.get_consumed_resources() # Now sort! -amount is the positive value, drop unnecessary res (amount 0) needed_res = dict((res, -amount) for res, amount in needed_res.iteritems() if amount < 0) needed_res = sorted(needed_res.iteritems(), key=itemgetter(1), reverse=True) needed_res_container.removeAllChildren() for i, (res, amount) in enumerate(needed_res): icon = create_resource_icon(res, self.instance.session.db) icon.max_size = icon.min_size = icon.size = (16, 16) label = Label(name="needed_res_lbl_%s" % i) label.text = u'{amount}t'.format(amount=amount) new_hbox = HBox(name="needed_res_box_%s" % i) new_hbox.addChildren(icon, label) needed_res_container.addChild(new_hbox) cancel_button = self.widget.findChild(name="BB_cancel_button") cancel_cb = Callback( CancelCurrentProduction(self.producer).execute, self.instance.session) cancel_button.capture(cancel_cb, event_name="mouseClicked") else: # display sth when nothing is produced container_inactive.parent.showChild(container_inactive) for w in (container_active, progress_container, cancel_container): if (Fife.getVersion() >= (0, 4, 0)): w.parent.hideChild(w) else: if not w in w.parent.hidden_children: w.parent.hideChild(w) self.widget.adaptLayout()
def refresh(self): """This function is called by the TabWidget to redraw the widget.""" super(BoatbuilderTab, self).refresh() main_container = self.widget.findChild(name="BB_main_tab") container_active = main_container.findChild(name="container_active") container_inactive = main_container.findChild(name="container_inactive") progress_container = main_container.findChild(name="BB_progress_container") cancel_container = main_container.findChild(name="BB_cancel_container") needed_res_container = self.widget.findChild(name="BB_needed_resources_container") # a boatbuilder is considered active here if it build sth, no matter if it's paused production_lines = self.producer.get_production_lines() if production_lines: cancel_container.parent.showChild(cancel_container) # Set progress progress_container.parent.showChild(progress_container) progress = math.floor(self.producer.get_production_progress() * 100) self.widget.findChild(name='progress').progress = progress progress_perc = self.widget.findChild(name='BB_progress_perc') progress_perc.text = u'{progress}%'.format(progress=progress) container_active.parent.showChild(container_active) if not container_inactive in container_inactive.parent.hidden_children: container_inactive.parent.hideChild(container_inactive) # Update boatbuilder queue queue = self.producer.get_unit_production_queue() queue_container = container_active.findChild(name="queue_container") queue_container.removeAllChildren() for place_in_queue, unit_type in enumerate(queue): image = self.__class__.SHIP_THUMBNAIL.format(type_id=unit_type) helptext = _(u"{ship} (place in queue: {place})") #xgettext:python-format helptext.format(ship=self.instance.session.db.get_unit_type_name(unit_type), place=place_in_queue+1) # people don't count properly, always starting at 1.. icon_name = "queue_elem_"+str(place_in_queue) icon = Icon(name=icon_name, image=image, helptext=helptext) rm_from_queue_cb = Callback(RemoveFromQueue(self.producer, place_in_queue).execute, self.instance.session) icon.capture(rm_from_queue_cb, event_name="mouseClicked") queue_container.addChild( icon ) # Set built ship info production_line = self.producer._get_production(production_lines[0]) produced_unit_id = production_line.get_produced_units().keys()[0] name = self.instance.session.db.get_unit_type_name(produced_unit_id) container_active.findChild(name="headline_BB_builtship_label").text = _(name) ship_icon = container_active.findChild(name="BB_cur_ship_icon") ship_icon.helptext = self.instance.session.db.get_ship_tooltip(produced_unit_id) ship_icon.image = self.__class__.SHIP_PREVIEW_IMG.format(type_id=produced_unit_id) button_active = container_active.findChild(name="toggle_active_active") button_inactive = container_active.findChild(name="toggle_active_inactive") to_active = not self.producer.is_active() if not to_active: # swap what we want to show and hide button_active, button_inactive = button_inactive, button_active if not button_active in button_active.parent.hidden_children: button_active.parent.hideChild(button_active) button_inactive.parent.showChild(button_inactive) set_active_cb = Callback(self.producer.set_active, active=to_active) button_inactive.capture(set_active_cb, event_name="mouseClicked") upgrades_box = container_active.findChild(name="BB_upgrades_box") upgrades_box.removeAllChildren() # upgrades_box.addChild(Label(text=u"+ love")) # upgrades_box.addChild(Label(text=u"+ affection")) # no upgrades in 2010.1 release ---^ upgrades_box.stylize('menu_black') # Update needed resources production = self.producer.get_productions()[0] needed_res = production.get_consumed_resources() # Now sort! -amount is the positive value, drop unnecessary res (amount 0) needed_res = dict((res, -amount) for res, amount in needed_res.iteritems() if amount < 0) needed_res = sorted(needed_res.iteritems(), key=itemgetter(1), reverse=True) needed_res_container.removeAllChildren() for i, (res, amount) in enumerate(needed_res): icon = create_resource_icon(res, self.instance.session.db) icon.max_size = icon.min_size = icon.size = (16, 16) label = Label(name="needed_res_lbl_%s" % i) label.text = u'{amount}t'.format(amount=amount) new_hbox = HBox(name="needed_res_box_%s" % i) new_hbox.addChildren(icon, label) needed_res_container.addChild(new_hbox) cancel_button = self.widget.findChild(name="BB_cancel_button") cancel_cb = Callback(CancelCurrentProduction(self.producer).execute, self.instance.session) cancel_button.capture(cancel_cb, event_name="mouseClicked") else: # display sth when nothing is produced container_inactive.parent.showChild(container_inactive) for w in (container_active, progress_container, cancel_container): if not w in w.parent.hidden_children: w.parent.hideChild(w) self.widget.adaptLayout()
def refresh(self): """This function is called by the TabWidget to redraw the widget.""" super(BoatbuilderTab, self).refresh() main_container = self.widget.findChild(name="BB_main_tab") container_active = main_container.findChild(name="container_active") container_inactive = main_container.findChild(name="container_inactive") progress_container = main_container.findChild(name="BB_progress_container") cancel_container = main_container.findChild(name="BB_cancel_container") needed_res_container = self.widget.findChild(name="BB_needed_resources_container") # a boatbuilder is considered active here if it build sth, no matter if it's paused production_lines = self.producer.get_production_lines() if production_lines: if cancel_container is None: main_container.addChild(main_container.cancel_container) cancel_container = main_container.cancel_container if needed_res_container is None: main_container.insertChildBefore(main_container.needed_res_container, cancel_container) needed_res_container = main_container.needed_res_container # Set progress if progress_container is None: main_container.insertChildBefore( main_container.progress_container, self.widget.findChild(name="BB_needed_resources_container")) progress_container = main_container.progress_container progress = math.floor(self.producer.get_production_progress() * 100) self.widget.findChild(name='progress').progress = progress self.widget.findChild(name='BB_progress_perc').text = u'{progress}%'.format(progress=progress) # remove other container, but save it if container_inactive is not None: main_container.container_inactive = container_inactive main_container.removeChild( container_inactive ) if container_active is None: main_container.insertChildBefore( main_container.container_active, progress_container) container_active = main_container.container_active # Update boatbuilder queue queue = self.producer.get_unit_production_queue() queue_container = container_active.findChild(name="queue_container") queue_container.removeAllChildren() for place_in_queue, unit_type in enumerate(queue): image = self.__class__.SHIP_THUMBNAIL.format(type_id=unit_type) #xgettext:python-format helptext = _(u"{ship} (place in queue: {place})").format( ship=self.instance.session.db.get_unit_type_name(unit_type), place=place_in_queue+1 ) # people don't count properly, always starting at 1.. icon_name = "queue_elem_"+str(place_in_queue) icon = Icon(name=icon_name, image=image, helptext=helptext) icon.capture( Callback(RemoveFromQueue(self.producer, place_in_queue).execute, self.instance.session), event_name="mouseClicked" ) queue_container.addChild( icon ) # Set built ship info produced_unit_id = self.producer._get_production(production_lines[0]).get_produced_units().keys()[0] produced_unit_id = self.producer._get_production(production_lines[0]).get_produced_units().keys()[0] (name,) = self.instance.session.db.cached_query("SELECT name FROM unit WHERE id = ?", produced_unit_id)[0] container_active.findChild(name="headline_BB_builtship_label").text = _(name) container_active.findChild(name="BB_cur_ship_icon").helptext = "Storage: 4 slots, 120t \nHealth: 100" container_active.findChild(name="BB_cur_ship_icon").image = "content/gui/images/objects/ships/116/%s.png" % (produced_unit_id) button_active = container_active.findChild(name="toggle_active_active") button_inactive = container_active.findChild(name="toggle_active_inactive") if not self.producer.is_active(): # if production is paused # remove active button, if it's there, and save a reference to it if button_active is not None: container_active.button_active = button_active container_active.removeChild( button_active ) # restore inactive button, if it isn't in the gui if button_inactive is None: # insert at the end container_active.insertChild(container_active.button_inactive, \ len(container_active.children)) container_active.mapEvents({ 'toggle_active_inactive' : Callback(self.producer.set_active, active=True) }) # TODO: make this button do sth else: # remove inactive button, if it's there, and save a reference to it if button_inactive is not None: container_active.button_inactive = button_inactive container_active.removeChild( button_inactive ) # restore active button, if it isn't in the gui if button_active is None: # insert at the end container_active.insertChild(container_active.button_active, \ len(container_active.children)) container_active.mapEvents({ 'toggle_active_active' : Callback(self.producer.set_active, active=False) }) upgrades_box = container_active.findChild(name="BB_upgrades_box") for child in upgrades_box.children[:]: upgrades_box.removeChild(child) # upgrades_box.addChild( pychan.widgets.Label(text=u"+ love") ) # upgrades_box.addChild( pychan.widgets.Label(text=u"+ affection") ) # no upgrades in 2010.1 release ---^ upgrades_box.stylize('menu_black') # Update needed resources production = self.producer.get_productions()[0] still_needed_res = production.get_consumed_resources() # Now sort! still_needed_res = sorted(still_needed_res.iteritems(), key=operator.itemgetter(1)) main_container.findChild(name="BB_needed_res_label").text = _('Resources still needed:') i = 0 for res, amount in still_needed_res: if amount == 0: continue # Don't show res that are not really needed anymore assert i <= 3, "Only 3 still needed res for ships are currently supported" icon_path = get_res_icon_path(res, 16) needed_res_container.findChild(name="BB_needed_res_icon_"+str(i+1)).image = icon_path needed_res_container.findChild(name="BB_needed_res_lbl_"+str(i+1)).text = unicode(-1*amount)+u't' # -1 makes them positive i += 1 if i >= 3: break for j in xrange(i, 3): # these are not filled by a resource, so we need to make it invisible needed_res_container.findChild(name="BB_needed_res_icon_"+str(j+1)).image = None needed_res_container.findChild(name="BB_needed_res_lbl_"+str(j+1)).text = u"" cancel_button = self.widget.findChild(name="BB_cancel_button") cancel_button.capture( Callback(CancelCurrentProduction(self.producer).execute, self.instance.session), event_name="mouseClicked" ) else: # display sth when nothing is produced # remove other container, but save it if container_active is not None: main_container.container_active = container_active main_container.removeChild( container_active ) if container_inactive is None: main_container.insertChildBefore( main_container.container_inactive, progress_container) container_inactive = main_container.container_inactive if progress_container is not None: main_container.progress_container = progress_container main_container.removeChild(progress_container) if needed_res_container is not None: main_container.needed_res_container = needed_res_container main_container.removeChild(needed_res_container) if cancel_container is not None: main_container.cancel_container = cancel_container main_container.removeChild(cancel_container) self.widget.adaptLayout()
def refresh(self): """This function is called by the TabWidget to redraw the widget.""" super(BoatbuilderTab, self).refresh() THUMB_PATH = "content/gui/images/objects/ships/116/%s.png" main_container = self.widget.findChild(name="BB_main_tab") container_active = main_container.findChild(name="container_active") container_inactive = main_container.findChild(name="container_inactive") progress_container = main_container.findChild(name="BB_progress_container") cancel_container = main_container.findChild(name="BB_cancel_container") needed_res_container = self.widget.findChild(name="BB_needed_resources_container") # a boatbuilder is considered active here if it build sth, no matter if it's paused production_lines = self.producer.get_production_lines() if production_lines: if cancel_container is None: main_container.addChild(main_container.cancel_container) cancel_container = main_container.cancel_container if needed_res_container is None: main_container.insertChildBefore(main_container.needed_res_container, cancel_container) needed_res_container = main_container.needed_res_container # Set progress if progress_container is None: main_container.insertChildBefore( main_container.progress_container, self.widget.findChild(name="BB_needed_resources_container")) progress_container = main_container.progress_container progress = math.floor(self.producer.get_production_progress() * 100) self.widget.findChild(name='progress').progress = progress self.widget.findChild(name='BB_progress_perc').text = u'{progress}%'.format(progress=progress) # remove other container, but save it if container_inactive is not None: main_container.container_inactive = container_inactive main_container.removeChild( container_inactive ) if container_active is None: main_container.insertChildBefore( main_container.container_active, progress_container) container_active = main_container.container_active # Update boatbuilder queue queue = self.producer.get_unit_production_queue() queue_container = container_active.findChild(name="queue_container") queue_container.removeAllChildren() for place_in_queue, unit_type in enumerate(queue): image = self.__class__.SHIP_THUMBNAIL.format(type_id=unit_type) #xgettext:python-format helptext = _(u"{ship} (place in queue: {place})").format( ship=self.instance.session.db.get_unit_type_name(unit_type), place=place_in_queue+1 ) # people don't count properly, always starting at 1.. icon_name = "queue_elem_"+str(place_in_queue) icon = Icon(name=icon_name, image=image, helptext=helptext) icon.capture( Callback(RemoveFromQueue(self.producer, place_in_queue).execute, self.instance.session), event_name="mouseClicked" ) queue_container.addChild( icon ) # Set built ship info produced_unit_id = self.producer._get_production(production_lines[0]).get_produced_units().keys()[0] name = self.instance.session.db.get_unit_type_name(produced_unit_id) container_active.findChild(name="headline_BB_builtship_label").text = _(name) container_active.findChild(name="BB_cur_ship_icon").helptext = "Storage: 4 slots, 120t \nHealth: 100" container_active.findChild(name="BB_cur_ship_icon").image = THUMB_PATH % produced_unit_id button_active = container_active.findChild(name="toggle_active_active") button_inactive = container_active.findChild(name="toggle_active_inactive") if not self.producer.is_active(): # if production is paused # remove active button, if it's there, and save a reference to it if button_active is not None: container_active.button_active = button_active container_active.removeChild( button_active ) # restore inactive button, if it isn't in the gui if button_inactive is None: # insert at the end container_active.insertChild(container_active.button_inactive, len(container_active.children)) container_active.mapEvents({ 'toggle_active_inactive' : Callback(self.producer.set_active, active=True) }) # TODO: make this button do sth else: # remove inactive button, if it's there, and save a reference to it if button_inactive is not None: container_active.button_inactive = button_inactive container_active.removeChild( button_inactive ) # restore active button, if it isn't in the gui if button_active is None: # insert at the end container_active.insertChild(container_active.button_active, len(container_active.children)) container_active.mapEvents({ 'toggle_active_active' : Callback(self.producer.set_active, active=False) }) upgrades_box = container_active.findChild(name="BB_upgrades_box") for child in upgrades_box.children[:]: upgrades_box.removeChild(child) # upgrades_box.addChild( pychan.widgets.Label(text=u"+ love") ) # upgrades_box.addChild( pychan.widgets.Label(text=u"+ affection") ) # no upgrades in 2010.1 release ---^ upgrades_box.stylize('menu_black') # Update needed resources production = self.producer.get_productions()[0] needed_res = production.get_consumed_resources() # Now sort! -amount is the positive value, drop unnecessary res (amount 0) needed_res = dict((res, -amount) for res, amount in needed_res.iteritems() if amount < 0) needed_res = sorted(needed_res.iteritems(), key=itemgetter(1), reverse=True) needed_res_container.removeAllChildren() for i, (res, amount) in enumerate(needed_res): icon = create_resource_icon(res, self.instance.session.db) icon.max_size = icon.min_size = icon.size = (16, 16) label = Label(name="needed_res_lbl_%s" % i) label.text = u'{amount}t'.format(amount=amount) new_hbox = HBox(name="needed_res_box_%s" % i) new_hbox.addChildren(icon, label) needed_res_container.addChild(new_hbox) cancel_button = self.widget.findChild(name="BB_cancel_button") cancel_cb = Callback(CancelCurrentProduction(self.producer).execute, self.instance.session) cancel_button.capture(cancel_cb, event_name="mouseClicked") else: # display sth when nothing is produced # remove other container, but save it if container_active is not None: main_container.container_active = container_active main_container.removeChild( container_active ) if container_inactive is None: main_container.insertChildBefore( main_container.container_inactive, progress_container) container_inactive = main_container.container_inactive if progress_container is not None: main_container.progress_container = progress_container main_container.removeChild(progress_container) if needed_res_container is not None: main_container.needed_res_container = needed_res_container main_container.removeChild(needed_res_container) if cancel_container is not None: main_container.cancel_container = cancel_container main_container.removeChild(cancel_container) self.widget.adaptLayout()