No project description provided
Project description
Clock
An event scheduler designed for asyncgui programs.
First, take a look at the callback-style code below that has nothing to do with asyncgui
.
If you've ever used Kivy
or Pyglet
, you may find it familiar.
from asyncgui_ext.clock import Clock
clock = Clock()
# Schedules a function to be called after a delay of 20 time units.
clock.schedule_once(lambda dt: print("Hello"), 20)
# Advances the clock by 10 time units.
clock.tick(10)
# The clock advanced by a total of 20 time units.
# The callback function will be called.
clock.tick(10) # => Hello
Next one is async/await-style code that involves asyncgui
, and does the same thing as the previous.
import asyncgui
from asyncgui_ext.clock import Clock, sleep
clock = Clock()
async def async_fn():
await sleep(clock, 20)
print("Hello")
asyncgui.start(async_fn())
clock.tick(10)
clock.tick(10) # => Hello
These two examples effectively illustrate how this module works but they are 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:
clock = pygame.time.Clock()
vclock = asyncgui_ext.clock.Clock()
# main loop
while running:
...
dt = clock.tick(fps)
vclock.tick(dt)
And if you are using Kivy
, you may want to do:
from kivy.clock import Clock
vclock = asyncui_ext.clock.Clock()
Clock.schedule_interval(vclock.tick, 0)
Installation
Pin the minor version.
poetry add asyncgui-ext-clock@~0.2
pip install "asyncgui-ext-clock>=0.2,<0.3"
Tested on
- CPython 3.10
- CPython 3.11
- CPython 3.12
Misc
- YouTube Demo (with Kivy)
Project details
Release history Release notifications | RSS feed
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
Hashes for asyncgui_ext_clock-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d05665dc12b293d3ab54512231ee904b6dc312873cd52fd7c7f5f5ea6d223e3 |
|
MD5 | b02b39a45673d95cb11e321ba9c4528f |
|
BLAKE2b-256 | 6d972a1929c477f611a8ed148803c3f36505d0df800fa26c259306a86ba47eba |