Modes manage the state and transition between different application modes. Typically such modes are presented as different screens that the user can navigate between, similar to the way a browser navigates web pages. Individual modes may be things like:
The modal framework provides a simple mechanism to ensure that modes are activated and deactivated properly. An activated mode is running and receives events. A deactivated mode is paused and does not receive events.
Modes may be managed as a last-in-first-out stack, or as a list, or ring of modes in sequence, or some combination of all.
For example usage see: the mode section of the tutorial.
Mode manager abstract base class.
The mode manager keeps a stack of modes where a single mode is active at one time. As modes are pushed on and popped from the stack, the mode at the top is always active. The current active mode receives events from the manager’s event dispatcher.
Hook executed when the last mode is popped from the manager. Implementing this method is optional for subclasses.
Parameters: |
|
---|
Pop the current mode off the top of the stack and deactivate it. The mode now at the top of the stack, if any is then activated.
Parameters: |
|
---|
Push a mode to the top of the mode stack and make it active
Parameters: |
|
---|
Remove the specified mode. If the mode is at the top of the stack, this is equivilent to pop_mode(). If not, no other modes are affected. If the mode is not in the manager, do nothing.
Parameters: |
|
---|
Exchange the specified mode with the mode at the top of the stack. This is similar to popping the current mode and pushing the specified one, but without activating the previous mode on the stack or executing on_last_mode_pop() if there is no previous mode.
Parameters: |
|
---|
pyglet.event.EventDispatcher object that the active mode receive events from.
The mode stack sequence. The last mode in the stack is the current active mode. Read-only.
A basic mode manager that wraps a single pyglet.event.EventDispatcher object for use by its modes.
An integrated mode manager and pyglet window for convenience. The window is the event dispatcher used by modes pushed to this manager.
Constructor arguments are identical to pyglet.window.Window
Application mode abstract base class
Subclasses must implement the step() method
Parameters: |
|
---|
Activate the mode for the given mode manager, if the mode is already active, do nothing
The default implementation schedules time steps at step_rate per second, sets the manager and sets the active flag to True.
Deactivate the mode, if the mode is not active, do nothing
The default implementation unschedules time steps for the mode and sets the active flag to False.
Execute a timestep for this mode. Must be defined by subclasses.
Parameters: |
|
---|
Tick the mode’s clock.
Parameters: |
|
---|
The pyglet.clock.Clock instance used as this mode’s clock. You should use this clock to schedule tasks for this mode, so they properly respect when the mode is active or inactive
Example:
my_mode.clock.schedule_once(my_cool_function, 4)
The BaseManager that manages this mode
A mode with multiple submodes. One submode is active at one time. Submodes can be switched to directly or switched in sequence. If the Multi is active, then one submode is always active.
Multis are useful when modes can switch in an order other than a LIFO stack, such as in “hotseat” multiplayer games, a “wizard” style ui, or a sequence of slides.
Note unlike a normal Mode, a Multi doesn’t have it’s own clock and step_rate. The active submode’s are used instead.
Activate the Multi for the specified manager. The previously active submode of the Multi is activated. If there is no previously active submode, then the first submode is made active. A Multi with no submodes cannot be activated
Activate the submode after the current submode in order. If there is no current submode, the first submode is activated.
Note if there is only one submode, it’s active, and loop is True (the default), then this method does nothing and the subnode remains active.
Parameters: |
|
---|---|
Returns: | The submode that was activated or None if there is no other submode to activate. |
Activate the submode before the current submode in order. If there is no current submode, the last submode is activated.
Note if there is only one submode, it’s active, and loop is True (the default), then this method does nothing and the subnode remains active.
Parameters: |
|
---|---|
Returns: | The submode that was activated or None if there is no other submode to activate. |
Activate the specified mode, adding it as a subnode if it is not already. If the mode is already the active submode, do nothing.
Parameters: |
|
---|
Add the submode, but do not make it active.
Parameters: |
|
---|
Deactivate the Multi for the specified manager. The active_submode, if any, is deactivated.
Remove the submode.
Parameters: |
|
---|
Tick the active submode’s clock.
Parameters: |
|
---|
The currently active submode