Пример #1
0
class ImageButton(BasicTextWidget):
	"""
	A basic push button with three different images for the up, down and hover state.

	B{Work in progress.}

	New Attributes
	==============

	  - up_image: String: The source location of the Image for the B{unpressed} state.
	  - down_image: String: The source location of the Image for the B{pressed} state.
	  - hover_image: String: The source location of the Image for the B{unpressed hovered} state.
	"""

	ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [ Attr('up_image'),
												Attr('down_image'),
												PointAttr('offset'),
												Attr('hover_image')
											  ]

	DEFAULT_UPIMAGE = ""
	DEFAULT_DOWNIMAGE = ""
	DEFAULT_HOVERIMAGE = ""
	DEFAULT_OFFSET = 0,0
	def __init__(self, 
				 parent = None, 
				 name = None,
				 size = None,
				 min_size = None, 
				 max_size = None, 
				 helptext = None, 
				 position = None, 
				 style = None, 
				 hexpand = None,
				 vexpand = None,
				 font = None,
				 base_color = None,
				 background_color = None,
				 foreground_color = None,
				 selection_color = None,
				 border_size = None,
				 position_technique = None,
				 is_focusable = None,
				 comment = None,
				 margins = None,
				 text = None,
				 up_image=None,
				 down_image=None,
				 hover_image=None,
				 offset=None,
				 real_widget=None):

		if real_widget is None:
			self.real_widget = fife.TwoButton()
		else:
			self.real_widget = real_widget
		
		# set the defaulst
		offset = self.DEFAULT_OFFSET
		
		super(ImageButton,self).__init__(parent=parent, 
										 name=name, 
										 size=size, 
										 min_size=min_size, 
										 max_size=max_size,
										 helptext=helptext, 
										 position=position,
										 style=style, 
										 hexpand=hexpand, 
										 vexpand=vexpand,
										 font=font,
										 base_color=base_color,
										 background_color=background_color,
										 foreground_color=foreground_color,
										 selection_color=selection_color,
										 border_size=border_size,
										 position_technique=position_technique,
										 is_focusable=is_focusable,
										 comment=comment,
										 margins=margins,
										 text=text)
		
		if up_image is not None: 
			self.up_image = up_image
		else:
			self.up_image = self.DEFAULT_UPIMAGE
			
		if down_image is not None: 
			self.down_image = down_image
		else:
			self.down_image = self.DEFAULT_DOWNIMAGE
			
		if hover_image is not None: 
			self.hover_image = hover_image
		else:
			self.hover_image = self.DEFAULT_HOVERIMAGE
		
		# Override anything set when stylize was called
		if offset is not None: self.offset = offset

		
	def clone(self, prefix):
		
		imgButtonClone = ImageButton(None, 
						self._createNameWithPrefix(prefix),
						self.size,
						self.min_size, 
						self.max_size, 
						self.helptext, 
						self.position, 
						self.style, 
						self.hexpand,
						self.vexpand,
						self.font,
						self.base_color,
						self.background_color,
						self.foreground_color,
						self.selection_color,
						self.border_size,
						self.position_technique,
						self.is_focusable,
						self.comment,
						self.margins,
						self.text,
						self.up_image,
						self.down_image,
						self.hover_image,
						self.offset)
		return imgButtonClone
		
	
	up_image = ImageProperty("UpImage")
	down_image = ImageProperty("DownImage")
	hover_image = ImageProperty("HoverImage")

	def _setOffset(self, offset):
		self.real_widget.setDownOffset(offset[0], offset[1])
	def _getOffset(self):
		return (self.real_widget.getDownXOffset(), self.real_widget.getDownYOffset())
	offset = property(_getOffset,_setOffset)

	def resizeToContent(self, recurse=True):
		th, tw = 0, 0
		if self.text:
			th = self.real_font.getHeight()#+self.real_font.getSpacing()
			tw = self.real_font.getWidth(text2gui(self.text))#+self.real_font.getSpacing()
		self.height = max(
			self._prop_upimage["image"].getHeight(),
			self._prop_downimage["image"].getHeight(),
			self._prop_hoverimage["image"].getHeight(),
			th) + self.margins[1]*2
		self.width = max(
			self._prop_upimage["image"].getWidth(),
			self._prop_downimage["image"].getWidth(),
			self._prop_hoverimage["image"].getWidth(),
			tw) + self.margins[0]*2
Пример #2
0
class ImageButton(Button):
    """
	A basic push button with six different images for the up, down and hover state.

	New Attributes
	==============

	  - up_image: String: The source location of the Image for the B{unpressed} state.
	  - down_image: String: The source location of the Image for the B{pressed} state.
	  - hover_image: String: The source location of the Image for the B{unpressed hovered} state.
	  - in_up_image: String: The source location of the Image for the B{unpressed} inactive state.
	  - in_down_image: String: The source location of the Image for the B{pressed} inactive state.
	  - in_hover_image: String: The source location of the Image for the B{unpressed hovered} inactive state.
	"""

    ATTRIBUTES = Button.ATTRIBUTES + [
        Attr('up_image'),
        Attr('down_image'),
        Attr('hover_image'),
        Attr('in_up_image'),
        Attr('in_down_image'),
        Attr('in_hover_image')
    ]

    #DEFAULT_OFFSET = 0,0

    def __init__(self,
                 parent=None,
                 name=None,
                 size=None,
                 min_size=None,
                 max_size=None,
                 fixed_size=None,
                 margins=None,
                 padding=None,
                 helptext=None,
                 position=None,
                 style=None,
                 hexpand=None,
                 vexpand=None,
                 font=None,
                 base_color=None,
                 background_color=None,
                 foreground_color=None,
                 selection_color=None,
                 border_color=None,
                 outline_color=None,
                 border_size=None,
                 outline_size=None,
                 position_technique=None,
                 is_focusable=None,
                 comment=None,
                 text=None,
                 active=None,
                 alignment=None,
                 offset=None,
                 up_image=None,
                 down_image=None,
                 hover_image=None,
                 in_up_image=None,
                 in_down_image=None,
                 in_hover_image=None,
                 real_widget=None):

        if real_widget is None:
            real_widget = fifechan.ImageButton()
        self.real_widget = real_widget

        # set the defaulst
        #offset = self.DEFAULT_OFFSET

        super(ImageButton,
              self).__init__(parent=parent,
                             name=name,
                             size=size,
                             min_size=min_size,
                             max_size=max_size,
                             fixed_size=fixed_size,
                             margins=margins,
                             padding=padding,
                             helptext=helptext,
                             position=position,
                             style=style,
                             hexpand=hexpand,
                             vexpand=vexpand,
                             font=font,
                             base_color=base_color,
                             background_color=background_color,
                             foreground_color=foreground_color,
                             selection_color=selection_color,
                             border_color=border_color,
                             outline_color=outline_color,
                             border_size=border_size,
                             outline_size=outline_size,
                             position_technique=position_technique,
                             is_focusable=is_focusable,
                             comment=comment,
                             text=text,
                             active=active,
                             alignment=alignment,
                             offset=offset,
                             real_widget=self.real_widget)

        # for the case that image can not be found, e.g. invalid path
        # the ImageButton is removed from the manager
        try:
            self.up_image = up_image
            self.down_image = down_image
            self.hover_image = hover_image
            self.in_up_image = in_up_image
            self.in_down_image = in_down_image
            self.in_hover_image = in_hover_image
        except Exception:
            get_manager().removeWidget(self)
            raise

        # Override anything set when stylize was called
        #if offset is not None: self.offset = offset

    def clone(self, prefix):

        imgButtonClone = ImageButton(
            None, self._createNameWithPrefix(prefix), self.size, self.min_size,
            self.max_size, self.fixed_size, self.margins, self.padding,
            self.helptext, self.position, self.style, self.hexpand,
            self.vexpand, self.font, self.base_color, self.background_color,
            self.foreground_color, self.selection_color, self.border_color,
            self.outline_color, self.border_size, self.outline_size,
            self.position_technique, self.is_focusable, self.comment,
            self.text, self.active, self.alignment, self.offset, self.up_image,
            self.down_image, self.hover_image, self.in_up_image,
            self.in_down_image, self.in_hover_image)
        return imgButtonClone

    up_image = ImageProperty("UpImage")
    down_image = ImageProperty("DownImage")
    hover_image = ImageProperty("HoverImage")
    in_up_image = ImageProperty("InactiveUpImage")
    in_down_image = ImageProperty("InactiveDownImage")
    in_hover_image = ImageProperty("InactiveHoverImage")
Пример #3
0
class CheckBox(ImageButton):
    """
	A basic checkbox.

	New Attributes
	==============

	  - marked: Boolean value, whether the checkbox is checked or not.
	  - marker_style: Integer: The visual style of the marker.
	  - background_image: String: Optional image for the background, the size should also include the caption.

	Data
	====
	The marked status can be read and set via L{distributeData} and L{collectData}
	"""

    ATTRIBUTES = ImageButton.ATTRIBUTES + [
        BoolAttr('marked'),
        IntAttr('marker_style'),
        Attr('background_image')
    ]

    DEFAULT_MARKED = False
    # 0=Checkmark, 1=Cross, 2=Dot, 3=Rhombus, 4=Image
    DEFAULT_MARKER_STYLE = 0
    DEFAULT_OFFSET = 0, 0

    def __init__(self,
                 parent=None,
                 name=None,
                 size=None,
                 min_size=None,
                 max_size=None,
                 fixed_size=None,
                 margins=None,
                 padding=None,
                 helptext=None,
                 position=None,
                 style=None,
                 hexpand=None,
                 vexpand=None,
                 font=None,
                 base_color=None,
                 background_color=None,
                 foreground_color=None,
                 selection_color=None,
                 border_color=None,
                 outline_color=None,
                 border_size=None,
                 outline_size=None,
                 position_technique=None,
                 is_focusable=None,
                 comment=None,
                 text=None,
                 active=None,
                 alignment=None,
                 offset=None,
                 up_image=None,
                 down_image=None,
                 hover_image=None,
                 in_up_image=None,
                 in_down_image=None,
                 in_hover_image=None,
                 marked=None,
                 marker_style=None,
                 background_image=None):

        self.real_widget = fifechan.CheckBox()

        super(CheckBox, self).__init__(parent=parent,
                                       name=name,
                                       size=size,
                                       min_size=min_size,
                                       max_size=max_size,
                                       fixed_size=fixed_size,
                                       margins=margins,
                                       padding=padding,
                                       helptext=helptext,
                                       position=position,
                                       style=style,
                                       hexpand=hexpand,
                                       vexpand=vexpand,
                                       font=font,
                                       base_color=base_color,
                                       background_color=background_color,
                                       foreground_color=foreground_color,
                                       selection_color=selection_color,
                                       border_color=border_color,
                                       outline_color=outline_color,
                                       border_size=border_size,
                                       outline_size=outline_size,
                                       position_technique=position_technique,
                                       is_focusable=is_focusable,
                                       comment=comment,
                                       text=text,
                                       active=active,
                                       alignment=alignment,
                                       offset=offset,
                                       up_image=up_image,
                                       down_image=down_image,
                                       hover_image=hover_image,
                                       in_up_image=in_up_image,
                                       in_down_image=in_down_image,
                                       in_hover_image=in_hover_image,
                                       real_widget=self.real_widget)

        # set provided attributes or defaults
        if marked is not None: self.marked = marked
        else: self.marked = self.DEFAULT_MARKED

        if marker_style is not None: self.marker_style = marker_style
        else: self.marker_style = self.DEFAULT_MARKER_STYLE

        # for the case that image can not be found, e.g. invalid path
        # the Checkbox is removed from the manager
        try:
            self.background_image = background_image
        except Exception:
            get_manager().removeWidget(self)
            raise

        # Prepare Data collection framework
        self.accepts_data = True
        self._realGetData = self._isMarked
        self._realSetData = self._setMarked

    def clone(self, prefix):
        checkboxClone = CheckBox(
            None, self._createNameWithPrefix(prefix), self.size, self.min_size,
            self.max_size, self.fixed_size, self.margins, self.padding,
            self.helptext, self.position, self.style, self.hexpand,
            self.vexpand, self.font, self.base_color, self.background_color,
            self.foreground_color, self.selection_color, self.border_color,
            self.outline_color, self.border_size, self.outline_size,
            self.position_technique, self.is_focusable, self.comment,
            self.text, self.active, self.alignment, self.offset, self.up_image,
            self.down_image, self.hover_image, self.in_up_image,
            self.in_down_image, self.in_hover_image, self.marked,
            self.marker_style, self.background_image)
        return checkboxClone

    def _isMarked(self):
        return self.real_widget.isSelected()

    def _setMarked(self, mark):
        self.real_widget.setSelected(mark)

    marked = property(_isMarked, _setMarked)

    def _getMarkerStyle(self):
        return self.real_widget.getMarkerStyle()

    def _setMarkerStyle(self, style):
        self.real_widget.setMarkerStyle(style)

    marker_style = property(_getMarkerStyle, _setMarkerStyle)

    background_image = ImageProperty("BackgroundImage")
Пример #4
0
class ImageProgressBar(Widget):
    """
	An image progress bar.

	New Attributes
	==============

	  - image: String or GuiImage: The source location of the Image or a direct GuiImage
	  - max_icons: Maximal count of icons
	  - icons: Current count of active icons
	  - orientation: Horizontal (0) or Vertical (1)
	  - opaque: True if the widget is opaque, false otherwise.
	"""
    ATTRIBUTES = Widget.ATTRIBUTES + [
        Attr('bar_image'),
        Attr('foreground_image'),
        IntAttr('max_value'),
        IntAttr('value'),
        IntAttr('orientation'),
        BoolAttr('opaque')
    ]

    DEFAULT_OPAQUE = True

    def __init__(self,
                 parent=None,
                 name=None,
                 size=None,
                 min_size=None,
                 max_size=None,
                 fixed_size=None,
                 margins=None,
                 padding=None,
                 helptext=None,
                 position=None,
                 style=None,
                 hexpand=None,
                 vexpand=None,
                 font=None,
                 base_color=None,
                 background_color=None,
                 foreground_color=None,
                 selection_color=None,
                 border_color=None,
                 outline_color=None,
                 border_size=None,
                 outline_size=None,
                 position_technique=None,
                 is_focusable=None,
                 comment=None,
                 bar_image=None,
                 foreground_image=None,
                 max_value=None,
                 value=None,
                 orientation=None,
                 opaque=None):

        self.real_widget = fifechan.ImageProgressBar()
        self.opaque = opaque or self.DEFAULT_OPAQUE

        super(ImageProgressBar,
              self).__init__(parent=parent,
                             name=name,
                             size=size,
                             min_size=min_size,
                             max_size=max_size,
                             fixed_size=fixed_size,
                             margins=margins,
                             padding=padding,
                             helptext=helptext,
                             position=position,
                             style=style,
                             hexpand=hexpand,
                             vexpand=vexpand,
                             font=font,
                             base_color=base_color,
                             background_color=background_color,
                             foreground_color=foreground_color,
                             selection_color=selection_color,
                             border_color=border_color,
                             outline_color=outline_color,
                             border_size=border_size,
                             outline_size=outline_size,
                             position_technique=position_technique,
                             is_focusable=is_focusable,
                             comment=comment)

        # for the case that image can not be found, e.g. invalid path
        # the Widget is removed from the manager
        try:
            self.bar_image = bar_image
            self.foreground_image = foreground_image
        except Exception:
            get_manager().removeWidget(self)
            raise

        if max_value is not None: self.max_value = max_value
        if value is not None: self.value = value

    def clone(self, prefix):
        imageClone = ImageProgressBar(
            None, self._createNameWithPrefix(prefix), self.size, self.min_size,
            self.max_size, self.fixed_size, self.margins, self.padding,
            self.helptext, self.position, self.style, self.hexpand,
            self.vexpand, self.font, self.base_color, self.background_color,
            self.foreground_color, self.selection_color, self.border_color,
            self.outline_color, self.border_size, self.outline_size,
            self.position_technique, self.is_focusable, self.comment,
            self.bar_image, self.foreground_image, self.max_value, self.value,
            self.orientation, self.opaque)

        return imageClone

    _bar_image = ImageProperty("BarImage")
    _foreground_image = ImageProperty("ForegroundImage")

    def _setBarImage(self, source):
        self._bar_image = source

    def _getBarImage(self):
        return self._bar_image

    bar_image = property(_getBarImage, _setBarImage)

    def _setForegroundImage(self, source):
        self._foreground_image = source

    def _getForegroundImage(self):
        return self._foreground_image

    foreground_image = property(_getForegroundImage, _setForegroundImage)

    def _setMaxValue(self, maxValue):
        if type(maxValue) != int:
            raise RuntimeError(
                "ImageProgressBar max value should be an integer")
        self.real_widget.setMaxValue(maxValue)

    def _getMaxValue(self):
        return self.real_widget.getMaxValue()

    max_value = property(_getMaxValue, _setMaxValue)

    def _setValue(self, value):
        if type(value) != int:
            raise RuntimeError("ImageProgressBar value should be an integer")
        self.real_widget.setValue(value)

    def _getValue(self):
        return self.real_widget.getValue()

    value = property(_getValue, _setValue)

    def _setOrientation(self, orientation):
        self.real_widget.setOrientation(orientation)

    def _getOrientation(self):
        return self.real_widget.getOrientation()

    orientation = property(_getOrientation, _setOrientation)

    def _setOpaque(self, opaque):
        self.real_widget.setOpaque(opaque)

    def _getOpaque(self):
        return self.real_widget.isOpaque()

    opaque = property(_getOpaque, _setOpaque)
Пример #5
0
class Icon(Widget):
    """
	An image icon.

	New Attributes
	==============

	  - image: String or GuiImage: The source location of the Image or a direct GuiImage
	  - scale: Boolean: True if the image should be scaled to widget size, false otherwise.
	  - tile: Boolean: True if the image should be tiled to widget size, false otherwise.
	  - opaque: Boolean: True if the background of the icon should be drawn, false otherwise.
	"""
    ATTRIBUTES = Widget.ATTRIBUTES + [
        Attr('image'),
        BoolAttr('scale'),
        BoolAttr('tile'),
        BoolAttr('opaque')
    ]

    DEFAULT_SCALE = False
    DEFAULT_TILE = False
    DEFAULT_OPAQUE = False

    DEFAULT_MARGINS = 0, 0
    DEFAULT_PADDING = 0

    def __init__(self,
                 parent=None,
                 name=None,
                 size=None,
                 min_size=None,
                 max_size=None,
                 fixed_size=None,
                 margins=None,
                 padding=None,
                 helptext=None,
                 position=None,
                 style=None,
                 hexpand=None,
                 vexpand=None,
                 font=None,
                 base_color=None,
                 background_color=None,
                 foreground_color=None,
                 selection_color=None,
                 border_color=None,
                 outline_color=None,
                 border_size=None,
                 outline_size=None,
                 position_technique=None,
                 is_focusable=None,
                 comment=None,
                 image=None,
                 scale=None,
                 tile=None,
                 opaque=None):

        self.real_widget = fifechan.Icon(None)

        super(Icon, self).__init__(parent=parent,
                                   name=name,
                                   size=size,
                                   min_size=min_size,
                                   max_size=max_size,
                                   fixed_size=fixed_size,
                                   margins=margins,
                                   padding=padding,
                                   helptext=helptext,
                                   position=position,
                                   style=style,
                                   hexpand=hexpand,
                                   vexpand=vexpand,
                                   font=font,
                                   base_color=base_color,
                                   background_color=background_color,
                                   foreground_color=foreground_color,
                                   selection_color=selection_color,
                                   border_color=border_color,
                                   outline_color=outline_color,
                                   border_size=border_size,
                                   outline_size=outline_size,
                                   position_technique=position_technique,
                                   is_focusable=is_focusable,
                                   comment=comment)

        # set provided attributes or defaults
        if scale is not None: self.scale = scale
        else: self.scale = self.DEFAULT_SCALE

        if tile is not None: self.tile = tile
        else: self.tile = self.DEFAULT_TILE

        if opaque is not None: self.opaque = opaque
        else: self.opaque = self.DEFAULT_OPAQUE

        # for the case that image can not be found, e.g. invalid path
        # the Icon is removed from the manager
        try:
            self.image = image
        except Exception:
            get_manager().removeWidget(self)
            raise

        #if the size parameter is specified set it (again) to override
        #the icons size. That works only without layouting.
        if size is not None: self.size = size

    def clone(self, prefix):
        iconClone = Icon(None, self._createNameWithPrefix(prefix), self.size,
                         self.min_size, self.max_size, self.fixed_size,
                         self.margins, self.padding, self.helptext,
                         self.position, self.style, self.hexpand, self.vexpand,
                         self.font, self.base_color, self.background_color,
                         self.foreground_color, self.selection_color,
                         self.border_color, self.outline_color,
                         self.border_size, self.outline_size,
                         self.position_technique, self.is_focusable,
                         self.comment, self.image, self.scale)

        return iconClone

    image = ImageProperty("Image")

    def _setScaling(self, val):
        self.real_widget.setScaling(val)

    def _getScaling(self):
        return self.real_widget.isScaling()

    scale = property(_getScaling, _setScaling)

    def _setTiling(self, val):
        self.real_widget.setTiling(val)

    def _getTiling(self):
        return self.real_widget.isTiling()

    tile = property(_getTiling, _setTiling)

    def _setOpaque(self, val):
        self.real_widget.setOpaque(val)

    def _getOpaque(self):
        return self.real_widget.isOpaque()

    opaque = property(_getOpaque, _setOpaque)

    def _checkSize(self):
        if not self.scale:
            if self.image is not None:
                self.min_size = self.image.getWidth(), self.image.getHeight()
            else:
                self.min_size = self.real_widget.getWidth(
                ), self.real_widget.getHeight()
            self.max_size = self.min_size
            self.size = self.min_size
        else:
            if self.parent:
                self.min_size = self.parent.min_size
                self.max_size = self.parent.max_size
            else:
                self.min_size = Widget.DEFAULT_MIN_SIZE
                self.max_size = Widget.DEFAULT_MAX_SIZE
Пример #6
0
class Icon(Widget):
    """
	An image icon.

	New Attributes
	==============

	  - image: String or GuiImage: The source location of the Image or a direct GuiImage
	"""
    ATTRIBUTES = Widget.ATTRIBUTES + [Attr('image')]

    def __init__(self,
                 parent=None,
                 name=None,
                 size=None,
                 min_size=None,
                 max_size=None,
                 helptext=None,
                 position=None,
                 style=None,
                 hexpand=None,
                 vexpand=None,
                 font=None,
                 base_color=None,
                 background_color=None,
                 foreground_color=None,
                 selection_color=None,
                 border_size=None,
                 position_technique=None,
                 is_focusable=None,
                 comment=None,
                 image=None):

        self.real_widget = fife.Icon(None)
        super(Icon, self).__init__(parent=parent,
                                   name=name,
                                   size=size,
                                   min_size=min_size,
                                   max_size=max_size,
                                   helptext=helptext,
                                   position=position,
                                   style=style,
                                   hexpand=hexpand,
                                   vexpand=vexpand,
                                   font=font,
                                   base_color=base_color,
                                   background_color=background_color,
                                   foreground_color=foreground_color,
                                   selection_color=selection_color,
                                   border_size=border_size,
                                   position_technique=position_technique,
                                   is_focusable=is_focusable,
                                   comment=comment)
        self.image = image

    def clone(self, prefix):
        iconClone = Icon(None, self._createNameWithPrefix(prefix), self.size,
                         self.min_size, self.max_size, self.helptext,
                         self.position, self.style, self.hexpand, self.vexpand,
                         self.font, self.base_color, self.background_color,
                         self.foreground_color, self.selection_color,
                         self.border_size, self.position_technique,
                         self.is_focusable, self.comment, self.image)

        return iconClone

    _image = ImageProperty("Image")

    def _setImage(self, source):
        self._image = source

    def _getImage(self):
        return self._image

    image = property(_getImage, _setImage)
Пример #7
0
class IconProgressBar(Widget):
    """
	An image icon.

	New Attributes
	==============

	  - image: String or GuiImage: The source location of the Image or a direct GuiImage
	"""
    ATTRIBUTES = Widget.ATTRIBUTES + [
        Attr('image'),
        IntAttr('max_icons'),
        IntAttr('orientation'),
        BoolAttr('opaque')
    ]

    DEFAULT_OPAQUE = True

    def __init__(self,
                 parent=None,
                 name=None,
                 size=None,
                 min_size=None,
                 max_size=None,
                 helptext=None,
                 position=None,
                 style=None,
                 hexpand=None,
                 vexpand=None,
                 font=None,
                 base_color=None,
                 background_color=None,
                 foreground_color=None,
                 selection_color=None,
                 border_size=None,
                 position_technique=None,
                 is_focusable=None,
                 comment=None,
                 image=None,
                 max_icons=None,
                 orientation=None,
                 opaque=None):

        self.real_widget = fifechan.IconProgressBar()
        self.opaque = opaque or self.DEFAULT_OPAQUE

        super(IconProgressBar,
              self).__init__(parent=parent,
                             name=name,
                             size=size,
                             min_size=min_size,
                             max_size=max_size,
                             helptext=helptext,
                             position=position,
                             style=style,
                             hexpand=hexpand,
                             vexpand=vexpand,
                             font=font,
                             base_color=base_color,
                             background_color=background_color,
                             foreground_color=foreground_color,
                             selection_color=selection_color,
                             border_size=border_size,
                             position_technique=position_technique,
                             is_focusable=is_focusable,
                             comment=comment)
        if image is not None: self.image = image
        if max_icons is not None: self.max_icons = max_icons

    def clone(self, prefix):
        iconClone = IconProgressBar(
            None, self._createNameWithPrefix(prefix), self.size, self.min_size,
            self.max_size, self.helptext, self.position, self.style,
            self.hexpand, self.vexpand, self.font, self.base_color,
            self.background_color, self.foreground_color, self.selection_color,
            self.border_size, self.position_technique, self.is_focusable,
            self.comment, self.image, self.max_icons)

        return iconClone

    _image = ImageProperty("Image")

    def advance(self):
        self.real_widget.advance()

    def reset(self):
        self.real_widget.reset()

    def _setImage(self, source):
        self._image = source

    def _getImage(self):
        return self._image

    image = property(_getImage, _setImage)

    def _setMaxIcons(self, maxIcons):
        if type(maxIcons) != int:
            raise RuntimeError(
                "IconProgressBar max icons should be an integer")
        self.real_widget.setMaxIcons(maxIcons)

    def _getMaxIcons(self):
        return self.real_widget.getMaxIcons()

    max_icons = property(_getMaxIcons, _setMaxIcons)

    def _setOrientation(self, orientation):
        self.real_widget.setOrientation(orientation)

    def _getOrientation(self):
        return self.real_widget.getOrientation()

    orientation = property(_getOrientation, _setOrientation)

    def _setOpaque(self, opaque):
        self.real_widget.setOpaque(opaque)

    def _getOpaque(self):
        return self.real_widget.isOpaque()

    opaque = property(_getOpaque, _setOpaque)
Пример #8
0
class Icon(Widget):
    """
	An image icon.

	New Attributes
	==============

	  - image: String or GuiImage: The source location of the Image or a direct GuiImage
	"""
    ATTRIBUTES = Widget.ATTRIBUTES + [Attr('image'), BoolAttr('scale')]

    def __init__(self,
                 parent=None,
                 name=None,
                 size=None,
                 min_size=None,
                 max_size=None,
                 helptext=None,
                 position=None,
                 style=None,
                 hexpand=None,
                 vexpand=None,
                 font=None,
                 base_color=None,
                 background_color=None,
                 foreground_color=None,
                 selection_color=None,
                 border_size=None,
                 position_technique=None,
                 is_focusable=None,
                 comment=None,
                 image=None,
                 scale=None):

        self.real_widget = fifechan.Icon(None)
        super(Icon, self).__init__(parent=parent,
                                   name=name,
                                   size=size,
                                   min_size=min_size,
                                   max_size=max_size,
                                   helptext=helptext,
                                   position=position,
                                   style=style,
                                   hexpand=hexpand,
                                   vexpand=vexpand,
                                   font=font,
                                   base_color=base_color,
                                   background_color=background_color,
                                   foreground_color=foreground_color,
                                   selection_color=selection_color,
                                   border_size=border_size,
                                   position_technique=position_technique,
                                   is_focusable=is_focusable,
                                   comment=comment)

        if scale is not None: self.scale = scale

        self.image = image

        #if the size parameter is specified set it (again) to override
        #the icons size.
        if size is not None: self.size = size

    def clone(self, prefix):
        iconClone = Icon(None, self._createNameWithPrefix(prefix), self.size,
                         self.min_size, self.max_size, self.helptext,
                         self.position, self.style, self.hexpand, self.vexpand,
                         self.font, self.base_color, self.background_color,
                         self.foreground_color, self.selection_color,
                         self.border_size, self.position_technique,
                         self.is_focusable, self.comment, self.image,
                         self.scale)

        return iconClone

    _image = ImageProperty("Image")

    def _setImage(self, source):
        self._image = source
        self._checkSize()

    def _getImage(self):
        return self._image

    image = property(_getImage, _setImage)

    def _setScaling(self, val):
        self.real_widget.setScaling(val)
        self._checkSize()

    def _getScaling(self):
        return self.real_widget.isScaling()

    scale = property(_getScaling, _setScaling)

    def _checkSize(self):
        if not self.scale:
            if self.image is not None:
                self.min_size = self.image.getWidth(), self.image.getHeight()
            else:
                self.min_size = self.real_widget.getWidth(
                ), self.real_widget.getHeight()
            self.max_size = self.min_size
            self.size = self.min_size
        else:
            if self.parent:
                self.min_size = self.parent.min_size
                self.max_size = self.parent.max_size
            else:
                self.min_size = Widget.DEFAULT_MIN_SIZE
                self.max_size = Widget.DEFAULT_MAX_SIZE