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
clock = Clock()
async def async_fn():
await clock.sleep(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.3
pip install "asyncgui-ext-clock>=0.3,<0.4"
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
File details
Details for the file asyncgui_ext_clock-0.3.0.tar.gz
.
File metadata
- Download URL: asyncgui_ext_clock-0.3.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.4.0-182-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d5c3d6e521960570e507c6e42089b4243ff0cf7365a85f108d048f7222ee33e |
|
MD5 | 67424d74735fe71d856e36be1eec4800 |
|
BLAKE2b-256 | a56a24f84107d82802b5fb214c409ba6e61228571704df47670310dfef6e29a2 |
Provenance
File details
Details for the file asyncgui_ext_clock-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: asyncgui_ext_clock-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.4.0-182-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | efa14b2d1ddb33e31d34834f6161b8f2b972185c37850200d07c2a0b8f0378be |
|
MD5 | 36f9983791d1ddfef0076bd0d534ad84 |
|
BLAKE2b-256 | 6e657c1dc6a3d1f68f39338ee182527279729e8711234044d9751f0278205d13 |