2016-12-04 08:37:01 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2020-05-01 09:41:06 +02:00
|
|
|
import os
|
2016-12-04 08:37:01 +01:00
|
|
|
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 20:11:02 +02:00
|
|
|
core.event.trigger('update', modules.keys())
|
|
|
|
core.event.trigger('draw')
|
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-01-19 15:36:52 +01:00
|
|
|
config = core.config.Config(sys.argv[1:])
|
2020-05-01 09:41:06 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
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-05-01 09:41:06 +02:00
|
|
|
if config.debug():
|
|
|
|
modules.append(core.module.load('debug', config, theme))
|
|
|
|
|
2020-01-19 15:36:52 +01:00
|
|
|
for module in config.modules():
|
2020-04-26 16:40:48 +02:00
|
|
|
modules.append(core.module.load(module, config, theme))
|
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-16 14:30:45 +01:00
|
|
|
core.event.trigger('update')
|
2020-04-12 20:11:02 +02:00
|
|
|
core.event.trigger('draw')
|
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-04-28 20:25: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
|