[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("")
|
||||
|
||||
class ModuleConfig(object):
|
||||
def __init__(self, config, prefix):
|
||||
self._prefix = prefix
|
||||
def __init__(self, config, name, alias):
|
||||
self._prefix = alias if alias else name
|
||||
self._config = config
|
||||
|
||||
def prefix(self):
|
||||
return self._prefix
|
||||
|
||||
def set(self, name, value):
|
||||
name = self._prefix + name
|
||||
return self._config.set(name, value)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import importlib
|
||||
import bumblebee.theme
|
||||
import bumblebee.output
|
||||
import bumblebee.config
|
||||
import bumblebee.modules
|
||||
|
||||
class Engine:
|
||||
|
@ -13,7 +14,10 @@ class Engine:
|
|||
def load_module(self, modulespec):
|
||||
name = modulespec["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):
|
||||
for m in self._config.modules():
|
||||
|
|
|
@ -2,7 +2,6 @@ import os
|
|||
import pkgutil
|
||||
import importlib
|
||||
|
||||
import bumblebee.config
|
||||
import bumblebee.modules
|
||||
|
||||
def modules():
|
||||
|
@ -27,12 +26,11 @@ class ModuleDescription(object):
|
|||
return getattr(self._mod, "parameters", lambda: [ "n/a" ])()
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, output, config, alias=None):
|
||||
def __init__(self, output, config):
|
||||
self._output = output
|
||||
self._alias = alias
|
||||
name = "{}.".format(alias if alias else self.__module__.split(".")[-1])
|
||||
self._config = bumblebee.config.ModuleConfig(config, name)
|
||||
self._config = config
|
||||
|
||||
def register_callbacks(self):
|
||||
buttons = [
|
||||
{ "name": "left-click", "id": 1 },
|
||||
{ "name": "middle-click", "id": 2 },
|
||||
|
@ -58,6 +56,6 @@ class Module(object):
|
|||
return "default"
|
||||
|
||||
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
|
||||
|
|
|
@ -9,8 +9,8 @@ def parameters():
|
|||
return [ "battery.device: The device to read from (defaults to BAT0)" ]
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._battery = config.parameter("device", "BAT0")
|
||||
self._capacity = 100
|
||||
self._status = "Unknown"
|
||||
|
|
|
@ -9,8 +9,8 @@ def parameters():
|
|||
]
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._brightness = 0
|
||||
self._max = 0
|
||||
self._percent = 0
|
||||
|
|
|
@ -7,8 +7,8 @@ def description():
|
|||
return "Enable/disable auto screen lock."
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._activated = 0
|
||||
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' ])
|
||||
|
|
|
@ -15,8 +15,8 @@ def parameters():
|
|||
]
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._status = "default"
|
||||
self._fmt = self._config.parameter("format", "{artist} - {title} {position}/{duration}")
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ def parameters():
|
|||
]
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._perc = psutil.cpu_percent(percpu=False)
|
||||
|
||||
output.add_callback(module=self.instance(), button=1, cmd="gnome-system-monitor")
|
||||
|
|
|
@ -12,8 +12,8 @@ def parameters():
|
|||
]
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._path = self._config.parameter("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)
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
|
||||
self._counter = {}
|
||||
self._thread = threading.Thread(target=get_dnf_info, args=(self,))
|
||||
|
|
|
@ -13,8 +13,8 @@ def parameters():
|
|||
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
|
||||
self._languages = self._config.parameter("lang", "en").split("|")
|
||||
self._idx = 0
|
||||
|
|
|
@ -12,8 +12,8 @@ def parameters():
|
|||
]
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._cpus = 1
|
||||
try:
|
||||
self._cpus = multiprocessing.cpu_count()
|
||||
|
|
|
@ -12,8 +12,8 @@ def parameters():
|
|||
]
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._mem = psutil.virtual_memory()
|
||||
|
||||
output.add_callback(module=self.instance(), button=1, cmd="gnome-system-monitor")
|
||||
|
|
|
@ -10,8 +10,8 @@ def parameters():
|
|||
]
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._exclude = tuple(filter(len, self._config.parameter("exclude", "lo,virbr,docker,vboxnet,veth").split(",")))
|
||||
self._state = "down"
|
||||
self._typecache = {}
|
||||
|
|
|
@ -6,8 +6,8 @@ def description():
|
|||
return "Displays available updates per repository for pacman."
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._count = 0
|
||||
|
||||
def widgets(self):
|
||||
|
|
|
@ -56,8 +56,8 @@ def get_rtt(obj):
|
|||
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
|
||||
self._counter = {}
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ def parameters():
|
|||
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
|
||||
self._module = self.__module__.split(".")[-1]
|
||||
self._left = 0
|
||||
|
|
|
@ -8,8 +8,8 @@ def parameters():
|
|||
return [ "spacer.text: Text to draw (defaults to '')" ]
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
|
||||
def widgets(self):
|
||||
return bumblebee.output.Widget(self, self._config.parameter("text", ""))
|
||||
|
|
|
@ -21,8 +21,8 @@ def default_format(module):
|
|||
return default
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
|
||||
module = self.__module__.split(".")[-1]
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ def parameters():
|
|||
]
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
|
||||
self._widgets = []
|
||||
|
||||
|
|
|
@ -14,8 +14,6 @@ def read_input(output):
|
|||
if line == "[": continue
|
||||
if line == "]": break
|
||||
|
||||
DEVNULL = open(os.devnull, 'wb')
|
||||
|
||||
event = json.loads(line)
|
||||
cb = output.callback(event)
|
||||
if cb:
|
||||
|
|
Loading…
Reference in a new issue