def __init__(self, session): super().__init__(session) self.setGlobalListener(True) self._last_mmb_scroll_point = [0, 0] # coordinates of last mouse positions self.last_exact_world_location = fife.ExactModelCoordinate() self._hover_instances_update_scheduled = False self.middle_scroll_active = False class CmdListener(fife.ICommandListener): pass self.cmdlist = CmdListener() horizons.globals.fife.eventmanager.addCommandListener(self.cmdlist) self.cmdlist.onCommand = self.onCommand if not self.__class__.send_hover_instances_update: # clear HoverInstancesChanged.broadcast(self, set()) self.__class__.last_hover_instances = WeakList() else: # need updates about scrolling here self.session.view.add_change_listener(self._schedule_hover_instance_update) self._schedule_hover_instance_update() class CoordsTooltip: @classmethod def get_instance(cls, cursor_tool): if cursor_tool.session.ingame_gui.coordinates_tooltip is not None: inst = cursor_tool.session.ingame_gui.coordinates_tooltip inst.cursor_tool = cursor_tool return inst else: return CoordsTooltip(cursor_tool) def __init__(self, cursor_tool, **kwargs): super().__init__(**kwargs) cursor_tool.session.ingame_gui.coordinates_tooltip = self self.cursor_tool = cursor_tool self.enabled = False self.icon = Icon(position=(1, 1)) # 0, 0 is currently not supported by tooltips def toggle(self): self.enabled = not self.enabled if not self.enabled and self.icon.tooltip_shown: self.icon.hide_tooltip() def show_evt(self, evt): if self.enabled: if evt.isConsumedByWidgets(): if self.icon.tooltip_shown: self.icon.hide_tooltip() return x, y = self.cursor_tool.get_world_location(evt).to_tuple() self.icon.helptext = '{:d}, {:d} '.format(x, y) + T("Press H to remove this hint") self.icon.position_tooltip(evt) self.icon.show_tooltip() self.tooltip = CoordsTooltip.get_instance(self)
def __init__(self, session): super(NavigationTool, self).__init__(session) self._last_mmb_scroll_point = [0, 0] # coordinates of last mouse positions self.last_exact_world_location = fife.ExactModelCoordinate() self._hover_instances_update_scheduled = False self.middle_scroll_active = False class CmdListener(fife.ICommandListener): pass self.cmdlist = CmdListener() horizons.globals.fife.eventmanager.addCommandListener(self.cmdlist) self.cmdlist.onCommand = self.onCommand if not self.__class__.send_hover_instances_update: # clear HoverInstancesChanged.broadcast(self, set()) self.__class__.last_hover_instances = WeakList() else: # need updates about scrolling here self.session.view.add_change_listener( self._schedule_hover_instance_update) self._schedule_hover_instance_update() class CoordsTooltip(object): @classmethod def get_instance(cls, cursor_tool): if cursor_tool.session.ingame_gui.coordinates_tooltip is not None: inst = cursor_tool.session.ingame_gui.coordinates_tooltip inst.cursor_tool = cursor_tool return inst else: return CoordsTooltip(cursor_tool) def __init__(self, cursor_tool, **kwargs): super(CoordsTooltip, self).__init__(**kwargs) cursor_tool.session.ingame_gui.coordinates_tooltip = self self.cursor_tool = cursor_tool self.enabled = False self.icon = Icon(position=( 1, 1)) # 0, 0 is currently not supported by tooltips def toggle(self): self.enabled = not self.enabled if not self.enabled and self.icon.tooltip_shown: self.icon.hide_tooltip() def show_evt(self, evt): if self.enabled: x, y = self.cursor_tool.get_world_location(evt).to_tuple() self.icon.helptext = u'%d, %d ' % (x, y) + _( "Press H to remove this hint") self.icon.position_tooltip(evt) self.icon.show_tooltip() self.tooltip = CoordsTooltip.get_instance(self)
def _send_hover_instance_upate(self): """Broadcast update with new instances below mouse (hovered). At most called in a certain interval, not after every mouse move in order to prevent delays.""" self._hover_instances_update_scheduled = False where = fife.Point(self.last_event_pos.x, self.last_event_pos.y) instances = set(self.get_hover_instances(where)) # only send when there were actual changes if instances != set(self.__class__.last_hover_instances): self.__class__.last_hover_instances = WeakList(instances) HoverInstancesChanged.broadcast(self, instances)
def _send_hover_instance_upate(self): """Broadcast update with new instances below mouse (hovered). At most called in a certain interval, not after every mouse move in order to prevent delays.""" self._hover_instances_update_scheduled = False where = fife.Point(self.__class__.last_event_pos.x, self.__class__.last_event_pos.y) instances = set(self.get_hover_instances(where)) # only send when there were actual changes if instances != set(self.__class__.last_hover_instances): self.__class__.last_hover_instances = WeakList(instances) HoverInstancesChanged.broadcast(self, instances)
def __init__(self, session): super(NavigationTool, self).__init__(session) self._last_mmb_scroll_point = [0, 0] # coordinates of last mouse positions self.last_exact_world_location = fife.ExactModelCoordinate() self._hover_instances_update_scheduled = False self.middle_scroll_active = False class CmdListener(fife.ICommandListener): pass self.cmdlist = CmdListener() horizons.main.fife.eventmanager.addCommandListener(self.cmdlist) self.cmdlist.onCommand = self.onCommand if not self.__class__.send_hover_instances_update: # clear HoverInstancesChanged.broadcast(self, set()) self.__class__.last_hover_instances = WeakList() else: # need updates about scrolling here self.session.view.add_change_listener(self._schedule_hover_instance_update) self._schedule_hover_instance_update() class CoordsTooltip(object): @classmethod def get_instance(cls, cursor_tool): if cursor_tool.session.coordinates_tooltip is not None: inst = cursor_tool.session.coordinates_tooltip inst.cursor_tool = cursor_tool return inst else: return CoordsTooltip(cursor_tool) def __init__(self, cursor_tool, **kwargs): super(CoordsTooltip, self).__init__(**kwargs) cursor_tool.session.coordinates_tooltip = self self.cursor_tool = cursor_tool self.enabled = False self.icon = Icon() def toggle(self): self.enabled = not self.enabled if not self.enabled and self.icon.tooltip_shown: self.icon.hide_tooltip() def show_evt(self, evt): if self.enabled: x, y = self.cursor_tool.get_world_location_from_event(evt).to_tuple() self.icon.helptext = u'%f, %f ' % (x, y) + _("Press H to remove this hint") self.icon.position_tooltip(evt) self.icon.show_tooltip() self.tooltip = CoordsTooltip.get_instance(self)