bumblebee-status/bumblebee-status
2020-04-26 10:34:25 +02:00

78 lines
2.1 KiB
Python
Executable file

#!/usr/bin/env python
import sys
import json
import select
import logging
import threading
import core.config
import core.output
import core.module
import core.input
import core.event
def handle_input(output):
poll = select.poll()
poll.register(sys.stdin.fileno(), select.POLLIN)
while True:
events = poll.poll()
modules = {}
for fileno, event in events:
line = '['
while line.startswith('['):
line = sys.stdin.readline().strip(',').strip()
logging.info('input event: {}'.format(line))
try:
event = json.loads(line)
core.input.trigger(event)
if 'name' in event:
modules[event['name']] = True
except ValueError:
pass
core.event.trigger('update', modules.keys())
core.event.trigger('draw')
poll.unregister(sys.stdin.fileno())
def main():
logging.basicConfig(
level=logging.DEBUG,
format="[%(asctime)s] %(module)-16s %(levelname)-8s %(message)s",
stream=sys.stderr
)
config = core.config.Config(sys.argv[1:])
theme = core.theme.Theme(config.theme(), config.iconset())
output = core.output.i3(theme, config)
modules = []
input_thread = threading.Thread(target=handle_input, args=(output,))
input_thread.daemon = True
input_thread.start()
for module in config.modules():
modules.append(core.module.load(module, config))
modules[-1].theme = theme # TODO: make this nice (ctor)
output.modules(modules)
core.event.trigger('start')
while True:
core.event.trigger('update')
core.event.trigger('draw')
output.wait(config.interval())
core.event.trigger('stop')
if __name__ == "__main__":
main()
try:
main()
except Exception as e:
output = core.output.i3()
output.modules(core.module.Error(module='main', error=e))
output.draw('start')
output.update()
output.draw('statusline')
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4