2016-12-04 08:37:01 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import sys
|
2020-02-08 13:56:52 +01:00
|
|
|
import json
|
|
|
|
import select
|
|
|
|
import logging
|
|
|
|
import threading
|
|
|
|
|
2020-01-19 15:36:52 +01:00
|
|
|
import core.config
|
2020-01-19 13:29:34 +01:00
|
|
|
import core.output
|
2020-02-01 21:37:38 +01:00
|
|
|
import core.module
|
2020-02-08 13:56:52 +01:00
|
|
|
import core.input
|
2020-02-16 14:30:45 +01:00
|
|
|
import core.event
|
2020-02-08 13:56:52 +01:00
|
|
|
|
2020-02-08 14:22:43 +01:00
|
|
|
def handle_input(output):
|
2020-02-08 13:56:52 +01:00
|
|
|
poll = select.poll()
|
|
|
|
poll.register(sys.stdin.fileno(), select.POLLIN)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
events = poll.poll()
|
|
|
|
|
2020-02-08 14:22:43 +01:00
|
|
|
modules = {}
|
2020-02-08 13:56:52 +01:00
|
|
|
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)
|
2020-02-08 14:22:43 +01:00
|
|
|
if 'name' in event:
|
|
|
|
modules[event['name']] = True
|
2020-02-08 13:56:52 +01:00
|
|
|
except ValueError:
|
|
|
|
pass
|
2020-04-12 14:44:34 +02:00
|
|
|
core.event.trigger('update-modules', modules.keys())
|
2020-02-16 14:30:45 +01:00
|
|
|
core.event.trigger('update')
|
2020-02-08 13:56:52 +01:00
|
|
|
|
|
|
|
poll.unregister(sys.stdin.fileno())
|
2017-09-16 12:22:20 +02:00
|
|
|
|
2016-12-04 08:37:01 +01:00
|
|
|
def main():
|
2020-02-08 13:56:52 +01:00
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.DEBUG,
|
|
|
|
format="[%(asctime)s] %(module)-16s %(levelname)-8s %(message)s",
|
|
|
|
stream=sys.stderr
|
|
|
|
)
|
|
|
|
|
2020-01-19 15:36:52 +01:00
|
|
|
config = core.config.Config(sys.argv[1:])
|
2020-02-09 13:46:56 +01:00
|
|
|
theme = core.theme.Theme(config.theme(), config.iconset())
|
2020-03-01 14:08:16 +01:00
|
|
|
output = core.output.i3(theme, config)
|
2020-01-19 13:29:34 +01:00
|
|
|
modules = []
|
2020-02-08 13:56:52 +01:00
|
|
|
|
2020-02-08 14:22:43 +01:00
|
|
|
input_thread = threading.Thread(target=handle_input, args=(output,))
|
2020-02-08 13:56:52 +01:00
|
|
|
input_thread.daemon = True
|
|
|
|
input_thread.start()
|
|
|
|
|
2020-01-19 15:36:52 +01:00
|
|
|
for module in config.modules():
|
2020-02-03 21:30:06 +01:00
|
|
|
modules.append(core.module.load(module, config))
|
2020-02-02 14:18:13 +01:00
|
|
|
output.modules(modules)
|
2020-02-16 14:30:45 +01:00
|
|
|
core.event.trigger('start')
|
2020-01-19 13:29:34 +01:00
|
|
|
while True:
|
2020-02-09 13:25:34 +01:00
|
|
|
output.update()
|
2020-02-16 14:30:45 +01:00
|
|
|
core.event.trigger('update')
|
2020-01-26 13:31:20 +01:00
|
|
|
output.wait(config.interval())
|
2020-02-16 14:30:45 +01:00
|
|
|
core.event.trigger('stop')
|
2016-12-09 19:29:16 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-03-30 21:18:28 +02:00
|
|
|
main()
|
2020-02-16 13:50:15 +01:00
|
|
|
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))
|
2020-02-16 13:50:15 +01:00
|
|
|
output.draw('start')
|
|
|
|
output.update()
|
|
|
|
output.draw('statusline')
|
2016-12-04 08:37:01 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|