From b27956071f3a67e487fc1eee10e65e446259a779 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Thu, 30 Apr 2020 12:46:57 +0200 Subject: [PATCH] [core/widget] Make module an attribute Instead of having an artifical getter/setter method, just make module a plain attribute. --- core/module.py | 2 +- core/output.py | 2 +- core/theme.py | 4 ++-- core/widget.py | 11 +++-------- modules/contrib/dnf.py | 2 +- modules/contrib/pacman.py | 2 +- modules/core/redshift.py | 2 +- modules/core/xrandr.py | 6 ++---- 8 files changed, 12 insertions(+), 19 deletions(-) diff --git a/core/module.py b/core/module.py index 3919ea3..5432df5 100644 --- a/core/module.py +++ b/core/module.py @@ -33,7 +33,7 @@ class Module(core.input.Object): self.__config = config self.__widgets = widgets if isinstance(widgets, list) else [ widgets ] for widget in self.__widgets: - widget.module(self) + widget.module = self self.__name = None self.alias = self.__config.get('__alias__', None) self.next_update = None diff --git a/core/output.py b/core/output.py index a85880a..1ba740d 100644 --- a/core/output.py +++ b/core/output.py @@ -162,7 +162,7 @@ class i3(object): def blocks(self, module): blocks = [] for widget in module.widgets(): - if widget.module() and self.__config.autohide(widget.module().name()): + if widget.module and self.__config.autohide(widget.module.name()): if not any(state in widget.state() for state in [ 'warning', 'critical']): continue if module.hidden(): diff --git a/core/theme.py b/core/theme.py index a28d191..0ece69e 100644 --- a/core/theme.py +++ b/core/theme.py @@ -114,8 +114,8 @@ class Theme(object): value = merge_replace(value, self.__data.get(key, value), key) - if widget.module(): - value = merge_replace(value, self.get(widget.module().name(), None, {}).get(key, value), key) + if widget.module: + value = merge_replace(value, self.get(widget.module.name(), None, {}).get(key, value), key) if not key in widget.state(): for state in widget.state(): diff --git a/core/widget.py b/core/widget.py index 3c42efb..0c12e99 100644 --- a/core/widget.py +++ b/core/widget.py @@ -6,7 +6,7 @@ class Widget(util.store.Store, core.input.Object): def __init__(self, full_text='', name=None, module=None): super(Widget, self).__init__() self.__full_text = full_text - self.__module = module + self.module = module self.name = name def full_text(self, value=None): @@ -17,18 +17,13 @@ class Widget(util.store.Store, core.input.Object): return self.__full_text(self) return self.__full_text - def module(self, module=None): - if not module: - return self.__module - self.__module = module - def state(self): rv = [] if self.get('state', None): tmp = self.get('state') rv = tmp[:] if isinstance(tmp, list) else [tmp] - if self.__module: - tmp = self.__module.state(self) + if self.module: + tmp = self.module.state(self) rv.extend(tmp if isinstance(tmp, list) else [tmp]) return rv diff --git a/modules/contrib/dnf.py b/modules/contrib/dnf.py index e9dce5b..83e52cf 100644 --- a/modules/contrib/dnf.py +++ b/modules/contrib/dnf.py @@ -46,7 +46,7 @@ def get_dnf_info(widget): widget.set('enhancements', enhancements) widget.set('other', other) - core.event.trigger('update', [ widget.module().id ], redraw_only=True) + core.event.trigger('update', [ widget.module.id ], redraw_only=True) class Module(core.module.Module): @core.decorators.every(minutes=30) diff --git a/modules/contrib/pacman.py b/modules/contrib/pacman.py index 64b47a9..2d8245a 100644 --- a/modules/contrib/pacman.py +++ b/modules/contrib/pacman.py @@ -43,7 +43,7 @@ def get_pacman_info(widget, path): for i in range(len(repos)): widget.set(repos[i], count[i]) - core.event.trigger('update', [ widget.module().id ], redraw_only=True) + core.event.trigger('update', [ widget.module.id ], redraw_only=True) class Module(core.module.Module): @core.decorators.every(minutes=30) diff --git a/modules/core/redshift.py b/modules/core/redshift.py index 1729d84..1ad29d0 100644 --- a/modules/core/redshift.py +++ b/modules/core/redshift.py @@ -62,7 +62,7 @@ def get_redshift_value(module): widget.set('state', 'transition') match = re.search(r'(\d+)\.\d+% ([a-z]+)', line) widget.set('transition', '({}% {})'.format(match.group(1), match.group(2))) - core.event.trigger('update', [ widget.module().id ], redraw_only=True) + core.event.trigger('update', [ widget.module.id ], redraw_only=True) class Module(core.module.Module): @core.decorators.every(seconds=10) diff --git a/modules/core/xrandr.py b/modules/core/xrandr.py index 6d2f931..77cda49 100644 --- a/modules/core/xrandr.py +++ b/modules/core/xrandr.py @@ -66,19 +66,17 @@ class Module(core.module.Module): widget = self.widget(display) if not widget: - widget = core.widget.Widget(full_text=display, name=display) + widget = core.widget.Widget(full_text=display, name=display, module=self) core.input.register(widget, button=1, cmd=self._toggle) core.input.register(widget, button=3, cmd=self._toggle) new_widgets.append(widget) - widget.module(self) widget.set('state', 'on' if m else 'off') widget.set('pos', int(m.group(1)) if m else sys.maxsize) self.widgets(new_widgets) if self._autoupdate == False: - widget = core.widget.Widget(full_text='') - widget.module(self) + widget = core.widget.Widget(full_text='', module=self) widget.set('state', 'refresh') core.input.register(widget, button=1, cmd=self._refresh) self.widgets().append(widget)