Have c# event handler
Project description
Event-Driven Framework
Overview
This package provides a flexible event-driven mechanism designed for applications requiring custom event handling. At its core is the EventListener class, which allows you to easily subscribe, unsubscribe, and invoke listeners (callbacks). This class is particularly suited for event-driven architectures such as GUI applications, asynchronous programming, and custom event handling in various types of software.
Key Features
- Event Subscription: Easily subscribe single or multiple callbacks to events.
- Event Invocation: Trigger all registered listeners with specified arguments.
- Listener Management: Unsubscribe listeners individually or clear all listeners at once.
- Safe Execution: Ensures that all listeners are invoked safely.
Installation
To install the package, simply run:
pip install event_listener
Usage
Basic Example
from event_listener import EventListener
# Create an event listener instance
event = EventListener(name="SampleEvent")
# Define some example callback functions
def on_event_fired(arg1, arg2):
print(f"Event fired with arguments: {arg1}, {arg2}")
def on_event_fired_again(arg1, arg2):
print(f"Event fired again with arguments: {arg1}, {arg2}")
# Subscribe the callbacks to the event
event.subscribe(on_event_fired)
event.subscribe(on_event_fired_again)
# Invoke the event with some arguments
event.invoke("Hello", "World")
# Output:
# Event fired with arguments: Hello, World
# Event fired again with arguments: Hello, World
# Clear all listeners
event.clear()
# Or unsubscribe a specific listener
event.unsubscribe(on_event_fired)
Async listener
from event_listener import EventListenerAsync
# Create an event listener instance
event = EventListenerAsync(name="SampleEvent")
# Define some example callback functions
def on_event_fired(arg1, arg2):
print(f"Event fired with arguments: {arg1}, {arg2}")
def on_event_fired_again(arg1, arg2):
print(f"Event fired again with arguments: {arg1}, {arg2}")
# Subscribe the callbacks to the event
event.subscribe(on_event_fired)
event.subscribe(on_event_fired_again)
# Invoke will call every method in separate threads.
event.invoke_async("Hello", "World")
License This project is licensed under the MIT License. See the LICENSE file for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file event-listener-sharp-0.1.0.tar.gz.
File metadata
- Download URL: event-listener-sharp-0.1.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aaa834f63aca76b0206e86ad80513a41d8428ca141c9a8a3d2eb7296de4b1c81
|
|
| MD5 |
9010b8662815616180bc5e96d92598fb
|
|
| BLAKE2b-256 |
19f47d72a84dbd0b74a6f5035657732fde7c140b29af9618fac16b4856b4b362
|
File details
Details for the file event_listener_sharp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: event_listener_sharp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d94b8d3a12ffd0ef4525fb67a5c8a6f59fbf2f182d60e3a20b16352ce3928fa
|
|
| MD5 |
b8e6a89cfbcae893132abcc810c4e0bf
|
|
| BLAKE2b-256 |
3cd2f6dab89cc71d72860e1c72f9fefbe1b24f16d5a404e1f12e5420da86fa8b
|