mirror of https://github.com/Desuuuu/klipper.git
klippy: Add a basic event dispatch mechanism
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
fedf90680e
commit
216905ceca
|
@ -58,6 +58,7 @@ class Printer:
|
|||
self.is_shutdown = False
|
||||
self.run_result = None
|
||||
self.state_cb = [gc.printer_state]
|
||||
self.event_handlers = {}
|
||||
def get_start_args(self):
|
||||
return self.start_args
|
||||
def get_reactor(self):
|
||||
|
@ -188,6 +189,10 @@ class Printer:
|
|||
def invoke_async_shutdown(self, msg):
|
||||
self.reactor.register_async_callback(
|
||||
(lambda e: self.invoke_shutdown(msg)))
|
||||
def register_event_handler(self, event, callback):
|
||||
self.event_handlers.setdefault(event, []).append(callback)
|
||||
def send_event(self, event, *params):
|
||||
return [cb(*params) for cb in self.event_handlers.get(event, [])]
|
||||
def request_exit(self, result):
|
||||
self.run_result = result
|
||||
self.reactor.end()
|
||||
|
|
Loading…
Reference in New Issue