[core/module] Make name and module_name attributes
This commit is contained in:
parent
b27956071f
commit
1e4955d4b8
4 changed files with 9 additions and 13 deletions
|
@ -34,7 +34,9 @@ class Module(core.input.Object):
|
|||
self.__widgets = widgets if isinstance(widgets, list) else [ widgets ]
|
||||
for widget in self.__widgets:
|
||||
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.next_update = None
|
||||
|
||||
|
@ -46,13 +48,13 @@ class Module(core.input.Object):
|
|||
def parameter(self, key, default=None):
|
||||
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)
|
||||
# TODO retrieve from config file
|
||||
return 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):
|
||||
pass
|
||||
|
@ -66,12 +68,6 @@ class Module(core.input.Object):
|
|||
self.__widgets = [module.widget()]
|
||||
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):
|
||||
if widgets:
|
||||
self.__widgets = widgets
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -115,7 +115,7 @@ 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)
|
||||
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():
|
||||
|
|
|
@ -66,8 +66,8 @@ class module(unittest.TestCase):
|
|||
|
||||
def test_module_Name(self):
|
||||
module = TestModule()
|
||||
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.name, 'module has wrong name')
|
||||
self.assertEqual('test_module', module.module_name, 'module has wrong name')
|
||||
|
||||
def testvalid_parameter(self):
|
||||
cfg = core.config.Config(shlex.split('-p test_module.foo=5'))
|
||||
|
|
Loading…
Reference in a new issue