2020-02-04 21:10:05 +01:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
"""Displays the current date and time.
|
2020-02-04 21:10:05 +01:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
* datetime.format: strftime()-compatible formatting string
|
|
|
|
* datetime.locale: locale to use rather than the system default
|
2020-05-03 11:15:52 +02:00
|
|
|
"""
|
2020-02-04 21:10:05 +01:00
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
import datetime
|
|
|
|
import locale
|
|
|
|
|
|
|
|
import core.module
|
|
|
|
import core.widget
|
2020-02-07 21:28:29 +01:00
|
|
|
import core.input
|
2020-02-04 21:10:05 +01:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-02-04 21:10:05 +01:00
|
|
|
class Module(core.module.Module):
|
2020-04-26 16:39:24 +02:00
|
|
|
def __init__(self, config, theme):
|
|
|
|
super().__init__(config, theme, core.widget.Widget(self.full_text))
|
2020-02-07 21:28:29 +01:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
core.input.register(self, button=core.input.LEFT_MOUSE, cmd="calendar")
|
|
|
|
self._fmt = self.parameter("format", self.default_format())
|
2020-02-04 21:10:05 +01:00
|
|
|
l = locale.getdefaultlocale()
|
|
|
|
if not l or l == (None, None):
|
2020-05-03 11:15:52 +02:00
|
|
|
l = ("en_US", "UTF-8")
|
|
|
|
lcl = self.parameter("locale", ".".join(l))
|
2020-02-04 21:10:05 +01:00
|
|
|
try:
|
2020-05-03 11:15:52 +02:00
|
|
|
locale.setlocale(locale.LC_TIME, lcl.split("."))
|
2020-02-04 21:10:05 +01:00
|
|
|
except Exception as e:
|
2020-05-03 11:15:52 +02:00
|
|
|
locale.setlocale(locale.LC_TIME, ("en_US", "UTF-8"))
|
2020-02-04 21:10:05 +01:00
|
|
|
|
|
|
|
def default_format(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
return "%x %X"
|
2020-02-04 21:10:05 +01:00
|
|
|
|
2020-02-23 14:47:47 +01:00
|
|
|
def full_text(self, widget):
|
2020-02-04 21:10:05 +01:00
|
|
|
enc = locale.getpreferredencoding()
|
|
|
|
retval = datetime.datetime.now().strftime(self._fmt)
|
2020-05-03 11:15:52 +02:00
|
|
|
if hasattr(retval, "decode"):
|
2020-02-04 21:10:05 +01:00
|
|
|
return retval.decode(enc)
|
|
|
|
return retval
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-02-04 21:10:05 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|