class ToggleButton(ImageButton): """ A basic push button that can be toggled. New Attributes ============== - group: String: The group the button belongs to. Only one button in each group will be toggled at one time. - toggled: Boolean: Whether the button is toggled or not. Data ==== The toggled status can be read and set via L{distributeData} and L{collectData} """ ATTRIBUTES = ImageButton.ATTRIBUTES + [Attr('group'), BoolAttr('toggled')] DEFAULT_GROUP = "" DEFAULT_TOGGLED = False 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, group=None, toggled=None): self.real_widget = fifechan.ToggleButton() super(ToggleButton, 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 group is not None: self.group = group else: self.group = self.DEFAULT_GROUP if toggled is not None: self.toggled = toggled else: self.toggled = self.DEFAULT_TOGGLED # Prepare Data collection framework self.accepts_data = True self._realGetData = self._isToggled self._realSetData = self._setToggled def clone(self, prefix): toggleButtonClone = ToggleButton( 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.group, self.toggled) return toggleButtonClone def _setGroup(self, group): if group is None: group = "" self.real_widget.setGroup(group) def _getGroup(self): return self.real_widget.getGroup() group = property(_getGroup, _setGroup) def _setToggled(self, toggled): self.real_widget.setSelected(toggled) def _isToggled(self): return self.real_widget.isSelected() toggled = property(_isToggled, _setToggled)
class Button(BasicTextWidget): """ A basic push button. New Attributes ============== - active: Bool: If false the button is inactiv then it looks gray. - alignment: Int: Sets the alignment of the caption. The alignment is relative to the center of the button. - offset: Point: The offset of the caption when the button is pressed. """ ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [ BoolAttr('active'), IntAttr('alignment'), PointAttr('offset') ] DEFAULT_ACTIVE = True # 0=Left, 1=Center, 2=Right DEFAULT_ALIGNMENT = 1 DEFAULT_OFFSET = 1, 1 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, real_widget=None): if real_widget is None: self.real_widget = fifechan.Button("") else: self.real_widget = real_widget # set the defaults #offset = self.DEFAULT_OFFSET super(Button, 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) # set provided attributes or defaults if active is not None: self.active = active else: self.active = self.DEFAULT_ACTIVE if alignment is not None: self.alignment = alignment else: self.alignment = self.DEFAULT_ALIGNMENT if offset is not None: self.offset = offset else: self.offset = self.DEFAULT_OFFSET def clone(self, prefix): btnClone = Button( 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) return btnClone def _setActive(self, active): self.real_widget.setActive(active) def _isActive(self): return self.real_widget.isActive() active = property(_isActive, _setActive) def _setAlignment(self, alignment): self.real_widget.setAlignment(alignment) def _getAlignment(self): return self.real_widget.getAlignment() alignment = property(_getAlignment, _setAlignment) 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 _setXOffset(self, x): self.real_widget.setDownXOffset(x) def _getXOffset(self): return self.real_widget.getDownXOffset() x_offset = property(_getXOffset, _setXOffset) def _setYOffset(self, y): self.real_widget.setDownYOffset(y) def _getYOffset(self): return self.real_widget.getDownYOffset() y_offset = property(_getYOffset, _setYOffset)
class DockArea(ResizableWindow): """ This is a window class that can be resizable and it's possible to dock Panels. New Attributes ============== - active: If true, the DockArea is active and Panels can be docked to it. - side: Allows to specify the side for expanding. - highlight_color: Color that is used if a Panel enters the DockArea. """ ATTRIBUTES = ResizableWindow.ATTRIBUTES + [ BoolAttr('active'), UnicodeAttr('side'), ColorAttr('highlight_color'), ] DEFAULT_MARGINS = 0 DEFAULT_PADDING = 0 DEFAULT_SPACING = 0 DEFAULT_ACTIVE = True DEFAULT_HIGHLIGHT_COLOR = (200, 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, background_image = None, opaque = None, layout = None, spacing = None, uniform_size = None, _real_widget = None, title = None, titlebar_height = None, movable = None, resizable = None, top_resizable = None, right_resizable = None, bottom_resizable = None, left_resizable = None, shove = None, cursors = None, active = None, side = None, highlight_color = None): if _real_widget is None: _real_widget = fifechan.DockArea() super(DockArea,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, background_image=background_image, opaque=opaque, layout=layout, spacing=spacing, uniform_size=uniform_size, _real_widget=_real_widget, title=title, titlebar_height=titlebar_height, movable=movable, resizable=resizable, top_resizable=top_resizable, right_resizable=right_resizable, bottom_resizable=bottom_resizable, left_resizable=left_resizable, shove=shove, cursors=cursors) if active is not None: self.active = active else: self.active = self.DEFAULT_ACTIVE if side is not None: self.side = side if highlight_color is not None: self.highlight_color = highlight_color else: self.highlight_color = self.DEFAULT_HIGHLIGHT_COLOR def clone(self, prefix): dockAreaClone = DockArea(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.background_image, self.opaque, self.layout, self.spacing, self.uniform_size, None, self.title, self.titlebar_height, self.movable, self.resizable, self.top_resizable, self.right_resizable, self.bottom_resizable, self.left_resizable, self.shove, self.cursors, self.active, self.side, self.highlight_color) dockAreaClone.addChildren(self._cloneChildren(prefix)) return dockAreaClone def addChild(self, widget): super(DockArea,self).addChild(widget) widget.docked = True def _getActiveDockArea(self): return self.real_widget.isActiveDockArea() def _setActiveDockArea(self, active): self.real_widget.setActiveDockArea(active) active = property(_getActiveDockArea, _setActiveDockArea) def isTopSide(self): return self.real_widget.isTopSide() def setTopSide(self, side): self.real_widget.setTopSide(side) def isRightSide(self): return self.real_widget.isRightSide() def setRightSide(self, side): self.real_widget.setRightSide(side) def isBottomSide(self): return self.real_widget.isBottomSide() def setBottomSide(self, side): self.real_widget.setBottomSide(side) def isLeftSide(self): return self.real_widget.isLeftSide() def setLeftSide(self, side): self.real_widget.setLeftSide(side) def _getSide(self): if self.real_widget.isTopSide(): return 'top' elif self.real_widget.isRightSide(): return 'right' elif self.real_widget.isBottomSide(): return 'bottom' elif self.real_widget.isLeftSide(): return 'left' return '' def _setSide(self, side): self.setTopSide(False) self.setRightSide(False) self.setBottomSide(False) self.setLeftSide(False) if side == 'top': self.setTopSide(True) elif side == 'right': self.setRightSide(True) elif side == 'bottom': self.setBottomSide(True) elif side == 'left': self.setLeftSide(True) side = property(_getSide, _setSide) highlight_color = ColorProperty("HighlightColor")
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)
class Window(Container): """ A L{VBox} with a draggable title bar aka a window New Attributes ============== - title: The Caption of the window - titlebar_height: The height of the window title bar - movable: Can the Window be moved with the mouse """ ATTRIBUTES = Container.ATTRIBUTES + [ UnicodeAttr('title'), IntAttr('titlebar_height'), BoolAttr('movable') ] DEFAULT_LAYOUT = 'Vertical' DEFAULT_TITLE = u"title" DEFAULT_TITLE_HEIGHT = 16 DEFAULT_MOVABLE = True DEFAULT_POSITION_TECHNIQUE = "automatic" 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, background_image=None, opaque=None, layout=None, spacing=None, uniform_size=None, _real_widget=None, title=None, titlebar_height=None, movable=None): if _real_widget is None: _real_widget = fifechan.Window() super(Window, 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, background_image=background_image, opaque=opaque, layout=layout, spacing=spacing, uniform_size=uniform_size, _real_widget=_real_widget) if titlebar_height is not None: if titlebar_height == 0: titlebar_height = self.real_font.getHeight() + 4 self.titlebar_height = titlebar_height else: self.titlebar_height = self.real_font.getHeight() + 4 if title is not None: self.title = title else: self.title = self.DEFAULT_TITLE if movable is not None: self.movable = movable else: self.movable = self.DEFAULT_MOVABLE def clone(self, prefix): windowClone = Window( 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.background_image, self.opaque, self.layout, self.spacing, self.uniform_size, None, self.title, self.titlebar_height, self.movable) windowClone.addChildren(self._cloneChildren(prefix)) return windowClone def _getTitle(self): return gui2text(self.real_widget.getCaption()) def _setTitle(self, text): self.real_widget.setCaption(text2gui(text)) title = property(_getTitle, _setTitle) def _getTitleBarHeight(self): return self.real_widget.getTitleBarHeight() def _setTitleBarHeight(self, h): self.real_widget.setTitleBarHeight(h) titlebar_height = property(_getTitleBarHeight, _setTitleBarHeight) def _getMovable(self): return self.real_widget.isMovable() def _setMovable(self, move): self.real_widget.setMovable(move) movable = property(_getMovable, _setMovable)
class CurveGraph(Widget): """ A curve graph widget New Attributes ============== - coordinates: int list: x and y coordinates - thickness': int: Line thickness, default 1 - controll_points: bool: Adds internal controll points, default True - opaque: bool: default False """ ATTRIBUTES = Widget.ATTRIBUTES + [ IntListAttr('coordinates'), IntAttr('thickness'), BoolAttr('controll_points'), BoolAttr('opaque') ] DEFAULT_HEXPAND = False DEFAULT_VEXPAND = False DEFAULT_THICKNESS = 1 DEFAULT_CONTROLL_POINTS = True DEFAULT_OPAQUE = False 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, opaque = None, coordinates = None, thickness = None, controll_points = None): self.real_widget = fifechan.CurveGraph() self.opaque = self.DEFAULT_OPAQUE self.thickness = self.DEFAULT_THICKNESS self.controll_points = self.DEFAULT_CONTROLL_POINTS super(CurveGraph, 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) if opaque is not None: self.opaque = opaque if coordinates is not None: self.coordinates = coordinates if thickness is not None: self.thickness = thickness if controll_points is not None: self.controll_points = controll_points def clone(self, prefix): curveGraphClone = CurveGraph(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.opaque, self.coordinates, self.thickness, self.controll_points) return curveGraphClone def _setOpaque(self, opaque): self.real_widget.setOpaque(opaque) def _getOpaque(self): return self.real_widget.isOpaque() opaque = property(_getOpaque, _setOpaque) def _setCoordinates(self, coordinates): # reset if coordinates is None or len(coordinates) == 0: self.real_widget.resetPointVector() return # int list to point vector if isinstance(coordinates[0], int): coords = fifechan.FcnPointVector() for i in range(0, len(coordinates)-1, 2): coords.append(fifechan.Point(coordinates[i], coordinates[i+1])) self.real_widget.setPointVector(coords) return self.real_widget.setPointVector(coordinates) def _getCoordinates(self): return self.real_widget.getPointVector() coordinates = property(_getCoordinates, _setCoordinates) def _setThickness(self, thickness): self.real_widget.setThickness(thickness) def _getThickness(self): return self.real_widget.getThickness() thickness = property(_getThickness, _setThickness) def _setControllPoints(self, controll): self.real_widget.setAutomaticControllPoints(controll) def _getControllPoints(self): return self.real_widget.isAutomaticControllPoints() controll_points = property(_getControllPoints, _setControllPoints)
class RadioButton(BasicTextWidget): """ A basic radiobutton (an exclusive checkbox). New Attributes ============== - marked: Boolean: Whether the checkbox is checked or not. - group: String: All RadioButtons with the same group name can only be checked exclusively. Data ==== The marked status can be read and set via L{distributeData} and L{collectData} """ ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [ BoolAttr('marked'), Attr('group') ] DEFAULT_GROUP = "_no_group_" 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, group = None): self.real_widget = fifechan.RadioButton() self.group = self.DEFAULT_GROUP super(RadioButton,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, text=text) if group is not None: self.group = group # Prepare Data collection framework self.accepts_data = True self._realGetData = self._isMarked self._realSetData = self._setMarked # Initial data stuff inherited. def clone(self, prefix): rbuttonClone = RadioButton(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.group) return rbuttonClone def _isMarked(self): return self.real_widget.isSelected() def _setMarked(self,mark): self.real_widget.setSelected(mark) marked = property(_isMarked,_setMarked) def _setGroup(self,group): self.real_widget.setGroup(group) def _getGroup(self): return self.real_widget.getGroup() group = property(_getGroup,_setGroup) def resizeToContent(self,recurse=True): self.width = self.real_font.getWidth(text2gui(self.text)) + 35# Size of the Checked box? self.height = self.real_font.getHeight()
class Widget(object): """ This is the common widget base class, which provides most of the wrapping functionality. Attributes ========== Widgets are manipulated (mostly) through attributes - and these can all be set by XML attributes. Derived widgets will have other attributes. Please see their B{New Attributes} sections. The types of the attributes are pretty straightforward, but note that Position and Color attribute types will also accept C{fife.Point} and C{fife.Color} values. - name: String: The identification of the widget, most useful if it is unique within a given widget hiarachy. This is used to find widgets by L{mapEvents},L{distributeInitialData},L{distributeData} and L{collectData}. - position: Position: The position relative to the parent widget - or on screen, if this is the root widget. - size: Position: The real size of the widget (including border and margins). Usually you do not need to set this. A notable exception is the L{ScrollArea}. - min_size: Position: The minimal size this widget is allowed to have. This is enforced through the accessor methods of the actual size attribute. - max_size: Position: The maximal size this widget is allowed to have. This is enforced through the accessor methods of the actual size attribute. - margins: Integer list: The margin clears an area around an element (outside the border) and is completely transparent. - padding: Integer list: The padding clears an area around the content (inside the border) of the element. - base_color: Color - background_color: Color - foreground_color: Color - selection_color: Color - border_color: Color - outline_color: Color - font: String: This should identify a font that was loaded via L{loadFonts} before. - helptext: Unicode: Text which can be used for e.g. tooltips. - comment: Unicode: Additional text stored by the widget. Not used by PyChan directly. Can be used by the client for additional info about the widget. - border_size: Integer: The size of the border in pixels. - position_technique: This can be either "automatic" or "explicit" - only L{Window} has this set to "automatic" which results in new windows being centered on screen (for now). If it is set to "explicit" the position attribute will not be touched. - vexpand: Bool: True. Proportion to expand this widget vertically. - hexpand: Bool: True. Proportion to expand this widget horizontally. Convenience Attributes ====================== These attributes are convenience/shorthand versions of above mentioned attributes and assignment will reflect the associated attributes values. E.g. the following is equivalent:: # Set X position, leave Y alone widget.x = 10 # Same here posi = widget.position widget.position = (10, posi[1]) Here they are. - x: Integer: The horizontal part of the position attribute. - y: Integer: The vertical part of the position attribute. - width: Integer: The horizontal part of the size attribute. - height: Integer: The vertical part of the size attribute. """ ATTRIBUTES = [ Attr('name'), PointAttr('position'), PointAttr('min_size'), PointAttr('size'), PointAttr('max_size'), PointAttr('fixed_size'), IntListAttr('margins'), IntListAttr('padding'), ColorAttr('base_color'), ColorAttr('background_color'), ColorAttr('foreground_color'), ColorAttr('selection_color'), ColorAttr('border_color'), ColorAttr('outline_color'), Attr('style'), Attr('font'), IntAttr('border_size'), IntAttr('outline_size'), Attr('position_technique'), BoolAttr('vexpand'), BoolAttr('hexpand'), UnicodeAttr('helptext'), BoolAttr('is_focusable'), UnicodeAttr('comment') ] DEFAULT_NAME = '__unnamed__' DEFAULT_HEXPAND = False DEFAULT_VEXPAND = False DEFAULT_MAX_SIZE = 500000, 500000 DEFAULT_SIZE = -1, -1 DEFAULT_MIN_SIZE = 0, 0 DEFAULT_MARGINS = 0, 0 DEFAULT_PADDING = 0 DEFAULT_HELPTEXT = u"" DEFAULT_POSITION = 0, 0 DEFAULT_FONT = "default" DEFAULT_BORDER_SIZE = 0 DEFAULT_OUTLINE_SIZE = 0 DEFAULT_POSITION_TECHNIQUE = "explicit" DEFAULT_COMMENT = u"" HIDE_SHOW_ERROR = """\ You can only show/hide the top widget of a hierachy. Use 'addChild' or 'removeChild' to add/remove labels for example. """ 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): # Make sure the real_widget has been created assert (hasattr(self, 'real_widget')) self.event_mapper = events.EventMapper(self) # Flag to indicate if the Widget is added to the Manager self._added = False # Flag to indicate if the Widget is added to # the top Widget list of the Manager self._top_added = False # Only needed for tabs self.tab = None # Data distribution & retrieval settings self.accepts_data = False self.accepts_initial_data = False #set all defaults if get_manager().compat_layout: self.hexpand, self.vexpand = 0, 0 else: self.hexpand = self.DEFAULT_HEXPAND self.vexpand = self.DEFAULT_VEXPAND self.name = self.DEFAULT_NAME self.has_name = False self.position = self.DEFAULT_POSITION self.position_technique = self.DEFAULT_POSITION_TECHNIQUE self.font = self.DEFAULT_FONT self.min_size = self.DEFAULT_MIN_SIZE self.max_size = self.DEFAULT_MAX_SIZE self.size = self.DEFAULT_SIZE self.margins = self.DEFAULT_MARGINS self.padding = self.DEFAULT_PADDING self.border_size = self.DEFAULT_BORDER_SIZE self.outline_size = self.DEFAULT_OUTLINE_SIZE self.helptext = self.DEFAULT_HELPTEXT self.comment = self.DEFAULT_COMMENT self._usedPrefixes = [] # Parent attribute makes sure we only have one parent, # that tests self.__parent - so make sure we have the attr here. self.__parent = None self.parent = parent # Inherit and apply style if style is None and parent: style = parent.style self.style = style or "default" # override everything style has set if vexpand is not None: self.vexpand = vexpand if hexpand is not None: self.hexpand = hexpand if name is not None: self.name = name self.has_name = True if position is not None: self.position = position if position_technique is not None: self.position_technique = position_technique if font is not None: self.font = font # only set this if it's provided if is_focusable is not None: self.is_focusable = is_focusable if min_size is not None: self.min_size = min_size if max_size is not None: self.max_size = max_size if size is not None: self.size = size if fixed_size is not None: self.fixed_size = fixed_size if margins is not None: self.margins = margins if padding is not None: self.padding = padding if border_size is not None: self.border_size = border_size if outline_size is not None: self.outline_size = outline_size if helptext is not None: self.helptext = helptext if comment is not None: self.comment = comment # these are set in the default style if base_color is not None: self.base_color = base_color if background_color is not None: self.background_color = background_color if foreground_color is not None: self.foreground_color = foreground_color if selection_color is not None: self.selection_color = selection_color if border_color is not None: self.border_color = border_color if outline_color is not None: self.outline_color = outline_color # add this widget to the manager get_manager().addWidget(self) def clone(self, prefix): """ Clones this widget. Concrete widgets should implement this one, if not, an exception should be raised. Prefix is used to create the name of the cloned widget. """ raise RuntimeError("No implementation of clone method for %s" % self.__class__) def execute(self, bind, focus=None): """ Execute a dialog synchronously. As argument a dictionary mapping widget names to return values is expected. Events from these widgets will cause this function to return with the associated return value. This function will not return until such an event occurs. The widget will be shown before execution and hidden afterwards. You can only execute root widgets. @param focus: name of child widget which should have focus. Defaults to main widget. Note: This feature is not tested well, and the API will probably change. Otherwise have fun:: # Okay this a very condensed example :-) return pychan.loadXML("contents/gui/dialog.xml").execute({ 'okButton' : True, 'closeButton' : False }) """ if not get_manager().can_execute: raise RuntimeError("Synchronous execution is not set up!") if self.__parent: raise RuntimeError("You can only 'execute' root widgets, not %s!" % str(self)) for name, returnValue in list(bind.items()): def _quitThisDialog(returnValue=returnValue): get_manager().breakFromMainLoop(returnValue) self.hide() self.findChild(name=name).capture(_quitThisDialog, group_name="__execute__") self.show() if focus and self.findChild(name=focus): self.findChild(name=focus).is_focusable = True self.findChild(name=focus).requestFocus() else: self.is_focusable = True self.requestFocus() return get_manager().mainLoop() def requestFocus(self): """ Requests focus. The widget must be focusable in order for this to work. See the is_focusable property. """ if self.isVisible(): self.real_widget.requestFocus() def isModalFocusable(self): """ Checks if a widget is modal focusable. True if no other widget has modal focus, false otherwise. """ return self.real_widget.isModalFocusable() def isModalFocused(self): """ Checks if the widget or it's parent has modal focus. """ return self.real_widget.isModalFocused() def requestModalFocus(self): """ Requests modal focus. When a widget has modal focus, only that widget and it's children may recieve input. The widget must be modal focusable in order for this to work. Therefore, no other widget should has modal focus. """ if self.isVisible(): if self.isModalFocusable(): self.real_widget.requestModalFocus() def releaseModalFocus(self): """ Releases modal focus. """ if self.isModalFocused(): self.real_widget.releaseModalFocus() def isModalMouseInputFocusable(self): """ Checks if a widget is modal mouse input focusable. True if no other widget has modal mouse input focus, false otherwise. """ return self.real_widget.isModalMouseInputFocusable() def isModalMouseInputFocused(self): """ Checks if the widget or it's parent has modal mouse input focus. """ return self.real_widget.isModalMouseInputFocused() def requestModalMouseInputFocus(self): """ Requests modal mouse input focus. When a widget has modal input focus that widget will be the only widget receiving input even if the input occurs outside of the widget and no matter what the input is. The widget must be modal mouse input focusable in order for this to work. Therefore, no other widget should has modal input focus. """ if self.isVisible(): if self.isModalMouseInputFocusable(): self.real_widget.requestModalMouseInputFocus() def releaseModalMouseInputFocus(self): """ Releases modal mouse input focus. """ if self.isModalMouseInputFocused(): self.real_widget.releaseModalMouseInputFocus() def match(self, **kwargs): """ Matches the widget against a list of key-value pairs. Only if all keys are attributes and their value is the same it returns True. """ for k, v in list(kwargs.items()): if v != getattr(self, k, None): return False return True def capture(self, callback, event_name="action", group_name="default"): """ Add a callback to be executed when the widget event occurs on this widget. The callback must be either a callable or None. The old event handler (if any) will be overridden by the callback. If None is given, the event will be disabled. You can query L{isCaptured} wether this widgets events are currently captured. It might be useful to check out L{tools.callbackWithArguments}. @param callback: Event callback - may accept keyword arguments event and widget. @param event_name: The event to capture - may be one of L{events.EVENTS} and defaults to "action" @param group_name: Event group. Event groups are used to have different B{channels} which don't interfere with each other. For derived widgets that need to capture events it's advised to use the group_name 'widget'. The 'default' group is used by default, and should be reserved for the application programmers. """ self.event_mapper.capture(event_name, callback, group_name) def isCaptured(self): """ Check whether this widgets events are captured (a callback is installed) or not. """ return bool(self.event_mapper.getCapturedEvents()) def show(self): """ Show the widget and all contained widgets. """ # add this widget to the manager if not self._added: get_manager().addWidget(self) if self.parent is None and not self._top_added: get_manager().addTopWidget(self) # add childs of this widget to the manager def _show(shown_widget): get_manager().addWidget(shown_widget) self.deepApply(_show) if self.isVisible() and self.isSetVisible(): self.beforeShow() self.adaptLayout() if self.parent is None: get_manager().placeWidget(self, self.position_technique) return self.beforeShow() # Show real widget to distribute a widgetShown event. self.real_widget.setVisible(True) self.adaptLayout() if self.parent is None: get_manager().placeWidget(self, self.position_technique) def hide(self, free=False): """ Hide the widget and all contained widgets. """ # remove this widget from the manager if self._added: get_manager().removeWidget(self) if self.parent is None and self._top_added: get_manager().removeTopWidget(self) # remove childs of this widget from the manager def _hide(hidden_widget): get_manager().removeWidget(hidden_widget) self.deepApply(_hide) if not self.isVisible() and not self.isSetVisible(): self.adaptLayout() self.afterHide() return # Hide real widget to distribute a widgetHidden event. self.real_widget.setVisible(False) if free: if self.parent: self.parent.removeChild(self) self.removeAllChildren() self.adaptLayout() self.afterHide() def isVisible(self): """ Check whether the widget is currently shown, either directly or as part of a container widget. """ return self.real_widget.isVisible() def isSetVisible(self): """ Check the real widget visible flag. It checks not if the widget is currently shown! This is needed e.g. if the parent is already hidden but we want to hide the child too. """ return self.real_widget.isSetVisible() def adaptLayout(self, recurse=True): """ Execute the Layout engine. Automatically called by L{show}. In case you want to relayout a visible widget. This function will automatically perform the layout adaption from the top-most layouted widget. To make this clear consider this arrangement:: VBox 1 - Container VBox 2 - HBox - Label If you call adaptLayout on the Label the layout from the VBox 2 will get recalculated, while the VBox 1 stays untouched. @param recurse: Pass False here to force the layout to start from this widget. """ self.real_widget.adaptLayout(recurse) def beforeShow(self): """ This method is called just before the widget is shown. You can override this in derived widgets to add finalization behaviour. NOTE: - if your widget is a container, you have to call _resetTiling(), as you will loose this call by using your override method """ def afterHide(self): """ This method is called just before the widget is hidden. You can override this in derived widgets to add finalization behaviour. """ def findChildren(self, **kwargs): """ Find all contained child widgets by attribute values. Usage:: closeButtons = root_widget.findChildren(name='close') buttons = root_widget.findChildren(__class__=pychan.widgets.Button) """ children = [] def _childCollector(widget): if widget.match(**kwargs): children.append(widget) self.deepApply(_childCollector) return children def getNamedChildren(self, include_unnamed=False): """ Create a dictionary of child widgets with the keys being their name. This will contain only Widgets which have a name different from "__unnamed__" (which is the default). @param include_unnamed: Defaults to false. If this is true unnamed widgets are added, too. The values are lists of widgets, so not only unique names are handled correctly. Usage:: children = widget.getNamedChildren() for widget in children.get("info",[]) print widget.name , " == info" """ children = {} if include_unnamed: def _childCollector(widget): children.setdefault(widget._name, []).append(widget) else: def _childCollector(widget): if widget.has_name: children.setdefault(widget._name, []).append(widget) self.deepApply(_childCollector) return children def findChild(self, **kwargs): """ Find the first contained child widgets by attribute values. Usage:: closeButton = root_widget.findChild(name='close') """ if list(kwargs.keys()) == ["name"]: return self.findChildByName(kwargs["name"]) children = self.findChildren(**kwargs) if children: return children[0] return None def findChildByName(self, name): """ Find first contained child widget by its name. Note that this is the fast version of findChild(name="...") and that you don't have to call this explicitly, it is used if possible. """ result = [] def _childCollector(widget): if widget._name == name: result.append(widget) raise StopTreeWalking try: self.deepApply(_childCollector) except StopTreeWalking: return result[0] return None def addChild(self, widget): """ This function adds a widget as child widget and is only implemented in container widgets. You'll need to call L{adaptLayout} if the container is already shown, to adapt the layout to the new widget. This doesn't happen automatically. """ raise RuntimeError( "Trying to add a widget to %s, which doesn't allow this." % repr(self)) def insertChild(self, widget, position): """ This function inserts a widget a given index in the child list. See L{addChild} and L{insertChildBefore} """ raise RuntimeError( "Trying to insert a widget to %s, which doesn't allow this." % repr(self)) def insertChildBefore(self, widget, before): """ Inserts a child widget before a given widget. If the widget isn't found, the widget is appended to the children list. See L{addChild} and L{insertChild} """ raise RuntimeError( "Trying to insert a widget to %s, which doesn't allow this." % repr(self)) def addChildren(self, *widgets): """ Add multiple widgets as children. Only implemented for container widgets. See also L{addChild} Usage:: container.addChildren( widget1, widget2, ... ) # or you can use this on a list container.addChildren( [widget1,widget2,...] ) """ if len(widgets) == 1 and not isinstance(widgets[0], Widget): widgets = widgets[0] for widget in widgets: self.addChild(widget) def removeChild(self, widget): """ This function removes a direct child widget and is only implemented in container widgets. You'll need to call L{adaptLayout} if the container is already shown, to adapt the layout to the removed widget. This doesn't happen automatically. """ raise RuntimeError( "Trying to remove a widget from %s, which is not a container widget." % repr(self)) def removeChildren(self, *widgets): """ Remove a list of direct child widgets. All widgets have to be direct child widgets. To 'clear' a container take a look at L{removeAllChildren}. See also L{removeChild}. Usage:: container.removeChildren( widget1, widget2, ... ) # or you can use this on a list container.removeChildren( [widget1,widget2,...] ) """ if len(widgets) == 1 and not isinstance(widgets[0], Widget): widgets = widgets[0] for widget in widgets: self.removeChild(widget) def removeAllChildren(self): """ This function will remove all direct child widgets. This will work even for non-container widgets. """ children = self.findChildren(parent=self) for widget in children: self.removeChild(widget) def mapEvents(self, eventMap, ignoreMissing=False): """ Convenience function to map widget events to functions in a batch. Subsequent calls of mapEvents will merge events with different widget names and override the previously set callback. You can also pass C{None} instead of a callback, which will disable the event completely. @param eventMap: A dictionary with widget/event names as keys and callbacks as values. @param ignoreMissing: Normally this method raises a RuntimeError, when a widget can not be found - this behaviour can be overriden by passing True here. The keys in the dictionary are parsed as C{"widgetName/eventName"} with the slash separating the two. If no slash is found the eventName is assumed to be "action". Additionally you can supply a group name or channel C{"widgetName/eventName/groupName"}. Event handlers from one group are not overridden by handlers from another group. The default group name is C{"default"}. Example:: guiElement.mapEvents({ "button" : guiElement.hide, "button/mouseEntered" : toggleButtonColorGreen, "button/mouseExited" : toggleButtonColorBlue, }) """ children = self.getNamedChildren(include_unnamed=True) for descr, func in list(eventMap.items()): name, event_name, group_name = events.splitEventDescriptor(descr) #print name, event_name, group_name widgets = children.get(name, []) if widgets: for widget in widgets: widget.capture(func, event_name=event_name, group_name=group_name) elif not ignoreMissing: raise RuntimeError("No widget with the name: %s" % name) def setInitialData(self, data): """ Set the initial data on a widget, what this means depends on the Widget. In case the widget does not accept initial data, a L{RuntimeError} is thrown. """ if not self.accepts_initial_data: raise RuntimeError( "Trying to set data on a widget that does not accept initial data. Widget: %s Data: %s " % (repr(self), repr(data))) self._realSetInitialData(data) def setData(self, data): """ Set the user-mutable data on a widget, what this means depends on the Widget. In case the widget does not accept data, a L{RuntimeError} is thrown. This is inverse to L{getData}. """ if not self.accepts_data: raise RuntimeError( "Trying to set data on a widget that does not accept data.") self._realSetData(data) def getData(self): """ Get the user-mutable data of a widget, what this means depends on the Widget. In case the widget does not have user mutable data, a L{RuntimeError} is thrown. This is inverse to L{setData}. """ if not self.accepts_data: raise RuntimeError( "Trying to retrieve data from a widget that does not accept data." ) return self._realGetData() def distributeInitialData(self, initialDataMap): """ Distribute B{initial} (not mutable by the user) data from a dictionary over the widgets in the hierachy using the keys as names and the values as the data (which is set via L{setInitialData}). If more than one widget matches - the data is set on ALL matching widgets. By default a missing widget is just ignored. Use it like this:: guiElement.distributeInitialData({ 'myTextField' : 'Hello World!', 'myListBox' : ["1","2","3"] }) """ children = self.getNamedChildren(include_unnamed=True) for name, data in list(initialDataMap.items()): widgetList = children.get(name, []) for widget in widgetList: widget.setInitialData(data) def distributeData(self, dataMap): """ Distribute data from a dictionary over the widgets in the hierachy using the keys as names and the values as the data (which is set via L{setData}). This will only accept unique matches. Use it like this:: guiElement.distributeData({ 'myTextField' : 'Hello World!', 'myListBox' : ["1","2","3"] }) """ children = self.getNamedChildren(include_unnamed=True) for name, data in list(dataMap.items()): widgetList = children.get(name, []) if len(widgetList) != 1: if get_manager().debug: self.listNamedWidgets() raise RuntimeError( "DistributeData can only handle widgets with unique names." ) widgetList[0].setData(data) def collectDataAsDict(self, widgetNames): """ Collect data from a widget hierachy by names into a dictionary. This can only handle UNIQUE widget names (in the hierachy) and will raise a RuntimeError if the number of matching widgets is not equal to one. Usage:: data = guiElement.collectDataAsDict(['myTextField','myListBox']) print "You entered:",data['myTextField']," and selected ",data['myListBox'] """ children = self.getNamedChildren(include_unnamed=True) dataMap = {} for name in widgetNames: widgetList = children.get(name, []) if len(widgetList) != 1: if get_manager().debug: self.listNamedWidgets() raise RuntimeError( "CollectData can only handle widgets with unique names.") dataMap[name] = widgetList[0].getData() return dataMap def collectData(self, *widgetNames): """ Collect data from a widget hierachy by names. This can only handle UNIQUE widget names (in the hierachy) and will raise a RuntimeError if the number of matching widgets is not equal to one. This function takes an arbitrary number of widget names and returns a list of the collected data in the same order. In case only one argument is given, it will return just the data, with out putting it into a list. Usage:: # Multiple element extraction: text, selected = guiElement.collectData('myTextField','myListBox') print "You entered:",text," and selected item nr",selected # Single elements are handled gracefully, too: test = guiElement.collectData('testElement') """ children = self.getNamedChildren(include_unnamed=True) dataList = [] for name in widgetNames: widgetList = children.get(name, []) if len(widgetList) != 1: if get_manager().debug: self.listNamedWidgets() raise RuntimeError( "CollectData can only handle widgets with unique names.") dataList.append(widgetList[0].getData()) if len(dataList) == 1: return dataList[0] return dataList def listNamedWidgets(self): """ This function will print a list of all currently named child-widgets to the standard output. This is useful for debugging purposes. """ def _printNamedWidget(widget): if widget.name != Widget.DEFAULT_NAME: print(widget.name.ljust(20), repr(widget).ljust(50), repr(widget.__parent)) print("Named child widgets of ", repr(self)) print("name".ljust(20), "widget".ljust(50), "parent") self.deepApply(_printNamedWidget) def stylize(self, style, **kwargs): """ Recursively apply a style to all widgets. """ def _restyle(widget): get_manager().stylize(widget, style, **kwargs) self.deepApply(_restyle) def resizeToContent(self, recurse=True): """ Try to shrink the widget, so that it fits closely around its content. Do not call directly. """ self.real_widget.resizeToContent(recurse) def expandContent(self, recurse=True): """ Try to expand any spacer in the widget within the current size. Do not call directly. """ self.real_widget.expandContent(recurse) def _recursiveResizeToContent(self): """ Recursively call L{resizeToContent}. Uses L{deepApply}. Do not call directly. """ self.real_widget.resizeToContent(True) def _recursiveExpandContent(self): """ Recursively call L{expandContent}. Uses L{deepApply}. Do not call directly. """ self.real_widget.expandContent(True) def deepApply(self, visitorFunc, leaves_first=True, shown_only=False): """ Recursively apply a callable to all contained widgets and then the widget itself. """ visitorFunc(self) def getAbsolutePos(self): """ Get absolute position on screen """ absX = self.x absY = self.y parent = self.parent while parent is not None: absX += parent.x absY += parent.y parent = parent.parent return (absX, absY) def sizeChanged(self): pass def __str__(self): return "%s(name='%s')" % (self.__class__.__name__, self.name) def __repr__(self): return "<%s(name='%s') at %x>" % (self.__class__.__name__, self.name, id(self)) def _setSize(self, size): if isinstance(size, fife.Point): self.width, self.height = size.x, size.y else: self.width, self.height = size def _getSize(self): return self.width, self.height def _setPosition(self, size): if isinstance(size, fife.Point): self.x, self.y = size.x, size.y else: self.x, self.y = size def _getPosition(self): return self.x, self.y def _setX(self, x): self.real_widget.setX(x) def _getX(self): return self.real_widget.getX() def _setY(self, y): self.real_widget.setY(y) def _getY(self): return self.real_widget.getY() def _setWidth(self, w): old_width = self.width self.real_widget.setWidth(w) w = self.real_widget.getWidth() if w != old_width: self.sizeChanged() def _getWidth(self): return self.real_widget.getWidth() def _setHeight(self, h): old_height = self.height self.real_widget.setHeight(h) h = self.real_widget.getHeight() if h != old_height: self.sizeChanged() def _getHeight(self): return self.real_widget.getHeight() def _getMinWidth(self): return self.min_size[0] def _getMaxWidth(self): return self.max_size[0] def _getMinHeight(self): return self.min_size[1] def _getMaxHeight(self): return self.max_size[1] def _setMinWidth(self, w): self.min_size = w, self.min_size[1] def _setMaxWidth(self, w): self.max_size = w, self.max_size[1] def _setMinHeight(self, h): self.min_size = self.min_size[0], h def _setMaxHeight(self, h): self.max_size = self.max_size[0], h def _setMinSize(self, size): self.real_widget.setMinSize(fifechan.Size(size[0], size[1])) def _getMinSize(self): size = self.real_widget.getMinSize() return (size.getWidth(), size.getHeight()) def _setMaxSize(self, size): self.real_widget.setMaxSize(fifechan.Size(size[0], size[1])) def _getMaxSize(self): size = self.real_widget.getMaxSize() return (size.getWidth(), size.getHeight()) def _setFixedSize(self, size): self.real_widget.setFixedSize(fifechan.Size(size[0], size[1])) def _getFixedSize(self): size = self.real_widget.getFixedSize() return (size.getWidth(), size.getHeight()) def isFixedSize(self): return self.real_widget.isFixedSize() def _setFont(self, font): self._font = font self.real_font = get_manager().getFont(font) self.real_widget.setFont(self.real_font) def _getFont(self): return self._font def _getOutlineSize(self): return self.real_widget.getOutlineSize() def _setOutlineSize(self, size): self.real_widget.setOutlineSize(size) def _getBorderSize(self): return self.real_widget.getBorderSize() def _setBorderSize(self, size): self.real_widget.setBorderSize(size) def _setMargins(self, margin): # Shorthand property if isinstance(margin, tuple) or isinstance(margin, list): if len(margin) == 4: # 0=top, 1=right, 2=bottom, 3=left self.real_widget.setMarginTop(margin[0]) self.real_widget.setMarginRight(margin[1]) self.real_widget.setMarginBottom(margin[2]) self.real_widget.setMarginLeft(margin[3]) elif len(margin) == 3: # 0=top, 1=right, 2=bottom, 1=left self.real_widget.setMarginTop(margin[0]) self.real_widget.setMarginRight(margin[1]) self.real_widget.setMarginBottom(margin[2]) self.real_widget.setMarginLeft(margin[1]) elif len(margin) == 2: # 0=top, 1=right, 0=bottom, 1=left self.real_widget.setMarginTop(margin[0]) self.real_widget.setMarginRight(margin[1]) self.real_widget.setMarginBottom(margin[0]) self.real_widget.setMarginLeft(margin[1]) elif len(margin) == 1: # 0=top, 0=right, 0=bottom, 0=left self.real_widget.setMargin(margin[0]) else: self.real_widget.setMargin(margin) def _getMargins(self): return (self.real_widget.getMarginTop(), self.real_widget.getMarginRight(), self.real_widget.getMarginBottom(), self.real_widget.getMarginLeft()) def _setPadding(self, padding): # Shorthand property if isinstance(padding, tuple) or isinstance(padding, list): if len(padding) == 4: # 0=top, 1=right, 2=bottom, 3=left self.real_widget.setPaddingTop(padding[0]) self.real_widget.setPaddingRight(padding[1]) self.real_widget.setPaddingBottom(padding[2]) self.real_widget.setPaddingLeft(padding[3]) elif len(padding) == 3: # 0=top, 1=right, 2=bottom, 1=left self.real_widget.setPaddingTop(padding[0]) self.real_widget.setPaddingRight(padding[1]) self.real_widget.setPaddingBottom(padding[2]) self.real_widget.setPaddingLeft(padding[1]) elif len(padding) == 2: # 0=top, 1=right, 0=bottom, 1=left self.real_widget.setPaddingTop(padding[0]) self.real_widget.setPaddingRight(padding[1]) self.real_widget.setPaddingBottom(padding[0]) self.real_widget.setPaddingLeft(padding[1]) elif len(padding) == 1: # 0=top, 0=right, 0=bottom, 0=left self.real_widget.setPadding(padding[0]) else: self.real_widget.setPadding(padding) def _getPadding(self): return (self.real_widget.getPaddingTop(), self.real_widget.getPaddingRight(), self.real_widget.getPaddingBottom(), self.real_widget.getPaddingLeft()) base_color = ColorProperty("BaseColor") background_color = ColorProperty("BackgroundColor") foreground_color = ColorProperty("ForegroundColor") selection_color = ColorProperty("SelectionColor") outline_color = ColorProperty("OutlineColor") border_color = ColorProperty("BorderColor") def _getStyle(self): return self._style def _setStyle(self, style): self._style = style get_manager().stylize(self, style) style = property(_getStyle, _setStyle) def _getParent(self): if self.__parent is not None: return self.__parent() return None def _setParent(self, parent): if parent and not issubclass(type(parent), Widget): raise RuntimeError("Parent must be subclass of the Widget type.") if self.__parent is not None and self.__parent() is not parent: if self.__parent() is not None and parent is not None: print("Widget containment fumble:", self, self.__parent, parent) self.__parent().removeChild(self) if parent is not None: self.__parent = weakref.ref(parent) else: self.__parent = None parent = property(_getParent, _setParent) def _setName(self, name): self._name = name if name != Widget.DEFAULT_NAME: self.has_name = True def _getName(self): # __str__ relies on self.name return getattr(self, '_name', '__no_name_yet__') name = property(_getName, _setName) def _setFocusable(self, b): self.real_widget.setFocusable(b) def _isFocusable(self): return self.real_widget.isFocusable() def _setHExpand(self, expand): self.real_widget.setHorizontalExpand(expand) def _isHExpand(self): return self.real_widget.isHorizontalExpand() def _setVExpand(self, expand): self.real_widget.setVerticalExpand(expand) def _isVExpand(self): return self.real_widget.isVerticalExpand() def _createNameWithPrefix(self, prefix): if not isinstance(prefix, str): raise RuntimeError("Widget names should be prefixed with a string") if prefix in self._usedPrefixes: raise RuntimeError("Widget %s already cloned with prefix %s" % (self.name, prefix)) if len(prefix) == 0: raise RuntimeError( "New widget name cannot be created with an empty prefix") self._usedPrefixes.append(prefix) return prefix + self.name x = property(_getX, _setX) y = property(_getY, _setY) width = property(_getWidth, _setWidth) height = property(_getHeight, _setHeight) min_width = property(_getMinWidth, _setMinWidth) min_height = property(_getMinHeight, _setMinHeight) max_width = property(_getMaxWidth, _setMaxWidth) max_height = property(_getMaxHeight, _setMaxHeight) size = property(_getSize, _setSize) min_size = property(_getMinSize, _setMinSize) max_size = property(_getMaxSize, _setMaxSize) fixed_size = property(_getFixedSize, _setFixedSize) position = property(_getPosition, _setPosition) font = property(_getFont, _setFont) outline_size = property(_getOutlineSize, _setOutlineSize) border_size = property(_getBorderSize, _setBorderSize) is_focusable = property(_isFocusable, _setFocusable) margins = property(_getMargins, _setMargins) padding = property(_getPadding, _setPadding) is_focusable = property(_isFocusable, _setFocusable) hexpand = property(_isHExpand, _setHExpand) vexpand = property(_isVExpand, _setVExpand)
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)
class ResizableWindow(Window): """ This is a window class that can be resizable. New Attributes ============== - resizable: Allows resizing with the mouse. If disabled all the side parameters are ignored. - top_resizable: If true, the window can be resized at the top side. - right_resizable: If true, the window can be resized at the right side. - bottom_resizable: If true, the window can be resized at the bottom side. - left_resizable: If true, the window can be resized at the left side. - shove: That allows pull and push in case the min/max size is reached. - cursors: List that contains the cursor definitions. Left, Right, Top, Bottom, LeftTop, RightTop, LeftBottom, RightBottom """ DEFAULT_RESIZABLE = True DEFAULT_TOP_RESIZABLE = True DEFAULT_RIGHT_RESIZABLE = True DEFAULT_BOTTOM_RESIZABLE = True DEFAULT_LEFT_RESIZABLE = True DEFAULT_SHOVE = False ATTRIBUTES = Window.ATTRIBUTES + [ BoolAttr('resizable'), BoolAttr('top_resizable'), BoolAttr('right_resizable'), BoolAttr('bottom_resizable'), BoolAttr('left_resizable'), BoolAttr('shove'), MixedListAttr('cursors') ] DIRECTION_LIST = [ fifechan.ResizableWindow.CURSOR_DIRECTION_L, fifechan.ResizableWindow.CURSOR_DIRECTION_R, fifechan.ResizableWindow.CURSOR_DIRECTION_T, fifechan.ResizableWindow.CURSOR_DIRECTION_B, fifechan.ResizableWindow.CURSOR_DIRECTION_LT, fifechan.ResizableWindow.CURSOR_DIRECTION_RT, fifechan.ResizableWindow.CURSOR_DIRECTION_LB, fifechan.ResizableWindow.CURSOR_DIRECTION_RB ] 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, background_image=None, opaque=None, layout=None, spacing=None, uniform_size=None, _real_widget=None, title=None, titlebar_height=None, movable=None, resizable=None, top_resizable=None, right_resizable=None, bottom_resizable=None, left_resizable=None, shove=None, cursors=None): if _real_widget is None: _real_widget = fifechan.ResizableWindow() super(ResizableWindow, 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, background_image=background_image, opaque=opaque, layout=layout, spacing=spacing, uniform_size=uniform_size, _real_widget=_real_widget, title=title, titlebar_height=titlebar_height, movable=movable) if resizable is not None: self.resizable = resizable else: self.resizable = self.DEFAULT_RESIZABLE if top_resizable is not None: self.top_resizable = top_resizable else: self.top_resizable = self.DEFAULT_TOP_RESIZABLE if right_resizable is not None: self.right_resizable = right_resizable else: self.right_resizable = self.DEFAULT_RIGHT_RESIZABLE if bottom_resizable is not None: self.bottom_resizable = bottom_resizable else: self.bottom_resizable = self.DEFAULT_BOTTOM_RESIZABLE if left_resizable is not None: self.left_resizable = left_resizable else: self.left_resizable = self.DEFAULT_LEFT_RESIZABLE if shove is not None: self.shove = shove else: self.shove = self.DEFAULT_SHOVE if cursors is not None: self.cursors = cursors def clone(self, prefix): windowClone = ResizableWindow( 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.background_image, self.opaque, self.layout, self.spacing, self.uniform_size, None, self.title, self.titlebar_height, self.movable, self.resizable, self.top_resizable, self.right_resizable, self.bottom_resizable, self.left_resizable, self.shove, self.cursors) windowClone.addChildren(self._cloneChildren(prefix)) return windowClone def _setResizable(self, resizable): self.real_widget.setResizable(resizable) def _getResizable(self): return self.real_widget.getResizable() resizable = property(_getResizable, _setResizable) def _setTopResizable(self, resizable): self.real_widget.setTopResizable(resizable) def _getTopResizable(self): return self.real_widget.getTopResizable() top_resizable = property(_getTopResizable, _setTopResizable) def _setRightResizable(self, resizable): self.real_widget.setRightResizable(resizable) def _getRightResizable(self): return self.real_widget.getRightResizable() right_resizable = property(_getRightResizable, _setRightResizable) def _setBottomResizable(self, resizable): self.real_widget.setBottomResizable(resizable) def _getBottomResizable(self): return self.real_widget.getBottomResizable() bottom_resizable = property(_getBottomResizable, _setBottomResizable) def _setLeftResizable(self, resizable): self.real_widget.setLeftResizable(resizable) def _getLeftResizable(self): return self.real_widget.getLeftResizable() left_resizable = property(_getLeftResizable, _setLeftResizable) def _setShove(self, shove): self.real_widget.setShove(shove) def _getShove(self): return self.real_widget.getShove() shove = property(_getShove, _setShove) def _setCursor(self, direction, cursor): self.real_widget.set(direction, cursor) def _getCursor(self, direction): type = self.real_widget.getType(direction) if type is fife.CURSOR_NATIVE: return self.real_widget.getId(direction) elif type is fife.CURSOR_IMAGE: return self.real_widget.getImage(direction) elif type is fife.CURSOR_Animation: return self.real_widget.getAnimation(direction) cursor = property(_getCursor, _setCursor) def _setCursors(self, cursors): if cursors is not None: i = 0 for c in cursors: if isinstance(c, str): # we need a fife image c = get_manager().loadImage(c, gui=False) self.real_widget.set(self.DIRECTION_LIST[i], c) i += 1 def _getCursors(self): cursors = [] for d in self.DIRECTION_LIST: cursors.append(self.cursor(d)) return cursors cursors = property(_getCursors, _setCursors)
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
class PieGraph(Widget): """ A pie graph widget New Attributes ============== - coordinates: int list: x and y coordinates - thickness': int: Line thickness, default 1 - pie_color: color: Pie color - opaque: bool: default False """ ATTRIBUTES = Widget.ATTRIBUTES + [ PointAttr('center'), IntAttr('radius'), BoolAttr('opaque'), MixedListAttr('segments') ] DEFAULT_HEXPAND = False DEFAULT_VEXPAND = False DEFAULT_RADIUS = 10 DEFAULT_OPAQUE = False 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, opaque=None, center=None, radius=None, segments=None): self.real_widget = fifechan.PieGraph() self.opaque = self.DEFAULT_OPAQUE self.radius = self.DEFAULT_RADIUS self._segments = [] super(PieGraph, 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) if opaque is not None: self.opaque = opaque if center is not None: self.center = center if radius is not None: self.radius = radius if segments is not None: self.segments = segments def clone(self, prefix): pieGraphClone = PieGraph( 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.opaque, self.center, self.radius, self.segments) return pieGraphClone def update(self): self.real_widget.clearSegments() for s in self._segments: self.real_widget.addSegment(s.start_angle, s.stop_angle, s.color) def _setOpaque(self, opaque): self.real_widget.setOpaque(opaque) def _getOpaque(self): return self.real_widget.isOpaque() opaque = property(_getOpaque, _setOpaque) def _setCenter(self, center): # point check if isinstance(center, fifechan.Point): self.real_widget.setCenter(center) return self.real_widget.setCenter(center[0], center[1]) def _getCenter(self): return (self.real_widget.getCenterX(), self.real_widget.getCenterY()) center = property(_getCenter, _setCenter) def _setRadius(self, radius): self.real_widget.setRadius(radius) def _getRadius(self): return self.real_widget.getRadius() radius = property(_getRadius, _setRadius) def addSegment(self, start, stop, color): segment = PieSegment(self, start, stop, color) self._segments.append(segment) self.real_widget.addSegment(segment.start_angle, segment.stop_angle, segment.color) def removeSegment(self, start, stop, color): tmp_color = color if isinstance(color, tuple): tmp_color = fifechan.Color(*color) for s in self._segments: if s.start_angle == start and s.stop_angle == stop and s.color == tmp_color: self._segments.remove(s) self.update() break def clearSegments(self): self._segments = [] self.real_widget.clearSegments() def _setSegments(self, segments): self._segments = [] if segments is None: self.real_widget.clearSegments() return if isinstance(segments[0], PieSegment): self._segments = segments else: for i in range(0, len(segments), 3): segment = PieSegment(self, segments[i], segments[i + 1], segments[i + 2]) self._segments.append(segment) self.update() def _getSegments(self): return self._segments segments = property(_getSegments, _setSegments)
class CheckBox(BasicTextWidget): """ A basic checkbox. New Attributes ============== - marked: Boolean value, whether the checkbox is checked or not. Data ==== The marked status can be read and set via L{distributeData} and L{collectData} """ ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [BoolAttr('marked')] DEFAULT_MARKED = False 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, marked=None): self.real_widget = fifechan.CheckBox() self.marked = self.DEFAULT_MARKED super(CheckBox, 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 marked is not None: self.marked = marked # 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.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.marked) return checkboxClone def _isMarked(self): return self.real_widget.isSelected() def _setMarked(self, mark): self.real_widget.setSelected(mark) marked = property(_isMarked, _setMarked)
class ToggleButton(ImageButton): """ A basic push button that can be toggled. Unfortunately a bit of code duplication from ImageButton. New Attributes ============== - group: String: The group the button belongs to. Only one button in each group will be toggled at one time. - toggled: Boolean: Whether the button is toggled or not. """ ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [ Attr('up_image'), Attr('down_image'), Attr('hover_image'), PointAttr('offset'), Attr('group'), BoolAttr('toggled') ] DEFAULT_GROUP = "" DEFAULT_TOGGLED = False 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, group = None, toggled = None): group = self.DEFAULT_GROUP toggled = self.DEFAULT_TOGGLED super(ToggleButton,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, up_image=up_image, down_image=down_image, hover_image=hover_image, offset=offset, real_widget=fifechan.ToggleButton()) if group is not None: self.group = group if toggled: self.toggled = toggled def clone(self, prefix): toggleButtonClone = ToggleButton(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, self.group) return toggleButtonClone def _setGroup(self,group): if group is not None and group != "": self.real_widget.setGroup( group ) def _getGroup(self): return self.real_widget.getGroup() group = property(_getGroup,_setGroup) def _setToggled(self, toggled): self.real_widget.setToggled( toggled ) def _isToggled(self): return self.real_widget.isToggled() toggled = property(_isToggled, _setToggled) def resizeToContent(self, recurse=True): # NOTE: Figure out how the spacing comes into play tw, th = 0, 0 if self.text: th = self.real_font.getHeight() + self.real_widget.getSpacing() tw = self.real_font.getWidth(text2gui(self.text)) + self.real_widget.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
class ScrollArea(Widget): """ A wrapper around another (content) widget. New Attributes ============== - content: The wrapped widget. - vertical_scrollbar: Boolean: Set this to False to hide the Vertical scrollbar - horizontal_scrollbar: Boolean: Set this to False to hide the Horizontal scrollbar """ ATTRIBUTES = Widget.ATTRIBUTES + [ BoolAttr("vertical_scrollbar"), BoolAttr("horizontal_scrollbar"), IntAttr("vertical_scroll_amount"), IntAttr("horizontal_scroll_amount") ] DEFAULT_HEXPAND = True DEFAULT_VEXPAND = 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, content=None, vertical_scrollbar=None, horizontal_scrollbar=None, vertical_scroll_amount=None, horizontal_scroll_amount=None): self.real_widget = fifechan.ScrollArea() self._content = None super(ScrollArea, 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) if content is not None: self.content = content if vertical_scrollbar is not None: self.vertical_scrollbar = vertical_scrollbar if horizontal_scrollbar is not None: self.horizontal_scrollbar = horizontal_scrollbar if vertical_scroll_amount is not None: self.vertical_scroll_amount = vertical_scroll_amount if horizontal_scroll_amount is not None: self.horizontal_scroll_amount = horizontal_scroll_amount def clone(self, prefix): scrollareaClone = ScrollArea( 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, None, #NOTE since content is a widget hierarchy it should be cloned too self.vertical_scrollbar, self.horizontal_scrollbar, self.vertical_scroll_amount, self.horizontal_scroll_amount) scrollareaClone.content = self.content.clone(prefix) return scrollareaClone def addChild(self, widget): self.content = widget widget.parent = self def removeChild(self, widget): if self._content != widget: raise RuntimeError("%s does not have %s as direct child widget." % (str(self), str(widget))) self.content = None widget.parent = None def _setContent(self, content): if content is None: self.real_widget.setContent(content) else: self.real_widget.setContent(content.real_widget) self._content = content def _getContent(self): return self._content content = property(_getContent, _setContent) def deepApply(self, visitorFunc, leaves_first=True, shown_only=False): if leaves_first: if self._content: self._content.deepApply(visitorFunc, leaves_first=leaves_first, shown_only=shown_only) visitorFunc(self) if not leaves_first: if self._content: self._content.deepApply(visitorFunc, leaves_first=leaves_first, shown_only=shown_only) def _visibilityToScrollPolicy(self, visibility): if visibility: return fifechan.ScrollArea.ShowAuto return fifechan.ScrollArea.ShowNever def _scrollPolicyToVisibility(self, policy): if policy == fifechan.ScrollArea.ShowNever: return False return True def _setHorizontalScrollbar(self, visibility): self.real_widget.setHorizontalScrollPolicy( self._visibilityToScrollPolicy(visibility)) def _setVerticalScrollbar(self, visibility): self.real_widget.setVerticalScrollPolicy( self._visibilityToScrollPolicy(visibility)) def _getHorizontalScrollbar(self): return self._scrollPolicyToVisibility( self.real_widget.getHorizontalScrollPolicy()) def _getVerticalScrollbar(self): return self._scrollPolicyToVisibility( self.real_widget.getVerticalScrollPolicy()) def getVerticalMaxScroll(self): return self.real_widget.getVerticalMaxScroll() def getHorizontalMaxScroll(self): return self.real_widget.getHorizontalMaxScroll() def _getHorizontalScrollAmount(self): return self.real_widget.getHorizontalScrollAmount() def _setHorizontalScrollAmount(self, scroll_amount): return self.real_widget.setHorizontalScrollAmount(scroll_amount) def _getVerticalScrollAmount(self): return self.real_widget.getVerticalScrollAmount() def _setVerticalScrollAmount(self, scroll_amount): return self.real_widget.setVerticalScrollAmount(scroll_amount) vertical_scrollbar = property(_getVerticalScrollbar, _setVerticalScrollbar) horizontal_scrollbar = property(_getHorizontalScrollbar, _setHorizontalScrollbar) horizontal_scroll_amount = property(_getHorizontalScrollAmount, _setHorizontalScrollAmount) vertical_scroll_amount = property(_getVerticalScrollAmount, _setVerticalScrollAmount)
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")
class BarGraph(Widget): """ A bar graph widget New Attributes ============== - bar_position: x and y coordinate - bar_width': int: default 10 - bar_height: int: default 10 - opaque: bool: default False """ ATTRIBUTES = Widget.ATTRIBUTES + [ PointAttr('bar_position'), IntAttr('bar_width'), IntAttr('bar_height'), BoolAttr('opaque') ] DEFAULT_HEXPAND = False DEFAULT_VEXPAND = False DEFAULT_OPAQUE = False DEFAULT_BAR_POSITION = 0, 0 DEFAULT_BAR_WIDTH = 10 DEFAULT_BAR_HEIGHT = 10 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, opaque=None, bar_position=None, bar_width=None, bar_height=None): self.real_widget = fifechan.BarGraph() self.opaque = self.DEFAULT_OPAQUE self.bar_positon = self.DEFAULT_BAR_POSITION self.bar_width = self.DEFAULT_BAR_WIDTH self.bar_height = self.DEFAULT_BAR_HEIGHT super(BarGraph, 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) if opaque is not None: self.opaque = opaque if bar_position is not None: self.bar_position = bar_position if bar_width is not None: self.bar_width = bar_width if bar_height is not None: self.bar_height = bar_height def clone(self, prefix): barGraphClone = BarGraph( 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.opaque, self.bar_positon, self.bar_width, self.bar_height) return barGraphClone def _setOpaque(self, opaque): self.real_widget.setOpaque(opaque) def _getOpaque(self): return self.real_widget.isOpaque() opaque = property(_getOpaque, _setOpaque) def _setBarPosition(self, bar_position): self.real_widget.setBarPosition(bar_position[0], bar_position[1]) def _getBarPosition(self): return (self.real_widget.getBarX(), self.real_widget.getBarY()) bar_position = property(_getBarPosition, _setBarPosition) def _setBarWidth(self, bar_width): self.real_widget.setBarWidth(bar_width) def _getBarWidth(self): return self.real_widget.getBarWidth() bar_width = property(_getBarWidth, _setBarWidth) def _setBarHeight(self, bar_height): self.real_widget.setBarHeight(bar_height) def _getBarHeight(self): return self.real_widget.getBarHeight() bar_height = property(_getBarHeight, _setBarHeight)
class Container(Widget): """ This is the basic container class. It provides space in which child widgets can be position via the position attribute. If you want to use the layout engine, you have to use derived containers with vertical or horizontal orientation (L{VBox} or L{HBox}) New Attributes ============== - background_image - Set this to a GuiImage or a resource location (simply a filename). The image will be tiled over the background area. - opaque - Boolean: Whether the background should be drawn at all. Set this to False to make the widget transparent. - spacing - Set the vertical and horizontal spacing between the childs. - uniform_size - Boolean: If true, the free space is distributed in a way that the size of the childrens will be equal (if possible), otherwise the free space will evenly distributed. """ ATTRIBUTES = Widget.ATTRIBUTES + [ Attr('background_image'), BoolAttr('opaque'), UnicodeAttr('layout'), PointAttr('spacing'), BoolAttr('uniform_size') ] DEFAULT_BACKGROUND = None DEFAULT_OPAQUE = True #DEFAULT_MARGINS = 0,0 #DEFAULT_PADDING = 5 DEFAULT_SPACING = 0, 0 DEFAULT_UNIFORM_SIZE = False DEFAULT_LAYOUT = 'Absolute' 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, background_image=None, opaque=None, layout=None, spacing=None, uniform_size=None, _real_widget=None): self.real_widget = _real_widget or fifechan.Container() self.children = [] self._background = [] self._background_image = None self.background_image = self.DEFAULT_BACKGROUND self.opaque = self.DEFAULT_OPAQUE #self.layout = self.DEFAULT_LAYOUT super(Container, 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) if opaque is not None: self.opaque = opaque if background_image is not None: self.background_image = background_image if layout is not None: self.layout = layout else: self.layout = self.DEFAULT_LAYOUT if spacing is not None: self.spacing = spacing else: self.spacing = self.DEFAULT_SPACING if uniform_size is not None: self.uniform_size = uniform_size else: self.uniform_size = self.DEFAULT_UNIFORM_SIZE def clone(self, prefix): containerClone = Container( 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.background_image, self.opaque, self.layout, self.spacing, self.uniform_size, None) containerClone.addChildren(self._cloneChildren(prefix)) return containerClone def addChild(self, widget): """ Adds a child widget to the container. This makes the childs widgets visible state the same as the containers. i.e. if the containter is visible the child will be as well and if the container widget is hidden so will the child. The child however WILL be shown when you show the container widget. If you want the child to be hidden when you show the container widget you must call child.hide(). """ widget.parent = self if widget.max_size[0] > self.max_size[0] or widget.max_size[ 1] > self.max_size[1]: widget.max_size = self.max_size self.children.append(widget) self.real_widget.add(widget.real_widget) # add all to the manager def _add(added_widget): if not added_widget._added: get_manager().addWidget(added_widget) if added_widget._top_added: get_manager().removeTopWidget(added_widget) widget.deepApply(_add) def insertChild(self, widget, position): if position > len(self.children) or 0 - position > len(self.children): print("insertChild: Warning: Index overflow.", end=' ') if position >= 0: self.addChild(widget) else: self.insertChild(widget, 0) return children = self.children[0:position] + [widget ] + self.children[position:] #assert len(children) == len(self.children) + 1 for child_to_remove in self.children[:]: self.removeChild(child_to_remove) for child in children: self.addChild(child) def insertChildBefore(self, widget, before): if before not in self.children: raise RuntimeError( "Couldn't find widget %s as child of %s - in insertChildBefore" % (str(widget), str(before))) self.insertChild(widget, self.children.index(before)) def removeChild(self, widget): if not widget in self.children: raise RuntimeError("%s does not have %s as direct child widget." % (str(self), str(widget))) if widget in self.children: self.children.remove(widget) self.real_widget.remove(widget.real_widget) widget.parent = None # remove all from the manager def _remove(removed_widget): if removed_widget._added: get_manager().removeWidget(removed_widget) if removed_widget._top_added: get_manager().removeTopWidget(removed_widget) widget.deepApply(_remove) def hideChild(self, child, free=False): # remove child from the manager if child._added: get_manager().removeWidget(child) if child._top_added: get_manager().removeTopWidget(child) # remove childs of the child from the manager def _hide(hidden_widget): get_manager().removeWidget(hidden_widget) child.deepApply(_hide) if child.isVisible() or child.isSetVisible(): # Hide real widget to distribute a widgetHidden event. child.real_widget.setVisible(False) if free: self.removeChild(child) self.adaptLayout() self.afterHide() def showChild(self, child): # add child to the manager if not child._added: get_manager().addWidget(child) # add childs of child to the manager def _show(shown_widget): get_manager().addWidget(shown_widget) child.deepApply(_show) child.beforeShow() if not child.isVisible() or not child.isSetVisible(): # Show real widget to distribute a widgetShown event. child.real_widget.setVisible(True) self.adaptLayout() def add(self, *widgets): print( "PyChan: Deprecation warning: Please use 'addChild' or 'addChildren' instead." ) self.addChildren(*widgets) def getMaxChildrenWidth(self): if not self.children: return 0 w = 0 for widget in self.children: if not widget.real_widget.isVisible(): continue w = max(widget.width, w) return w def getMaxChildrenHeight(self): if not self.children: return 0 h = 0 for widget in self.children: if not widget.real_widget.isVisible(): continue h = max(widget.height, h) return h def deepApply(self, visitorFunc, leaves_first=True, shown_only=False): if not shown_only: children = self.children else: children = [w for w in self.children if w.real_widget.isVisible()] if leaves_first: for child in children: child.deepApply(visitorFunc, leaves_first=leaves_first, shown_only=shown_only) visitorFunc(self) if not leaves_first: for child in children: child.deepApply(visitorFunc, leaves_first=leaves_first, shown_only=shown_only) def beforeShow(self): # This is required because beforeShow() is NOT called on nested # containers or child widgets. This ensures that background tiled # images are shown properly def _resetTilingChildren(widget): tilingMethod = getattr(widget, "_resetTiling", None) if callable(tilingMethod): tilingMethod() self.deepApply(_resetTilingChildren) self._resetTiling() def _resetTiling(self): image = self._background_image if image is None: return back_w, back_h = self.width, self.height # Now tile the background over the widget self._background = [] icon = fifechan.Icon(image) icon.setTiling(True) # Skips background rendering icon.setOpaque(False) icon.setSize(back_w, back_h) self._background.append(icon) self.real_widget.setBackgroundWidget(icon) def setBackgroundImage(self, image): #self._background = getattr(self,'_background',None) if image is None: self._background_image = None if len(self._background) > 0: self.real_widget.setBackgroundWidget(None) self._background = [] return # Background generation is done in _resetTiling if not isinstance(image, fife.GuiImage): image = get_manager().loadImage(image) self._background_image = image def getBackgroundImage(self): return self._background_image background_image = property(getBackgroundImage, setBackgroundImage) def _setOpaque(self, opaque): self.real_widget.setOpaque(opaque) def _getOpaque(self): return self.real_widget.isOpaque() opaque = property(_getOpaque, _setOpaque) def _setVerticalSpacing(self, space): self.real_widget.setVerticalSpacing(space) def _getVerticalSpacing(self): return self.real_widget.getVerticalSpacing() vspacing = property(_getVerticalSpacing, _setVerticalSpacing) def _setHorizontalSpacing(self, space): self.real_widget.setHorizontalSpacing(space) def _getHorizontalSpacing(self): return self.real_widget.getHorizontalSpacing() hspacing = property(_getHorizontalSpacing, _setHorizontalSpacing) def _setSpacing(self, space): # Shorthand property if isinstance(space, tuple): self.vspacing = space[0] self.hspacing = space[1] else: self.vspacing = space self.hspacing = space def _getSpacing(self): return (self.vspacing, self.hspacing) spacing = property(_getSpacing, _setSpacing) def _setLayout(self, layout): if layout == 'vertical' or layout == 'Vertical' or layout == 'VERTICAL': self.real_widget.setLayout(fifechan.Container.Vertical) elif layout == 'horizontal' or layout == 'Horizontal' or layout == 'HORIZONTAL': self.real_widget.setLayout(fifechan.Container.Horizontal) elif layout == 'circular' or layout == 'Circular' or layout == 'CIRCULAR': self.real_widget.setLayout(fifechan.Container.Circular) elif layout == 'autosize' or layout == 'AutoSize' or layout == 'AUTOSIZE': self.real_widget.setLayout(fifechan.Container.AutoSize) else: self.real_widget.setLayout(fifechan.Container.Absolute) def _getLayout(self): if self.real_widget.getLayout() == fifechan.Container.Circular: return 'Circular' elif self.real_widget.getLayout() == fifechan.Container.Horizontal: return 'Horizontal' elif self.real_widget.getLayout() == fifechan.Container.Vertical: return 'Vertical' elif self.real_widget.getLayout() == fifechan.Container.AutoSize: return 'AutoSize' return 'Absolute' layout = property(_getLayout, _setLayout) def _setUniformSize(self, uniform): self.real_widget.setUniformSize(uniform) def _getUniformSize(self): return self.real_widget.isUniformSize() uniform_size = property(_getUniformSize, _setUniformSize) def _cloneChildren(self, prefix): """ Clones each child and return the clones in a list. """ cloneList = [child.clone(prefix) for child in self.children] return cloneList
class Panel(ResizableWindow): """ The Panel class can be docked or undocked from Dock Areas. If the Panel is added to a DockArea e.g. by XML loading, then it will automatically docked. By default undock will add the Panel to the parent of the DockArea, that can also be the top widget. New Attributes ============== - dockable: If true, the Panel can be docked/undocked to DockAreas. """ ATTRIBUTES = ResizableWindow.ATTRIBUTES + [ BoolAttr('dockable'), ] DEFAULT_DOCKABLE = 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, background_image=None, opaque=None, _real_widget=None, title=None, titlebar_height=None, movable=None, resizable=None, top_resizable=None, right_resizable=None, bottom_resizable=None, left_resizable=None, shove=None, cursors=None, dockable=None): if _real_widget is None: _real_widget = fifechan.Panel() super(Panel, 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, background_image=background_image, opaque=opaque, _real_widget=_real_widget, title=title, titlebar_height=titlebar_height, movable=movable, resizable=resizable, top_resizable=top_resizable, right_resizable=right_resizable, bottom_resizable=bottom_resizable, left_resizable=left_resizable, shove=shove, cursors=cursors) if dockable is not None: self.dockable = dockable else: self.dockable = self.DEFAULT_DOCKABLE self._foundDockArea = None self._barPressedLeft = False self._barPressedRight = False self._barReleasedLeft = False self._barReleasedRight = False self.capture(self.mousePressed, "mousePressed", "Panel") self.capture(self.mouseReleased, "mouseReleased", "Panel") self.capture(self.mouseDragged, "mouseDragged", "Panel") def clone(self, prefix): panelClone = Panel( 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.background_image, self.opaque, None, self.title, self.titlebar_height, self.movable, self.resizable, self.top_resizable, self.right_resizable, self.bottom_resizable, self.left_resizable, self.shove, self.cursors, self.dockable) panelClone.addChildren(self._cloneChildren(prefix)) return panelClone def _getDocked(self): return self.real_widget.isDocked() def _setDocked(self, docked): self.real_widget.setDocked(docked) docked = property(_getDocked, _setDocked) def _getDockable(self): return self.real_widget.isDockable() def _setDockable(self, dockable): self.real_widget.setDockable(dockable) dockable = property(_getDockable, _setDockable) def getDockArea(self): if not self.docked: dockAreas = [] # all top widgets are used for the search if not self.parent: topWidgets = get_manager().allTopHierachyWidgets for t in topWidgets: dockAreas.extend(t.findChildren(__class__=DockArea)) else: # only all childs are used for the search dockAreas = self.parent.findChildren(__class__=DockArea) # reverse order so inner/deeper Areas are preferred dockAreas.reverse() # try to find an intersecting and active DockArea dim = fife.Rect(0, 0, self.width, self.height) dim.x, dim.y = self.getAbsolutePos() for d in dockAreas: if d.real_widget.isActiveDockArea(): ddim = fife.Rect(0, 0, d.width, d.height) ddim.x, ddim.y = d.getAbsolutePos() if dim.intersects(ddim): return d return None else: return self.parent def afterDock(self): """ called after dockTo() process if the panel is docked overwrite this to e.g. keep a record on where the widget was last docked """ pass def afterUndock(self): """ called after undockTo() process if the panel is undocked overwrite and implement this in your Panel instance to e.g. restore a particular default position (otherwise the panel would re-appear on the center) """ pass def dockTo(self, widget): # Dock the Panel to the given widget. if not self.docked and widget is not self.parent and self.dockable: widget.real_widget.setHighlighted(False) # map coordinates to new parent and remove it from old parent if self.parent: self.x = (self.x // (self.parent.width // 100)) * (widget.width // 100) self.y = (self.y // (self.parent.height // 100)) * (widget.height // 100) self.parent.removeChild(self) else: self.x = (self.x // (get_manager().hook.screen_width // 100)) * ( widget.width // 100) self.y = (self.y // (get_manager().hook.screen_height // 100)) * ( widget.height // 100) get_manager().removeTopWidget(self) # dock it to new parent widget.addChild(self) self.docked = True self.afterDock() def undockTo(self, widget): # Undock the Panel to the given widget. if self.docked and widget is not self.parent and self.dockable: self.parent.removeChild(self) # undock to main gui if widget is None: get_manager().addTopWidget(self) else: widget.addChild(self) self.docked = False self.afterUndock() def mousePressed(self, event): h = self.real_widget.getBorderSize() + self.real_widget.getPaddingTop( ) + self.real_widget.getTitleBarHeight() self._barPressedLeft = event.getButton( ) == 1 and event.getY() <= h and event.getY( ) > self.real_widget.getResizableBorderDistance() self._barPressedRight = event.getButton( ) == 2 and event.getY() <= h and event.getY( ) > self.real_widget.getResizableBorderDistance() self._barReleasedLeft = False self._barReleasedRight = False def mouseReleased(self, event): h = self.real_widget.getBorderSize() + self.real_widget.getPaddingTop( ) + self.real_widget.getTitleBarHeight() self._barReleasedLeft = event.getButton( ) == 1 and event.getY() <= h and event.getY( ) > self.real_widget.getResizableBorderDistance() self._barReleasedRight = event.getButton( ) == 2 and event.getY() <= h and event.getY( ) > self.real_widget.getResizableBorderDistance() releasedLeft = self._barPressedLeft and self._barReleasedLeft releasedRight = self._barPressedRight and self._barReleasedRight self._barPressedLeft = False self._barPressedRight = False if releasedLeft and self._foundDockArea and not self.docked: self.dockTo(self._foundDockArea()) elif releasedRight and self.docked: # by default it undocks to the parent of the DockArea if self.parent.parent: newParent = self.parent.parent self.undockTo(newParent) else: self.undockTo(None) def mouseDragged(self, event): # disable highlighting if self._foundDockArea is not None: self._foundDockArea().real_widget.setHighlighted(False) self._foundDockArea = None if not self.docked and self._barPressedLeft: dock = self.getDockArea() # enable highlighting for dock area if dock is not None and dock.real_widget.isActiveDockArea(): self._foundDockArea = weakref.ref(dock) self._foundDockArea().real_widget.setHighlighted(True)
class Label(BasicTextWidget): """ A basic label - displaying a string. Also allows text wrapping and onMouse hover callbacks. New Attributes ============== - wrap_text: Boolean: Enable/Disable automatic text wrapping. Disabled by default. Currently to actually see text wrapping you have to explicitly set a max_size with the desired width of the text, as the layout engine is not capable of deriving the maximum width from a parent container. """ ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [BoolAttr('wrap_text')] DEFAULT_WRAP_TEXT = False 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, wrap_text=None): self.real_widget = fifechan.Label("") self.wrap_text = self.DEFAULT_WRAP_TEXT super(Label, 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) if wrap_text is not None: self.wrap_text = wrap_text def clone(self, prefix): lblClone = Label(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.wrap_text) return lblClone def _setTextWrapping(self, wrapping): self.real_widget.setTextWrapping(wrapping) def _getTextWrapping(self): self.real_widget.isTextWrapping() wrap_text = property(_getTextWrapping, _setTextWrapping)
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
class AnimationIcon(Widget): """ An animation icon. New Attributes ============== - animation: String : The source location of the Animation xml. - 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('animation'), BoolAttr('scale'), BoolAttr('tile'), BoolAttr('opaque'), BoolAttr('repeating'), BoolAttr('play') ] DEFAULT_MARGINS = 0, 0 DEFAULT_PADDING = 0 DEFAULT_SCALE = False DEFAULT_TILE = False DEFAULT_OPAQUE = False DEFAULT_REPEATING = True DEFAULT_PLAY = 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, animation=None, scale=None, tile=None, opaque=None, repeating=None, play=None): self.real_widget = fifechan.AnimationIcon() self._anim = None super(AnimationIcon, 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 animation can not be found, e.g. invalid path # the AnimationIcon is removed from the manager try: self.animation = animation except Exception: get_manager().removeWidget(self) raise if repeating is not None: self.repeating = repeating else: self.repeating = self.DEFAULT_REPEATING if play is not None: self.play = play else: self.play = self.DEFAULT_PLAY #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 = AnimationIcon( 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.animation, self.scale, self.tile, self.opaque, self.repeating, self.play) return iconClone def _setAnimation(self, anim): if anim is not None: if isinstance(anim, fife.Animation): self._anim = anim else: if anim is not "": # use xml loader self._anim = loadXMLAnimation(get_manager().hook.engine, anim) self.real_widget.setAnimation(self._anim) def _getAnimation(self): return self._anim animation = property(_getAnimation, _setAnimation) 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 _setRepeating(self, repeat): self.real_widget.setRepeating(repeat) def _getRepeating(self): return self.real_widget.isRepeating() repeating = property(_getRepeating, _setRepeating) def startPlaying(self): self.real_widget.play() def isPlaying(self): return self.real_widget.isPlaying() def pausePlaying(self): self.real_widget.pause() def stopPlaying(self): self.real_widget.stop() def _setPlaying(self, play): if play is True: self.startPlaying() else: self.stopPlaying() def _getPlaying(self): return self.isPlaying() play = property(_getPlaying, _setPlaying)
class Container(Widget): """ This is the basic container class. It provides space in which child widgets can be position via the position attribute. If you want to use the layout engine, you have to use derived containers with vertical or horizontal orientation (L{VBox} or L{HBox}) New Attributes ============== - padding - Integer: Not used in the Container class istelf, distance between child widgets. - background_image - Set this to a GuiImage or a resource location (simply a filename). The image will be tiled over the background area. - opaque - Boolean: Whether the background should be drawn at all. Set this to False to make the widget transparent. - children - Just contains the list of contained child widgets. Do NOT modify. """ ATTRIBUTES = Widget.ATTRIBUTES + [ IntAttr('padding'), Attr('background_image'), BoolAttr('opaque'), PointAttr('margins') ] DEFAULT_OPAQUE = True DEFAULT_MARGINS = 5, 5 DEFAULT_PADDING = 5 DEFAULT_BACKGROUND = None 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, padding=None, background_image=None, opaque=None, margins=None, _real_widget=None): self.real_widget = _real_widget or fifechan.Container() self.children = [] self.children_position_cache = [] self._background = [] self._background_image = None self.background_image = self.DEFAULT_BACKGROUND self.margins = self.DEFAULT_MARGINS self.padding = self.DEFAULT_PADDING self.opaque = self.DEFAULT_OPAQUE super(Container, 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 margins is not None: self.margins = margins if padding is not None: self.padding = padding if opaque is not None: self.opaque = opaque if background_image is not None: self.background_image = background_image def clone(self, prefix): containerClone = Container( 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.padding, self.background_image, self.opaque, self.margins) containerClone.addChildren(self._cloneChildren(prefix)) return containerClone def addChild(self, widget): """ Adds a child widget to the container. This makes the childs widgets visible state the same as the containers. i.e. if the containter is visible the child will be as well and if the container widget is hidden so will the child. The child however WILL be shown when you show the container widget. If you want the child to be hidden when you show the container widget you must call child.hide(). """ if isinstance(widget, Spacer): self.addSpacer(widget) return widget.parent = self if widget.max_size[0] > self.max_size[0] or widget.max_size[ 1] > self.max_size[1]: widget.max_size = self.max_size self.children.append(widget) self.children_position_cache.append(widget) self.real_widget.add(widget.real_widget) # add all to the manager def _add(added_widget): if not added_widget._added: get_manager().addWidget(added_widget) if added_widget._top_added: get_manager().removeTopWidget(added_widget) widget.deepApply(_add) def insertChild(self, widget, position): if position > len(self.children) or 0 - position > len(self.children): print "insertChild: Warning: Index overflow.", if position >= 0: self.addChild(widget) else: self.insertChild(widget, 0) return children = self.children[0:position] + [widget ] + self.children[position:] #assert len(children) == len(self.children) + 1 for child_to_remove in self.children[:]: self.removeChild(child_to_remove) for child in children: self.addChild(child) def insertChildBefore(self, widget, before): if before not in self.children: raise RuntimeError( "Couldn't find widget %s as child of %s - in insertChildBefore" % (str(widget), str(before))) self.insertChild(widget, self.children.index(before)) def removeChild(self, widget): if not widget in self.children: raise RuntimeError("%s does not have %s as direct child widget." % (str(self), str(widget))) if widget in self.children: self.children.remove(widget) self.real_widget.remove(widget.real_widget) if widget in self.children_position_cache: self.children_position_cache.remove(widget) widget.parent = None # remove all from the manager def _remove(removed_widget): if removed_widget._added: get_manager().removeWidget(removed_widget) if removed_widget._top_added: get_manager().removeTopWidget(removed_widget) widget.deepApply(_remove) def hideChild(self, child, free=False): # remove child from the manager if child._added: get_manager().removeWidget(child) if child._top_added: get_manager().removeTopWidget(child) # remove childs of the child from the manager def _hide(hidden_widget): get_manager().removeWidget(hidden_widget) child.deepApply(_hide) if child.isVisible() or child.isSetVisible(): # Hide real widget to distribute a widgetHidden event. child.real_widget.setVisible(False) if free: self.removeChild(child) self.adaptLayout() self.afterHide() def showChild(self, child): # add child to the manager if not child._added: get_manager().addWidget(child) # add childs of child to the manager def _show(shown_widget): get_manager().addWidget(shown_widget) child.deepApply(_show) child.beforeShow() if not child.isVisible() or not child.isSetVisible(): # Show real widget to distribute a widgetShown event. child.real_widget.setVisible(True) self.adaptLayout() def add(self, *widgets): print "PyChan: Deprecation warning: Please use 'addChild' or 'addChildren' instead." self.addChildren(*widgets) def getMaxChildrenWidth(self): if not self.children: return 0 w = 0 for widget in self.children: if not widget.real_widget.isVisible(): continue w = max(widget.width, w) return w def getMaxChildrenHeight(self): if not self.children: return 0 h = 0 for widget in self.children: if not widget.real_widget.isVisible(): continue h = max(widget.height, h) return h def deepApply(self, visitorFunc, leaves_first=True, shown_only=False): if not shown_only: children = self.children else: children = filter(lambda w: w.real_widget.isVisible(), self.children) if leaves_first: for child in children: child.deepApply(visitorFunc, leaves_first=leaves_first, shown_only=shown_only) visitorFunc(self) if not leaves_first: for child in children: child.deepApply(visitorFunc, leaves_first=leaves_first, shown_only=shown_only) def beforeShow(self): # This is required because beforeShow() is NOT called on nested # containers or child widgets. This ensures that background tiled # images are shown properly def _resetTilingChildren(widget): tilingMethod = getattr(widget, "_resetTiling", None) if callable(tilingMethod): tilingMethod() self.deepApply(_resetTilingChildren) self._resetTiling() def _resetTiling(self): image = self._background_image if image is None: return back_w, back_h = self.width, self.height map(self.real_widget.remove, self._background) # Now tile the background over the widget self._background = [] icon = fifechan.Icon(image) icon.setTiling(True) icon.setSize(back_w, back_h) self._background.append(icon) map(self.real_widget.add, self._background) icon.requestMoveToBottom() def setBackgroundImage(self, image): self._background = getattr(self, '_background', None) if image is None: self._background_image = None map(self.real_widget.remove, self._background) self._background = [] return # Background generation is done in _resetTiling if not isinstance(image, fife.GuiImage): image = get_manager().loadImage(image) self._background_image = image def getBackgroundImage(self): return self._background_image background_image = property(getBackgroundImage, setBackgroundImage) def _setOpaque(self, opaque): self.real_widget.setOpaque(opaque) def _getOpaque(self): return self.real_widget.isOpaque() opaque = property(_getOpaque, _setOpaque) def _cloneChildren(self, prefix): """ Clones each child and return the clones in a list. """ cloneList = [child.clone(prefix) for child in self.children] return cloneList