With this commit, it is possible to provide a list of formats for the
clock module. You can cycle through these different formats with the mousewheel. It is backward compatible.
This commit is contained in:
parent
32c1b36c93
commit
f3c549bb24
@ -14,12 +14,13 @@ class Clock(IntervalModule):
|
||||
"""
|
||||
|
||||
settings = (
|
||||
("format", "stftime format string, `None` means to use the default, locale-dependent format"),
|
||||
("format", "list of stftime format string, `None` means to use the default, locale-dependent format. Can cycle between formats with mousewheel"),
|
||||
("color", "RGB hexadecimal code color specifier, default to #ffffff, set to `i3Bar` to use i3 bar default"),
|
||||
)
|
||||
format = None
|
||||
color = "#ffffff"
|
||||
interval = 1
|
||||
currentFormatId = 0
|
||||
|
||||
def init(self):
|
||||
if self.format is None:
|
||||
@ -29,15 +30,26 @@ class Clock(IntervalModule):
|
||||
lang = locale.getlocale()[0]
|
||||
if lang == 'en_US':
|
||||
# MDY format - United States of America
|
||||
self.format = "%a %b %-d %X"
|
||||
self.format = ["%a %b %-d %X"]
|
||||
else:
|
||||
# DMY format - almost all other countries
|
||||
self.format = "%a %-d %b %X"
|
||||
self.format = ["%a %-d %b %X"]
|
||||
|
||||
elif isinstance(self.format,str):
|
||||
self.format=[self.format]
|
||||
|
||||
def run(self):
|
||||
self.output = {
|
||||
"full_text": datetime.datetime.now().strftime(self.format),
|
||||
# todo find local
|
||||
"full_text": datetime.datetime.now().strftime(self.format[self.currentFormatId]),
|
||||
"urgent": False,
|
||||
}
|
||||
if self.color != "i3Bar":
|
||||
self.output["color"] = self.color
|
||||
|
||||
|
||||
def on_upscroll(self):
|
||||
self.currentFormatId = (self.currentFormatId + 1)% len(self.format)
|
||||
|
||||
def on_downscroll(self):
|
||||
self.currentFormatId = (self.currentFormatId - 1)% len(self.format)
|
||||
|
Loading…
Reference in New Issue
Block a user