Skip to content

Commit

Permalink
add option to use 24h time format
Browse files Browse the repository at this point in the history
  • Loading branch information
amit9838 committed Jun 3, 2024
1 parent 95a9172 commit b10a8dd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 12 deletions.
11 changes: 6 additions & 5 deletions data/io.github.amit9838.mousam.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
<summary>Use Gradient Background</summary>
<description>Apply gradient background on main window corresponding to weather condition</description>
</key>

<key name="use-inch-for-prec" type="b">
<default>false</default>
<summary>Use Inch for precipitation</summary>
</key>

<key name="window-maximized" type="b">
<key name="use-24h-clock" type="b">
<default>false</default>
<summary>Launch the app in maximized mode.</summary>
<summary>Use 24h hour clock</summary>
</key>
<key name="window-width" type="i">
<default>1160</default>
Expand All @@ -35,7 +33,10 @@
<default>818</default>
<summary>Main window height</summary>
</key>

<key name="window-maximized" type="b">
<default>false</default>
<summary>Launch the app in maximized mode.</summary>
</key>
<key name="unit" type="s">
<default>"metric"</default>
<summary>Mesaurement sysytem to use - metric,imperial</summary>
Expand Down
10 changes: 9 additions & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"])
Expand All @@ -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"])
Expand Down
4 changes: 4 additions & 0 deletions src/frontendForecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 5 additions & 3 deletions src/frontendHourlyDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
13 changes: 10 additions & 3 deletions src/frontendUiDrawDayNight.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cairo
from datetime import datetime
from .utils import get_cords, get_time_difference
from .config import settings


class DrawDayNight:
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions src/windowPreferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b10a8dd

Please sign in to comment.