diff --git a/data/io.github.amit9838.mousam.gschema.xml b/data/io.github.amit9838.mousam.gschema.xml index 6908760..eda1fac 100644 --- a/data/io.github.amit9838.mousam.gschema.xml +++ b/data/io.github.amit9838.mousam.gschema.xml @@ -17,15 +17,13 @@ Use Gradient Background Apply gradient background on main window corresponding to weather condition - false Use Inch for precipitation - - + false - Launch the app in maximized mode. + Use 24h hour clock 1160 @@ -35,7 +33,10 @@ 818 Main window height - + + false + Launch the app in maximized mode. + "metric" Mesaurement sysytem to use - metric,imperial diff --git a/src/config.py b/src/config.py index 119cdf2..8a44c15 100644 --- a/src/config.py +++ b/src/config.py @@ -17,6 +17,7 @@ def init_settings(self): "selected_city": "selected-city", "is_using_dynamic_bg": "use-gradient-bg", "is_using_inch_for_prec": "use-inch-for-prec", + "is_using_24h_clock": "use-24h-clock", "window_width": "window-width", "window_height": "window-height", "window_maximized": "window-maximized", @@ -55,6 +56,14 @@ def is_using_inch_for_prec(self): def is_using_inch_for_prec(self, value): self.settings.set_boolean(self._settings_map["is_using_inch_for_prec"], value) + @property + def is_using_24h_clock(self): + return self.settings.get_boolean(self._settings_map["is_using_24h_clock"]) + + @is_using_24h_clock.setter + def is_using_24h_clock(self, value): + self.settings.set_boolean(self._settings_map["is_using_24h_clock"], value) + @property def window_width(self): return self.settings.get_int(self._settings_map["window_width"]) @@ -71,7 +80,6 @@ def window_height(self): def window_height(self, value): self.settings.set_int(self._settings_map["window_height"], value) - @property def window_maximized(self): return self.settings.get_boolean(self._settings_map["window_maximized"]) diff --git a/src/frontendForecast.py b/src/frontendForecast.py index 82726f4..444122a 100644 --- a/src/frontendForecast.py +++ b/src/frontendForecast.py @@ -112,6 +112,10 @@ def page_stacks(self, page_name): ts = hourly_data.time.get('data')[idx+idx_offset] date_time = datetime.fromtimestamp(ts) dt_label = date_time.strftime("%I:%M %p") + + if settings.is_using_24h_clock: + dt_label = date_time.strftime("%H:%M") + temp_max_text = hourly_data.temperature_2m.get("data")[idx+idx_offset] temp_min_text = 0 weather_code = hourly_data.weathercode.get("data")[idx+idx_offset] diff --git a/src/frontendHourlyDetails.py b/src/frontendHourlyDetails.py index c4efd7e..6daf652 100644 --- a/src/frontendHourlyDetails.py +++ b/src/frontendHourlyDetails.py @@ -190,9 +190,11 @@ def create_stack_page(self, page_name): label_timestamp = Gtk.Label(label="") label_timestamp.set_css_classes(["text-6", "bold-2", "light-6"]) - tm = datetime.datetime.fromtimestamp(hourly_data.time.get("data")[i]) - tm = tm.strftime("%I:%M %p") - label_timestamp.set_text(tm) + time_stamp = datetime.datetime.fromtimestamp(hourly_data.time.get("data")[i]) + time_label = time_stamp.strftime("%I:%M %p") + if settings.is_using_24h_clock: + time_label = time_stamp.strftime("%H:%M") + label_timestamp.set_text(time_label) if i == nearest_current_time_idx: label_timestamp.set_text(_("Now")) diff --git a/src/frontendUiDrawDayNight.py b/src/frontendUiDrawDayNight.py index 99badc9..88cc6b3 100644 --- a/src/frontendUiDrawDayNight.py +++ b/src/frontendUiDrawDayNight.py @@ -7,6 +7,7 @@ import cairo from datetime import datetime from .utils import get_cords, get_time_difference +from .config import settings class DrawDayNight: @@ -79,12 +80,18 @@ def on_draw(self, widget, cr, width, height, data): t_data = get_time_difference(*get_cords()) target_time = t_data.get("target_time") - formatted_date_time = datetime.fromtimestamp(target_time).strftime("%I:%M %p") - text = formatted_date_time - # Calculate the position for text placement text_x = center_x - 30 text_y = center_y + 15 + + date_time = datetime.fromtimestamp(target_time) + formatted_date_time= date_time.strftime("%I:%M %p") + + if settings.is_using_24h_clock: + formatted_date_time= date_time.strftime("%H:%M") + text_x += 7 + + text = formatted_date_time # Move the text cursor to the calculated position context.move_to(text_x, text_y) diff --git a/src/windowPreferences.py b/src/windowPreferences.py index 506c42c..e0874b6 100644 --- a/src/windowPreferences.py +++ b/src/windowPreferences.py @@ -43,6 +43,20 @@ def __init__(self, application, **kwargs): gradient_row.add_suffix(self.g_switch_box) self.appearance_grp.add(gradient_row) + # Use 24h Clock Format + use_24h_clock_row = Adw.ActionRow.new() + use_24h_clock_row.set_activatable(True) + use_24h_clock_row.set_title(_("24 Hour Time Format")) + use_24h_clock_row.set_subtitle(_("Use 24 hour Time format (Refresh required)")) + + self.g_switch_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,valign=Gtk.Align.CENTER) + self.launch_max_switch = Gtk.Switch() + self.launch_max_switch.set_active(settings.is_using_24h_clock) + self.launch_max_switch.connect("state-set",self._on_click_use_24h_clock) + self.g_switch_box.append(self.launch_max_switch) + use_24h_clock_row.add_suffix(self.g_switch_box) + self.appearance_grp.add(use_24h_clock_row) + # Units and measurement self.measurement_group = Adw.PreferencesGroup.new() self.measurement_group.set_margin_top(20) @@ -92,6 +106,9 @@ def _use_gradient_bg(self,widget,state): def _on_click_launch_maximixed(self,widget,state): settings.should_launch_maximized = state + def _on_click_use_24h_clock(self,widget,state): + settings.is_using_24h_clock = state + def _change_unit(self,widget,value): if settings.unit != value: settings.unit = value