diff --git a/modules/contrib/datetimetz.py b/modules/contrib/datetimetz.py index be7f569..08c6631 100644 --- a/modules/contrib/datetimetz.py +++ b/modules/contrib/datetimetz.py @@ -18,14 +18,14 @@ from __future__ import absolute_import import datetime import locale import logging -try: - import pytz - import tzlocal -except: - pass -import bumblebee.input -import bumblebee.output -import bumblebee.engine +import pytz +import tzlocal + +import core.module +import core.widget +import core.input + +import util.format def default_format(module): default = '%x %X %Z' @@ -35,20 +35,21 @@ def default_format(module): default = '%X %Z' return default -class Module(bumblebee.engine.Module): - def __init__(self, engine, config): - super(Module, self).__init__(engine, config, - bumblebee.output.Widget(full_text=self.get_time)) - engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd=self.next_tz) - engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE, cmd=self.prev_tz) - self._fmt = self.parameter('format', default_format(self.name)) +class Module(core.module.Module): + def __init__(self, config): + super().__init__(config, core.widget.Widget(self.get_time)) + + core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.next_tz) + core.input.register(self, button=core.input.RIGHT_MOUSE, cmd=self.prev_tz) + self.__fmt = self.parameter('format', self.default_format()) + default_timezone = '' try: default_timezone = tzlocal.get_localzone().zone except Exception as e: logging.error('unable to get default timezone: {}'.format(str(e))) try: - self._timezones = self.parameter('timezone', default_timezone).split(',') + self._timezones = util.format.aslist(self.parameter('timezone', default_timezone)) except: self._timezones = [default_timezone] self._current_tz = 0 @@ -62,11 +63,14 @@ class Module(bumblebee.engine.Module): except Exception: locale.setlocale(locale.LC_TIME, ('en_US', 'UTF-8')) + def default_format(self): + return '%x %X %Z' + def get_time(self, widget): try: try: tz = pytz.timezone(self._timezones[self._current_tz].strip()) - retval = datetime.datetime.now(tz=tzlocal.get_localzone()).astimezone(tz).strftime(self._fmt) + retval = datetime.datetime.now(tz=tzlocal.get_localzone()).astimezone(tz).strftime(self.__fmt) except pytz.exceptions.UnknownTimeZoneError: retval = '[Unknown timezone: {}]'.format(self._timezones[self._current_tz].strip()) except Exception as e: diff --git a/modules/contrib/datetz.py b/modules/contrib/datetz.py new file mode 100644 index 0000000..48541dc --- /dev/null +++ b/modules/contrib/datetz.py @@ -0,0 +1,21 @@ +# pylint: disable=C0111,R0903 + +"""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 .datetimetz import Module + +class Module(Module): + @core.decorators.every(hours=1) + def __init__(self, config): + super().__init__(config) + + def default_format(self): + return '%x %Z' + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/modules/contrib/timetz.py b/modules/contrib/timetz.py new file mode 100644 index 0000000..aeaa6f6 --- /dev/null +++ b/modules/contrib/timetz.py @@ -0,0 +1,21 @@ +# pylint: disable=C0111,R0903 + +"""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 .datetimetz import Module + +class Module(Module): + @core.decorators.every(seconds=59) # ensures one update per minute + def __init__(self, config): + super().__init__(config) + + def default_format(self): + return '%X %Z' + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4