bumblebee-status/core/output.py
Tobias Witek 5d971267db [core/theme] Add preparatory work for themes
Add two new parameters: theme and iconset

Add a placeholder class core.theme.Theme, an instance of which is passed
in to the i3 output object (which is the only object that should ever
have need of the theme, hopefully).
2020-02-09 13:46:56 +01:00

63 lines
1.6 KiB
Python

import sys
import json
import time
import core.theme
class i3(object):
def __init__(self, theme=core.theme.Theme()):
self._modules = []
self._status = {}
def modules(self, modules=None):
if not modules:
return self._modules
self._modules = modules if isinstance(modules, list) else [ modules ]
def draw(self, what, args=None):
cb = getattr(self, what)
data = cb(args) if args else cb()
if 'data' in data:
sys.stdout.write(json.dumps(data['data']))
if 'suffix' in data:
sys.stdout.write(data['suffix'])
sys.stdout.write('\n')
sys.stdout.flush()
def start(self):
return {
'data': { 'version': 1, 'click_events': True },
'suffix': '\n[',
}
def stop(self):
return { 'suffix': '\n]' }
def widgets(self, module):
widgets = []
for widget in module.widgets():
widgets.append({
'full_text': widget.full_text(),
'instance': widget.id(),
'name': module.id(),
})
return widgets
def update(self, affected_modules=None):
for module in self._modules:
module.update()
self._status[module] = self.widgets(module)
def statusline(self):
widgets = []
for module in self._modules:
widgets += self._status[module]
return {
'data': widgets,
'suffix': ','
}
def wait(self, interval):
time.sleep(interval)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4