def on_hover_instances_changed(self, msg):
        """Check if we need to display a tooltip"""
        instances = msg.instances

        # only those that have icons
        instances = (i for i in instances if i in self.icons)
        # and belong to the player
        instances = [
            i for i in instances if hasattr(i, "owner")
            and hasattr(i.owner, "is_local_player") and i.owner.is_local_player
        ]

        if not instances:
            # hide
            self.tooltip_instance = None
            self.tooltip_icon.hide_tooltip()
        else:
            # get tooltip text, set, position and show
            self.tooltip_instance = instances[
                0]  # pick any (usually ordered by fife)

            icons_of_instance = self.icons[self.tooltip_instance]
            icon = max(icons_of_instance, key=StatusIcon.get_sorting_key())

            self.tooltip_icon.helptext = icon.helptext

            pos = NavigationTool.last_event_pos
            self.tooltip_icon.position_tooltip((pos.x, pos.y))
            self.tooltip_icon.show_tooltip()
	def on_hover_instances_changed(self, msg):
		"""Check if we need to display a tooltip"""
		instances = msg.instances

		# only those that have icons
		instances = (i for i in instances if i in self.icons)
		# and belong to the player
		instances = [i for i in instances if \
		             hasattr(i, "owner" ) and \
		             hasattr(i.owner, "is_local_player") and \
		             i.owner.is_local_player]

		if not instances:
			# hide
			self.tooltip_instance = None
			self.tooltip_icon.hide_tooltip()
		else:
			# get tooltip text, set, position and show
			self.tooltip_instance = instances[0] # pick any (usually ordered by fife)

			icons_of_instance = self.icons[self.tooltip_instance]
			icon = max(icons_of_instance, key=StatusIcon.get_sorting_key())

			self.tooltip_icon.helptext = icon.helptext

			pos = self.session.cursor.last_event_pos
			self.tooltip_icon.position_tooltip( (pos.x, pos.y) )
			self.tooltip_icon.show_tooltip()
	def on_add_icon_message(self, message):
		"""This is called by the message bus with AddStatusIcon messages"""
		assert isinstance(message, AddStatusIcon)
		icon_instance = message.icon.instance
		if not icon_instance in self.icons:
			self.icons[icon_instance] = []
		assert not message.icon in self.icons[icon_instance]
		self.icons[icon_instance].append(message.icon)
		# Sort, make sure highest icon is at top
		self.icons[icon_instance] = sorted(self.icons[icon_instance], key=StatusIcon.get_sorting_key(), reverse=True)
		# Now render the most important one
		self.__render_status(icon_instance, self.icons[icon_instance][0])
Example #4
0
	def on_add_icon_message(self, message):
		"""This is called by the message bus with AddStatusIcon messages"""
		assert isinstance(message, AddStatusIcon)
		icon_instance = message.icon.instance
		if not icon_instance in self.icons:
			self.icons[icon_instance] = []
		assert not message.icon in self.icons[icon_instance]
		self.icons[icon_instance].append(message.icon)
		# Sort, make sure highest icon is at top
		self.icons[icon_instance] = sorted(self.icons[icon_instance], key=StatusIcon.get_sorting_key(), reverse=True)
		# Now render the most important one
		self.__render_status(icon_instance, self.icons[icon_instance][0])

		if self.tooltip_instance is not None and self.tooltip_instance is icon_instance: # possibly have to update tooltip
			self.on_hover_instances_changed( HoverInstancesChanged(self, [self.tooltip_instance]) )