From 1cebe085675ea18dcb57ef5f87b352a8d0997d28 Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Sat, 7 Jul 2018 16:34:49 +0200 Subject: [PATCH] wip --- py3status/core.py | 30 ++++++++++++++++++++---------- py3status/module.py | 8 +++----- py3status/modules/wwan.py | 3 ++- tox.ini | 4 ++++ 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/py3status/core.py b/py3status/core.py index d1d7553a05..a66b6ecd8a 100644 --- a/py3status/core.py +++ b/py3status/core.py @@ -890,6 +890,7 @@ def create_output_modules(self): output_modules[name]['type'] = 'py3status' output_modules[name]['color'] = self.mappings_color.get(name) output_modules[name]['max_size'] = self.mappings_max_size.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: @@ -899,6 +900,7 @@ def create_output_modules(self): output_modules[name]['type'] = 'i3status' output_modules[name]['color'] = self.mappings_color.get(name) output_modules[name]['max_size'] = self.mappings_max_size.get(name) + output_modules[name]['short_format'] = self.mappings_short_format.get(name) self.output_modules = output_modules @@ -921,9 +923,15 @@ def create_mappings(self, config): max_size = None mappings[name] = max_size + short_format = self.get_config_attribute(name, 'short_format') + if hasattr(max_size, '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): """ @@ -934,6 +942,7 @@ def process_module_output(self, module): outputs = module['module'].get_latest() color = module['color'] max_size = module['max_size'] + short_format = module['short_format'] for output in outputs: if color: @@ -942,16 +951,17 @@ def process_module_output(self, module): output['color'] = color if 'short_text' not in output: - full_text = output['full_text'] - if int(max_size) >= 1: - short = full_text[:max_size] if len(full_text) > int(max_size) else full_text - short = short + '..' if len(short + '..') < len(full_text) else short - output['short_text'] = short - elif max_size is True: - size = int((len(full_text) + 1) / 2) - short = full_text[:size] - short = short + '..' if len(short + '..') < len(full_text) else short - output['short_text'] = short + if not short_format and output['full_text']: + full_text = output['full_text'] + if max_size and int(max_size) >= 1: + short = full_text[:max_size] if len(full_text) > int(max_size) else full_text + short = short + '..' if len(short + '..') < len(full_text) else short + output['short_text'] = short + elif max_size and isinstance(max_size, str): + size = int((len(full_text) + 1) / 2) + short = full_text[:size] + short = short + '..' if len(short + '..') < len(full_text) else short + output['short_text'] = short # Create the json string output. return ','.join([dumps(x) for x in outputs]) diff --git a/py3status/module.py b/py3status/module.py index d7476d8184..dc64363f9d 100644 --- a/py3status/module.py +++ b/py3status/module.py @@ -649,19 +649,17 @@ 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 + + # allow_urgent param = fn(self.module_full_name, 'allow_urgent') if hasattr(param, 'none_setting'): 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 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 70f25c097c..af4c47eea0 100644 --- a/tox.ini +++ b/tox.ini @@ -2,11 +2,15 @@ [testenv] deps = + coverage pytest pytest-flake8 commands = pytest --flake8 + coverage erase + coverage run --omit=**/__init__.py --source=modules -m py.test + coverage report [flake8] max-line-length = 99