From 3b15bf58e76888e47ac631fc370003213b53ddbb Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Tue, 8 Sep 2026 02:28:04 +0900 Subject: [PATCH] feat: add time of day icon --- dzgui/const/constants.py | 2 ++ dzgui/views/components/icon.py | 3 +++ dzgui/views/dialogs/calc.py | 25 ++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/dzgui/const/constants.py b/dzgui/const/constants.py index 6089941..c0ff071 100644 --- a/dzgui/const/constants.py +++ b/dzgui/const/constants.py @@ -55,6 +55,8 @@ VIEW_CONCEAL = "view-conceal-symbolic" VIEW_REVEAL = "view-reveal-symbolic" WARNING = "dialog-warning-symbolic" WEB_BROWSER = "web-browser-symbolic" +DAY_ICON = "weather-clear-symbolic" +NIGHT_ICON = "weather-clear-night-symbolic" SEPARATOR = "SEPARATOR" diff --git a/dzgui/views/components/icon.py b/dzgui/views/components/icon.py index a8abd11..a0f8b1e 100644 --- a/dzgui/views/components/icon.py +++ b/dzgui/views/components/icon.py @@ -9,3 +9,6 @@ class Icon(Gtk.Image): super().__init__( icon_name=name, icon_size=Gtk.IconSize.BUTTON, margin_start=l_margin ) + + def set_from_icon_name(self, name: str) -> None: + super().set_from_icon_name(name, Gtk.IconSize.BUTTON) diff --git a/dzgui/views/dialogs/calc.py b/dzgui/views/dialogs/calc.py index 1086190..5278c92 100644 --- a/dzgui/views/dialogs/calc.py +++ b/dzgui/views/dialogs/calc.py @@ -3,9 +3,11 @@ from dataclasses import dataclass from datetime import datetime, time, timedelta from typing import Literal -from dzgui.views.components.labels import BoldLabel +from dzgui.const.constants import DAY_ICON, NIGHT_ICON from dzgui.strings import calc -from dzgui.views.components.box import VBox +from dzgui.views.components.icon import Icon +from dzgui.views.components.labels import BoldLabel +from dzgui.views.components.box import VBox, HBox gi.require_version("Gtk", "3.0") from gi.repository import Gtk, GLib, GObject # type: ignore # noqa E402 @@ -99,6 +101,11 @@ class ServerClock: split = server_time.time.split(":") return int(split[0]), int(split[1]) + def is_day(self) -> bool: + if DAY_START_TIME <= self.cur_time.time() <= DAY_END_TIME: + return True + return False + def _increment_with_offset(self) -> Literal[True]: factor = self.get_accel_factor(self.cur_time) elapsed = self.local_clock.get_elapsed_time() @@ -365,6 +372,13 @@ class TimePickerFrame(Gtk.Frame): h1 = BoldLabel(calc.heading_server_time) h2 = BoldLabel(calc.heading_target_time) + self.icon_indicator = Icon(DAY_ICON) + self.update_server_icon() + + server_time_box = HBox(10) + server_time_box.set_halign(Gtk.Align.CENTER) + server_time_box.extend([self.server_timelabel, self.icon_indicator]) + flowbox = Gtk.FlowBox( row_spacing=10, column_spacing=50, @@ -378,14 +392,19 @@ class TimePickerFrame(Gtk.Frame): flowbox.add(h1) flowbox.add(h2) flowbox.add(self.local_timelabel) - flowbox.add(self.server_timelabel) + flowbox.add(server_time_box) flowbox.add(self.picker) self.add(flowbox) + def update_server_icon(self) -> None: + icon = DAY_ICON if self.server_time.is_day() else NIGHT_ICON + self.icon_indicator.set_from_icon_name(icon) + def _on_server_clock_increment(self, emitter: Emitter, time_now: datetime) -> None: t = time_now.time().strftime("%H:%M") self.server_timelabel.set_text(t) + self.update_server_icon() def _on_local_clock_increment( self, emitter: Emitter, time_now: datetime, elapsed: timedelta