Skip to content

Commit

Permalink
make precipitation unit optional
Browse files Browse the repository at this point in the history
  • Loading branch information
amit9838 committed Feb 24, 2024
1 parent fa1e165 commit ded9d72
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
5 changes: 5 additions & 0 deletions data/io.github.amit9838.mousam.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<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="launch-maximized" type="b">
<default>false</default>
<summary>Launch the app in maximized mode.</summary>
Expand Down
4 changes: 2 additions & 2 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

icons = {
"0": icon_loc + "clear-day.svg",
"1": icon_loc + "clear-day.svg",
"1": icon_loc + "overcast-day.svg",
"2": icon_loc + "overcast-day.svg",
"3": icon_loc + "overcast.svg",
"51": icon_loc + "partly-cloudy-day-drizzle.svg",
Expand Down Expand Up @@ -31,7 +31,7 @@
"99": icon_loc + "snowflake.svg",

"0n": icon_loc + "clear-night.svg",
"1n": icon_loc + "clear-night.svg",
"1n": icon_loc + "overcast-night.svg",
"2n": icon_loc + "overcast-night.svg",
"3n": icon_loc + "overcast.svg",
"51n": icon_loc + "partly-cloudy-night-drizzle.svg",
Expand Down
8 changes: 4 additions & 4 deletions src/frontendHourlyDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ def create_stack_page(self, page_name):

# Precipitation page
settings = Gio.Settings(schema_id="io.github.amit9838.mousam")
measurement_type = settings.get_string("measure-type")
use_inch_for_prec = settings.get_boolean("use-inch-for-prec")

max_prec = max(hourly_data.precipitation.get("data")[:24])
unit = hourly_data.precipitation.get("unit")
if measurement_type == "imperial":
if use_inch_for_prec:
max_prec = max_prec / 25.4
unit = "inch"

Expand Down Expand Up @@ -175,7 +175,7 @@ def create_stack_page(self, page_name):
no_prec_label.set_halign(Gtk.Align.CENTER)
no_prec_label.set_margin_top(40)
no_prec_label.set_margin_bottom(40)
graphic_box.set_css_classes(["custom_card_hourly"])
graphic_box.set_css_classes(["custom_card_hourly",'bg_light_grey'])
graphic_box.append(no_prec_label)
graphic_container.append(graphic_box)
return
Expand Down Expand Up @@ -244,7 +244,7 @@ def create_stack_page(self, page_name):
elif page_name == "prec":
bar_obj = None
prec = hourly_data.precipitation.get("data")[i]
if measurement_type == "imperial":
if use_inch_for_prec:
prec = hourly_data.precipitation.get("data")[i] / 25.4
if max_prec == 0:
bar_obj = DrawBar(0)
Expand Down
4 changes: 2 additions & 2 deletions src/mousam.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, *args, **kwargs):

self.main_window = self
self.settings = Gio.Settings(schema_id="io.github.amit9838.mousam")
self.set_default_size(1160, 750)
self.set_default_size(1160, 760)
self.set_title("")
# Adding a button into header
self.header = Adw.HeaderBar()
Expand Down Expand Up @@ -109,7 +109,7 @@ def show_loader(self):

container_loader = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
container_loader.set_margin_top(220)
container_loader.set_margin_bottom(290)
container_loader.set_margin_bottom(300)

# Create loader
loader = Gtk.Spinner()
Expand Down
23 changes: 20 additions & 3 deletions src/windowPreferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def __init__(self, application, **kwargs):
self.settings = application.settings
selected_city = self.settings.get_string('selected-city')
added_cities = list(self.settings.get_strv('added-cities'))
# use_gradient = self.settings.get_boolean('use-gradient-bg')
should_launch_maximized = self.settings.get_boolean('launch-maximized')
cities = [x.split(',')[0] for x in added_cities]
measurement_type = get_measurement_type()
Expand Down Expand Up @@ -57,7 +56,7 @@ def __init__(self, application, **kwargs):
launch_maximized = Adw.ActionRow.new()
launch_maximized.set_activatable(True)
launch_maximized.set_title(_("Launch Maximized"))
launch_maximized.set_subtitle(_("Launch the weather app in maximized mode (Restart required)"))
launch_maximized.set_subtitle(_("Launch the weather app in maximized mode (Refresh required)"))

self.g_switch_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,valign=Gtk.Align.CENTER)
self.launch_max_switch = Gtk.Switch()
Expand Down Expand Up @@ -93,6 +92,22 @@ def __init__(self, application, **kwargs):
self.measurement_group.add(self.imperial_unit)
GLib.idle_add(self.metric_unit.activate) if measurement_type == 'metric' else GLib.idle_add(self.imperial_unit.activate)

self.prec_unit_group = Adw.PreferencesGroup.new()
self.prec_unit_group.set_margin_top(20)
self.appearance_grp.add(self.prec_unit_group)

self.prec_unit = Adw.ActionRow.new()
self.prec_unit.set_title(_('Show precipitation in inch'))
self.prec_unit.set_subtitle(_("This option better works during heavy preciptaion (Refresh required)"))
self.prec_unit_switch_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,valign=Gtk.Align.CENTER)
self.prec_unit.set_activatable(True)
self.use_inch_switch = Gtk.Switch()
self.use_inch_switch.set_active(self.settings.get_boolean('use-inch-for-prec'))
self.use_inch_switch.connect("state-set",self._use_inch_for_precipation)
self.prec_unit_switch_box.append(self.use_inch_switch)
self.prec_unit.add_suffix(self.prec_unit_switch_box)
self.prec_unit_group.add(self.prec_unit)

# =============== Appearance Methods ===============
def _use_gradient_bg(self,widget,state):
self.settings.set_value("use-gradient-bg",GLib.Variant("b",state))
Expand All @@ -104,7 +119,6 @@ def _change_unit(self,widget,value):
global measurement_type
if measurement_type != value:
self.settings.set_value("measure-type",GLib.Variant("s",value))
# GLib.idle_add(self.application.refresh_weather,self.application,False)
measurement_type = get_measurement_type()

# Ignore refreshing weather within 5 second
Expand All @@ -118,3 +132,6 @@ def _change_unit(self,widget,value):
self.add_toast(create_toast(_("Switched to - {}").format(value.capitalize()),1))
thread = threading.Thread(target=self.application._load_weather_data,name="load_data")
thread.start()

def _use_inch_for_precipation(self,widget,state):
self.settings.set_value("use-inch-for-prec",GLib.Variant("b",state))

0 comments on commit ded9d72

Please sign in to comment.