From a2104f5d2f0d6629ab05b81783b530ee2f04cca5 Mon Sep 17 00:00:00 2001 From: enkore Date: Sun, 24 Feb 2013 20:13:57 +0100 Subject: [PATCH] Removed support for indicating the position of a module --- i3pystatus/__init__.py | 26 +++----------------------- i3pystatus/core/util.py | 6 +++++- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/i3pystatus/__init__.py b/i3pystatus/__init__.py index 57c8480..49cda69 100644 --- a/i3pystatus/__init__.py +++ b/i3pystatus/__init__.py @@ -1,11 +1,9 @@ #!/usr/bin/env python import sys -import types from threading import Thread import time import functools -import collections from .core import io from .core.util import * @@ -19,7 +17,6 @@ __all__ = [ class Module(SettingsBase): output = None - position = 0 def registered(self, status_handler): """Called when this module is registered with a status handler""" @@ -28,7 +25,7 @@ class Module(SettingsBase): if self.output: if "name" not in self.output: self.output["name"] = self.__name__ - json.insert(self.position, self.output) + json.insert(0, self.output) class AsyncModule(Module): def registered(self, status_handler): @@ -61,32 +58,15 @@ class i3pystatus: self.finder = ModuleFinder() - def get_instance_for_module(self, module, position, args, kwargs): - if isinstance(module, types.ModuleType): - if not isinstance(position, int) and not args: - # If the user does this: register(modsde, mdesettings) with mdesettings - # being a dict Python will put mdesettings into the position argument - # , and not into *args. Let's fix that. - # If she uses keyword arguments, everything is fine :-) - args = (position,) - position = 0 - - module = self.finder.instanciate_class_from_module(module, *args, **kwargs) - elif args or kwargs: - raise ValueError("Additional arguments are invalid if 'module' is already an object") - - return (module, position) - - def register(self, module, position=0, *args, **kwargs): + def register(self, module, *args, **kwargs): """Register a new module.""" if not module: # One can pass in False or None, if he wishes to temporarily disable a module return - module, position = self.get_instance_for_module(module, position, args, kwargs) + module = self.finder.instanciate_class_from_module(module, *args, **kwargs) self.modules.append(module) - module.position = position module.registered(self) def run(self): diff --git a/i3pystatus/core/util.py b/i3pystatus/core/util.py index 5268bd1..0348bb2 100644 --- a/i3pystatus/core/util.py +++ b/i3pystatus/core/util.py @@ -131,4 +131,8 @@ class ClassFinder: return classes[0] def instanciate_class_from_module(self, module, *args, **kwargs): - return self.get_class(module)(*args, **kwargs) + if isinstance(module, types.ModuleType): + return self.get_class(module)(*args, **kwargs) + elif args or kwargs: + raise ValueError("Additional arguments are invalid if 'module' is already an object") + return module