bumblebee-status/bumblebee-status

78 lines
2 KiB
Text
Raw Normal View History

#!/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
2020-04-12 14:44:34 +02:00
core.event.trigger('update-modules', modules.keys())
core.event.trigger('update')
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))
output.modules(modules)
core.event.trigger('start')
while True:
output.update()
core.event.trigger('update')
output.wait(config.interval())
core.event.trigger('stop')
if __name__ == "__main__":
main()
try:
main()
except Exception as e:
output = core.output.i3()
2020-03-28 13:44:45 +01:00
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