diff options
| author | Ultrabug <ultrabug@gentoo.org> | 2013-04-17 15:40:42 +0200 |
|---|---|---|
| committer | Ultrabug <ultrabug@gentoo.org> | 2013-04-17 15:40:42 +0200 |
| commit | 4968dd768aec5dddf83b9d062a8f6839f0e5edd4 (patch) | |
| tree | 7b149d09b5975e4049222494ba13ff850b950453 | |
| parent | 52ed808d44b9fe4ebd30aa8ae7d0fc9abc19a660 (diff) | |
respect positions on injected classes outputs
| -rwxr-xr-x | py3status/__init__.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/py3status/__init__.py b/py3status/__init__.py index 3ba0a8d..956a585 100755 --- a/py3status/__init__.py +++ b/py3status/__init__.py @@ -95,14 +95,19 @@ def print_output(prefix, output_list, modules_cache): """ Merge current user-classes cache with i3status' output and display on i3bar """ - for module in modules_cache: - index, json = modules_cache[module] - for j in output_list: - if j['name'] == json['name']: - j.update(json) - break - else: - output_list.insert(index, json) + inject = [] + for class_name in sorted( modules_cache.keys() ): + for module in modules_cache[class_name]: + index, json = modules_cache[class_name][module] + for n, j in enumerate(output_list): + if j['name'] == json['name']: + output_list.pop(n) + break + inject.insert(index, json) + + # inject back user classes in the right order + for i in reversed(inject): + output_list.insert(0, i) output = prefix+dumps(output_list) print_line(output) @@ -282,6 +287,7 @@ class UserModules(Thread): ) if module and class_inst: self.classes[file_name] = (class_inst, []) + self.cache[file_name] = {} for method in dir(class_inst): if not method.startswith('__'): self.classes[file_name][1].append(method) @@ -303,7 +309,7 @@ class UserModules(Thread): try: # handle a cache on user class methods results try: - index, result = self.cache[my_method] + index, result = self.cache[class_name][my_method] if time() > result['cached_until']: raise KeyError('cache timeout') except KeyError: @@ -329,7 +335,7 @@ class UserModules(Thread): assert 'full_text' in result, "missing 'full_text' key" assert 'name' in result, "missing 'name' key" finally: - self.cache[my_method] = (index, result) + self.cache[class_name][my_method] = (index, result) except Exception: err = sys.exc_info()[1] syslog(LOG_ERR, "injection failed (%s)" % str(err)) |
