[core] Remove alias from module
Hide alias concept for modules in the engine. That way, the individual modules never get to know about whether a module has been aliased or not. see #23
This commit is contained in:
parent
f306366629
commit
2f3f171ca5
21 changed files with 48 additions and 45 deletions
|
@ -35,10 +35,13 @@ class print_usage(argparse.Action):
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
class ModuleConfig(object):
|
class ModuleConfig(object):
|
||||||
def __init__(self, config, prefix):
|
def __init__(self, config, name, alias):
|
||||||
self._prefix = prefix
|
self._prefix = alias if alias else name
|
||||||
self._config = config
|
self._config = config
|
||||||
|
|
||||||
|
def prefix(self):
|
||||||
|
return self._prefix
|
||||||
|
|
||||||
def set(self, name, value):
|
def set(self, name, value):
|
||||||
name = self._prefix + name
|
name = self._prefix + name
|
||||||
return self._config.set(name, value)
|
return self._config.set(name, value)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import importlib
|
import importlib
|
||||||
import bumblebee.theme
|
import bumblebee.theme
|
||||||
import bumblebee.output
|
import bumblebee.output
|
||||||
|
import bumblebee.config
|
||||||
import bumblebee.modules
|
import bumblebee.modules
|
||||||
|
|
||||||
class Engine:
|
class Engine:
|
||||||
|
@ -13,7 +14,10 @@ class Engine:
|
||||||
def load_module(self, modulespec):
|
def load_module(self, modulespec):
|
||||||
name = modulespec["name"]
|
name = modulespec["name"]
|
||||||
module = importlib.import_module("bumblebee.modules.{}".format(name))
|
module = importlib.import_module("bumblebee.modules.{}".format(name))
|
||||||
return getattr(module, "Module")(self._output, self._config, modulespec["alias"])
|
cfg = bumblebee.config.ModuleConfig(self._config, name, modulespec["alias"])
|
||||||
|
obj = getattr(module, "Module")(self._output, cfg)
|
||||||
|
obj.register_callbacks()
|
||||||
|
return obj
|
||||||
|
|
||||||
def load_modules(self):
|
def load_modules(self):
|
||||||
for m in self._config.modules():
|
for m in self._config.modules():
|
||||||
|
|
|
@ -2,7 +2,6 @@ import os
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import importlib
|
import importlib
|
||||||
|
|
||||||
import bumblebee.config
|
|
||||||
import bumblebee.modules
|
import bumblebee.modules
|
||||||
|
|
||||||
def modules():
|
def modules():
|
||||||
|
@ -27,12 +26,11 @@ class ModuleDescription(object):
|
||||||
return getattr(self._mod, "parameters", lambda: [ "n/a" ])()
|
return getattr(self._mod, "parameters", lambda: [ "n/a" ])()
|
||||||
|
|
||||||
class Module(object):
|
class Module(object):
|
||||||
def __init__(self, output, config, alias=None):
|
def __init__(self, output, config):
|
||||||
self._output = output
|
self._output = output
|
||||||
self._alias = alias
|
self._config = config
|
||||||
name = "{}.".format(alias if alias else self.__module__.split(".")[-1])
|
|
||||||
self._config = bumblebee.config.ModuleConfig(config, name)
|
|
||||||
|
|
||||||
|
def register_callbacks(self):
|
||||||
buttons = [
|
buttons = [
|
||||||
{ "name": "left-click", "id": 1 },
|
{ "name": "left-click", "id": 1 },
|
||||||
{ "name": "middle-click", "id": 2 },
|
{ "name": "middle-click", "id": 2 },
|
||||||
|
@ -58,6 +56,6 @@ class Module(object):
|
||||||
return "default"
|
return "default"
|
||||||
|
|
||||||
def instance(self, widget=None):
|
def instance(self, widget=None):
|
||||||
return self._alias if self._alias else self.__module__.split(".")[-1]
|
return self._config.prefix()
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -9,8 +9,8 @@ def parameters():
|
||||||
return [ "battery.device: The device to read from (defaults to BAT0)" ]
|
return [ "battery.device: The device to read from (defaults to BAT0)" ]
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
self._battery = config.parameter("device", "BAT0")
|
self._battery = config.parameter("device", "BAT0")
|
||||||
self._capacity = 100
|
self._capacity = 100
|
||||||
self._status = "Unknown"
|
self._status = "Unknown"
|
||||||
|
|
|
@ -9,8 +9,8 @@ def parameters():
|
||||||
]
|
]
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
self._brightness = 0
|
self._brightness = 0
|
||||||
self._max = 0
|
self._max = 0
|
||||||
self._percent = 0
|
self._percent = 0
|
||||||
|
|
|
@ -7,8 +7,8 @@ def description():
|
||||||
return "Enable/disable auto screen lock."
|
return "Enable/disable auto screen lock."
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
self._activated = 0
|
self._activated = 0
|
||||||
output.add_callback(module="caffeine.activate", button=1, cmd=[ 'notify-send "Consuming caffeine"', 'xset s off' ])
|
output.add_callback(module="caffeine.activate", button=1, cmd=[ 'notify-send "Consuming caffeine"', 'xset s off' ])
|
||||||
output.add_callback(module="caffeine.deactivate", button=1, cmd=[ 'notify-send "Out of coffee"', 'xset s default' ])
|
output.add_callback(module="caffeine.deactivate", button=1, cmd=[ 'notify-send "Out of coffee"', 'xset s default' ])
|
||||||
|
|
|
@ -15,8 +15,8 @@ def parameters():
|
||||||
]
|
]
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
self._status = "default"
|
self._status = "default"
|
||||||
self._fmt = self._config.parameter("format", "{artist} - {title} {position}/{duration}")
|
self._fmt = self._config.parameter("format", "{artist} - {title} {position}/{duration}")
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@ def parameters():
|
||||||
]
|
]
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
self._perc = psutil.cpu_percent(percpu=False)
|
self._perc = psutil.cpu_percent(percpu=False)
|
||||||
|
|
||||||
output.add_callback(module=self.instance(), button=1, cmd="gnome-system-monitor")
|
output.add_callback(module=self.instance(), button=1, cmd="gnome-system-monitor")
|
||||||
|
|
|
@ -12,8 +12,8 @@ def parameters():
|
||||||
]
|
]
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
self._path = self._config.parameter("path", "/")
|
self._path = self._config.parameter("path", "/")
|
||||||
|
|
||||||
output.add_callback(module=self.instance(), button=1, cmd="nautilus {}".format(self._path))
|
output.add_callback(module=self.instance(), button=1, cmd="nautilus {}".format(self._path))
|
||||||
|
|
|
@ -59,8 +59,8 @@ def get_dnf_info(obj):
|
||||||
obj.set("other", other)
|
obj.set("other", other)
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
|
|
||||||
self._counter = {}
|
self._counter = {}
|
||||||
self._thread = threading.Thread(target=get_dnf_info, args=(self,))
|
self._thread = threading.Thread(target=get_dnf_info, args=(self,))
|
||||||
|
|
|
@ -13,8 +13,8 @@ def parameters():
|
||||||
|
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
|
|
||||||
self._languages = self._config.parameter("lang", "en").split("|")
|
self._languages = self._config.parameter("lang", "en").split("|")
|
||||||
self._idx = 0
|
self._idx = 0
|
||||||
|
|
|
@ -12,8 +12,8 @@ def parameters():
|
||||||
]
|
]
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
self._cpus = 1
|
self._cpus = 1
|
||||||
try:
|
try:
|
||||||
self._cpus = multiprocessing.cpu_count()
|
self._cpus = multiprocessing.cpu_count()
|
||||||
|
|
|
@ -12,8 +12,8 @@ def parameters():
|
||||||
]
|
]
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
self._mem = psutil.virtual_memory()
|
self._mem = psutil.virtual_memory()
|
||||||
|
|
||||||
output.add_callback(module=self.instance(), button=1, cmd="gnome-system-monitor")
|
output.add_callback(module=self.instance(), button=1, cmd="gnome-system-monitor")
|
||||||
|
|
|
@ -10,8 +10,8 @@ def parameters():
|
||||||
]
|
]
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
self._exclude = tuple(filter(len, self._config.parameter("exclude", "lo,virbr,docker,vboxnet,veth").split(",")))
|
self._exclude = tuple(filter(len, self._config.parameter("exclude", "lo,virbr,docker,vboxnet,veth").split(",")))
|
||||||
self._state = "down"
|
self._state = "down"
|
||||||
self._typecache = {}
|
self._typecache = {}
|
||||||
|
|
|
@ -6,8 +6,8 @@ def description():
|
||||||
return "Displays available updates per repository for pacman."
|
return "Displays available updates per repository for pacman."
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
self._count = 0
|
self._count = 0
|
||||||
|
|
||||||
def widgets(self):
|
def widgets(self):
|
||||||
|
|
|
@ -56,8 +56,8 @@ def get_rtt(obj):
|
||||||
|
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
|
|
||||||
self._counter = {}
|
self._counter = {}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,8 @@ def parameters():
|
||||||
|
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
|
|
||||||
self._module = self.__module__.split(".")[-1]
|
self._module = self.__module__.split(".")[-1]
|
||||||
self._left = 0
|
self._left = 0
|
||||||
|
|
|
@ -8,8 +8,8 @@ def parameters():
|
||||||
return [ "spacer.text: Text to draw (defaults to '')" ]
|
return [ "spacer.text: Text to draw (defaults to '')" ]
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
|
|
||||||
def widgets(self):
|
def widgets(self):
|
||||||
return bumblebee.output.Widget(self, self._config.parameter("text", ""))
|
return bumblebee.output.Widget(self, self._config.parameter("text", ""))
|
||||||
|
|
|
@ -21,8 +21,8 @@ def default_format(module):
|
||||||
return default
|
return default
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
|
|
||||||
module = self.__module__.split(".")[-1]
|
module = self.__module__.split(".")[-1]
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ def parameters():
|
||||||
]
|
]
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config, alias):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config, alias)
|
super(Module, self).__init__(output, config)
|
||||||
|
|
||||||
self._widgets = []
|
self._widgets = []
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,6 @@ def read_input(output):
|
||||||
if line == "[": continue
|
if line == "[": continue
|
||||||
if line == "]": break
|
if line == "]": break
|
||||||
|
|
||||||
DEVNULL = open(os.devnull, 'wb')
|
|
||||||
|
|
||||||
event = json.loads(line)
|
event = json.loads(line)
|
||||||
cb = output.callback(event)
|
cb = output.callback(event)
|
||||||
if cb:
|
if cb:
|
||||||
|
|
Loading…
Reference in a new issue