From 2ab575d190c1d963b6a9c32ef897958c0667b7f5 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Fri, 1 May 2020 15:33:31 +0200 Subject: [PATCH] [core] do not scroll errors to make errors easier to diagnose, do not scroll them, but instead fully show them. also, re-introduce the supplementary fields for the dwm bridge, kudos to @somospocos --- core/decorators.py | 1 - core/module.py | 5 ----- core/output.py | 21 ++++++++++++--------- doc/NOTES.md | 5 +---- tests/core/test_module.py | 2 +- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/core/decorators.py b/core/decorators.py index 6fcbf99..9c9e37c 100644 --- a/core/decorators.py +++ b/core/decorators.py @@ -19,7 +19,6 @@ def every(hours=0, minutes=0, seconds=0): def scrollable(func): def wrapper(module, widget): text = func(module, widget) - widget.set('_raw', text) if not text: return text width = widget.get('theme.width', util.format.asint(module.parameter('width', 30))) diff --git a/core/module.py b/core/module.py index 6dd92e4..72a79b2 100644 --- a/core/module.py +++ b/core/module.py @@ -101,11 +101,6 @@ class Error(Module): self.__module = module self.__error = error - self.set('scrolling.bounce', False) - self.set('scrolling.speed', 2) - self.set('width', 15) - - @core.decorators.scrollable def full_text(self, widget): return '{}: {}'.format(self.__module, self.__error) diff --git a/core/output.py b/core/output.py index 351f39d..6237f1d 100644 --- a/core/output.py +++ b/core/output.py @@ -12,7 +12,10 @@ def dump_json(obj): def assign(src, dst, key, src_key=None, default=None): if not src_key: - src_key = key.replace('_', '-') # automagically replace - with _ + if key.startswith('_'): + src_key = key + else: + src_key = key.replace('_', '-') # automagically replace _ with - for k in src_key if isinstance(src_key, list) else [src_key]: if k in src: @@ -80,7 +83,8 @@ class block(object): for k in [ 'name', 'instance', 'separator_block_width', 'border', 'border_top', - 'border_bottom', 'border_left', 'border_right', 'markup' + 'border_bottom', 'border_left', 'border_right', 'markup', + '_raw', '_suffix', '_prefix' ]: assign(self.__attributes, result, k) @@ -93,13 +97,12 @@ class block(object): def __format(self, text): if text is None: return None - prefix = self.pangoize(self.__attributes.get('prefix')) - suffix = self.pangoize(self.__attributes.get('suffix')) - return '{}{}{}'.format( - self.__pad(prefix), - text, - self.__pad(suffix) - ) + prefix = self.__pad(self.pangoize(self.__attributes.get('prefix'))) + suffix = self.__pad(self.pangoize(self.__attributes.get('suffix'))) + self.set('_prefix', prefix) + self.set('_suffix', suffix) + self.set('_raw', text) + return '{}{}{}'.format(prefix, text, suffix) class i3(object): def __init__(self, theme=core.theme.Theme(), config=core.config.Config([])): diff --git a/doc/NOTES.md b/doc/NOTES.md index 898dcff..716637f 100644 --- a/doc/NOTES.md +++ b/doc/NOTES.md @@ -26,7 +26,4 @@ - theme.exclude (battery) - help output - configuration files -- custom fields __ in output for dwm bridge -- default separators -- make a create_widget call in module -- do not scroll errors? +- use add_widget() instead of core.widget.Widget() diff --git a/tests/core/test_module.py b/tests/core/test_module.py index b206d38..1d82a7e 100644 --- a/tests/core/test_module.py +++ b/tests/core/test_module.py @@ -36,7 +36,7 @@ class module(unittest.TestCase): module = core.module.load(module_name=self.validModuleName, config=config) module.widget().full_text() self.assertEqual('Error', module.__class__.__name__, 'an invalid module must be a core.module.Error') - self.assertEqual(module.widget().get('_raw'), 'test: some-error') + self.assertEqual(module.widget().full_text(), 'test: some-error') def test_loadvalid_module(self): module = core.module.load(module_name=self.validModuleName)