[core] Use core.event to decouple main and output

Make output act on events, not on concrete calls.
This commit is contained in:
Tobias Witek 2020-02-16 14:30:45 +01:00
parent c1df1686c1
commit a4904d998f
2 changed files with 9 additions and 4 deletions

View file

@ -10,6 +10,7 @@ import core.config
import core.output import core.output
import core.module import core.module
import core.input import core.input
import core.event
def handle_input(output): def handle_input(output):
poll = select.poll() poll = select.poll()
@ -32,7 +33,7 @@ def handle_input(output):
except ValueError: except ValueError:
pass pass
output.update(modules.keys()) output.update(modules.keys())
output.draw('statusline') core.event.trigger('update')
poll.unregister(sys.stdin.fileno()) poll.unregister(sys.stdin.fileno())
@ -55,12 +56,12 @@ def main():
for module in config.modules(): for module in config.modules():
modules.append(core.module.load(module, config)) modules.append(core.module.load(module, config))
output.modules(modules) output.modules(modules)
output.draw('start') core.event.trigger('start')
while True: while True:
output.update() output.update()
output.draw('statusline') core.event.trigger('update')
output.wait(config.interval()) output.wait(config.interval())
output.draw('stop') core.event.trigger('stop')
if __name__ == "__main__": if __name__ == "__main__":
try: try:

View file

@ -3,12 +3,16 @@ import json
import time import time
import core.theme import core.theme
import core.event
class i3(object): class i3(object):
def __init__(self, theme=core.theme.Theme()): def __init__(self, theme=core.theme.Theme()):
self._modules = [] self._modules = []
self._status = {} self._status = {}
self._theme = theme 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): def modules(self, modules=None):
if not modules: if not modules: