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 = (
|
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"),
|
("color", "RGB hexadecimal code color specifier, default to #ffffff, set to `i3Bar` to use i3 bar default"),
|
||||||
)
|
)
|
||||||
format = None
|
format = None
|
||||||
color = "#ffffff"
|
color = "#ffffff"
|
||||||
interval = 1
|
interval = 1
|
||||||
|
currentFormatId = 0
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
if self.format is None:
|
if self.format is None:
|
||||||
@ -29,15 +30,26 @@ class Clock(IntervalModule):
|
|||||||
lang = locale.getlocale()[0]
|
lang = locale.getlocale()[0]
|
||||||
if lang == 'en_US':
|
if lang == 'en_US':
|
||||||
# MDY format - United States of America
|
# MDY format - United States of America
|
||||||
self.format = "%a %b %-d %X"
|
self.format = ["%a %b %-d %X"]
|
||||||
else:
|
else:
|
||||||
# DMY format - almost all other countries
|
# 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):
|
def run(self):
|
||||||
self.output = {
|
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,
|
"urgent": False,
|
||||||
}
|
}
|
||||||
if self.color != "i3Bar":
|
if self.color != "i3Bar":
|
||||||
self.output["color"] = self.color
|
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