peng3d.gui.layered - Layered Widgets¶
-
class
peng3d.gui.layered.LayeredWidget(name: Optional[str], submenu: SubMenu, window: Any = None, peng: Any = None, *, pos: Union[List[float], Callable[[float, float, float, float], Tuple[float, float]], layout.LayoutCell], size: Union[List[float], Callable[[float, float], Tuple[float, float]], None] = None, bg=None, layers=[])[source]¶ Layered Widget allowing for easy creation of custom widgets.
A Layered Widget consists of (nearly) any amount of layers in a specific order.
All Layers should be subclasses of
BasicWidgetLayerorWidgetLayer.layersmust be a list of 2-tuples of(layer,z_index).-
addLayer(layer, z_index=None)[source]¶ Adds the given layer at the given Z Index.
If
z_indexis not given, the Z Index specified by the layer will be used.
-
delete()[source]¶ Deletes all layers within this LayeredWidget before deleting itself.
Recommended to call if you are removing the widget, but not yet exiting the interpreter.
-
draw()[source]¶ Draws all layers of this LayeredWidget.
This should normally be unneccessary, since it is recommended that layers use Vertex Lists instead of OpenGL Immediate Mode.
-
getLayer(name)[source]¶ Returns the layer corresponding to the given name.
Raises: KeyError – If there is no Layer with the given name.
-
on_redraw()[source]¶ Draws the background and the widget itself.
Subclasses should use
super()to call this method, or rendering may glitch out.
-
redraw_layer(name)[source]¶ Redraws the given layer.
Raises: ValueError – If there is no Layer with the given name.
-
-
class
peng3d.gui.layered.BasicWidgetLayer(name, widget, z_index=None)[source]¶ Base class for all Layers to be used with
LayeredWidget().Not to be confused with
peng3d.layer.Layer(), these classes are not compatible.It is recommended to use
WidgetLayer()instead, since functionality is limited in this basic class.Note that the
z_indexwill default to a reasonable value for most subclasses and thus is not required to be given explicitly. Thez_indexfor this Layer defaults to0.-
delete()[source]¶ Deletes this Layer.
Currently only deletes VertexLists registered with
regVList().
-
draw()[source]¶ Called to draw the layer.
Note that using this function is discouraged, use Pyglet Vertex Lists instead.
If you want to call this method manually, call
_draw()instead. This will make sure thatpredraw()andpostdraw()are called.
-
on_redraw()[source]¶ Called by the parent widget if this Layer should be redrawn.
Note that it is recommended to call the Baseclass Variant of this Method first when overwriting it. See
WidgetLayer.on_redraw()for more information.
-
-
class
peng3d.gui.layered.WidgetLayer(name, widget, z_index=None, border=[0, 0], offset=[0, 0])[source]¶ Subclass of
WidgetLayer()adding commonly used utility features.This subclass adds a border and offset system.
The
borderis a 2-tuple of(x_border,y_border). The border is applied to all sides, resulting in the size being decreased by two pixel per pixel border width.offsetis relative to the bottom left corner of the screen.-
border¶ Property to be used for setting and getting the border of the layer.
Note that setting this property causes an immediate redraw.
-
getPos()[source]¶ Returns the absolute position and size of the layer.
This method is intended for use in vertex position calculation, as the border and offset have already been applied.
The returned value is a 4-tuple of
(sx,sy,ex,ey). The two values starting with an s are the “start” position, or the lower-left corner. The second pair of values signify the “end” position, or upper-right corner.
-
initialize()[source]¶ Called just before
on_redraw()is called the first time.
-
offset¶ Property to be used for setting and getting the offset of the layer.
Note that setting this property causes an immediate redraw.
-
on_redraw()[source]¶ Called when the Layer should be redrawn.
If a subclass uses the
initialize()Method, it is very important to also call the Super Class Method to prevent crashes.
-
-
class
peng3d.gui.layered.GroupWidgetLayer(name, widget, group=None, z_index=None, border=[0, 0], offset=[0, 0])[source]¶ Subclass of
WidgetLayer()allowing for using a pyglet group to manage OpenGL state.If no pyglet group is given,
pyglet.graphics.NullGroup()will be used.
-
class
peng3d.gui.layered.ImageWidgetLayer(name, widget, z_index=None, border=[0, 0], offset=[0, 0], img=[None, None])[source]¶ Subclass of
WidgetLayer()implementing a simple static image view.This layer can display any resource representable by the
ResourceManager().imgis a 2-tuple of(resource_name,category).The
z_indexfor this Layer defaults to1.-
initialize()[source]¶ Called just before
on_redraw()is called the first time.
-
on_redraw()[source]¶ Called when the Layer should be redrawn.
If a subclass uses the
initialize()Method, it is very important to also call the Super Class Method to prevent crashes.
-
-
class
peng3d.gui.layered.DynImageWidgetLayer(name, widget, z_index=None, border=[0, 0], offset=[0, 0], imgs={}, default=None)[source]¶ Subclass of
WidgetLayerallowing for dynamic images.imgsis a dictionary of names to 2-tuples of(resource_name,category).If no default image name is given, a semi-random one will be selected.
The
z_indexfor this Layer defaults to1.-
addImage(name, rsrc)[source]¶ Adds an image to the internal registry.
rsrcshould be a 2-tuple of(resource_name,category).
-
initialize()[source]¶ Called just before
on_redraw()is called the first time.
-
on_redraw()[source]¶ Called when the Layer should be redrawn.
If a subclass uses the
initialize()Method, it is very important to also call the Super Class Method to prevent crashes.
-
switchImage(name)[source]¶ Switches the active image to the given name.
Raises: ValueError – If there is no such image
-
-
class
peng3d.gui.layered.FramedImageWidgetLayer(name, widget, z_index=None, border=[0, 0], offset=[0, 0], imgs={}, default=None, frame=[[2, 10, 2], [2, 10, 2]], scale=(0, 0), repeat_edge=False, repeat_center=False, tex_size=None)[source]¶ Subclass of
DynImageWidgetLayerallowing for dynamically smart scaled images.Similar to
FramedImageButton. Allows for scaling and/or repeating the borders, corners and center independently.Note that the
tex_sizeparameter, if not given, will be derived from a random texture that has been given inimgs. Also note that theframe,scale,repeat_edgeandrepeat_centerparameters are identical for all images.-
initialize()[source]¶ Called just before
on_redraw()is called the first time.
-
on_redraw()[source]¶ Called when the Layer should be redrawn.
If a subclass uses the
initialize()Method, it is very important to also call the Super Class Method to prevent crashes.
-
-
class
peng3d.gui.layered.ImageButtonWidgetLayer(name, widget, z_index=None, border=[0, 0], offset=[0, 0], img_idle=None, img_pressed=None, img_hover=None, img_disabled=None)[source]¶ Subclass of
DynImageWidgetLayer()that acts like anImageButton().The
img_*arguments are of the same format as inDynImageWidgetLayer().This class internally uses the
BasicWidget.getState()method for getting the state of the widget.
-
class
peng3d.gui.layered.LabelWidgetLayer(name, widget, z_index=None, border=[0, 0], offset=[0, 0], label='', font_size=None, font=None, font_color=None, multiline=False, style=None)[source]¶ Subclass of
WidgetLayer()displaying arbitrary plain text.Note that this method internally uses a pyglet Label that is centered on the Layer.
The
z_indexfor this Layer defaults to2.-
label¶ Property for accessing the text of the label.
-
-
class
peng3d.gui.layered.FormattedLabelWidgetLayer(name, widget, z_index=None, border=[0, 0], offset=[0, 0], label='', font_size=None, font=None, font_color=None, multiline=False, style=None)[source]¶ Subclass of
WidgetLayer()serving as a base class for other formatted label layers.The Label Type can be set via the class attribute
cls, it should be set to any class that is compatible withpyglet.text.Label.It is recommended to use one of the subclasses of this class instead of this class directly.
The
z_indexfor this Layer defaults to2.-
label¶ Property for accessing the text of the label.
Note that depending on the type of format, this property may not exactly represent the original text as it is converted internally.
-
-
class
peng3d.gui.layered.HTMLLabelWidgetLayer(name, widget, z_index=None, border=[0, 0], offset=[0, 0], label='', font_size=None, font=None, font_color=None, multiline=False, style=None)[source]¶ Subclass of
FormattedLabelWidgetLayerimplementing a basic HTML Label.Note that not all tags are supported, see the docs for
pyglet.text.HTMLLabelfor details.
-
class
peng3d.gui.layered.BaseBorderWidgetLayer(name, widget, z_index=None, base_border=[0, 0], base_offset=[0, 0], border=[4, 4, 4, 4, 4, 4, 4, 4], style='flat', batch=None, change_on_press=None)[source]¶ Subclass of
WidgetLayerthat displays a basic border around the layer.Note that not all styles will look good with this class, see
ButtonBorderWidgetLayer()for more information.Note that the
borderandoffsetarguments have been renamed tobase_borderandbase_offsetto prevent naming conflicts.Subclasses may set the
n_verticesvalue to change the number of vertices orchange_on_pressto change the default value for the argument of the same name. By default, 36 vertices are used andchanged_on_pressis set toTrue.The
z_indexfor this Layer defaults to0.5.-
addStyle(name, func)[source]¶ Adds a style to the layer.
Note that styles must be registered seperately for each layer.
nameis the (string) name of the style.funcwill be called with its arguments as(bg,o,i,s,h), seegetColors()for more information.
-
genVertices()[source]¶ Called to generate the vertices used by this layer.
The length of the output of this method should be three times the
n_verticesattribute.See the source code of this method for more information about the order of the vertices.
-
getColors()[source]¶ Overrideable function that generates the colors to be used by various styles.
Should return a 5-tuple of
(bg,o,i,s,h).bgis the base color of the background.ois the outer color, it is usually the same as the background color.iis the inner color, it is usually lighter than the background color.sis the shadow color, it is usually quite a bit darker than the background.his the highlight color, it is usually quite a bit lighter than the background.The returned values may also be statically overridden by setting the
color_attribute to anything butNone.
-
initialize()[source]¶ Called just before
on_redraw()is called the first time.
-
is_hovering¶ Read-only helper property to be used by styles for determining if the layer 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_pressis disabled.
-
on_redraw()[source]¶ Called when the Layer should be redrawn.
If a subclass uses the
initialize()Method, it is very important to also call the Super Class Method to prevent crashes.
-
pressed¶ Read-only helper property to be used by styles for determining if the layer 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_pressis disabled.
-
-
class
peng3d.gui.layered.ButtonBorderWidgetLayer(name, widget, z_index=None, base_border=[0, 0], base_offset=[0, 0], border=[4, 4], style='flat', batch=None, change_on_press=None)[source]¶ Subclass of
BaseBorderWidgetLayer()implementing Button-Style borders.This class is based on the
ButtonBackgroundclass. This means that most styles are also available here and should look identical.Note that this class uses only 20 vertices and is thus not compatible with styles created for use with
BaseBorderWidgetLayer.Also note that the
borderargument also only receives two values instead of eight.