def draw_widget(self): """ Updates whole messagewidget (all messages): draw icons. Inactive messages need their icon hovered to display their text again """ button_space = self.widget.findChild(name="button_space") button_space.removeAllChildren() # Remove old buttons for index, message in enumerate(self.active_messages): if (self.item + index) >= len(self.active_messages): # Only display most recent notifications continue button = ImageButton() button.name = str(index) button.up_image = message.up_image button.hover_image = message.hover_image button.down_image = message.down_image button.is_focusable = False # show text on hover events = { button.name + "/mouseEntered": Callback(self.show_text, index), button.name + "/mouseExited": self.hide_text, } # init callback to something callable to improve robustness callback = Callback(lambda: None) if message.x is not None and message.y is not None: # move camera to source of event on click, if there is a source callback = Callback.ChainedCallbacks( callback, # this makes it so the order of callback assignment doesn't matter Callback(self.session.view.center, message.x, message.y), Callback(self.session.ingame_gui.minimap.highlight, (message.x, message.y) ) ) if message.type == "logbook": # open logbook to relevant page callback = Callback.ChainedCallbacks( callback, # this makes it so the order of callback assignment doesn't matter Callback(self.session.ingame_gui.logbook.show, message.created) ) if callback: events[button.name] = callback button.mapEvents(events) button_space.addChild(button) button_space.resizeToContent() self.widget.size = button_space.size
def draw_widget(self): """ Updates whole messagewidget (all messages): draw icons. Inactive messages need their icon hovered to display their text again """ button_space = self.widget.findChild(name="button_space") button_space.removeAllChildren() # Remove old buttons for index, message in enumerate(self.active_messages): if (self.item + index) >= len(self.active_messages): # Only display most recent notifications continue button = ImageButton() button.name = str(index) button.up_image = message.up_image button.hover_image = message.hover_image button.down_image = message.down_image button.is_focusable = False # show text on hover events = { button.name + "/mouseEntered": Callback(self.show_text, index), button.name + "/mouseExited": self.hide_text, } # init callback to something callable to improve robustness callback = Callback(lambda: None) if message.x is not None and message.y is not None: # move camera to source of event on click, if there is a source callback = Callback.ChainedCallbacks( callback, # this makes it so the order of callback assignment doesn't matter Callback(self.session.view.center, message.x, message.y), Callback(self.session.ingame_gui.minimap.highlight, (message.x, message.y))) if message.type == "logbook": # open logbook to relevant page callback = Callback.ChainedCallbacks( callback, # this makes it so the order of callback assignment doesn't matter Callback(self.session.ingame_gui.logbook.show, message.created)) if callback: events[button.name] = callback button.mapEvents(events) button_space.addChild(button) button_space.resizeToContent() self.widget.size = button_space.size
def _init_tabs(self): """Add enough tabbuttons for all widgets.""" def on_tab_removal(tabwidget): # called when a tab is being removed (via weakref since tabs shouldn't have references to the parent tabwidget) # If one tab is removed, the whole tabwidget will die.. # This is easy usually the desired behaviour. if tabwidget(): tabwidget().on_remove() # Load buttons for index, tab in enumerate(self._tabs): # don't add a reference to the tab.add_remove_listener(Callback(on_tab_removal, weakref.ref(self))) container = Container(name="container_%s" % index) background = Icon(name="bg_%s" % index) button = ImageButton(name=str(index)) if self.current_tab is tab: background.image = tab.button_background_image_active button.up_image = tab.button_active_image else: background.image = tab.button_background_image button.up_image = tab.button_up_image button.down_image = tab.button_down_image button.hover_image = tab.button_hover_image button.is_focusable = False button.size = (50, 50) button.capture(Callback(self._show_tab, index)) if hasattr(tab, 'helptext') and tab.helptext is not None: button.helptext = tab.helptext container.size = background.size container.addChild(background) container.addChild(button) self.content.addChild(container) self.widget.size = (50, 55 * len(self._tabs)) self.widget.adaptLayout() self._apply_layout_hack()
def _init_tabs(self): """Add enough tabbuttons for all widgets.""" def on_tab_removal(tabwidget): # called when a tab is being removed (via weakref since tabs shouldn't have references to the parent tabwidget) # If one tab is removed, the whole tabwidget will die.. # This is easy usually the desired behaviour. if tabwidget(): tabwidget().on_remove() # Load buttons for index, tab in enumerate(self._tabs): # don't add a reference to the tab.add_remove_listener(Callback(on_tab_removal, weakref.ref(self))) container = Container(name="container_%s" % index) background = Icon(name="bg_%s" % index) button = ImageButton(name=str(index)) if self.current_tab is tab: background.image = tab.button_background_image_active button.up_image = tab.button_active_image else: background.image = tab.button_background_image button.up_image = tab.button_up_image button.down_image = tab.button_down_image button.hover_image = tab.button_hover_image button.is_focusable = False button.size = (50, 50) button.capture(Callback(self._show_tab, index)) if hasattr(tab, 'helptext') and tab.helptext is not None: button.helptext = tab.helptext container.size = background.size container.addChild(background) container.addChild(button) self.content.addChild(container) self.widget.size = (50, 55*len(self._tabs)) self.widget.adaptLayout() self._apply_layout_hack()