From ecb6c54052e885f5c1bba195ef6b60f4fd3ce6a4 Mon Sep 17 00:00:00 2001 From: philipdexter Date: Fri, 15 Mar 2013 21:20:24 -0400 Subject: [PATCH] Add the ability to change the position of a module in the i3bar Create a method `move' in modules.py to insert the module's json in a different position than the default 0. --- i3pystatus/core/__init__.py | 4 +++- i3pystatus/core/modules.py | 6 +++++- i3pystatus/core/util.py | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/i3pystatus/core/__init__.py b/i3pystatus/core/__init__.py index 17d6f8b..ccac0b6 100644 --- a/i3pystatus/core/__init__.py +++ b/i3pystatus/core/__init__.py @@ -23,7 +23,9 @@ class Status: """Register a new module.""" if module: - self.modules.append(module, *args, **kwargs) + return self.modules.append(module, *args, **kwargs) + else: + return None def run_command_endpoint(self): for command in io.JSONIO(io=io.IOHandler(sys.stdin, open(os.devnull,"w")), skiplines=1).read(): diff --git a/i3pystatus/core/modules.py b/i3pystatus/core/modules.py index a70de73..f1c1050 100644 --- a/i3pystatus/core/modules.py +++ b/i3pystatus/core/modules.py @@ -10,6 +10,7 @@ __all__ = [ class Module(SettingsBase): output = None + position = 0 def registered(self, status_handler): """Called when this module is registered with a status handler""" @@ -19,7 +20,7 @@ class Module(SettingsBase): if "name" not in self.output: self.output["name"] = self.__name__ self.output["instance"] = str(id(self)) - json.insert(0, self.output) + json.insert(self.position, self.output) def on_click(self, button): if button == 1: # Left mouse button @@ -27,6 +28,9 @@ class Module(SettingsBase): elif button == 3: # Right mouse button self.on_rightclick() + def move(self, position): + self.position = position + def on_leftclick(self): pass diff --git a/i3pystatus/core/util.py b/i3pystatus/core/util.py index 2334ee4..aae8f5f 100644 --- a/i3pystatus/core/util.py +++ b/i3pystatus/core/util.py @@ -46,6 +46,7 @@ class ModuleList(collections.UserList): module = self.finder.instanciate_class_from_module(module, *args, **kwargs) module.registered(self.status_handler) super().append(module) + return module def get_by_id(self, find_id): find_id = int(find_id)