allow date format in clock tooltip text #104

This commit is contained in:
piotr
2022-04-15 01:18:25 +02:00
parent 11336063c3
commit 8cb747a19c
3 changed files with 26 additions and 3 deletions

View File

@@ -105,6 +105,7 @@ SKELETON_PANEL: dict = {
"clock": {
"format": "%a, %d. %b %H:%M:%S",
"tooltip-text": "",
"tooltip-date-format": False,
"on-left-click": "",
"on-middle-click": "",
"on-right-click": "",
@@ -1000,6 +1001,7 @@ class EditorWrapper(object):
defaults = {
"format": "%a, %d. %b %H:%M:%S",
"tooltip-text": "",
"tooltip-date-format": False,
"on-left-click": "",
"on-middle-click": "",
"on-right-click": "",
@@ -1021,6 +1023,9 @@ class EditorWrapper(object):
self.eb_tooltip_text = builder.get_object("tooltip-text")
self.eb_tooltip_text.set_text(settings["tooltip-text"])
self.eb_tooltip_date = builder.get_object("tooltip-date")
self.eb_tooltip_date.set_active(settings["tooltip-date-format"])
self.eb_on_left_click = builder.get_object("on-left-click")
self.eb_on_left_click.set_text(settings["on-left-click"])
@@ -1057,6 +1062,7 @@ class EditorWrapper(object):
settings["format"] = self.eb_format.get_text()
settings["tooltip-text"] = self.eb_tooltip_text.get_text()
settings["tooltip-date-format"] = self.eb_tooltip_date.get_active()
settings["on-left-click"] = self.eb_on_left_click.get_text()
settings["on-middle-click"] = self.eb_on_middle_click.get_text()
settings["on-right-click"] = self.eb_on_right_click.get_text()

View File

@@ -250,6 +250,7 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">See 'man date' for format details</property>
<property name="halign">start</property>
<property name="stock">gtk-about</property>
</object>
<packing>
@@ -258,7 +259,19 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkCheckButton" id="tooltip-date">
<property name="label" translatable="yes">date format</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="tooltip-text" translatable="yes">Allow using 'date' format for tooltip text</property>
<property name="halign">start</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<placeholder/>

View File

@@ -27,6 +27,7 @@ class Clock(Gtk.EventBox):
check_key(settings, "root-css-name", "root-clock")
check_key(settings, "css-name", "clock")
check_key(settings, "tooltip-text", "")
check_key(settings, "tooltip-date-format", False)
check_key(settings, "on-left-click", "")
check_key(settings, "on-right-click", "")
check_key(settings, "on-middle-click", "")
@@ -59,8 +60,10 @@ class Clock(Gtk.EventBox):
if settings["interval"] > 0:
Gdk.threads_add_timeout_seconds(GLib.PRIORITY_LOW, settings["interval"], self.refresh)
def update_widget(self, output):
def update_widget(self, output, tooltip=""):
self.label.set_text(output)
if self.settings["tooltip-date-format"] and tooltip:
self.set_tooltip_text(tooltip)
return False
@@ -68,7 +71,8 @@ class Clock(Gtk.EventBox):
now = datetime.now()
try:
time = now.strftime(self.settings["format"])
GLib.idle_add(self.update_widget, time)
tooltip = now.strftime(self.settings["tooltip-text"])
GLib.idle_add(self.update_widget, time, tooltip)
except Exception as e:
print(e)