[core] Add themes to module constructor
This commit is contained in:
parent
354d723b7c
commit
1f94eab927
4 changed files with 10 additions and 10 deletions
|
@ -12,14 +12,14 @@ except Exception as e:
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def load(module_name, config=core.config.Config([])):
|
||||
def load(module_name, config=core.config.Config([]), theme=None):
|
||||
error = None
|
||||
module_short, alias = (module_name.split(':') + [module_name])[0:2]
|
||||
config.set('__alias__', alias)
|
||||
for namespace in [ 'core', 'contrib' ]:
|
||||
try:
|
||||
mod = importlib.import_module('modules.{}.{}'.format(namespace, module_short))
|
||||
return getattr(mod, 'Module')(config)
|
||||
return getattr(mod, 'Module')(config, theme)
|
||||
except ImportError as e:
|
||||
log.fatal('failed to import {}: {}'.format(module_short, e))
|
||||
if not error or module_short in error:
|
||||
|
@ -28,7 +28,7 @@ def load(module_name, config=core.config.Config([])):
|
|||
return Error(config=config, module=module_name, error=error)
|
||||
|
||||
class Module(core.input.Object):
|
||||
def __init__(self, config=core.config.Config([]), widgets=[]):
|
||||
def __init__(self, config=core.config.Config([]), theme=None, widgets=[]):
|
||||
super().__init__()
|
||||
self.__config = config
|
||||
self.__widgets = widgets if isinstance(widgets, list) else [ widgets ]
|
||||
|
@ -90,8 +90,8 @@ class Module(core.input.Object):
|
|||
return None
|
||||
|
||||
class Error(Module):
|
||||
def __init__(self, module, error, config=core.config.Config([])):
|
||||
super().__init__(config, core.widget.Widget(self.full_text))
|
||||
def __init__(self, module, error, config=core.config.Config([]), theme=None):
|
||||
super().__init__(config, theme, core.widget.Widget(self.full_text))
|
||||
self.__module = module
|
||||
self.__error = error
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ import core.module
|
|||
import core.config
|
||||
|
||||
class TestModule(core.module.Module):
|
||||
def __init__(self, config=None):
|
||||
def __init__(self, config=None, theme=None):
|
||||
config = core.config.Config([])
|
||||
super().__init__(config, core.widget.Widget(self.get))
|
||||
super().__init__(config, theme, core.widget.Widget(self.get))
|
||||
self.text = ''
|
||||
|
||||
@core.decorators.scrollable
|
||||
|
|
|
@ -6,8 +6,8 @@ import core.module
|
|||
import core.config
|
||||
|
||||
class TestModule(core.module.Module):
|
||||
def __init__(self, widgets, config=core.config.Config([])):
|
||||
super().__init__(config, widgets)
|
||||
def __init__(self, widgets, config=core.config.Config([]), theme=None):
|
||||
super().__init__(config, theme, widgets)
|
||||
self.states = []
|
||||
|
||||
def update(self):
|
||||
|
|
|
@ -6,7 +6,7 @@ import modules.core.kernel
|
|||
class kernel(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.someKernel = 'this-is-my-kernel'
|
||||
self.module = modules.core.kernel.Module(config=core.config.Config([]))
|
||||
self.module = modules.core.kernel.Module(config=core.config.Config([]), theme=None)
|
||||
|
||||
def test_full_text(self):
|
||||
with unittest.mock.patch('modules.core.kernel.platform') as platform:
|
||||
|
|
Loading…
Reference in a new issue