42. gui.drawlock — A locking mechanism for the drawing functions.

42.1. Classes defined in module gui.drawlock

class gui.drawlock.DrawLock[source]

A timed lock to slow down drawing processes

wait()[source]

Wait for the drawing lock to be released.

This method can be called to wait until the lock is released, while still processing GUI events.

lock(time=None)[source]

Lock the drawing function for the next time seconds.

If a no time is specified, a global value is used.

block()[source]

Lock the drawing function indefinitely.

release()[source]

Release the lock on the drawing function.

If a timer is running, cancel it.

free()[source]

Release the lock and prevent waits until allow() is called.

allow()[source]

Allow draw waits.

This is called after a free() to reinstall the draw locking.

class gui.drawlock.Repeater(func, duration=-1, maxcount=-1, sleep=0)[source]

Repeatedly execute a function.

The Repeater class provides functionality to repeatedly execute a function, while allowing the GUI to process events so that user interactivity can continue. It also avoids using too much CPU time while running empty. The function can be repeated until one of the following conditions is met:

  • the called function returns a value that evaluates to True
  • a specified time has elapsed
  • a number of executions has been reached
  • and external event stops the execution

Parameters:

  • func: if callable, this function will be called repeatedly why the Repeater class is active. The function will be passed all the extra parameters *args and **kargs. If the function returns a value that does not evaluate to False, execution is halted.
  • duration: max duration for the repeated execution. If < 0, repeats indefinitely.
  • maxcount: max number of executions. If < 0, there is no limit.
  • sleep: extra time to sleep between two executions. The actual time between two executions may be higher, because any GUI events will also be executed. If your function does not do anything, setting a value > 0 is recommended to avoid high CPU usage while running idle.

Execution is started by calling the start() method. The method returns after some event has made it to stop, with an exitcode of:

  • 1, if the stop() method was used
  • 2, if a timeout occurred
  • 3, if the maximum number of excutions occurred,
  • or else, with the value returned by the function.
start(*args, **kargs)[source]

Start repeated execution

timeOut()[source]

Stop the repeater because of a timeout

stop(exitcode=1)[source]

Interrupt a repeater with given exitcode