An event scheduler for asyncgui programs
Project description
Clock
Event scheduler designed for asyncgui programs.
import asyncgui
from asyncgui_ext.clock import Clock
clock = Clock()
async def async_fn():
await clock.sleep(20) # Waits for 20 time units
print("Hello")
asyncgui.start(async_fn())
clock.tick(10) # Advances the clock by 10 time units.
clock.tick(10) # Total of 20 time units. The task above will wake up, and prints 'Hello'.
The example above effectively illustrate how this module works but it's not practical.
In a real-world program, you probably want to call clock.tick()
in a loop or schedule it to be called repeatedly using another scheduling API.
For example, if you are using PyGame
, you may want to do:
pygame_clock = pygame.time.Clock()
clock = asyncgui_ext.clock.Clock()
# main loop
while running:
...
dt = pygame_clock.tick(fps)
clock.tick(dt)
And if you are using Kivy
, you may want to do:
from kivy.clock import Clock
clock = asyncui_ext.clock.Clock()
Clock.schedule_interval(clock.tick, 0)
Installation
Pin the minor version.
poetry add asyncgui-ext-clock@~0.5
pip install "asyncgui-ext-clock>=0.5,<0.6"
Tested on
- CPython 3.10
- CPython 3.11
- CPython 3.12
Misc
- YouTube Demo (with Kivy)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for asyncgui_ext_clock-0.5.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 511ebdfaf644f2f3e30b6c9656345c0781c994b0d63ce7b51dbd7a098a164a4e |
|
MD5 | 725fd08945647bae709a792faad5d13a |
|
BLAKE2b-256 | d98cb20636cd11fd44a23b6c9840d9cff58e916c6b95c241058dcc22ef465e18 |