[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:
parent
9cd9ff626d
commit
b27956071f
8 changed files with 12 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue