2016-11-05 07:54:36 +01:00
|
|
|
import os
|
|
|
|
import pkgutil
|
|
|
|
import importlib
|
|
|
|
|
|
|
|
import bumblebee.modules
|
|
|
|
|
|
|
|
def modules():
|
|
|
|
result = []
|
|
|
|
path = os.path.dirname(bumblebee.modules.__file__)
|
|
|
|
for mod in [ name for _, name, _ in pkgutil.iter_modules([path])]:
|
|
|
|
result.append(ModuleDescription(mod))
|
|
|
|
return result
|
|
|
|
|
|
|
|
class ModuleDescription(object):
|
|
|
|
def __init__(self, name):
|
|
|
|
self._name = name
|
|
|
|
self._mod =importlib.import_module("bumblebee.modules.{}".format(name))
|
|
|
|
|
|
|
|
def name(self):
|
|
|
|
return str(self._name)
|
|
|
|
|
|
|
|
def description(self):
|
2016-11-05 16:18:53 +01:00
|
|
|
return getattr(self._mod, "description", lambda: "n/a")()
|
2016-11-05 07:54:36 +01:00
|
|
|
|
2016-11-05 16:18:53 +01:00
|
|
|
def parameters(self):
|
|
|
|
return getattr(self._mod, "parameters", lambda: [ "n/a" ])()
|
2016-10-30 17:56:04 +01:00
|
|
|
|
|
|
|
class Module(object):
|
2016-12-02 18:53:34 +01:00
|
|
|
def __init__(self, output, config):
|
2016-11-05 13:09:28 +01:00
|
|
|
self._output = output
|
2016-12-02 18:53:34 +01:00
|
|
|
self._config = config
|
2016-10-30 17:56:04 +01:00
|
|
|
|
2016-12-02 18:53:34 +01:00
|
|
|
def register_callbacks(self):
|
2016-11-05 15:39:21 +01:00
|
|
|
buttons = [
|
|
|
|
{ "name": "left-click", "id": 1 },
|
|
|
|
{ "name": "middle-click", "id": 2 },
|
|
|
|
{ "name": "right-click", "id": 3 },
|
|
|
|
{ "name": "wheel-up", "id": 4 },
|
|
|
|
{ "name": "wheel-down", "id": 5 },
|
|
|
|
]
|
|
|
|
for button in buttons:
|
|
|
|
if self._config.parameter(button["name"], None):
|
|
|
|
output.add_callback(
|
|
|
|
module=self.instance(),
|
|
|
|
button=button["id"],
|
|
|
|
cmd=self._config.parameter(button["name"])
|
|
|
|
)
|
|
|
|
|
2016-11-05 13:42:26 +01:00
|
|
|
def critical(self, widget):
|
2016-10-31 11:35:12 +01:00
|
|
|
return False
|
|
|
|
|
2016-11-05 13:42:26 +01:00
|
|
|
def warning(self, widget):
|
2016-10-31 11:35:12 +01:00
|
|
|
return False
|
|
|
|
|
2016-11-05 13:42:26 +01:00
|
|
|
def state(self, widget):
|
2016-10-31 07:18:57 +01:00
|
|
|
return "default"
|
|
|
|
|
2016-11-05 15:28:33 +01:00
|
|
|
def instance(self, widget=None):
|
2016-12-02 18:53:34 +01:00
|
|
|
return self._config.prefix()
|
2016-11-05 13:23:46 +01:00
|
|
|
|
2016-10-30 17:56:04 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|