[core] Move "every" to decorators module

This commit is contained in:
tobi-wan-kenobi 2020-03-29 14:36:44 +02:00
parent 11ebcee29a
commit c625baa47a
3 changed files with 11 additions and 10 deletions

View file

@ -1,5 +1,14 @@
import util.format 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 scrollable(func):
def wrapper(module, widget): def wrapper(module, widget):
text = func(module, widget) text = func(module, widget)

View file

@ -12,15 +12,6 @@ except Exception as e:
log = logging.getLogger(__name__) 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): def load(module_name, config=None):
error = None error = None
for namespace in [ 'core', 'contrib' ]: for namespace in [ 'core', 'contrib' ]:

View file

@ -6,9 +6,10 @@ import platform
import core.module import core.module
import core.widget import core.widget
import core.decorators
class Module(core.module.Module): class Module(core.module.Module):
@core.module.every(minutes=60) @core.decorators.every(minutes=60)
def __init__(self, config): def __init__(self, config):
super().__init__(config, core.widget.Widget(self.full_text)) super().__init__(config, core.widget.Widget(self.full_text))