[core/module] Make name and module_name attributes

This commit is contained in:
tobi-wan-kenobi 2020-04-30 12:50:24 +02:00
parent b27956071f
commit 1e4955d4b8
4 changed files with 9 additions and 13 deletions

View file

@ -34,7 +34,9 @@ class Module(core.input.Object):
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.module_name = self.__module__.split('.')[-1]
self.name = self.module_name
self.alias = self.__config.get('__alias__', None) self.alias = self.__config.get('__alias__', None)
self.next_update = None self.next_update = None
@ -46,13 +48,13 @@ class Module(core.input.Object):
def parameter(self, key, default=None): def parameter(self, key, default=None):
value = default value = default
for prefix in [ self.name(), self.module_name(), self.alias ]: for prefix in [ self.name, self.module_name, self.alias ]:
value = self.__config.get('{}.{}'.format(prefix, key), value) value = self.__config.get('{}.{}'.format(prefix, key), value)
# TODO retrieve from config file # TODO retrieve from config file
return value return value
def set(self, key, value): def set(self, key, value):
self.__config.set('{}.{}'.format(self.name(), key), value) self.__config.set('{}.{}'.format(self.name, key), value)
def update(self): def update(self):
pass pass
@ -66,12 +68,6 @@ class Module(core.input.Object):
self.__widgets = [module.widget()] self.__widgets = [module.widget()]
self.update = module.update self.update = module.update
def name(self):
return self.__name if self.__name else self.module_name()
def module_name(self):
return self.__module__.split('.')[-1]
def widgets(self, widgets=None): def widgets(self, widgets=None):
if widgets: if widgets:
self.__widgets = widgets self.__widgets = widgets

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

@ -115,7 +115,7 @@ 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

@ -66,8 +66,8 @@ class module(unittest.TestCase):
def test_module_Name(self): def test_module_Name(self):
module = TestModule() module = TestModule()
self.assertEqual('test_module', module.name(), 'module has wrong name') self.assertEqual('test_module', module.name, 'module has wrong name')
self.assertEqual('test_module', module.module_name(), 'module has wrong name') self.assertEqual('test_module', module.module_name, 'module has wrong name')
def testvalid_parameter(self): def testvalid_parameter(self):
cfg = core.config.Config(shlex.split('-p test_module.foo=5')) cfg = core.config.Config(shlex.split('-p test_module.foo=5'))