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-01 21:37:38 +01:00
|
|
|
self.clear()
|
|
|
|
|
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-01 21:37:38 +01:00
|
|
|
def draw(self, what):
|
|
|
|
data = getattr(self, what)()
|
|
|
|
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]' }
|
|
|
|
|
|
|
|
def clear(self):
|
|
|
|
self._statusline = []
|
2020-01-19 13:29:34 +01:00
|
|
|
|
2020-02-01 21:37:38 +01:00
|
|
|
def statusline(self):
|
2020-02-02 14:18:13 +01:00
|
|
|
status = []
|
|
|
|
for module in self._modules:
|
|
|
|
for widget in module.widgets():
|
|
|
|
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-02 14:18:13 +01:00
|
|
|
'data': 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
|