def __init__(self, image, width, height, *args, **kwargs): Widget.__init__(self, width, height, *args, **kwargs) if image is None: self.image = pygame.Surface((0, 0)) else: self.setImage(image)
def __init__(self, width, height, *args, **kwargs): self.image = pygame.Surface((width, height)) Widget.__init__(self, width, height, *args, **kwargs) if 'background' in kwargs: background = kwargs['background'] else: background = (255, 255, 255) if 'border' in kwargs: border = kwargs['border'] else: border = None self.image.fill(background) if border is not None: pygame.draw.rect(self.image, border[1], self.rect, border[0]) self.widgets = [] initialWidgets = kwargs.pop('contents', []) for widget in initialWidgets: if type(widget) == type([]): self.add(*widget) else: self.add(widget)
def __init__(self, text, color=(0, 0, 0), background=(255, 255, 255), padding=(0, 0), width=None, height=None, **kwargs): Widget.__init__(self, 1, 1, **kwargs) self.color = color self.background = background self.text = text self.padding = padding self.width = width self.height = height self._render() self._dirty = False
def moveToBack(self): # move all child widgets to their appropriate layers in front of self widgets = self._getWidgetsByLayer() layers = widgets.keys() # sort the keys so that we proceed from highest layer to lowest layers.sort(reverse=True) for layer in layers: # move this first widget to the back firstWidget = widgets[layer][0] firstWidget.moveToBack() # move the remaining widgets in this layer to the same layer for widget in widgets[layer][1:]: widget.changeLayer(firstWidget.layer) Widget.moveToBack(self)
def __init__(self, width, *args, **kwargs): root = kwargs.get('root') # _progress ranges from 0 to width self._progress = 0 self._width = width # this is the number of pixels to adjust per progress % point self._progressPixelStep = width / 100.0 self._baseImage = root.getGameObject() \ .getSpriteSource('gui') \ .get(self.PROGRESS_SPRITE) self._prepImage() Widget.__init__(self, width, self.image.get_height(), *args, **kwargs)
def __init__(self, callback, *args, **kwargs): Widget.__init__(self, *args, **kwargs) BaseButton.__init__(self, callback)
def changeLayer(self, layer): Widget.changeLayer(self, layer) for widget in self.widgets: widget.updateLayer()
def kill(self): for widget in self.widgets: widget.kill() Widget.kill(self)
def hide(self): Widget.hide(self) for widget in self.widgets: widget.hide()
def show(self): Widget.show(self) for widget in self.widgets: widget.show()
def updateLayer(self): Widget.updateLayer(self) for widget in self.widgets: widget.updateLayer()
def update(self, *args): Widget.update(self, *args) if self._dirty: self._render() self._dirty = False
def __init__(self, sheetName, *args, **kwargs): root = kwargs.get('root') self.image = root.getGameObject().getSpriteSource('gui').get(sheetName) Widget.__init__(self, self.image.get_width(), self.image.get_height(), *args, **kwargs)