listeners.tick package

Provides tick listener based functionality.

class listeners.tick.Delay(delay, callback, args=(), kwargs=None, cancel_on_level_end=False)[source]

Bases: core.WeakAutoUnload

Execute a callback after a given delay.

__init__(delay, callback, args=(), kwargs=None, cancel_on_level_end=False)[source]

Initialize the delay.

Parameters:
  • delay (float) – The delay in seconds.
  • callback – A callable object that should be called after the delay expired.
  • args (tuple) – Arguments that should be passed to the callback.
  • kwargs (dict) – Keyword arguments that should be passed to the callback.
  • cancel_on_level_end (bool) – Whether or not to cancel the delay at the end of the map.
Raises:

ValueError – Raised if the given callback is not callable.

_unload_instance()[source]
cancel()[source]

Cancel the delay.

Raises:ValueError – Raised if the delay is not running.
execute()[source]

Call the callback.

Returns:The result of callback.
args = None

Arguments to pass to the callback.

callback = None

Callback to call when the delay expired.

cancel_on_level_end = None

Whether or not to cancel the delay at the end of the map.

delay = None

Delay in seconds.

exec_time = None

Time when the delay will be executed.

kwargs = None

Keyword arguments to pass to the callback.

running

Return True if the delay running.

Return type:bool
time_elapsed

Return the amount of time (in seconds) since the Delay started.

Return type:float
time_remaining

Return the remaining time (in seconds) until the Delay ends.

Return type:float
class listeners.tick.GameThread(group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None)[source]

Bases: threading.Thread

Workaround for threading.Thread.

class listeners.tick.Repeat(callback, args=(), kwargs=None, cancel_on_level_end=False)[source]

Bases: core.AutoUnload

Class used to create and call repeats.

__init__(callback, args=(), kwargs=None, cancel_on_level_end=False)[source]

Store all instance attributes.

Parameters:
  • callback – A callable object that should be called at the end of each loop.
  • args (tuple) – Arguments that should be passed to the callback.
  • kwargs (dict) – Keyword arguments that should be passed to the callback.
  • cancel_on_level_end (bool) – Whether or not to cancel the repeat at the end of the map.
Raises:

ValueError – Raised if the given callback is not callable.

_execute()[source]

Execute the repeat’s callback with its arguments and keywords.

_unload_instance()[source]

Stop the repeat with being unloaded.

extend(adjustment)[source]

Add to the number of loops to be made.

Parameters:adjustment (int) – The number of loops to be added to the limit.
Raises:ValueError – Raised if given adjustment is not a positive integer.
pause()[source]

Pause the repeat.

Pausing allows the repeat to be resumed.

reduce(adjustment)[source]

Reduce the number of loops to be made.

Parameters:adjustment (int) – The number of loops to be removed from the limit.
Raises:ValueError – Raised if given adjustment is not a positive integer.
restart()[source]

Restart the repeat.

resume()[source]

Resume the repeat.

Can only resume if in paused status.

start(interval, limit=inf, execute_on_start=False)[source]

Start the repeat loop.

Parameters:
  • interval (float) – The time (in seconds) for each loop.
  • limit (int) – The maximum number of times to loop. If math.inf is passed, there is no limit, and the Repeat will loop indefinitely.
  • execute_on_start (bool) – Whether to execute the callback when the Repeat is started. Note that this does not affect the ‘limit’ as the number of loops will remain the same.
stop()[source]

Stop the repeat loop.

adjusted_loops

Return the number of loops that have been adjusted.

Return type:int
delay_time_elapsed

Return the time elapsed in the current loop.

Return type:float
delay_time_remaining

Return the time remaining in the current loop.

Return type:float
interval

Return the interval in which the callback will be called.

Return type:int
loops_elapsed

Return the current number of loops made in the repeat.

Return type:int
loops_remaining

Return the remaining number of loops in the repeat.

Return type:int
original_loops

Return the number of loops the repeat has been started with.

Return type:int
status

Return the status of the repeat.

Return type:RepeatStatus
total_loops

Return the total number of loops to be made.

Return type:int
total_time

Return the total time it will take to complete the repeat.

Return type:float
total_time_elapsed

Return the elapsed time since the repeat started.

Return type:float
total_time_remaining

Return the remaining time till the end of the repeat.

Return type:float
class listeners.tick.RepeatStatus[source]

Bases: enum.IntEnum

Class used to store RepeatStatus values.

_member_type_

alias of int

_generate_next_value_(name, start, count, last_values)
PAUSED = <RepeatStatus.PAUSED: 3>
RUNNING = <RepeatStatus.RUNNING: 2>
STOPPED = <RepeatStatus.STOPPED: 1>
_member_map_ = OrderedDict([('STOPPED', <RepeatStatus.STOPPED: 1>), ('RUNNING', <RepeatStatus.RUNNING: 2>), ('PAUSED', <RepeatStatus.PAUSED: 3>)])
_member_names_ = ['STOPPED', 'RUNNING', 'PAUSED']
_value2member_map_ = {1: <RepeatStatus.STOPPED: 1>, 2: <RepeatStatus.RUNNING: 2>, 3: <RepeatStatus.PAUSED: 3>}