evts
—connect inputs with callbacks¶
-
evt_component_names
= {0: (), 1: ('button',), 2: ('neg', 'pos'), 4: ('left', 'right', 'up', 'down')}¶ {n_components: component_names}
for event components, giving a sequence of component names corresponding to their indices for an event’s number of components.
-
class
BaseEvent
[source]¶ Bases:
engine.evt.inputs.Input
Abstract event base class.
Subclasses must implement methods
Event.add()
,Event.rm()
, and eitherEvent.gen_cb_args()
orrespond()
.-
components
= 0¶ Like
Input.components
—the number of components the event can handle.
-
device
= 'evt'¶
-
eh
¶ Containing
EventHandler
, orNone
.
-
cb
(*cbs) → self[source]¶ Add any number of callbacks to
cbs
.For all event types, if a callback is determined not to be able to take arguments, it is not passed any.
-
respond
(changed)[source]¶ Handle inputs and call callbacks.
Parameters: changed – whether any inputs changed in any way. Called by the containing
EventHandler
, and guaranteed to be called every time the handler is updated (which should happen every frame).
-
inp_down
(i, component)[source]¶ Used by subclasses to handle
ButtonInput
instances.Parameters: - i – the calling input.
- component – the input’s component that has been toggled down.
-
inp_up
(i, component)[source]¶ Used by subclasses to handle
ButtonInput
instances.Parameters: - i – the calling input.
- component – the input’s component that has been toggled up.
-
-
class
Event
(*inps)[source]¶ Bases:
engine.evt.evts.BaseEvent
Connects inputs and callbacks.
Takes any number of inputs like
add()
.This event type calls callbacks with a single
pygame.event.Event
instance, once for each event gathered by the inputs.-
add
(*inps) → new_inputs[source]¶ Add inputs to this event.
Returns: a list of inputs that weren’t already registered with this event. Takes any number of inputs or
(input, evt_components = None, input_components = None)
tuples.evt_components
is a sequence of the component indices (or a single component index) of this event that this input provides data for. Defaults to every component, in order. Instead of indices, components can also be names fromevt_component_names
.input_components
is a sequence of the component indices of (or a single component index) of the input to match up toevt_components
. Defaults to every component of the input, in order.
If there is a mismatch in numbers of components,
ValueError
is raised.
-
rm
(*inps)[source]¶ Remove inputs from this event.
Takes any number of
Input
instances and ignores missing items.
-
gen_cb_args
(changed)[source]¶ Generate sets of arguments to call callbacks with.
Parameters: changed – whether any inputs changed in any way. This is implemented as an iterator, with each value a sequence of arguments to pass to each callback. Guaranteed to be called whenever
BaseEvent.respond()
is.
-
-
class
MultiEvent
(inps, *args, **kw)[source]¶ Bases:
engine.evt.evts.BaseEvent
Base class for generating multiples of
Event
subclasses.Parameters: - inps – a sequence of inputs as taken as arguments by
Event
. - args – positional arguments to pass to every sub-event on instantiation.
- kw – keyword arguments to pass to every sub-event.
Subclasses must define a
child
attribute giving the class that this is to be a multiple of, and amultiple
attribute giving the number of sub-events to wrap. They should take note of the behaviour ofgen_cb_args()
, possibly wrapping it.-
evts
= None¶ A list of sub-events, in order of the components they map to.
-
inputs
¶
-
eh
¶ Containing
EventHandler
, orNone
.
- inps – a sequence of inputs as taken as arguments by
-
class
Button
(*items[, initial_delay][, repeat_delay][, dbl_click_time])[source]¶ Bases:
engine.evt.evts.Event
,engine.evt.inputs.ButtonInput
Button event. Also acts as a
ButtonInput
.Parameters: - items – each item is either an input as taken by
Event
, or a button mode (one ofbmode.DOWN
,bmode.UP
,bmode.HELD
andbmode.REPEAT
) or a bitwise-OR of button modes. - initial_delay – if the
bmode.REPEAT
mode is given, this is the initial delay in seconds before a button starts repeating while held. - repeat_delay – like initial_delay, the time between repeats in seconds.
- dbl_click_time – if the
bmode.DBLCLICK
mode is given, this is the maximum delay in seconds between down events for a double-click event to be registered.
Callbacks are called with
{mode: count}
for eachmode
given, wherecount
is the number of occurrences of events corresponding to that mode that have happened within the last frame.The
count
forbmode.HELD
is only ever0
or1
, and indicates whether the button was held at the end of the frame.The
count
forbmode.REPEAT
may only be> 1
if either repeat rate is greater than the current framerate.The
count
forbmode.DBLCLICK
may only be> 1
if at least 3 down events are registered within a frame.-
name
= 'button'¶
-
components
= 1¶
-
modes
= None¶ A bitwise-OR of all button modes passed to the constructor.
-
initial_delay
= None¶ As passed to the constructor.
-
repeat_delay
= None¶ As passed to the constructor.
-
dbl_click_time
= None¶ As passed to the constructor.
- items – each item is either an input as taken by
-
class
Button2
(*items[, initial_delay][, repeat_delay][, dbl_click_time])[source]¶ Bases:
engine.evt.evts.MultiEvent
A 2-component version of
Button
.Callbacks are called with
(button, evts)
, wherebutton
is the button this applies to (0
or1
) andevts
is the argument passed byButton
.-
name
= 'button2'¶
-
multiple
= 2¶
-
-
class
Button4
(*items[, initial_delay][, repeat_delay][, dbl_click_time])[source]¶ Bases:
engine.evt.evts.Button2
A 4-component version of
Button
.Callbacks are called with
(axis, dirn, evts)
, where we treat the 4 buttons as being (left, up, right, down).axis
corresponds to the x or y axis (0
(left, right) or1
) anddirn
gives the button’s direction (-1
(left, up) or1
).evts
is the argument passed byButton
.-
name
= 'button4'¶
-
multiple
= 4¶
-
-
class
Axis
(*inps[, thresholds])[source]¶ Bases:
engine.evt.evts.Event
,engine.evt.inputs.AxisInput
Axis event. Also acts as an
AxisInput
.Parameters: The magnitude of the axis position for a button is
1
if it is held, else0
.Callbacks are called every frame with the current axis position (after summing over each registered input and restricting to
-1 <= x <= 1
).-
name
= 'axis'¶
-
components
= 2¶
-
-
class
Axis2
(*inps)[source]¶ Bases:
engine.evt.evts.MultiEvent
A double
Axis
.Callbacks are called every frame with a list of axis positions for each of the two axes.
-
name
= 'axis2'¶
-
multiple
= 2¶
-
-
class
RelAxis
(*inps[, bdy][, thresholds])[source]¶ Bases:
engine.evt.evts.Event
,engine.evt.inputs.RelAxisInput
Relative axis event. Also acts as a
RelAxisInput
.Parameters: - inps – inputs as taken by
Event
. - bdy – to act as an axis input, as taken by
RelAxisInput
. - thresholds – as taken by
AxisInput
.
Each input is scaled by a positive number (see
add()
for details).The magnitude of the relative position for an axis is its position, and for a button is
1
if it is held, else0
.Callbacks are called with the total, scaled relative change over all inputs registered with this event.
-
name
= 'relaxis'¶
-
components
= 2¶
- inps – inputs as taken by