class documentation

class EventCallback:

Constructor: EventCallback(obj, cb, name)

View In Hierarchy

Encapsulates a callback and the calling of it. It handles these cases: * callback is None; do nothing * callback is async; create a task for it and run it on the event loop * callback is a regular function; call it synchronously on the next loop * caller has annotated with @to_thread; call it on threadpool Exceptions from the user callback are caught and logged. TODO: Also supports detection of args and kwargs as optional.??

Method __call__ How to actually call the callback. evt = EventCallback(...) evt() # or more explicitly, evt.call()
Method __init__ @param obj The object initiating the callback (e.g. a certain stage or sprite). Usually this doesn't change for the lifetime of the callback setting. @param cb The callback. May be a regular or async function, or None for no action...
Method clone Clone this handler to make a copy using the new object. Used during Sprite cloning to attach the same callbacks to the new object. Any existing tasks are not cloned.
Method name @return the name given to this callback, mostly for debugging
Method set Set/reset the callback to the given function 'cb'. If an existing previous callback is in progress, it is cancelled. @param cb A regular or async function. See class doc for details. May also be None.
Method _call_async Call an 'async' callback as an asyncio task. Returns immediately after the task is scheduled.
Method _call_noop Do nothing when callback is None
Method _call_sync Call the callback synchronously while handling exceptions. Ensures we're on the UI thread as a safety measure.
Method _call_threaded Kick the callback to a separate thread and treat that as the task.
Async Method _safe_call_async Wrapper for calling the async callback and doing the housekeeping of the tracked task when finished. This ensures it runs in the same slice as the callback, as opposed to using add_done_callback(), which posts it additionally and could run later.
Method _safe_call_sync Call the callback synchronously while handling exceptions
Instance Variable _cb Undocumented
Instance Variable _doCall Undocumented
Instance Variable _name Undocumented
Instance Variable _obj Undocumented
Instance Variable _task Undocumented
def __call__(self, *args):

How to actually call the callback. evt = EventCallback(...) evt() # or more explicitly, evt.call()

def __init__(self, obj, cb, name=''):

@param obj The object initiating the callback (e.g. a certain stage or sprite). Usually this doesn't change for the lifetime of the callback setting. @param cb The callback. May be a regular or async function, or None for no action. @param name Optional name used for debugging. If omitted, this will try to find the __name__ of the callback function.

def clone(self, newObj):

Clone this handler to make a copy using the new object. Used during Sprite cloning to attach the same callbacks to the new object. Any existing tasks are not cloned.

def name(self):

@return the name given to this callback, mostly for debugging

def set(self, cb):

Set/reset the callback to the given function 'cb'. If an existing previous callback is in progress, it is cancelled. @param cb A regular or async function. See class doc for details. May also be None.

def _call_async(self, *args):

Call an 'async' callback as an asyncio task. Returns immediately after the task is scheduled.

def _call_noop(self, *args):

Do nothing when callback is None

def _call_sync(self, *args):

Call the callback synchronously while handling exceptions. Ensures we're on the UI thread as a safety measure.

def _call_threaded(self, *args):

Kick the callback to a separate thread and treat that as the task.

async def _safe_call_async(self, *args):

Wrapper for calling the async callback and doing the housekeeping of the tracked task when finished. This ensures it runs in the same slice as the callback, as opposed to using add_done_callback(), which posts it additionally and could run later.

def _safe_call_sync(self, *args):

Call the callback synchronously while handling exceptions

_cb =

Undocumented

_doCall =

Undocumented

_name =

Undocumented

_obj =

Undocumented

_task =

Undocumented