Exemplo n.º 1
0
	def show_tooltip(self):
		if not self.helptext:
			return
		if self.gui is None:
			self.__init_gui()

		#HACK: support icons in build menu
		# Code below exists for the sole purpose of build menu tooltips showing
		# resource icons. Even supporting that is a pain (as you will see),
		# so if you think you need icons in other tooltips, maybe reconsider.
		# [These unicode() calls brought to you by status icon tooltip code.]
		buildmenu_icons = self.icon_regexp.findall(unicode(self.helptext))
		# Remove the weird stuff before displaying text.
		replaced = self.icon_regexp.sub('', unicode(self.helptext))
		# Specification looks like [[Buildmenu 1:250 4:2 6:2]]
		if buildmenu_icons:
			hbox = HBox(position=(7, 5), padding=0)
			for spec in buildmenu_icons[0].split():
				(res_id, amount) = spec.split(':')
				label = Label(text=amount+'  ')
				icon = Icon(image=get_res_icon_path(int(res_id)), size=(16, 16),
				            scale=True)
				# For compatibility with FIFE 0.3.5 and older, also set min/max.
				icon.max_size = icon.min_size = (16, 16)
				hbox.addChildren(icon, label)
			hbox.adaptLayout()
			# Now display the 16x16px "required resources" icons in the last line.
			self.gui.addChild(hbox)

		#HACK: wrap tooltip text
		# This looks better than splitting into several lines and joining them.
		# It works because replace_whitespace in `fill` defaults to True.
		replaced = replaced.replace(r'\n', self.CHARS_PER_LINE * ' ')
		replaced = replaced.replace('[br]', self.CHARS_PER_LINE * ' ')
		tooltip = textwrap.fill(replaced, self.CHARS_PER_LINE)

		# Finish up the actual tooltip (text, background panel amount, layout).
		# To display build menu icons, we need another empty (first) line.
		self.bg.amount = len(tooltip.splitlines()) - 1 + bool(buildmenu_icons)
		self.label.text = bool(buildmenu_icons) * '\n' + tooltip
		self.gui.adaptLayout()
		self.gui.show()

		# NOTE: the below code in this method is a hack to resolve #2227
		# cannot find a better way to fix it, cause in fife.pychan, it seems
		# if a widget gets hidden or removed, the children of that widget are not
		# hidden or removed properly (at least in Python code)

		# update topmost_widget every time the tooltip is shown
		# this is to dismiss the tooltip later, see _check_hover_alive
		target_widget = self
		while target_widget:
			self.topmost_widget = target_widget
			target_widget = target_widget.parent

		# add an event to constantly check whether the hovered widget is still there
		# if this is no longer there, dismiss the tooltip widget
		ExtScheduler().add_new_object(self._check_hover_alive, self, run_in=0.5, loops=-1)
Exemplo n.º 2
0
	def show_tooltip(self):
		if self.shown is True:
			return
		self.shown = True

		if not self.helptext:
			return
		if self.gui is None:
			self.__init_gui()

		#HACK: support icons in build menu
		# Code below exists for the sole purpose of build menu tooltips showing
		# resource icons. Even supporting that is a pain (as you will see),
		# so if you think you need icons in other tooltips, maybe reconsider.
		# [These unicode() calls brought to you by status icon tooltip code.]
		buildmenu_icons = self.icon_regexp.findall(unicode(self.helptext))
		# Remove the weird stuff before displaying text.
		replaced = self.icon_regexp.sub('', unicode(self.helptext))
		# Specification looks like [[Buildmenu 1:250 4:2 6:2]]
		if buildmenu_icons:
			hbox = HBox(position=(7, 5), padding=0)
			for spec in buildmenu_icons[0].split():
				(res_id, amount) = spec.split(':')
				label = Label(text=amount+'  ')
				icon = Icon(image=get_res_icon_path(int(res_id)), size=(16, 16))
				# For compatibility with FIFE 0.3.5 and older, also set min/max.
				icon.max_size = icon.min_size = (16, 16)
				hbox.addChildren(icon, label)
			hbox.adaptLayout()
			# Now display the 16x16px "required resources" icons in the last line.
			self.gui.addChild(hbox)

		#HACK: wrap tooltip text
		# This looks better than splitting into several lines and joining them.
		# It works because replace_whitespace in `fill` defaults to True.
		replaced = replaced.replace(r'\n', self.CHARS_PER_LINE * ' ')
		replaced = replaced.replace('[br]', self.CHARS_PER_LINE * ' ')
		tooltip = textwrap.fill(replaced, self.CHARS_PER_LINE)

		# Finish up the actual tooltip (text, background panel amount, layout).
		# To display build menu icons, we need another empty (first) line.
		self.bg.amount = len(tooltip.splitlines()) - 1 + bool(buildmenu_icons)
		self.label.text = bool(buildmenu_icons) * '\n' + tooltip
		self.gui.adaptLayout()
		self.gui.show()
Exemplo n.º 3
0
	def show_tooltip(self):
		if not self.helptext:
			return
		if self.gui is None:
			self.__init_gui()

		#HACK: support icons in build menu
		# Code below exists for the sole purpose of build menu tooltips showing
		# resource icons. Even supporting that is a pain (as you will see),
		# so if you think you need icons in other tooltips, maybe reconsider.
		# [These unicode() calls brought to you by status icon tooltip code.]
		buildmenu_icons = self.icon_regexp.findall(unicode(self.helptext))
		# Remove the weird stuff before displaying text.
		replaced = self.icon_regexp.sub('', unicode(self.helptext))
		# Specification looks like [[Buildmenu 1:250 4:2 6:2]]
		if buildmenu_icons:
			hbox = HBox(position=(7, 5), padding=0)
			for spec in buildmenu_icons[0].split():
				(res_id, amount) = spec.split(':')
				label = Label(text=amount+'  ')
				icon = Icon(image=get_res_icon_path(int(res_id)), size=(16, 16))
				# For compatibility with FIFE 0.3.5 and older, also set min/max.
				icon.max_size = icon.min_size = (16, 16)
				hbox.addChildren(icon, label)
			hbox.adaptLayout()
			# Now display the 16x16px "required resources" icons in the last line.
			self.gui.addChild(hbox)

		#HACK: wrap tooltip text
		# This looks better than splitting into several lines and joining them.
		# It works because replace_whitespace in `fill` defaults to True.
		replaced = replaced.replace(r'\n', self.CHARS_PER_LINE * ' ')
		replaced = replaced.replace('[br]', self.CHARS_PER_LINE * ' ')
		tooltip = textwrap.fill(replaced, self.CHARS_PER_LINE)

		# Finish up the actual tooltip (text, background panel amount, layout).
		# To display build menu icons, we need another empty (first) line.
		self.bg.amount = len(tooltip.splitlines()) - 1 + bool(buildmenu_icons)
		self.label.text = bool(buildmenu_icons) * '\n' + tooltip
		self.gui.adaptLayout()
		self.gui.show()
Exemplo n.º 4
0
    def show_tooltip(self):
        if not self.helptext:
            return
        if self.gui is None:
            self.__init_gui()

        # Compare and reset timer value if difference from current time shorter than X sec.
        if (time.time() - self.cooldown) < 1:
            return
        else:
            self.cooldown = time.time()

        #HACK: support icons in build menu
        # Code below exists for the sole purpose of build menu tooltips showing
        # resource icons. Even supporting that is a pain (as you will see),
        # so if you think you need icons in other tooltips, maybe reconsider.
        # [These unicode() calls brought to you by status icon tooltip code.]
        buildmenu_icons = self.icon_regexp.findall(str(self.helptext))
        # Remove the weird stuff before displaying text.
        replaced = self.icon_regexp.sub('', str(self.helptext))
        # Specification looks like [[Buildmenu 1:250 4:2 6:2]]
        if buildmenu_icons:
            hbox = HBox(position=(7, 5))
            for spec in buildmenu_icons[0].split():
                (res_id, amount) = spec.split(':')
                label = Label(text=amount + '  ')
                icon = Icon(image=get_res_icon_path(int(res_id)),
                            size=(16, 16),
                            scale=True)
                hbox.addChildren(icon, label)
            hbox.adaptLayout()
            # Now display the 16x16px "required resources" icons in the last line.
            self.gui.addChild(hbox)

        #HACK: wrap tooltip text
        # This looks better than splitting into several lines and joining them.
        # It works because replace_whitespace in `fill` defaults to True.
        replaced = replaced.replace(r'\n', self.CHARS_PER_LINE * ' ')
        replaced = replaced.replace('[br]', self.CHARS_PER_LINE * ' ')
        tooltip = textwrap.fill(replaced, self.CHARS_PER_LINE)

        # Finish up the actual tooltip (text, background panel amount, layout).
        # To display build menu icons, we need another empty (first) line.
        self.bg.amount = len(tooltip.splitlines()) - 1 + bool(buildmenu_icons)
        self.label.text = bool(buildmenu_icons) * '\n' + tooltip
        self.gui.adaptLayout()
        self.gui.show()

        # NOTE: the below code in this method is a hack to resolve #2227
        # cannot find a better way to fix it, cause in fife.pychan, it seems
        # if a widget gets hidden or removed, the children of that widget are not
        # hidden or removed properly (at least in Python code)

        # update topmost_widget every time the tooltip is shown
        # this is to dismiss the tooltip later, see _check_hover_alive
        target_widget = self
        while target_widget:
            self.topmost_widget = target_widget
            target_widget = target_widget.parent

        # add an event to constantly check whether the hovered widget is still there
        # if this is no longer there, dismiss the tooltip widget
        ExtScheduler().add_new_object(self._check_hover_alive,
                                      self,
                                      run_in=0.5,
                                      loops=-1)