simpleguics2pygame — timer

simpleguics2pygame module: simpleguics2pygame/timer.

Class Timer.

Don’t require Pygame.

Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame

license:GPLv3 — Copyright (C) 2015, 2020 Olivier Pirson
author:Olivier Pirson — http://www.opimedia.be/
version:May 20, 2020
class SimpleGUICS2Pygame.simpleguics2pygame.timer.Timer(interval, timer_handler)[source]

Timer similar to SimpleGUI Timer of CodeSkulptor.

Don’t require Pygame.

__init__(interval, timer_handler)[source]

Set a time.

Don’t use directly, use create_timer().

Parameters:
  • interval – int or float > 0
  • timer_handler – function () -> *
__repr__()[source]

Return ‘<Timer object>’.

Returns:str
__weakref__

list of weak references to the object (if defined)

classmethod _running_nb()[source]

Return the number of running timers.

Returns:int >= 0
classmethod _running_some()[source]
Returns:True if at least one timer running, else False
classmethod _stop_all()[source]

Stop all timers.

(Not available in SimpleGUI of CodeSkulptor.)

Side effect: Empty Timer._timers_running.

_timers_running = {}

Dict {(Timer id): Timer} of all timers are running.

get_interval()[source]

Return the interval of this timer.

(Maybe available in SimpleGUI of CodeSkulptor but not in CodeSkulptor documentation!)

Returns:(int or float) > 0
is_running()[source]

If this timer is running then return True, else return False.

Returns:bool
start()[source]

Start this timer.

Warning

With SimpleGUICS2Pygame, Frame.start() is blocking until Frame.stop() execution or closing window. So timers must be started before, and states must be initialized before. (Or maybe after by a handler function.)

(Side effect: Add id(self): self in Timer._timers_running.)

stop()[source]

Stop this timer.

(Side effect: Remove id(self) of Timer. _timers_running.)

SimpleGUICS2Pygame.simpleguics2pygame.timer.create_timer(interval, timer_handler)[source]

Create and return a timer that will execute the function timer_handler every interval milliseconds.

The first execution of time_handler will take place after the first period.

(The timer can be started by Timer.start().)

Parameters:
  • interval – int or float > 0
  • timer_handler – function () -> *
Returns:

Timer

SimpleGUICS2Pygame.simpleguics2pygame.timer.__all__ = ('Timer', 'create_timer')

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable’s items.

If the argument is a tuple, the return value is the same object.

[source]