[core] Use core.event to decouple main and output
Make output act on events, not on concrete calls.
This commit is contained in:
parent
c1df1686c1
commit
a4904d998f
2 changed files with 9 additions and 4 deletions
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue