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.

cancel()[source]

Cancel the delay.

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

Call the callback.

Returns:The result of 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: core.WeakAutoUnload, threading.Thread

A subclass of threading.Thread that throws a warning if the plugin that created the thread has been unloaded while the thread is still running.

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.

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.

PAUSED = <RepeatStatus.PAUSED: 3>
RUNNING = <RepeatStatus.RUNNING: 2>
STOPPED = <RepeatStatus.STOPPED: 1>