bumblebee-status/bumblebee-status

91 lines
2.4 KiB
Text
Raw Normal View History

#!/usr/bin/env python
import os
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 20:11:02 +02:00
core.event.trigger('update', modules.keys())
core.event.trigger('draw')
poll.unregister(sys.stdin.fileno())
def main():
config = core.config.Config(sys.argv[1:])
level = logging.DEBUG if config.debug() else logging.ERROR
if config.logfile():
logging.basicConfig(
level=level,
format="[%(asctime)s] %(module)-16s %(levelname)-8s %(message)s",
filename=os.path.abspath(os.path.expanduser(config.logfile()))
)
else:
logging.basicConfig(
level=level,
format="[%(asctime)s] %(module)-16s %(levelname)-8s %(message)s",
stream=sys.stderr
)
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()
if config.debug():
modules.append(core.module.load('debug', config, theme))
for module in config.modules():
2020-04-26 16:40:48 +02:00
modules.append(core.module.load(module, config, theme))
output.modules(modules)
core.event.trigger('start')
while True:
core.event.trigger('update')
2020-04-12 20:11:02 +02:00
core.event.trigger('draw')
output.wait(config.interval())
core.event.trigger('stop')
if __name__ == "__main__":
2020-04-28 20:25:28 +02:00
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