diff --git a/bumblebee/config.py b/bumblebee/config.py index 8e95559..a494566 100644 --- a/bumblebee/config.py +++ b/bumblebee/config.py @@ -8,7 +8,7 @@ import bumblebee.module class Config(object): def __init__(self, args): self._raw = args - self._parser = self.parser() + self._parser = self._parser() self._indent = " "*4 if len(args) == 0: @@ -24,21 +24,15 @@ class Config(object): if self._args.list: self._parser.exit() - def parser(self): - parser = argparse.ArgumentParser(description="display system data in the i3bar") - parser.add_argument("-m", "--modules", nargs="+", - help="List of modules to load. The order of the list determines " - "their order in the i3bar (from left to right)", - default=[]) - parser.add_argument("-l", "--list", - help="List: 'modules', 'themes' ", - choices = [ "modules", "themes" ], - default="modules") - parser.add_argument("-t", "--theme", help="Specify which theme to use for " - "drawing the modules", - default="default") + def parameter(self, name, default): + # TODO + return default - return parser + def theme(self): + return self._args.theme + + def modules(self): + return self._args.modules def print_themes(self): print(textwrap.fill(", ".join(bumblebee.theme.themes()), @@ -57,4 +51,23 @@ class Config(object): 80, initial_indent=self._indent*2, subsequent_indent=self._indent*4) print "" + def _parser(self): + parser = argparse.ArgumentParser(description="display system data in the i3bar") + parser.add_argument("-m", "--modules", nargs="+", + help="List of modules to load. The order of the list determines " + "their order in the i3bar (from left to right)", + default=[], + ) + parser.add_argument("-l", "--list", + help="List: 'modules', 'themes' ", + choices = [ "modules", "themes" ], + ) + parser.add_argument("-t", "--theme", help="Specify which theme to use for " + "drawing the modules", + default="default", + ) + + return parser + + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/engine.py b/bumblebee/engine.py index 02cbde1..8834877 100644 --- a/bumblebee/engine.py +++ b/bumblebee/engine.py @@ -10,23 +10,23 @@ import bumblebee.output import bumblebee.modules class Engine: - def __init__(self, args): + def __init__(self, config): self._modules = [] - self._args = args - self._theme = bumblebee.theme.Theme(args) - self._output = bumblebee.output.output(args) + self._config = config + self._theme = bumblebee.theme.Theme(config) + self._output = bumblebee.output.output(config) - def load_module(self, modulespec): - name = modulespec.split(self._args.split)[0] - args = None if name == modulespec else modulespec.split(self._args.split)[1:] + def load_module(self, name): module = importlib.import_module("bumblebee.modules.{}".format(name)) - return getattr(module, "Module")(self._output, args) + return getattr(module, "Module")(self._output, self._config) def load_modules(self): - for m in self._args.modules: + for m in self._config.modules(): self._modules.append(self.load_module(m)) def register_event(self, eventspec): + return + # TODO event = eventspec.split(self._args.split) if len(event) < 3: raise Exception("invalid click event format, expected 3 parameters") @@ -37,6 +37,8 @@ class Engine: ) def register_events(self): + return + # TODO for e in self._args.events: self.register_event(e) diff --git a/bumblebee/module.py b/bumblebee/module.py index 495d146..9c4ab4b 100644 --- a/bumblebee/module.py +++ b/bumblebee/module.py @@ -32,7 +32,7 @@ class ModuleDescription(object): return "n/a" class Module(object): - def __init__(self, args): + def __init__(self, output, config): pass def data(self): diff --git a/bumblebee/modules/time.py b/bumblebee/modules/time.py index 48b8916..9a69d71 100644 --- a/bumblebee/modules/time.py +++ b/bumblebee/modules/time.py @@ -18,8 +18,8 @@ def description(): return "Displays the current time, using the optional format string as input for strftime." class Module(bumblebee.module.Module): - def __init__(self, output, args): - super(Module, self).__init__(args) + def __init__(self, output, config): + super(Module, self).__init__(output, config) module = self.__module__.split(".")[-1] default = "%x %X" @@ -28,8 +28,8 @@ class Module(bumblebee.module.Module): if module == "time": default = "%X" - self._fmt = args[0] if args else default - + param_name = "{}.format".format(module) + self._fmt = config.parameter(param_name, default) def data(self): return datetime.datetime.now().strftime(self._fmt) diff --git a/bumblebee/theme.py b/bumblebee/theme.py index 8b7e9bd..a0e4697 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -12,10 +12,10 @@ def themes(): class Theme: _cycle_index = 0 _cycle = None - def __init__(self, args): + def __init__(self, config): self._data = None path = os.path.dirname(os.path.realpath(__file__)) - with open("{}/{}.json".format(getpath(), args.theme)) as f: + with open("{}/{}.json".format(getpath(), config.theme())) as f: self._data = json.load(f) self._defaults = self._data.get("defaults", {}) self._cycle = self._defaults.get("cycle", [])