Message pump
A MessagePump
is a base class for any object which processes messages, which includes Widget, Screen, and App.
Tip
Most of the method here are useful in general app development.
MessagePump
class
¶
Base class which supplies a message pump.
app
property
¶
Get the current app.
Returns
Type | Description |
---|---|
'App[object]'
|
The current app. |
Raises
Type | Description |
---|---|
NoActiveAppError
|
if no active app could be found for the current asyncio context |
is_running
property
¶
Is the message pump running (potentially processing messages)?
call_after_refresh
method
¶
Schedule a callback to run after all messages are processed and the screen has been refreshed. Positional and keyword arguments are passed to the callable.
Parameters
Name | Type | Description | Default |
---|---|---|---|
callback |
Callback
|
A callable. |
required |
Returns
Type | Description |
---|---|
bool
|
|
call_later
method
¶
Schedule a callback to run after all messages are processed in this object. Positional and keywords arguments are passed to the callable.
Parameters
Name | Type | Description | Default |
---|---|---|---|
callback |
Callback
|
Callable to call next. |
required |
*args |
Any
|
Positional arguments to pass to the callable. |
()
|
**kwargs |
Any
|
Keyword arguments to pass to the callable. |
{}
|
Returns
Type | Description |
---|---|
bool
|
|
call_next
method
¶
check_idle
method
¶
Prompt the message pump to call idle if the queue is empty.
check_message_enabled
method
¶
disable_messages
method
¶
Disable message types from being processed.
dispatch_key
async
¶
Dispatch a key event to method.
This method will call the method named 'key_
Parameters
Name | Type | Description | Default |
---|---|---|---|
event |
events.Key
|
A key event. |
required |
Returns
Type | Description |
---|---|
bool
|
True if key was handled, otherwise False. |
Raises
Type | Description |
---|---|
DuplicateKeyHandlers
|
When there's more than 1 handler that could handle this key. |
on_event
async
¶
post_message
method
¶
prevent
method
¶
set_interval
method
¶
Call a function at periodic intervals.
Parameters
Name | Type | Description | Default |
---|---|---|---|
interval |
float
|
Time between calls. |
required |
callback |
TimerCallback | None
|
Function to call. |
None
|
name |
str | None
|
Name of the timer object. |
None
|
repeat |
int
|
Number of times to repeat the call or 0 for continuous. |
0
|
pause |
bool
|
Start the timer paused. |
False
|
Returns
Type | Description |
---|---|
Timer
|
A timer object. |
set_timer
method
¶
Make a function call after a delay.
Parameters
Name | Type | Description | Default |
---|---|---|---|
delay |
float
|
Time to wait before invoking callback. |
required |
callback |
TimerCallback | None
|
Callback to call after time has expired. |
None
|
name |
str | None
|
Name of the timer (for debug). |
None
|
pause |
bool
|
Start timer paused. |
False
|
Returns
Type | Description |
---|---|
Timer
|
A timer object. |