tailwind #9

Manually merged
peperunas merged 157 commits from tailwind into master 2020-12-28 18:38:52 +00:00
Showing only changes of commit 8391cec49e - Show all commits

View File

@ -164,23 +164,37 @@ class EventHandler:
def __init__(self):
self.event_handlers = {}
self.state_handlers = {}
self.any_events = []
self.any_state = []
async def call_event(self, status: SymbolStatus, event: Event):
async def call_event(self, event: Event, status: SymbolStatus):
value = event.kind.value
if value in self.event_handlers:
for h in self.event_handlers[value]:
if inspect.iscoroutinefunction(h):
await h(status, event)
await h(event, status)
else:
h(status, event)
h(event, status)
async def call_state(self, status: SymbolStatus, pw: PositionWrapper):
if pw.state in self.state_handlers:
for h in self.state_handlers[pw.state]:
for h in self.any_events:
if inspect.iscoroutinefunction(h):
await h(event, status)
else:
h(event, status)
async def call_state(self, state: PositionState, status: SymbolStatus):
if state in self.state_handlers:
for h in self.state_handlers[state]:
if inspect.iscoroutinefunction(h):
await h(status, pw)
await h(status)
else:
h(status, pw)
h(status)
for h in self.any_state:
if inspect.iscoroutinefunction(h):
await h(status)
else:
h(status)
def on_event(self, kind: EventKind):
value = kind.value
@ -203,3 +217,15 @@ class EventHandler:
return handler
return registerhandler
def on_any_event(self):
def registerhandle(handler):
self.any_events.append(handler)
return handler
return registerhandle
def on_any_state(self):
def registerhandle(handler):
self.any_state.append(handler)
return handler
return registerhandle