From c625baa47ad9fbe70b9295b8455c3e4eeab00930 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Sun, 29 Mar 2020 14:36:44 +0200 Subject: [PATCH] [core] Move "every" to decorators module --- core/decorators.py | 9 +++++++++ core/module.py | 9 --------- modules/core/kernel.py | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/core/decorators.py b/core/decorators.py index 4c241a8..2ec900a 100644 --- a/core/decorators.py +++ b/core/decorators.py @@ -1,5 +1,14 @@ import util.format +def every(minutes=0, seconds=0): + def decorator_init(init): + def call_init(obj, *args, **kwargs): + init(obj, *args, **kwargs) + if obj.parameter('interval') is None: + obj.set('interval', minutes*60 + seconds) + return call_init + return decorator_init + def scrollable(func): def wrapper(module, widget): text = func(module, widget) diff --git a/core/module.py b/core/module.py index a68d072..a2c0f3b 100644 --- a/core/module.py +++ b/core/module.py @@ -12,15 +12,6 @@ except Exception as e: log = logging.getLogger(__name__) -def every(minutes=0, seconds=0): - def decorator_init(init): - def call_init(obj, *args, **kwargs): - init(obj, *args, **kwargs) - if obj.parameter('interval') is None: - obj.set('interval', minutes*60 + seconds) - return call_init - return decorator_init - def load(module_name, config=None): error = None for namespace in [ 'core', 'contrib' ]: diff --git a/modules/core/kernel.py b/modules/core/kernel.py index 2ce05f1..fb8dc7c 100644 --- a/modules/core/kernel.py +++ b/modules/core/kernel.py @@ -6,9 +6,10 @@ import platform import core.module import core.widget +import core.decorators class Module(core.module.Module): - @core.module.every(minutes=60) + @core.decorators.every(minutes=60) def __init__(self, config): super().__init__(config, core.widget.Widget(self.full_text))