listeners.tick package

Provides tick listener based functionality.

class listeners.tick.Delay(*args, **kwargs)[source]

Bases: 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.

args

Arguments to pass to the callback.

callback

Callback to call when the delay expired.

cancel_on_level_end

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

delay

Delay in seconds.

exec_time

Time when the delay will be executed.

kwargs

Keyword arguments to pass to the callback.

property running

Return True if the delay running.

Return type:

bool

property time_elapsed

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

Return type:

float

property time_remaining

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

Return type:

float

class listeners.tick.GameThread(*args, **kwargs)[source]

Bases: WeakAutoUnload, 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(*args, **kwargs)[source]

Bases: 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.

property adjusted_loops

Return the number of loops that have been adjusted.

Return type:

int

property delay_time_elapsed

Return the time elapsed in the current loop.

Return type:

float

property delay_time_remaining

Return the time remaining in the current loop.

Return type:

float

property interval

Return the interval in which the callback will be called.

Return type:

int

property loops_elapsed

Return the current number of loops made in the repeat.

Return type:

int

property loops_remaining

Return the remaining number of loops in the repeat.

Return type:

int

property original_loops

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

Return type:

int

property status

Return the status of the repeat.

Return type:

RepeatStatus

property total_loops

Return the total number of loops to be made.

Return type:

int

property total_time

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

Return type:

float

property total_time_elapsed

Return the elapsed time since the repeat started.

Return type:

float

property total_time_remaining

Return the remaining time till the end of the repeat.

Return type:

float

class listeners.tick.RepeatStatus(*values)[source]

Bases: IntEnum

Class used to store RepeatStatus values.

PAUSED = 3
RUNNING = 2
STOPPED = 1