2020-02-01 21:37:38 +01:00
|
|
|
import sys
|
2020-01-19 13:29:34 +01:00
|
|
|
import json
|
2020-01-26 13:31:20 +01:00
|
|
|
import time
|
2020-01-19 13:29:34 +01:00
|
|
|
|
|
|
|
class i3(object):
|
2020-02-01 21:37:38 +01:00
|
|
|
def __init__(self):
|
2020-02-02 14:18:13 +01:00
|
|
|
self._modules = []
|
2020-02-08 14:22:43 +01:00
|
|
|
self._status = []
|
2020-02-01 21:37:38 +01:00
|
|
|
|
2020-02-02 14:18:13 +01:00
|
|
|
def modules(self, modules=None):
|
|
|
|
if not modules:
|
|
|
|
return self._modules
|
|
|
|
self._modules = modules if isinstance(modules, list) else [ modules ]
|
|
|
|
|
2020-02-08 14:22:43 +01:00
|
|
|
def draw(self, what, args=None):
|
|
|
|
cb = getattr(self, what)
|
|
|
|
data = cb(args) if args else cb()
|
2020-02-01 21:37:38 +01:00
|
|
|
if 'data' in data:
|
|
|
|
sys.stdout.write(json.dumps(data['data']))
|
|
|
|
if 'suffix' in data:
|
|
|
|
sys.stdout.write(data['suffix'])
|
|
|
|
sys.stdout.write('\n')
|
2020-02-02 21:21:24 +01:00
|
|
|
sys.stdout.flush()
|
2020-02-01 21:37:38 +01:00
|
|
|
|
2020-01-19 13:29:34 +01:00
|
|
|
def start(self):
|
2020-02-01 21:37:38 +01:00
|
|
|
return {
|
|
|
|
'data': { 'version': 1, 'click_events': True },
|
|
|
|
'suffix': '\n[',
|
|
|
|
}
|
2020-01-19 13:29:34 +01:00
|
|
|
|
|
|
|
def stop(self):
|
2020-02-01 21:37:38 +01:00
|
|
|
return { 'suffix': '\n]' }
|
|
|
|
|
2020-02-08 14:22:43 +01:00
|
|
|
def patch(self, affected_modules):
|
|
|
|
pass # TODO
|
2020-01-19 13:29:34 +01:00
|
|
|
|
2020-02-01 21:37:38 +01:00
|
|
|
def statusline(self):
|
2020-02-08 14:22:43 +01:00
|
|
|
self._status = []
|
2020-02-02 14:18:13 +01:00
|
|
|
for module in self._modules:
|
|
|
|
for widget in module.widgets():
|
2020-02-08 14:22:43 +01:00
|
|
|
self._status.append({
|
2020-02-08 13:45:52 +01:00
|
|
|
'full_text': widget.full_text(),
|
|
|
|
'instance': widget.id(),
|
|
|
|
'name': module.id(),
|
2020-02-02 14:18:13 +01:00
|
|
|
})
|
2020-02-01 21:37:38 +01:00
|
|
|
return {
|
2020-02-08 14:22:43 +01:00
|
|
|
'data': self._status,
|
2020-02-01 21:37:38 +01:00
|
|
|
'suffix': ','
|
|
|
|
}
|
2020-01-19 13:29:34 +01:00
|
|
|
|
2020-01-26 13:31:20 +01:00
|
|
|
def wait(self, interval):
|
|
|
|
time.sleep(interval)
|
|
|
|
|
2020-01-19 13:29:34 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|