From a4904d998faaf1a0f5729c9e17ba8724cd61b301 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 16 Feb 2020 14:30:45 +0100 Subject: [PATCH] [core] Use core.event to decouple main and output Make output act on events, not on concrete calls. --- bumblebee-status | 9 +++++---- core/output.py | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bumblebee-status b/bumblebee-status index 9526e62..112a704 100755 --- a/bumblebee-status +++ b/bumblebee-status @@ -10,6 +10,7 @@ import core.config import core.output import core.module import core.input +import core.event def handle_input(output): poll = select.poll() @@ -32,7 +33,7 @@ def handle_input(output): except ValueError: pass output.update(modules.keys()) - output.draw('statusline') + core.event.trigger('update') poll.unregister(sys.stdin.fileno()) @@ -55,12 +56,12 @@ def main(): for module in config.modules(): modules.append(core.module.load(module, config)) output.modules(modules) - output.draw('start') + core.event.trigger('start') while True: output.update() - output.draw('statusline') + core.event.trigger('update') output.wait(config.interval()) - output.draw('stop') + core.event.trigger('stop') if __name__ == "__main__": try: diff --git a/core/output.py b/core/output.py index 23b50e8..e90ba69 100644 --- a/core/output.py +++ b/core/output.py @@ -3,12 +3,16 @@ import json import time import core.theme +import core.event class i3(object): def __init__(self, theme=core.theme.Theme()): self._modules = [] self._status = {} self._theme = theme + core.event.register('start', self.draw, 'start') + core.event.register('update', self.draw, 'statusline') + core.event.register('stop', self.draw, 'stop') def modules(self, modules=None): if not modules: