Пример #1
0
class ToggleImageButton(tooltip.TooltipButton):
    """The ToggleImageButton is an extended ImageButton (Think decorator pattern).
	It adds one extra attribute inactive_image. You can then set the button active
	or inactive (only in code for now). Setting the ToggleImageButton to inactive
	will change all images (up, down and hover) to the inactive image. If you
	set it active again, everything will be reset.

	@param inactive_image The image that is to be used as inactive image.
	"""

    ATTRIBUTES = pychan.widgets.ImageButton.ATTRIBUTES + [
        Attr('inactive_image')
    ] + [UnicodeAttr('tooltip')]

    # These two constants are used to describe the state of the widget.
    ACTIVE = 0
    INACTIVE = 1

    def __init__(self, inactive_image="", **kwargs):
        self.state = None
        super(ToggleImageButton, self).__init__(**kwargs)
        self.state = self.ACTIVE
        self.inactive_image = inactive_image

    def toggle(self):
        if self.state == self.ACTIVE:
            self.set_inactive()
        else:
            self.set_active()

    def set_active(self):
        """Sets the button active. Restores up, down and hover image to
		previous state."""
        if self.state != self.ACTIVE:
            self.up_image, self.down_image, self.hover_image = self.old_images
            self.state = self.ACTIVE

    def set_inactive(self):
        """Sets the button inactive. Overrides up, down and hover image with
		inactive image."""
        if self.state != self.INACTIVE:
            self.old_images = (self.up_image, self.down_image,
                               self.hover_image)
            self.up_image = self.inactive_image
            self.down_image = self.inactive_image
            self.hover_image = self.inactive_image
            self.state = self.INACTIVE

    def _get_inactive_image(self):
        return self.__inactiveimage

    def _set_inactive_image(self, inactive_image):
        self.__inactiveimage = inactive_image

    inactive_image = property(_get_inactive_image, _set_inactive_image)
Пример #2
0
class TooltipProgressBar(_Tooltip, ProgressBar):
	"""The TooltipProgressBar is a modified progress bar widget. It can be used in xml files like this:
	<TooltipProgressbar tooltip=""/>
	Used to display tooltip on hover on buttons.
	Attributes same as Label widget with addition of tooltip="text string to display".
	Use '\n' to force newline.
	"""
	ATTRIBUTES = pychan.widgets.Label.ATTRIBUTES + [UnicodeAttr('tooltip')]
	def __init__(self, tooltip="", **kwargs):
		super(TooltipProgressBar, self).__init__(**kwargs)
		self.init_tooltip(tooltip)
Пример #3
0
class TooltipButton(_Tooltip, pychan.widgets.ImageButton):
	"""The TooltipButton is a modified image button widget. It can be used in xml files like this:
	<TooltipButton tooltip=""/>
	Used to display tooltip on hover on buttons.
	Attributes same as ImageButton widget with addition of tooltip="text string to display".
	Use '\n' to force newline.
	"""
	ATTRIBUTES = pychan.widgets.ImageButton.ATTRIBUTES + [UnicodeAttr('tooltip')]
	def __init__(self, tooltip = "", **kwargs):
		super(TooltipButton, self).__init__(**kwargs)
		self.init_tooltip(tooltip)