國人wqking開發,支持Python 3和Cython。
eventpy是一個 Python 事件庫,它提供的工具允許應用程式組件通過調度事件并監聽它們來相互通信。使用eventpy,您可以非常輕松地實作信號/插槽機制或觀察者模式。
GitHub:https://github.com/wqking/eventpy
特性
支持同步事件調度和異步事件佇列。
可配置和可擴展的策略。
支持嵌套事件。在處理事件期間,偵聽器可以安全地調度事件,追加/預置/插入/洗掉其他偵聽器。
執行緒安全。支持多執行緒。
用大量單元測驗來保證質量。
靈活易用。
偵聽器和事件可以是任何型別,不需要從任何基類繼承。
Version:0.0.1
???????License:Apache License Version 2.0
GitHub:https://github.com/wqking/eventpy
使用 CallbackList
# create a CallbackList
callbackList = CallbackList()
callbackList.append(lambda s, b : print("Got callback 1, s is %s b is %d" % (s, b)))
def anotherCallback(s, b) :
print("Got callback 2, s is %s b is %d" % (s, b))
callbackList.append(anotherCallback)
# Invoke the callback list
callbackList("Hello world", True)
使用 EventDispatcher
# create an EventDispatcher
dispatcher = EventDispatcher()
dispatcher.appendListener(3, lambda s, b : print("Got event 3, s is %s b is %d" % (s, b)))
dispatcher.appendListener(5, lambda s, b : print("Got event 5, s is %s b is %d" % (s, b)))
dispatcher.appendListener(5, lambda s, b : print("Got another event 5, s is %s b is %d" % (s, b)))
# Dispatch the events, the first argument is always the event type.
dispatcher.dispatch(3, "Hello", True)
dispatcher.dispatch(5, "World", False)
使用 EventQueue
# create an EventQueue
queue = eventqueue.EventQueue()
queue.appendListener(3, lambda s, n : print("Got event 3, s is %s n is %d" % (s, n)))
queue.appendListener(5, lambda s, n : print("Got event 5, s is %s n is %d" % (s, n)))
queue.appendListener(5, lambda s, n : print("Got another event 5, s is %s n is %d" % (s, n)))
# Enqueue the events, the first argument is always the event type.
# The listeners are not triggered during enqueue.
queue.enqueue(3, "Hello", 38)
queue.enqueue(5, "World", 58)
# Process the event queue, dispatch all queued events.
queue.process();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/92295.html
上一篇:python設計的程式如何采集電路中光敏傳感器資料并上傳至服務器進行實時監控
下一篇:Justin the ITer | Come to Ask about What Computer Language is the Best for Me
