[core] Add themes to module constructor

This commit is contained in:
tobi-wan-kenobi 2020-04-26 16:39:13 +02:00
parent 354d723b7c
commit 1f94eab927
4 changed files with 10 additions and 10 deletions

View file

@ -12,14 +12,14 @@ except Exception as e:
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def load(module_name, config=core.config.Config([])): def load(module_name, config=core.config.Config([]), theme=None):
error = None error = None
module_short, alias = (module_name.split(':') + [module_name])[0:2] module_short, alias = (module_name.split(':') + [module_name])[0:2]
config.set('__alias__', alias) config.set('__alias__', alias)
for namespace in [ 'core', 'contrib' ]: for namespace in [ 'core', 'contrib' ]:
try: try:
mod = importlib.import_module('modules.{}.{}'.format(namespace, module_short)) mod = importlib.import_module('modules.{}.{}'.format(namespace, module_short))
return getattr(mod, 'Module')(config) return getattr(mod, 'Module')(config, theme)
except ImportError as e: except ImportError as e:
log.fatal('failed to import {}: {}'.format(module_short, e)) log.fatal('failed to import {}: {}'.format(module_short, e))
if not error or module_short in error: 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) return Error(config=config, module=module_name, error=error)
class Module(core.input.Object): 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__() super().__init__()
self.__config = config self.__config = config
self.__widgets = widgets if isinstance(widgets, list) else [ widgets ] self.__widgets = widgets if isinstance(widgets, list) else [ widgets ]
@ -90,8 +90,8 @@ class Module(core.input.Object):
return None return None
class Error(Module): class Error(Module):
def __init__(self, module, error, config=core.config.Config([])): def __init__(self, module, error, config=core.config.Config([]), theme=None):
super().__init__(config, core.widget.Widget(self.full_text)) super().__init__(config, theme, core.widget.Widget(self.full_text))
self.__module = module self.__module = module
self.__error = error self.__error = error

View file

@ -6,9 +6,9 @@ import core.module
import core.config import core.config
class TestModule(core.module.Module): class TestModule(core.module.Module):
def __init__(self, config=None): def __init__(self, config=None, theme=None):
config = core.config.Config([]) config = core.config.Config([])
super().__init__(config, core.widget.Widget(self.get)) super().__init__(config, theme, core.widget.Widget(self.get))
self.text = '' self.text = ''
@core.decorators.scrollable @core.decorators.scrollable

View file

@ -6,8 +6,8 @@ import core.module
import core.config import core.config
class TestModule(core.module.Module): class TestModule(core.module.Module):
def __init__(self, widgets, config=core.config.Config([])): def __init__(self, widgets, config=core.config.Config([]), theme=None):
super().__init__(config, widgets) super().__init__(config, theme, widgets)
self.states = [] self.states = []
def update(self): def update(self):

View file

@ -6,7 +6,7 @@ import modules.core.kernel
class kernel(unittest.TestCase): class kernel(unittest.TestCase):
def setUp(self): def setUp(self):
self.someKernel = 'this-is-my-kernel' 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): def test_full_text(self):
with unittest.mock.patch('modules.core.kernel.platform') as platform: with unittest.mock.patch('modules.core.kernel.platform') as platform: