Package tdl :: Module event
[frames] | no frames]

Module event

source code

This module handles user input.

To handle user input you will likely want to use the event.get function or create a subclass of event.App.

But there are other options such as event.keyWait and event.isWindowClosed.

A few event attributes are actually string constants. Here's a reference for those:

Classes
  Event
Base Event class.
  Quit
Fired when the window is closed by the user.
  KeyEvent
  KeyDown
Fired when the user presses a key on the keyboard or a key repeats.
  KeyUp
Fired when the user releases a key on the keyboard.
  MouseButtonEvent
  MouseDown
Fired when a mouse button is pressed.
  MouseUp
Fired when a mouse button is released.
  MouseMotion
Fired when the mouse is moved.
  App
Application framework.
Functions
iterator
get()
Flushes the event queue and returns the list of events.
source code
Event or None
wait(timeout=None, flush=True)
Wait for an event.
source code
 
push(event)
Push an event into the event buffer.
source code
KeyDown
key_wait()
Waits until the user presses a key.
source code
 
set_key_repeat(delay=500, interval=0)
Change or disable key repeat.
source code
boolean
is_window_closed()
Returns True if the exit button on the window has been clicked and stays True afterwards.
source code
Function Details

get()

source code 

Flushes the event queue and returns the list of events.

This function returns Event objects that can be identified by their type attribute or their class.

Returns: iterator
Returns an iterable of objects derived from Event or anything put in a push call. If the iterator is deleted or otherwise interrupted before finishing the excess items are preserved for the next call.

wait(timeout=None, flush=True)

source code 

Wait for an event.

Parameters:
  • timeout (int or None) - The time in seconds that this function will wait before giving up and returning None.

    With the default value of None, this will block forever.

  • flush (boolean) - If True a call to tdl.flush will be made before listening for events.
Returns: Event or None
Returns an instance derived from Event, or None if the function has timed out. Anything added via push will also be returned.

Since: 1.4.0

push(event)

source code 

Push an event into the event buffer.

Parameters:
  • event (Event-like object) - The event will be available on the next call to event.get. An event pushed in the middle of a get will not show until the next time get called preventing push related infinite loops.

    This object should at least have a 'type' attribute.

key_wait()

source code 

Waits until the user presses a key. Then returns a KeyDown event.

Key events will repeat if held down.

A click to close the window will be converted into an Alt+F4 KeyDown event.

Returns: KeyDown

set_key_repeat(delay=500, interval=0)

source code 

Change or disable key repeat.

Parameters:
  • delay (int) - Milliseconds before a held key begins to repeat.

    Key repeat can be disabled entirely by setting a delay of zero.

  • interval (int) - Milliseconds between key repeats.

    An interval of zero will repeat every frame.