base_panel: Include time

This commit is contained in:
Jordan 2021-05-18 22:24:28 -04:00
parent 73b54f7aba
commit a0de521631
2 changed files with 35 additions and 1 deletions

View File

@ -53,7 +53,8 @@ class KlipperScreenConfig:
"value": "z-bolt","options":[
{"name": _("Z-bolt (default)"), "value": "z-bolt"},
{"name": _("Colorized"), "value": "colorized"}
]}}
]}},
{"24htime": {"section": "main", "name": _("24 Hour Time"), "type": "binary", "value": "True"}},
#{"": {"section": "main", "name": _(""), "type": ""}}
]

View File

@ -1,3 +1,4 @@
import datetime
import gi
import logging
@ -13,6 +14,8 @@ class BasePanel(ScreenPanel):
def __init__(self, screen, title, back=True, action_bar=True, printer_name=True):
super().__init__(screen, title, back, action_bar, printer_name)
self.current_panel = None
self.time_min = -1
self.time_format = self._config.get_main_config_option("24htime")
self.buttons_showing = {
'back': False if back else True
@ -75,6 +78,17 @@ class BasePanel(ScreenPanel):
if action_bar == True:
self.layout.put(self.control_grid, 0, 0)
self.control['time_box'] = Gtk.Box()
self.control['time_box'].set_halign(Gtk.Align.END)
self.control['time_box'].set_size_request(0, self.title_spacing)
self.control['time'] = Gtk.Label("00:00 AM")
self.control['time'].set_size_request(0, self.title_spacing)
self.control['time'].set_halign(Gtk.Align.END)
self.control['time'].set_valign(Gtk.Align.CENTER)
self.control['time_box'].pack_end(self.control['time'], True, 0, 0)
self.layout.put(self.control['time_box'], action_bar_width, 0)
self.layout.put(self.titlelbl, action_bar_width, 0)
self.layout.put(self.content, action_bar_width, self.title_spacing)
@ -82,6 +96,25 @@ class BasePanel(ScreenPanel):
# Create gtk items here
return
def activate(self):
size = self.control['time_box'].get_allocation().width
self.layout.remove(self.control['time_box'])
self.control['time_box'].set_size_request(size, self.title_spacing)
self.layout.put(self.control['time_box'], self._screen.width - size - 5, 0)
GLib.timeout_add_seconds(1, self.update_time)
self.update_time()
def update_time(self):
now = datetime.datetime.now()
confopt = self._config.get_main_config_option("24htime")
if now.minute != self.time_min or self.time_format != confopt:
if confopt == "True":
self.control['time'].set_text(now.strftime("%H:%M"))
else:
self.control['time'].set_text(now.strftime("%I:%M %p"))
return True
def add_content(self, panel):
self.current_panel = panel
self.set_title(panel.get_title())