peng3d.gui - 2D Widget based GUI System

class peng3d.gui.GUIMenu(name, window, peng, font='Arial', font_size=16, font_color=[62, 67, 73, 255], borderstyle='flat')[source]

peng3d.menu.Menu subclass adding 2D GUI Support.

Note that widgets are not managed directly by this class, but rather by each SubMenu.

addSubMenu(submenu)[source]

Adds a SubMenu to this Menu.

Note that nothing will be displayed unless a submenu is activated.

changeSubMenu(submenu)[source]

Changes the submenu that is displayed.

Raises:ValueError – if the name was not previously registered
draw()[source]

Draws each menu layer and the active submenu.

Note that the layers are drawn first and may be overridden by the submenu and widgets.

on_enter(old)[source]

Same as BasicMenu.on_enter(), but also calls Layer.on_menu_enter() on every layer.

submenu

Property containing the SubMenu instance that is currently active.

class peng3d.gui.SubMenu(name, menu, window, peng, font=None, font_size=None, font_color=None, borderstyle=None)[source]

Sub Menu of the GUI system.

Each instance must be registered with their menu to work properly, see GUIMenu.addSubMenu().

Actions supported by default:

enter is triggered everytime the on_enter() method has been called.

exit is triggered everytime the on_exit() method has been called.

send_form is triggered if the contained form is sent by either pressing enter or calling send_form().

addWidget(widget, order_key=0)[source]

Adds a widget to this submenu.

order_key optionally specifies the “layer” this widget will be on. Note that this does not work with batched widgets. All batched widgets will be drawn before widgets that use a custom draw() method.

delWidget(widget)[source]

Deletes the widget by the given name.

Note that this feature is currently experimental as there seems to be a memory leak with this method.

draw()[source]

Draws the submenu and its background.

Note that this leaves the OpenGL state set to 2d drawing.

form_valid(ctx=None)[source]

Called to pre-check if a form is valid.

Should be overridden by subclasses.

By default, this always returns true.

Parameters:ctx – Arbitrary context
Returns:If the form is valid
getWidget(name)[source]

Returns the widget with the given name.

send_form(ctx=None)[source]

Triggers whatever form data is entered to be sent.

Only causes action send_form to be sent if submenu is active and form_valid() returns true.

The given context is stored in form_ctx.

Parameters:ctx – Arbitrary context
Returns:If the form was actually sent
setBackground(bg)[source]

Sets the background of the submenu.

The background may be a RGB or RGBA color to fill the background with.

Alternatively, a peng3d.layer.Layer instance or other object with a .draw() method may be supplied. It is also possible to supply any other method or function that will get called.

Also, the strings flat, gradient, oldshadow and material may be given, resulting in a background that looks similar to buttons.

If the Background is None, the default background of the parent menu will be used.

Lastly, the string "blank" may be passed to skip background drawing.

class peng3d.gui.GUILayer(name, menu, window, peng)[source]

Hybrid of GUIMenu and peng3d.layer.Layer2D.

This class allows you to create Head-Up Displays and other overlays easily.

draw()[source]

Draws the Menu.