https://github.com/asyncgui/asyncgui-ext-clock
Event Scheduler
https://github.com/asyncgui/asyncgui-ext-clock
async
Last synced: about 1 year ago
JSON representation
Event Scheduler
- Host: GitHub
- URL: https://github.com/asyncgui/asyncgui-ext-clock
- Owner: asyncgui
- License: mit
- Created: 2024-01-19T07:59:28.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-09T15:21:22.000Z (over 1 year ago)
- Last Synced: 2024-11-10T12:52:06.524Z (over 1 year ago)
- Topics: async
- Language: Python
- Homepage: https://asyncgui.github.io/asyncgui-ext-clock/
- Size: 570 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Clock
*Event scheduler designed for asyncgui programs.*
```python
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:
```python
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:
```python
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
- CPython 3.13
- PyPy 3.10
## Misc
- [YouTube Demo](https://youtu.be/kPVzO8fF0yg) (with Kivy)