[core/widget] Make module an attribute

Instead of having an artifical getter/setter method, just make module a
plain attribute.
This commit is contained in:
tobi-wan-kenobi 2020-04-30 12:46:57 +02:00
parent 9cd9ff626d
commit b27956071f
8 changed files with 12 additions and 19 deletions

View file

@ -33,7 +33,7 @@ class Module(core.input.Object):
self.__config = config self.__config = config
self.__widgets = widgets if isinstance(widgets, list) else [ widgets ] self.__widgets = widgets if isinstance(widgets, list) else [ widgets ]
for widget in self.__widgets: for widget in self.__widgets:
widget.module(self) widget.module = self
self.__name = None self.__name = None
self.alias = self.__config.get('__alias__', None) self.alias = self.__config.get('__alias__', None)
self.next_update = None self.next_update = None

View file

@ -162,7 +162,7 @@ class i3(object):
def blocks(self, module): def blocks(self, module):
blocks = [] blocks = []
for widget in module.widgets(): 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']): if not any(state in widget.state() for state in [ 'warning', 'critical']):
continue continue
if module.hidden(): if module.hidden():

View file

@ -114,8 +114,8 @@ class Theme(object):
value = merge_replace(value, self.__data.get(key, value), key) value = merge_replace(value, self.__data.get(key, value), key)
if widget.module(): if widget.module:
value = merge_replace(value, self.get(widget.module().name(), None, {}).get(key, value), key) value = merge_replace(value, self.get(widget.module.name(), None, {}).get(key, value), key)
if not key in widget.state(): if not key in widget.state():
for state in widget.state(): for state in widget.state():

View file

@ -6,7 +6,7 @@ class Widget(util.store.Store, core.input.Object):
def __init__(self, full_text='', name=None, module=None): def __init__(self, full_text='', name=None, module=None):
super(Widget, self).__init__() super(Widget, self).__init__()
self.__full_text = full_text self.__full_text = full_text
self.__module = module self.module = module
self.name = name self.name = name
def full_text(self, value=None): 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(self)
return self.__full_text return self.__full_text
def module(self, module=None):
if not module:
return self.__module
self.__module = module
def state(self): def state(self):
rv = [] rv = []
if self.get('state', None): if self.get('state', None):
tmp = self.get('state') tmp = self.get('state')
rv = tmp[:] if isinstance(tmp, list) else [tmp] rv = tmp[:] if isinstance(tmp, list) else [tmp]
if self.__module: if self.module:
tmp = self.__module.state(self) tmp = self.module.state(self)
rv.extend(tmp if isinstance(tmp, list) else [tmp]) rv.extend(tmp if isinstance(tmp, list) else [tmp])
return rv return rv

View file

@ -46,7 +46,7 @@ def get_dnf_info(widget):
widget.set('enhancements', enhancements) widget.set('enhancements', enhancements)
widget.set('other', other) 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): class Module(core.module.Module):
@core.decorators.every(minutes=30) @core.decorators.every(minutes=30)

View file

@ -43,7 +43,7 @@ def get_pacman_info(widget, path):
for i in range(len(repos)): for i in range(len(repos)):
widget.set(repos[i], count[i]) 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): class Module(core.module.Module):
@core.decorators.every(minutes=30) @core.decorators.every(minutes=30)

View file

@ -62,7 +62,7 @@ def get_redshift_value(module):
widget.set('state', 'transition') widget.set('state', 'transition')
match = re.search(r'(\d+)\.\d+% ([a-z]+)', line) match = re.search(r'(\d+)\.\d+% ([a-z]+)', line)
widget.set('transition', '({}% {})'.format(match.group(1), match.group(2))) 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): class Module(core.module.Module):
@core.decorators.every(seconds=10) @core.decorators.every(seconds=10)

View file

@ -66,19 +66,17 @@ class Module(core.module.Module):
widget = self.widget(display) widget = self.widget(display)
if not widget: 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=1, cmd=self._toggle)
core.input.register(widget, button=3, cmd=self._toggle) core.input.register(widget, button=3, cmd=self._toggle)
new_widgets.append(widget) new_widgets.append(widget)
widget.module(self)
widget.set('state', 'on' if m else 'off') widget.set('state', 'on' if m else 'off')
widget.set('pos', int(m.group(1)) if m else sys.maxsize) widget.set('pos', int(m.group(1)) if m else sys.maxsize)
self.widgets(new_widgets) self.widgets(new_widgets)
if self._autoupdate == False: if self._autoupdate == False:
widget = core.widget.Widget(full_text='') widget = core.widget.Widget(full_text='', module=self)
widget.module(self)
widget.set('state', 'refresh') widget.set('state', 'refresh')
core.input.register(widget, button=1, cmd=self._refresh) core.input.register(widget, button=1, cmd=self._refresh)
self.widgets().append(widget) self.widgets().append(widget)