peng3d.peng
- Main Engine class¶
-
class
peng3d.peng.
Peng
(cfg: Optional[peng3d.config.Config] = None, *, style: Optional[Dict[str, Union[float, str, Type[Borderstyle]]]] = None)[source]¶ This Class should only be instantiated once per application, if you want to use multiple windows, see
createWindow()
.An Instance of this class represents the whole Engine, with all accompanying state and window/world objects.
Be sure to keep your instance accessible, as it will be needed to create most other classes.
-
addEventListener
(event: str, func: Callable, raiseErrors: bool = False)[source]¶ Adds a handler to the given event.
A event may have an arbitrary amount of handlers, though assigning too many handlers may slow down event processing.
For the format of
event
, seesendEvent()
.func
is the handler which will be executed with two arguments,event_type
anddata
, as supplied tosendEvent()
.If
raiseErrors
is True, exceptions caused by the handler will be re-raised. Defaults toFalse
.
-
addPygletListener
(event_type: str, handler: Callable)[source]¶ Registers an event handler.
The specified callable handler will be called every time an event with the same
event_type
is encountered.All event arguments are passed as positional arguments.
This method should be used to listen for pyglet events. For new code, it is recommended to use
addEventListener()
instead.See
handleEvent()
for information about tunneled pyglet events.For custom events, use
addEventListener()
instead.
-
createWindow
(cls=window.PengWindow, *args, **kwargs)[source]¶ Creates a new window using the supplied
cls
.If
cls
is not given,peng3d.window.PengWindow()
will be used.Any other positional or keyword arguments are passed to the class constructor.
Note that this method currently does not support using multiple windows.
Todo
Implement having multiple windows.
-
delEventListener
(event: str, func: Callable)[source]¶ Removes the given handler from the given event.
If the event does not exist, a
NameError
is thrown.If the handler has not been registered previously, also a
NameError
will be thrown.
-
handleEvent
(event_type: str, args: Tuple, window: Optional[pyglet.window.Window] = None)¶ Handles a pyglet event.
This method is called by
PengWindow.dispatch_event()
and handles all events.See
registerEventHandler()
for how to listen to these events.This method should be used to send pyglet events. For new code, it is recommended to use
sendEvent()
instead. For “tunneling” pyglet events, use event names of the formatpyglet:<event>
and for the data use{"args":<args as list>,"window":<window object or none>,"src":<event source>,"event_type":<event type>}
Note that you should send pyglet events only via this method, the above event will be sent automatically.
Do not use this method to send custom events, use
sendEvent()
instead.
-
registerEventHandler
(event_type: str, handler: Callable)¶ Registers an event handler.
The specified callable handler will be called every time an event with the same
event_type
is encountered.All event arguments are passed as positional arguments.
This method should be used to listen for pyglet events. For new code, it is recommended to use
addEventListener()
instead.See
handleEvent()
for information about tunneled pyglet events.For custom events, use
addEventListener()
instead.
-
run
(evloop: Optional[pyglet.app.EventLoop] = None)[source]¶ Runs the application main loop.
This method is blocking and needs to be called from the main thread to avoid OpenGL bugs that can occur.
evloop
may optionally be a subclass ofpyglet.app.base.EventLoop
to replace the default event loop.
-
sendEvent
(event: str, data: Optional[dict] = None)[source]¶ Sends an event with attached data.
event
should be a string of format<namespace>:<category1>.<subcategory2>.<name>
. There may be an arbitrary amount of subcategories. Also note that this format is not strictly enforced, but rather recommended by convention.data
may be any Python Object, but it usually is a dictionary containing relevant parameters. For example, most built-in events use a dictionary containing at least thepeng
key set to an instance of this class.If there are no handlers for the event, a corresponding message will be printed to the log file. To prevent spam, the maximum amount of ignored messages can be configured via
events.maxignore
and defaults to 3.If the config value
debug.events.dumpfile
is a file path, the event type will be added to an internal list and be saved to the given file during program exit.
-
sendPygletEvent
(event_type: str, args: Tuple, window: Optional[pyglet.window.Window] = None)[source]¶ Handles a pyglet event.
This method is called by
PengWindow.dispatch_event()
and handles all events.See
registerEventHandler()
for how to listen to these events.This method should be used to send pyglet events. For new code, it is recommended to use
sendEvent()
instead. For “tunneling” pyglet events, use event names of the formatpyglet:<event>
and for the data use{"args":<args as list>,"window":<window object or none>,"src":<event source>,"event_type":<event type>}
Note that you should send pyglet events only via this method, the above event will be sent automatically.
Do not use this method to send custom events, use
sendEvent()
instead.
-
-
class
peng3d.peng.
HeadlessPeng
(cfg: Union[dict, peng3d.config.Config, None] = None)[source]¶ Variant of peng that should work without having pyglet installed.
This class is intended for use in servers as a drop-in replacement for the normal engine class.
Note that this class is a work in progress and should not yet be relied upon.