2016-10-31 14:39:52 +01:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2016-10-30 17:30:09 +01:00
|
|
|
import datetime
|
2016-10-30 17:56:04 +01:00
|
|
|
import bumblebee.module
|
|
|
|
|
2016-11-05 16:18:53 +01:00
|
|
|
def description():
|
|
|
|
return "Displays the current time, using the optional format string as input for strftime."
|
|
|
|
|
|
|
|
def parameters():
|
2016-10-31 16:08:03 +01:00
|
|
|
module = __name__.split(".")[-1]
|
2016-11-05 16:18:53 +01:00
|
|
|
return [
|
|
|
|
"{}.format: strftime specification (defaults to {})".format(module, default_format(module))
|
|
|
|
]
|
|
|
|
|
|
|
|
def default_format(module):
|
|
|
|
default = "%x %X"
|
2016-10-31 16:08:03 +01:00
|
|
|
if module == "date":
|
2016-11-05 16:18:53 +01:00
|
|
|
default = "%x"
|
2016-10-31 16:08:03 +01:00
|
|
|
if module == "time":
|
2016-11-05 16:18:53 +01:00
|
|
|
default = "%X"
|
|
|
|
return default
|
2016-10-31 16:08:03 +01:00
|
|
|
|
2016-10-30 17:56:04 +01:00
|
|
|
class Module(bumblebee.module.Module):
|
2016-11-05 14:26:02 +01:00
|
|
|
def __init__(self, output, config, alias):
|
|
|
|
super(Module, self).__init__(output, config, alias)
|
2016-10-31 14:27:51 +01:00
|
|
|
|
2016-10-31 11:11:53 +01:00
|
|
|
module = self.__module__.split(".")[-1]
|
|
|
|
|
2016-11-05 16:33:35 +01:00
|
|
|
self._fmt = self._config.parameter("format", default_format(module))
|
2016-10-30 17:30:09 +01:00
|
|
|
|
2016-11-05 08:59:43 +01:00
|
|
|
def widgets(self):
|
2016-11-05 13:12:30 +01:00
|
|
|
return bumblebee.output.Widget(self, datetime.datetime.now().strftime(self._fmt))
|
2016-10-30 17:30:09 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|