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.
Parameter: | mode – The Mode object just popped from the manager |
---|
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.
Parameter: | mode – The Mode object popped from the stack |
---|
Push a mode to the top of the mode stack and make it active
Parameter: | mode – The Mode object to make active |
---|
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.
Parameter: | mode – The Mode object to remove from the manager. |
---|
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.
Parameter: | mode – The Mode object that was deactivated and replaced. |
---|
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.
Parameter: | dt (float) – The time delta since the last time step |
---|
Tick the mode’s clock.
Parameter: | dt (float) – The time delta since the last tick |
---|
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)
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 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.
Parameter: | loop (bool) – When activate_next() is called when the last submode is active, a True value for loop will cause the first submode to be activated. Otherwise the Multi is removed from its manager. |
---|---|
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.
Parameter: | loop (bool) – When activate_previous() is called when the first submode is active, a True value for loop will cause the last submode to be activated. Otherwise the Multi is removed from its manager. |
---|---|
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: |
|
---|
Remove the submode.
Parameter: | mode – The submode to remove, if omitted the active submode is removed. If the mode is not present, do nothing. If the mode is active, it is deactivated, and the next mode, if any is activated. If the last mode is removed, the Multi is removed from its manager. |
---|
Tick the active submode’s clock.
Parameter: | dt (float) – The time delta since the last tick |
---|