2016-11-05 08:59:43 +01:00
|
|
|
import inspect
|
2016-11-04 21:10:21 +01:00
|
|
|
import threading
|
2016-10-30 17:56:04 +01:00
|
|
|
|
2016-11-04 21:41:22 +01:00
|
|
|
def output(args):
|
|
|
|
import bumblebee.outputs.i3
|
|
|
|
return bumblebee.outputs.i3.Output(args)
|
|
|
|
|
2016-11-05 08:59:43 +01:00
|
|
|
class Widget(object):
|
|
|
|
def __init__(self, text, warning=False, critical=False, state=None):
|
|
|
|
self._name = inspect.getmodule(inspect.stack()[1][0]).__name__
|
|
|
|
self._text = text
|
|
|
|
self._warning = warning
|
|
|
|
self._critical = critical
|
|
|
|
self._state = state
|
|
|
|
|
|
|
|
def state(self):
|
|
|
|
return self._state
|
|
|
|
|
|
|
|
def warning(self):
|
|
|
|
return self._warning
|
|
|
|
|
|
|
|
def critical(self):
|
|
|
|
return self._critical
|
|
|
|
|
|
|
|
def module(self):
|
|
|
|
return self._name.split(".")[-1]
|
|
|
|
|
|
|
|
def name(self):
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
def text(self):
|
|
|
|
return self._text
|
|
|
|
|
2016-10-30 17:56:04 +01:00
|
|
|
class Output(object):
|
2016-11-05 08:59:43 +01:00
|
|
|
def __init__(self, config):
|
|
|
|
self._config = config
|
2016-11-01 07:46:26 +01:00
|
|
|
self._callbacks = {}
|
2016-11-04 21:10:21 +01:00
|
|
|
self._wait = threading.Condition()
|
|
|
|
self._wait.acquire()
|
2016-11-01 07:46:26 +01:00
|
|
|
|
2016-11-04 19:11:10 +01:00
|
|
|
def redraw(self):
|
2016-11-04 21:10:21 +01:00
|
|
|
self._wait.acquire()
|
|
|
|
self._wait.notify()
|
|
|
|
self._wait.release()
|
2016-11-04 19:11:10 +01:00
|
|
|
|
2016-11-01 07:58:50 +01:00
|
|
|
def add_callback(self, cmd, button, module=None):
|
2016-11-01 08:09:10 +01:00
|
|
|
if module:
|
|
|
|
module = module.replace("bumblebee.modules.", "")
|
2016-11-01 07:46:26 +01:00
|
|
|
self._callbacks[(
|
|
|
|
button,
|
|
|
|
module,
|
|
|
|
)] = cmd
|
|
|
|
|
|
|
|
def callback(self, event):
|
|
|
|
cb = self._callbacks.get((
|
|
|
|
event.get("button", -1),
|
|
|
|
event.get("name", None),
|
|
|
|
), None)
|
|
|
|
if cb is not None: return cb
|
|
|
|
cb = self._callbacks.get((
|
|
|
|
event.get("button", -1),
|
|
|
|
None,
|
|
|
|
), None)
|
|
|
|
return cb
|
2016-10-31 10:45:15 +01:00
|
|
|
|
2016-11-05 08:59:43 +01:00
|
|
|
def wait(self):
|
|
|
|
self._wait.wait(self._config.parameter("interval", 1))
|
2016-11-04 21:10:21 +01:00
|
|
|
|
2016-10-30 17:56:04 +01:00
|
|
|
def start(self):
|
|
|
|
pass
|
|
|
|
|
2016-11-05 08:59:43 +01:00
|
|
|
def draw(self, widgets, theme):
|
2016-10-30 17:56:04 +01:00
|
|
|
pass
|
|
|
|
|
2016-11-05 08:59:43 +01:00
|
|
|
def flush(self):
|
2016-10-30 17:56:04 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|