diff --git a/core/decorators.py b/core/decorators.py index 2ec900a..df555ff 100644 --- a/core/decorators.py +++ b/core/decorators.py @@ -1,11 +1,11 @@ import util.format -def every(minutes=0, seconds=0): +def every(hours=0, 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) + obj.set('interval', hours*3600 + minutes*60 + seconds) return call_init return decorator_init diff --git a/modules/core/brightness.py b/modules/core/brightness.py index 78f65d3..54598a7 100644 --- a/modules/core/brightness.py +++ b/modules/core/brightness.py @@ -1,12 +1,12 @@ # pylint: disable=C0111,R0903 -'''Displays the brightness of a display +"""Displays the brightness of a display Parameters: * brightness.step: The amount of increase/decrease on scroll in % (defaults to 2) * brightness.device_path: The device path (defaults to /sys/class/backlight/intel_backlight), can contain wildcards (in this case, the first matching path will be used) -''' +""" import glob import shutil @@ -14,8 +14,10 @@ import shutil import core.module import core.widget import core.input +import core.decorators class Module(core.module.Module): + @core.decorators.every(seconds=30) # takes 30s to pick up on "external" changes def __init__(self, config): super().__init__(config, core.widget.Widget(self.brightness)) diff --git a/modules/core/date.py b/modules/core/date.py index 38c4e62..2da8639 100644 --- a/modules/core/date.py +++ b/modules/core/date.py @@ -1,15 +1,17 @@ # pylint: disable=C0111,R0903 -'''Displays the current date and time. +"""Displays the current date and time. Parameters: * date.format: strftime()-compatible formatting string * date.locale: locale to use rather than the system default -''' +""" +import core.decorators from .datetime import Module class Module(Module): + @core.decorators.every(hours=1) def __init__(self, config): super().__init__(config) diff --git a/modules/core/nic.py b/modules/core/nic.py index 7f98ca0..b54680b 100644 --- a/modules/core/nic.py +++ b/modules/core/nic.py @@ -1,6 +1,6 @@ #pylint: disable=C0111,R0903 -'''Displays the name, IP address(es) and status of each available network interface. +"""Displays the name, IP address(es) and status of each available network interface. Requires the following python module: * netifaces @@ -10,7 +10,7 @@ Parameters: * nic.include: Comma-separated list of interfaces to include * nic.states: Comma-separated list of states to show (prefix with '^' to invert - i.e. ^down -> show all devices that are not in state down) * nic.format: Format string (defaults to '{intf} {state} {ip} {ssid}') -''' +""" import shutil import netifaces @@ -18,10 +18,12 @@ import subprocess import core.widget import core.module +import core.decorators import util.cli import util.format class Module(core.module.Module): + @core.decorators.every(seconds=10) def __init__(self, config): widgets = [] super().__init__(config, widgets) diff --git a/modules/core/redshift.py b/modules/core/redshift.py index 24cc6f1..d8850a8 100644 --- a/modules/core/redshift.py +++ b/modules/core/redshift.py @@ -1,6 +1,6 @@ # pylint: disable=C0111,R0903 -'''Displays the current color temperature of redshift +"""Displays the current color temperature of redshift Requires the following executable: * redshift @@ -11,7 +11,7 @@ Parameters: 'auto' uses whatever redshift is configured to do * redshift.lat : latitude if location is set to 'manual' * redshift.lon : longitude if location is set to 'manual' -''' +""" import threading import logging @@ -24,6 +24,7 @@ except ImportError: import core.module import core.widget import core.input +import core.decorators import util.cli @@ -75,6 +76,7 @@ def get_redshift_value(widget, location, lat, lon): widget.set('transition', ' '.join(line.split(' ')[2:])) class Module(core.module.Module): + @core.decorators.every(seconds=10) def __init__(self, config): widget = core.widget.Widget(self.text) super().__init__(config, widget) diff --git a/modules/core/time.py b/modules/core/time.py index a800103..f35186e 100644 --- a/modules/core/time.py +++ b/modules/core/time.py @@ -1,15 +1,17 @@ # pylint: disable=C0111,R0903 -'''Displays the current date and time. +"""Displays the current date and time. Parameters: * time.format: strftime()-compatible formatting string * time.locale: locale to use rather than the system default -''' +""" +import core.decorators from .datetime import Module class Module(Module): + @core.decorators.every(seconds=59) # ensures one update per minute def __init__(self, config): super().__init__(config) diff --git a/modules/core/xrandr.py b/modules/core/xrandr.py index a62e0f5..4b7d8b6 100644 --- a/modules/core/xrandr.py +++ b/modules/core/xrandr.py @@ -23,6 +23,7 @@ import sys import core.module import core.widget import core.input +import core.decorators import util.cli import util.format @@ -33,6 +34,7 @@ except: pass class Module(core.module.Module): + @core.decorators.every(seconds=5) # takes up to 5s to detect a new screen def __init__(self, config): widgets = [] super().__init__(config, widgets)