roundabout,
created on Saturday, 19 July 2025, 12:10:05 (1752927005),
received on Saturday, 26 July 2025, 07:40:05 (1753515605)
Author identity: vlad <vlad.muntoiu@gmail.com>
5f56fed5c8dc15ee584df07695c89315ecf3d2aa
applets/clock/__init__.py
@@ -0,0 +1,54 @@
import panorama_panel
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk, GLib
SECOND_PLACEHOLDERS = ("%c", "%s", "%S", "%T", "%X")
class ClockApplet(panorama_panel.Applet):
name = "Clock"
description = "Read the current time and date"
def __init__(self, orientation=Gtk.Orientation.HORIZONTAL, config=None):
super().__init__(orientation=orientation, config=config)
if config is None:
config = {}
self.button = Gtk.MenuButton()
self.button.set_has_frame(False) # flat look
self.label = Gtk.Label()
self.button.set_child(self.label)
# Create the monthly calendar
self.popover = Gtk.Popover()
self.calendar = Gtk.Calendar()
self.calendar.set_show_week_numbers(True)
self.popover.set_child(self.calendar)
self.button.set_popover(self.popover)
self.append(self.button)
self.formatting = config.get("formatting", "%c")
# Some placeholders require second precision, but not all of them. If not required,
# use minute precision
self.has_second_precision = any(placeholder in self.formatting for placeholder in SECOND_PLACEHOLDERS)
self.set_time()
def set_time(self):
datetime = GLib.DateTime.new_now_local()
self.label.set_text(datetime.format(self.formatting))
if self.has_second_precision:
current_ms = GLib.DateTime.new_now_local().get_microsecond() // 1000
GLib.timeout_add(1000 - current_ms + 1, self.set_time) # 1ms is added to ensure the clock is updated
else:
now = GLib.DateTime.new_now_local()
current_ms = now.get_second() * 1000 + now.get_microsecond() // 1000
GLib.timeout_add(60000 - current_ms + 1, self.set_time)
return False # Do not rerun the current timeout; a new one has been scheduled
def get_config(self):
return {"text": self.label.get_text()}
config.yaml
@@ -5,4 +5,7 @@ panels:
applets:
left:
- LabelApplet:
label: "Hello, world"
text: "Hello, world"
right:
- ClockApplet:
formatting: "%T, %a %-d %b %Y"
main.py
@@ -252,7 +252,6 @@ with open(get_config_file(), "r") as config_file:
item = list(applet.items())[0]
AppletClass = applets_by_name[item[0]]
options = item[1]
applet_widget = AppletClass(orientation=panel.get_orientation(), config=options)
area.append(applet_widget)