From 8083a35e0f2881e6b232742550852675838d8a5a Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Thu, 5 Jul 2018 23:43:23 +0200 Subject: [PATCH 1/4] handle i3status 'short_text'. simple way to transform with settings a 'max_size' globally for all module or per module. short_text is used if returned text size is larger than monitor. --- py3status/core.py | 8 ++++++++ py3status/module.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/py3status/core.py b/py3status/core.py index f5761c8481..193fd7d32f 100644 --- a/py3status/core.py +++ b/py3status/core.py @@ -932,13 +932,21 @@ def create_mappings(self, config): if hasattr(color, "none_setting"): color = None mappings[name] = color + + max_size = self.get_config_attribute(name, 'max_size') + if hasattr(max_size, 'none_setting'): + max_size = None + mappings[name] = max_size + # Store mappings for later use. + self.mappings_max_size = mappings self.mappings_color = mappings def process_module_output(self, module): """ Process the output for a module and return a json string representing it. Color processing occurs here. + Shortened text 'short_text' processing occurs here. """ outputs = module["module"].get_latest() color = module["color"] diff --git a/py3status/module.py b/py3status/module.py index 74a869a9e8..39e313bb47 100644 --- a/py3status/module.py +++ b/py3status/module.py @@ -659,6 +659,15 @@ def deprecation_log(item): param = True self.allow_urgent = param + # max_size + # get the value form the config or use the module default if + # supplied. + fn = self._py3_wrapper.get_config_attribute + param = fn(self.module_full_name, 'max_size') + if hasattr(param, 'none_setting'): + param = True + self.max_size = param + # get the available methods for execution for method in sorted(dir(class_inst)): if method.startswith("_"): From ac81cedb5bc6e5069fa809e6fc0b6dd242a9cd1c Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Sat, 7 Jul 2018 16:34:49 +0200 Subject: [PATCH 2/4] wip --- py3status/core.py | 38 +++++++++++++++++++++----------------- py3status/module.py | 6 +----- py3status/modules/wwan.py | 3 ++- tox.ini | 4 ++++ 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/py3status/core.py b/py3status/core.py index 193fd7d32f..d4dedccebf 100644 --- a/py3status/core.py +++ b/py3status/core.py @@ -904,18 +904,20 @@ def create_output_modules(self): for name in self.modules: if name not in output_modules: output_modules[name] = {} - output_modules[name]["position"] = positions.get(name, []) - output_modules[name]["module"] = self.modules[name] - output_modules[name]["type"] = "py3status" - output_modules[name]["color"] = self.mappings_color.get(name) + output_modules[name]['position'] = positions.get(name, []) + output_modules[name]['module'] = self.modules[name] + output_modules[name]['type'] = 'py3status' + output_modules[name]['color'] = self.mappings_color.get(name) + output_modules[name]['short_format'] = self.mappings_short_format.get(name) # i3status modules for name in i3modules: if name not in output_modules: output_modules[name] = {} - output_modules[name]["position"] = positions.get(name, []) - output_modules[name]["module"] = i3modules[name] - output_modules[name]["type"] = "i3status" - output_modules[name]["color"] = self.mappings_color.get(name) + output_modules[name]['position'] = positions.get(name, []) + output_modules[name]['module'] = i3modules[name] + output_modules[name]['type'] = 'i3status' + output_modules[name]['color'] = self.mappings_color.get(name) + output_modules[name]['short_format'] = self.mappings_short_format.get(name) self.output_modules = output_modules @@ -933,14 +935,14 @@ def create_mappings(self, config): color = None mappings[name] = color - max_size = self.get_config_attribute(name, 'max_size') - if hasattr(max_size, 'none_setting'): - max_size = None - mappings[name] = max_size + short_format = self.get_config_attribute(name, 'short_format') + if hasattr(short_format, 'none_setting'): + short_format = None + mappings[name] = short_format # Store mappings for later use. - self.mappings_max_size = mappings self.mappings_color = mappings + self.mappings_short_format = mappings def process_module_output(self, module): """ @@ -948,10 +950,12 @@ def process_module_output(self, module): Color processing occurs here. Shortened text 'short_text' processing occurs here. """ - outputs = module["module"].get_latest() - color = module["color"] - if color: - for output in outputs: + outputs = module['module'].get_latest() + color = module['color'] + short_format = module['short_format'] + + for output in outputs: + if color: # Color: substitute the config defined color if "color" not in output: output["color"] = color diff --git a/py3status/module.py b/py3status/module.py index 39e313bb47..8c42027352 100644 --- a/py3status/module.py +++ b/py3status/module.py @@ -650,8 +650,7 @@ def deprecation_log(item): if not hasattr(self.module_class, "py3"): setattr(self.module_class, "py3", Py3(self)) - # allow_urgent - # get the value form the config or use the module default if + # get the value from the config or use the module default if # supplied. fn = self._py3_wrapper.get_config_attribute param = fn(self.module_full_name, "allow_urgent") @@ -660,9 +659,6 @@ def deprecation_log(item): self.allow_urgent = param # max_size - # get the value form the config or use the module default if - # supplied. - fn = self._py3_wrapper.get_config_attribute param = fn(self.module_full_name, 'max_size') if hasattr(param, 'none_setting'): param = True diff --git a/py3status/modules/wwan.py b/py3status/modules/wwan.py index 022bfc3147..6802b87ae6 100644 --- a/py3status/modules/wwan.py +++ b/py3status/modules/wwan.py @@ -563,7 +563,8 @@ def wwan(self): response = { 'cached_until': self.py3.time_in(self.cache_timeout), - 'full_text': self.py3.safe_format(self.format, wwan_data) + 'full_text': self.py3.safe_format(self.format, wwan_data), + 'short_text': self.py3.safe_format(self.short_format, wwan_data) } if urgent: response['urgent'] = True diff --git a/tox.ini b/tox.ini index 279b3cf7af..e6435711f9 100644 --- a/tox.ini +++ b/tox.ini @@ -4,10 +4,14 @@ skip_missing_interpreters = True [testenv] skip_install = True deps = + coverage pytest pytest-flake8 commands = pytest --flake8 + coverage erase + coverage run --omit=**/__init__.py --source=modules -m py.test + coverage report [testenv:py36] skip_install = True From 1697d46d95668a67ed62dbcdadbc86244f44bcf8 Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Sun, 8 Jul 2018 15:38:33 +0200 Subject: [PATCH 3/4] wip --- py3status/module.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/py3status/module.py b/py3status/module.py index 8c42027352..96d321037f 100644 --- a/py3status/module.py +++ b/py3status/module.py @@ -190,10 +190,11 @@ def error_output(self, message, method_affected=None): color = None error = { - "full_text": message, - "color": color, - "instance": self.module_inst, - "name": self.module_name, + 'full_text': message, + 'short_text': message, + 'color': color, + 'instance': self.module_inst, + 'name': self.module_name, } for method in self.methods.values(): if method_affected and method["method"] != method_affected: @@ -279,7 +280,7 @@ def set_updated(self): output.extend(data) else: # if the output is not 'valid' then don't add it. - if data.get("full_text") or "separator" in data: + if data.get('full_text') or data.get('short_text') or 'separator' in data: if self.testing: data["cached_until"] = method.get("cached_until") output.append(data) @@ -682,12 +683,16 @@ def deprecation_log(item): # the method_obj stores infos about each method # of this module. method_obj = { - "cached_until": time(), - "call_type": params_type, - "instance": None, - "last_output": {"name": method, "full_text": ""}, - "method": method, - "name": None, + 'cached_until': time(), + 'call_type': params_type, + 'instance': None, + 'last_output': { + 'name': method, + 'full_text': '', + 'short_text': '' + }, + 'method': method, + 'name': None } self.methods[method] = method_obj From 4f3059b7e8edf6782d674cef1f8bf6fff3961b8e Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Mon, 3 Sep 2018 14:49:48 +0200 Subject: [PATCH 4/4] undo tox.ini --- py3status/core.py | 11 +---------- tox.ini | 4 ---- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/py3status/core.py b/py3status/core.py index d4dedccebf..8421205a6f 100644 --- a/py3status/core.py +++ b/py3status/core.py @@ -908,7 +908,6 @@ def create_output_modules(self): output_modules[name]['module'] = self.modules[name] output_modules[name]['type'] = 'py3status' output_modules[name]['color'] = self.mappings_color.get(name) - output_modules[name]['short_format'] = self.mappings_short_format.get(name) # i3status modules for name in i3modules: if name not in output_modules: @@ -917,7 +916,6 @@ def create_output_modules(self): output_modules[name]['module'] = i3modules[name] output_modules[name]['type'] = 'i3status' output_modules[name]['color'] = self.mappings_color.get(name) - output_modules[name]['short_format'] = self.mappings_short_format.get(name) self.output_modules = output_modules @@ -935,30 +933,23 @@ def create_mappings(self, config): color = None mappings[name] = color - short_format = self.get_config_attribute(name, 'short_format') - if hasattr(short_format, 'none_setting'): - short_format = None - mappings[name] = short_format - # Store mappings for later use. self.mappings_color = mappings - self.mappings_short_format = mappings def process_module_output(self, module): """ Process the output for a module and return a json string representing it. Color processing occurs here. - Shortened text 'short_text' processing occurs here. """ outputs = module['module'].get_latest() color = module['color'] - short_format = module['short_format'] for output in outputs: if color: # Color: substitute the config defined color if "color" not in output: output["color"] = color + # Create the json string output. return ",".join([dumps(x) for x in outputs]) diff --git a/tox.ini b/tox.ini index e6435711f9..279b3cf7af 100644 --- a/tox.ini +++ b/tox.ini @@ -4,14 +4,10 @@ skip_missing_interpreters = True [testenv] skip_install = True deps = - coverage pytest pytest-flake8 commands = pytest --flake8 - coverage erase - coverage run --omit=**/__init__.py --source=modules -m py.test - coverage report [testenv:py36] skip_install = True