peng3d.gui.button - Button Widgets

class peng3d.gui.button.Button(name, submenu, window, peng, pos=None, size=None, bg=None, border=[4, 4], borderstyle=None, label='Button', min_size=None, font_size=None, font=None, font_color=None, label_layer=1)[source]

Button Widget allowing the user to trigger specific actions.

By default, this Widget uses ButtonBackground as its Background class.

The border given is in pixels from the left/right and top/bottom, respectively.

The borderstyle may be either flat, which has no border at all, gradient, which fades from the inner color to the background color, oldshadow, which uses a simple fake shadow with the light from the top-left corner and material, which imitates Google Material Design shadows.

Also, the label of the button may only be a single line of text, anything else may produce undocumented behavior.

If necessary, the font size of the Label may be changed via the global Constant LABEL_FONT_SIZE, changes will only apply to Buttons created after change. The text color used is [62,67,73,255] in RGBA and the font used is Arial, which should be available on most systems.

delete()[source]

Deletes resources of this widget that require manual cleanup.

Currently removes all actions, event handlers and the background.

The background itself should automatically remove all vertex lists to avoid visual artifacts.

Note that this method is currently experimental, as it seems to have a memory leak.

label

Property for accessing the label of this Button.

on_redraw()[source]

Draws the background and the widget itself.

Subclasses should use super() to call this method, or rendering may glitch out.

redraw_label()[source]

Re-draws the label by calculating its position.

Currently, the label will always be centered on the Button.

class peng3d.gui.button.ButtonBackground(widget, border=[4, 4], borderstyle='flat', batch=None, change_on_press=None)[source]

Background for the Button Widget.

This background renders the button and its border, but not the label.

addBorderstyle(name, func)[source]

Adds a borderstyle to the background object.

Note that borderstyles must be registered seperately for each background object.

name is the (string) name of the borderstyle.

func will be called with its arguments as (bg,o,i,s,h), see getColors() for more information.

getColors()[source]

Overrideable function that generates the colors to be used by various borderstyles.

Should return a 5-tuple of (bg,o,i,s,h).

bg is the base color of the background.

o is the outer color, it is usually the same as the background color.

i is the inner color, it is usually lighter than the background color.

s is the shadow color, it is usually quite a bit darker than the background.

h is the highlight color, it is usually quite a bit lighter than the background.

getPosSize()[source]

Helper function converting the actual widget position and size into a usable and offsetted form.

This function should return a 6-tuple of (sx,sy,x,y,bx,by) where sx and sy are the size, x and y the position and bx and by are the border size.

All values should be in pixels and already include all offsets, as they are used directly for generation of vertex data.

This method can also be overridden to limit the background to a specific part of its widget.

init_bg()[source]

Called just before the background will be drawn the first time.

Commonly used to initialize vertex lists.

It is recommended to add all vertex lists to the submenu.batch2d Batch to speed up rendering and preventing glitches with grouping.

is_hovering

Read-only helper property to be used by borderstyles for determining if the widget should be rendered as hovered or not.

Note that this property may not represent the actual hovering state, it will always be False if change_on_press is disabled.

pressed

Read-only helper property to be used by borderstyles for determining if the widget should be rendered as pressed or not.

Note that this property may not represent the actual pressed state, it will always be False if change_on_press is disabled.

redraw_bg()[source]

Method called by the parent widget every time its Widget.redraw() method is called.

class peng3d.gui.button.ImageButton(name, submenu, window, peng, pos=None, size=None, bg=None, label='Button', font_size=None, font=None, font_color=None, bg_idle=None, bg_hover=None, bg_disabled=None, bg_pressed=None, label_layer=1)[source]

Subclass of Button using an image as a background instead.

By default, this Widget uses ImageBackground as its Background class.

There are no changes to any other mechanics of the Button, only visually.

class peng3d.gui.button.ImageBackground(widget, bg_idle=None, bg_hover=None, bg_disabled=None, bg_pressed=None)[source]

Background for the ImageButton Widget.

This background renders a image given based on whether the widget is pressed, hovered over or disabled.

It should also be possible to use this class as a background for most other Widgets.

init_bg()[source]

Called just before the background will be drawn the first time.

Commonly used to initialize vertex lists.

It is recommended to add all vertex lists to the submenu.batch2d Batch to speed up rendering and preventing glitches with grouping.

pressed

Read-only helper property to be used by borderstyles for determining if the widget should be rendered as pressed or not.

Note that this property may not represent the actual pressed state, it will always be False if change_on_press is disabled.

redraw_bg()[source]

Method called by the parent widget every time its Widget.redraw() method is called.

class peng3d.gui.button.FramedImageButton(name, submenu, window, peng, pos=None, size=None, bg=None, label='Button', font_size=None, font=None, font_color=None, bg_idle=None, bg_hover=None, bg_disabled=None, bg_pressed=None, frame=[[2, 10, 2], [2, 10, 2]], scale=(1, 1), repeat_edge=False, repeat_center=False, tex_size=None, label_layer=1)[source]

Subclass of ImageButton adding smart scaling to the background.

By default, this Widget uses FramedImageBackground as its Background class.

frame defines the ratio between the borders and the center. The sum of each item must be greater than zero, else a ZeroDivisionError may be thrown. Note that up to two items of each frame may be left as 0. This will cause the appropriate border or center to not be rendered at all.

tex_size may be left empty if a resource name is passed. It will then be automatically determined.

Todo

Document scale

class peng3d.gui.button.FramedImageBackground(widget, bg_idle=None, bg_hover=None, bg_disabled=None, bg_pressed=None, frame=[[2, 10, 2], [2, 10, 2]], scale=(0, 0), repeat_edge=False, repeat_center=False, tex_size=None)[source]

Background for the FramedImageButton Widget.

This background is similar to ImageBackground, but it attempts to scale smarter with less artifacts.

init_bg()[source]

Called just before the background will be drawn the first time.

Commonly used to initialize vertex lists.

It is recommended to add all vertex lists to the submenu.batch2d Batch to speed up rendering and preventing glitches with grouping.

redraw_bg()[source]

Method called by the parent widget every time its Widget.redraw() method is called.

class peng3d.gui.button.ToggleButton(name, submenu, window, peng, pos=None, size=None, bg=None, border=[4, 4], borderstyle=None, label='Button', min_size=None, font_size=None, font=None, font_color=None, label_layer=1)[source]

Variant of Button that stays pressed until clicked again.

This widgets adds the following actions:

  • press_down is called upon depressing the button
  • press_up is called upon releasing the button
  • click is changed to be called on every click on the button, e.g. like press_down and press_up combined
class peng3d.gui.button.Checkbox(name, submenu, window, peng, pos=None, size=None, bg=None, borderstyle=None, label='Checkbox', checkcolor=[240, 119, 70], font_size=None, font=None, font_color=None, label_layer=1)[source]

Variant of ToggleButton using a different visual indicator.

By default, this Widget uses CheckboxBackground as its Background class.

Note that the position and size given are for the indicator, the label will be bigger than the given size.

The label given will be displayed to the right of the Checkbox.

redraw_label()[source]

Re-calculates the position of the Label.

class peng3d.gui.button.CheckboxBackground(widget, borderstyle, checkcolor=[240, 119, 70], **kwargs)[source]

Background for the Checkbox Widget.

This background looks like a button, but adds a square in the middle if it is pressed.

The color of the square defaults to a tone of orange commonly found in GTK GUIs on Ubuntu.

init_bg()[source]

Called just before the background will be drawn the first time.

Commonly used to initialize vertex lists.

It is recommended to add all vertex lists to the submenu.batch2d Batch to speed up rendering and preventing glitches with grouping.

redraw_bg()[source]

Method called by the parent widget every time its Widget.redraw() method is called.