Simple event library built on top of Blinker
Project description
Event Handling with Blink
Event handling library built on top of Blinker.
Why use it instead of blink
Pi-Blink is a different pardigm and a different way of handling events. So if Blink makes more sense then you should certainly use it. In the Pi-Blink paradigm events are created which can be listened, and modified, across your application.
Some other benefits are Priority-Based Event Handling: This script introduces the concept of event priorities, allowing you to specify the order in which event listeners should be executed. This can be useful when you have multiple listeners for the same event and need to control their execution sequence.
Installation
You can install pi-blink
via pip:
pip install pi-blink
Basic Usage
Import
from pi_blink import blink
Create an event to listen to. This can be a class or primitive though classes are encouraged.
class MathEvent:
def __init__(self, value: int):
self.value = value
Set up listeners for the event.
@blink.listener(MathEvent)
def add3(event: MathEvent):
event.value += 3
@blink.listener(MathEvent)
def multiply2(event: MathEvent):
event.value *= 2
Create and send an event
e = MathEvent(1)
blink.send(e)
assert e.value == 8
Examples
Basic Example
from pi_blink import blink
class EventA:
def __init__(self):
self.order = []
@blink.listener(EventA)
def handle_event_a1(event : EventA):
event.order.append("a1")
@blink.listener(EventA)
def handle_event_a2(event : EventA):
event.order.append("a2")
if __name__ == "__main__":
event_a = EventA()
blink.send(event_a)
assert event_a.order == ["a1", "a2"]
Basic Example with Priority
from pi_blink import blink
class EventA:
def __init__(self):
self.order = []
@blink.listener(EventA)
def handle_event_a1(event : EventA):
event.order.append("a1")
@blink.listener(EventA, EventPriority.EARLY)
def handle_event_a2(event : EventA):
event.order.append("a2")
if __name__ == "__main__":
event_a = EventA()
blink.send(event_a)
assert event_a.order == ["a2", "a1"]
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 pi_blink-1.0.3.tar.gz
.
File metadata
- Download URL: pi_blink-1.0.3.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.9 Darwin/23.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ab2fd78bb119c03378dbbc772e2d40adddffb0972ee8ed55ab18ec726d4989d |
|
MD5 | b697f0ba766f86c55dcd99790e57086a |
|
BLAKE2b-256 | fc1cebcb33f373922346c5570de6559a9600ac0c2a30f0621f399929434f755c |
File details
Details for the file pi_blink-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: pi_blink-1.0.3-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.9 Darwin/23.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81945de6566f65211aedad38f8d9c0319958e14a436bc4e544c2af6cca7e605e |
|
MD5 | 7255f53cc2bea8192aa78cf25f2e8f61 |
|
BLAKE2b-256 | 8538d2e0cebc3aab8875d1f89ebb3ee0b51b3e85b877f2c19d878a97d998491f |