peng3d.gui
- 2D Widget based GUI System¶
-
class
peng3d.gui.
GUIMenu
(name: str, window: peng3d.window.PengWindow, peng: Any = None, font: Optional[str] = None, font_size: Optional[float] = None, font_color: Optional[List[int]] = None, borderstyle: Union[Type[Borderstyle], str, None] = None, style: Optional[Dict[str, Union[float, str, Type[Borderstyle]]]] = None)[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: peng3d.gui.SubMenu) → None[source]¶ Adds a
SubMenu
to this Menu.Note that nothing will be displayed unless a submenu is activated.
Deprecated since version 1.12.0: This method is no longer needed in most cases, since submenus now register themselves.
-
changeSubMenu
(submenu: str) → None[source]¶ Changes the submenu that is displayed.
Raises: ValueError – if the name was not previously registered
-
draw
() → None[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 callsLayer.on_menu_enter()
on every layer.
Property containing the
SubMenu
instance that is currently active.
-
-
class
peng3d.gui.
SubMenu
(name: str, menu: peng3d.gui.GUIMenu, window: Any = None, peng: Any = None, font: Optional[str] = None, font_size: Optional[float] = None, font_color: Optional[List[int]] = None, borderstyle: Union[Type[Borderstyle], str, None] = None, style: Optional[Dict[str, Union[float, str, Type[Borderstyle]]]] = None)[source]¶ Sub Menu of the GUI system.
Changed in version 1.12: Sub menus are automatically registered with their parent, using
addSubMenu()
is no longer necessary.Actions supported by default:
enter
is triggered everytime theon_enter()
method has been called.exit
is triggered everytime theon_exit()
method has been called.send_form
is triggered if the contained form is sent by either pressing enter or callingsend_form()
.-
addWidget
(widget: peng3d.gui.widgets.BasicWidget, order_key: int = 0) → None[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.Deprecated since version 1.12.0: This method is no longer needed in most cases, since widgets now register themselves by default.
-
delWidget
(widget: str) → None[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
() → None[source]¶ Draws the submenu and its background.
Note that this leaves the OpenGL state set to 2d drawing.
-
form_valid
(ctx=None) → bool[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: str) → peng3d.gui.widgets.BasicWidget[source]¶ Returns the widget with the given name.
-
send_form
(ctx=None) → bool[source]¶ Triggers whatever form data is entered to be sent.
Only causes action
send_form
to be sent if submenu is active andform_valid()
returns true.The given context is stored in
form_ctx
.Parameters: ctx – Arbitrary context Returns: If the form was actually sent
-
setBackground
(bg: Union[Layer, Callable, list, tuple, Background, str, Type[DEFER_BG]]) → None[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
andmaterial
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: str, menu: peng3d.menu.Menu, window: Optional[peng3d.window.PengWindow] = None, peng: Optional[peng3d.Peng] = None)[source]¶ Hybrid of
GUIMenu
andpeng3d.layer.Layer2D
.This class allows you to create Head-Up Displays and other overlays easily.