Skip to content

Commit

Permalink
Merge pull request #142 from billyeatcookies/24_hours_clock
Browse files Browse the repository at this point in the history
feat: Add 12/24 hour option for statusbar clock
  • Loading branch information
tomlin7 authored Oct 16, 2023
2 parents 9a38016 + b09513f commit 00e12fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 5 additions & 3 deletions biscuit/core/layout/statusbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ def __init__(self, master: Root, *args, **kwargs) -> None:
self.notif.pack(side=tk.RIGHT, padx=(0, 10))

# clock
self.clock = SClock(self, text="H:M:S", description="Time")
self.time_actionset = ActionSet(
"Configure clock format", "time:",
[("12 hours", lambda e=None: print("time 12 hours", e)),
("24 hours", lambda e=None: print("time 24 hours", e)),],
[("12 hours", lambda e=None: self.clock.use_24_hour_format(False)),
("24 hours", lambda e=None: self.clock.use_24_hour_format(True)),],
)
self.clock = SClock(self, text="H:M:S", function=lambda: self.base.palette.show_prompt('time:'), description="Time")
self.base.palette.register_actionset(lambda: self.time_actionset)
self.clock.change_function(function=lambda: self.base.palette.show_prompt('time:'))
self.clock.set_pack_data(side=tk.RIGHT)
self.clock.show()

Expand Down
9 changes: 7 additions & 2 deletions biscuit/core/layout/statusbar/utils/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
from .button import SButton


#TODO 12/24 actionset config
class SClock(SButton):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.hour_24_format = True
self.update()

def update(self) -> None:
time_live = time.strftime("%I:%M %p")
time_live = time.strftime("%H:%M:%S" if self.hour_24_format else "%I:%M:%S")
self.text_label.config(text=time_live)
self.after(200, self.update)

def use_24_hour_format(self, flag: str) -> None:
"Use 24 hour format for clock"
self.hour_24_format = flag
self.update()

0 comments on commit 00e12fd

Please sign in to comment.