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"]
Release files for pi-blink 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pi_blink-1.0.3.tar.gz | 6.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pi_blink-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.1 kB
Release files / pi_blink-1.0.3.tar.gz
| Download URL | pi_blink-1.0.3.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ab2fd78bb119c03378dbbc772e2d40adddffb0972ee8ed55ab18ec726d4989d
|
|
BLAKE2b-256 checksum How to use checksums |
fc1cebcb33f373922346c5570de6559a9600ac0c2a30f0621f399929434f755c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.11.9 Darwin/23.0.0
|
Release files / pi_blink-1.0.3-py3-none-any.whl
| Download URL | pi_blink-1.0.3-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
81945de6566f65211aedad38f8d9c0319958e14a436bc4e544c2af6cca7e605e
|
|
BLAKE2b-256 checksum How to use checksums |
8538d2e0cebc3aab8875d1f89ebb3ee0b51b3e85b877f2c19d878a97d998491f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.11.9 Darwin/23.0.0
|