diff --git a/src/backendAirPollution.py b/src/backendAirPollution.py index e594864..a46c913 100644 --- a/src/backendAirPollution.py +++ b/src/backendAirPollution.py @@ -13,7 +13,7 @@ def current_air_pollution(latitude: float, longitude: float, **kwargs): url = url + f"&hourly={hourly_fields}" try: - url = url + f"&timeformat=unixtime" + f"&forecast_days=1" + url = url + "&timeformat=unixtime" + "&forecast_days=1" response = requests.get(url) response.raise_for_status() # Raise an exception if the request was unsuccessful data = response.json() diff --git a/src/backendFindCity.py b/src/backendFindCity.py index 9550076..153c4df 100644 --- a/src/backendFindCity.py +++ b/src/backendFindCity.py @@ -16,7 +16,7 @@ def find_city(city, count=3): cities_res = response.json() cities = cities_res.get('results') cities_list = [] - if cities == None: + if cities is None: return cities_list for city in cities: data = { diff --git a/src/backendWeather.py b/src/backendWeather.py index 667d7c2..305282a 100644 --- a/src/backendWeather.py +++ b/src/backendWeather.py @@ -16,7 +16,7 @@ def __init__(self) -> None: global extend_url if settings.unit == "imperial": - extend_url = f"&temperature_unit=fahrenheit&wind_speed_unit=mph" + extend_url = "&temperature_unit=fahrenheit&wind_speed_unit=mph" else: extend_url = "" @@ -31,7 +31,7 @@ def current_weather(cls,latitude: float, longitude: float, **kwargs): url = url + f"¤t={current_fields}" + extend_url try: - url = url + f"&timeformat=unixtime" + url = url + "&timeformat=unixtime" response = requests.get(url) response.raise_for_status() # Raise an exception if the request was unsuccessful data = response.json() @@ -65,7 +65,7 @@ def forecast_hourly(cls,latitude: float, longitude: float, **kwargs): url = url + f"&hourly={hourly_fields}" + extend_url try: - url = url + f"&timeformat=unixtime" + url = url + "&timeformat=unixtime" response = requests.get(url) response.raise_for_status() # Raise an exception if the request was unsuccessful data = response.json() @@ -113,7 +113,7 @@ def forecast_daily(cls,latitude: float, longitude: float, **kwargs): url = url + f"&end_date={kwargs.get('end_date')}" try: - url = url + f"&timeformat=unixtime" + extend_url + url = url + "&timeformat=unixtime" + extend_url response = requests.get(url) response.raise_for_status() # Raise an exception if the request was unsuccessful data = response.json() diff --git a/src/constants.py b/src/constants.py index 1d890a2..975dddf 100644 --- a/src/constants.py +++ b/src/constants.py @@ -1,5 +1,3 @@ -import gettext - icon_loc = "@icon_location@/share/icons/hicolor/scalable/mousam_icons/" icons = { diff --git a/src/css/style.css b/src/css/style.css index 810a0b9..b403896 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -2,7 +2,7 @@ font-size: 30px; } .main_temp_label { - font-size: 3.7rem; + font-size: 3.5rem; } .btn_sm{ @@ -58,7 +58,7 @@ font-size: .95rem; } .text-7{ - font-size: 9rem; + font-size: .9rem; } .text-8{ font-size: .85rem; @@ -158,7 +158,7 @@ } .custom_card{ - padding:.5rem 1rem; + padding:.7rem .85rem; } .bar_container{ @@ -168,13 +168,13 @@ } .custom_card_forecast_item{ - padding: 0.12rem 1.5rem; + padding: 0rem 1.1rem; border-radius: .7rem; } .custom_card_hourly{ border-radius: .5rem; - padding: .7rem .7rem; + padding: .4rem .6rem; margin-top: .3rem; } diff --git a/src/frontendCardAirPollution.py b/src/frontendCardAirPollution.py index 2481bea..6bf3a00 100644 --- a/src/frontendCardAirPollution.py +++ b/src/frontendCardAirPollution.py @@ -1,13 +1,13 @@ import gi import time -gi.require_version("Gtk", "4.0") -gi.require_version("Adw", "1") from gi.repository import Gtk from .frontendUiDrawPollutionBar import PollutionBar from .config import settings +gi.require_version("Gtk", "4.0") +gi.require_version("Adw", "1") class CardAirPollution: def __init__(self): @@ -51,11 +51,6 @@ def create_card(self): icon.set_halign(Gtk.Align.END) icon.set_css_classes(["light-4"]) icon.set_tooltip_text(_("United States AQI standard")) - # icon.set_margin_end(20) - # title = Gtk.Label(label="info") - # title.set_hexpand(True) - # title.set_halign(Gtk.Align.END) - # title.set_css_classes(["text-4", "light-3", "bolda"]) card.attach(icon, 3, 0, 4, 2) # Main value (like windspeed = 32km/h) @@ -64,7 +59,7 @@ def create_card(self): ) card.attach(info_box, 0, 2, 4, 2) info_box.set_margin_start(10) - info_box.set_margin_top(20) + info_box.set_margin_top(15) main_val = Gtk.Label(label=self.air_apllution_data["hourly"]["us_aqi"][idx]) main_val.set_css_classes(["text-l3", "bold"]) diff --git a/src/frontendCardDayNight.py b/src/frontendCardDayNight.py index 8fcbe2c..e84ba95 100644 --- a/src/frontendCardDayNight.py +++ b/src/frontendCardDayNight.py @@ -1,16 +1,16 @@ from datetime import datetime import gi -gi.require_version("Gtk", "4.0") -gi.require_version("Adw", "1") from gi.repository import Gtk -from .frontendUiDrawDayNight import * +from .frontendUiDrawDayNight import DrawDayNight from .config import settings from .utils import ( get_cords, get_time_difference, ) +gi.require_version("Gtk", "4.0") +gi.require_version("Adw", "1") class CardDayNight: @@ -56,7 +56,7 @@ def create_card(self): card = Gtk.Grid(margin_top=10, margin_start=5, margin_bottom=0) self.card = card card.halign = Gtk.Align.FILL - card.set_row_spacing(5) + # card.set_row_spacing(5) card.set_css_classes(["view", "card", "custom_card"]) if settings.is_using_dynamic_bg: @@ -82,14 +82,14 @@ def create_card(self): card_info.attach(sun_rise_label, 0, 1, 1, 2) sun_rise = Gtk.Label(label=self.sun_rise) - sun_rise.set_margin_top(10) + sun_rise.set_margin_top(2) sun_rise.set_css_classes(["text-2a", "bold", "light-2"]) sun_rise.set_halign(Gtk.Align.START) card_info.attach(sun_rise, 0, 2, 3, 3) sun_set_label = Gtk.Label(label=_("Sunset")) sun_set_label.set_halign(Gtk.Align.START) - sun_set_label.set_margin_top(20) + sun_set_label.set_margin_top(15) sun_set_label.set_css_classes(["text-4", "light-4"]) card_info.attach(sun_set_label, 0, 4, 1, 2) @@ -99,11 +99,13 @@ def create_card(self): card_info.attach(sun_set, 0, 6, 3, 3) card_icon = Gtk.Grid() - card_icon.set_css_classes(["view", "card_infao"]) + card_icon.set_css_classes(["view"]) card_icon.add_css_class("transparent_0") + # card_icon.add_css_class("card_info") + card.attach(card_icon, 1, 2, 2, 1) - obj = DrawDayNight(self.degree, 200, 100) + obj = DrawDayNight(self.degree, 120, 90) card_icon.attach(obj.img_box, 0, 1, 1, 1) # Sun Rotation diff --git a/src/frontendCardSquare.py b/src/frontendCardSquare.py index 0fd1ecf..1230c06 100644 --- a/src/frontendCardSquare.py +++ b/src/frontendCardSquare.py @@ -47,10 +47,10 @@ def create_card(self): margin_start=5, margin_end=5, row_spacing=5, - column_spacing=25, + column_spacing=0, ) card.halign = Gtk.Align.FILL - card.set_size_request(200, 150) + card.set_size_request(170, 100) card.set_css_classes(["view", "card", "custom_card"]) if settings.is_using_dynamic_bg: @@ -65,10 +65,11 @@ def create_card(self): card.attach(title, 0, 0, 1, 2) # Info Grid: It contains - Main value,units, short description, sub description - card_info = Gtk.Grid(margin_top=5, row_spacing=0, column_spacing=0) + card_info = Gtk.Grid() card.attach(card_info, 0, 2, 1, 2) # Main value (like windspeed = 32km/h) + # convert pressure value to int self.main_val = int(self.main_val) if self.title == 'Pressure' else self.main_val main_val = Gtk.Label(label=self.main_val) main_val.set_css_classes(["text-1", "bold"]) @@ -77,26 +78,25 @@ def create_card(self): # Unit if the main value main_val_unit = Gtk.Label(label=self.main_val_unit) - main_val_unit.set_css_classes(["text-5", "light-3"]) + main_val_unit.set_css_classes(["text-7", "light-3"]) main_val_unit.set_halign(Gtk.Align.START) card_info.attach(main_val_unit, 3, 3, 1, 1) - # Short description + # Short description [light, moderate] desc_box = Gtk.Box() - desc_box.set_size_request(10, 30) + desc_box.set_size_request(5, 27) card_info.attach(desc_box, 0, 4, 6, 1) desc = Gtk.Label(label=self.desc) desc.set_css_classes(["text-5", "light-2", "bold-2"]) desc.set_wrap(True) - desc.set_margin_start(0) desc.set_halign(Gtk.Align.START) desc.set_valign(Gtk.Align.START) desc_box.append(desc) - # Sub description heading + # Sub description heading [dewpoint,from] sub_desc_heading = Gtk.Label(label=self.sub_desc_heading) - sub_desc_heading.set_css_classes(["text-4", "light-1"]) + sub_desc_heading.set_css_classes(["text-6", "light-1"]) sub_desc_heading.set_halign(Gtk.Align.START) card_info.attach(sub_desc_heading, 0, 5, 4, 1) @@ -106,7 +106,6 @@ def create_card(self): card_info.attach(sub_desc, 0, 6, 4, 1) card_icon = Gtk.Grid(halign=Gtk.Align.END) - card_icon.set_margin_top(5) card.attach(card_icon, 1, 2, 2, 1) icon_upper_text = Gtk.Label(label=self.text_up) @@ -116,7 +115,7 @@ def create_card(self): icon_upper_text.set_css_classes(["title-5"]) icon_upper_text.set_halign(Gtk.Align.CENTER) - icon_upper_text.set_margin_bottom(5) + icon_upper_text.set_margin_bottom(0) card_icon.attach(icon_upper_text, 0, 0, 1, 1) if self.title.lower() == "wind": diff --git a/src/frontendCurrentCond.py b/src/frontendCurrentCond.py index ef42751..0158412 100644 --- a/src/frontendCurrentCond.py +++ b/src/frontendCurrentCond.py @@ -23,7 +23,7 @@ def paint_ui(self): orientation=Gtk.Orientation.VERTICAL, hexpand=True, halign=Gtk.Align.START, - margin_top=40, + margin_top=30, ) self.attach(box_left, 0, 0, 1, 1) @@ -38,7 +38,7 @@ def paint_ui(self): icon_main = Gtk.Image().new_from_file(condition_icon) icon_main.set_hexpand(True) - icon_main.set_pixel_size(110) + icon_main.set_pixel_size(90) condition_grid.attach(icon_main, 0, 0, 1, 2) # Condition label @@ -47,7 +47,7 @@ def paint_ui(self): halign=Gtk.Align.START, valign=Gtk.Align.END, ) - cond_label.set_css_classes(["text-2a", "light-4", "bold-2"]) + cond_label.set_css_classes(["text-2b", "light-4", "bold-2"]) condition_grid.attach(cond_label, 1, 0, 1, 1) # Condition temperature diff --git a/src/frontendForecast.py b/src/frontendForecast.py index 444122a..9476c8e 100644 --- a/src/frontendForecast.py +++ b/src/frontendForecast.py @@ -5,73 +5,73 @@ from .constants import icons from .config import settings -gi.require_version('Gtk', '4.0') -gi.require_version('Adw', '1') +gi.require_version("Gtk", "4.0") +gi.require_version("Adw", "1") class Forecast(Gtk.Grid): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.set_margin_top(20) + self.set_margin_top(10) self.set_margin_bottom(5) self.set_margin_start(10) self.set_margin_end(5) - self.set_css_classes(['view', 'card', 'custom_card']) + self.set_css_classes(["view", "card", "custom_card"]) if settings.is_using_dynamic_bg: self.add_css_class("transparent_5") self.paint_ui() def paint_ui(self): - # ======== Tab Box ========== - tab_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, - hexpand=True, halign=Gtk.Align.CENTER) + tab_box = Gtk.Box( + orientation=Gtk.Orientation.VERTICAL, hexpand=True, halign=Gtk.Align.CENTER + ) self.attach(tab_box, 0, 0, 1, 1) style_buttons_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) - style_buttons_box.add_css_class('linked') + style_buttons_box.add_css_class("linked") style_buttons_box.set_margin_start(2) style_buttons_box.set_valign(Gtk.Align.CENTER) - tomorrow_btn = Gtk.ToggleButton.new_with_label(_('Tomorrow')) - tomorrow_btn.set_size_request(100,20) - tomorrow_btn.set_css_classes(['btn_sm']) + tomorrow_btn = Gtk.ToggleButton.new_with_label(_("Tomorrow")) + tomorrow_btn.set_size_request(80, 16) + tomorrow_btn.set_css_classes(["btn_sm"]) tomorrow_btn.do_clicked(tomorrow_btn) style_buttons_box.append(tomorrow_btn) - tomorrow_btn.connect('clicked', self._on_tomorrow_forecast_btn_clicked) + tomorrow_btn.connect("clicked", self._on_tomorrow_forecast_btn_clicked) - weekly_btn = Gtk.ToggleButton.new_with_label(_('Weekly')) - weekly_btn.set_size_request(100,20) - weekly_btn.set_css_classes(['btn_sm']) + weekly_btn = Gtk.ToggleButton.new_with_label(_("Weekly")) + weekly_btn.set_size_request(80, 16) + weekly_btn.set_css_classes(["btn_sm"]) weekly_btn.set_group(tomorrow_btn) style_buttons_box.append(weekly_btn) - weekly_btn.connect('clicked', self._on_weekly_btn_forecast_btn_clicked) + weekly_btn.connect("clicked", self._on_weekly_btn_forecast_btn_clicked) # =========== Forecast Page Stack ============ self.forecast_stack = Gtk.Stack.new() - self.forecast_stack.set_transition_type( - Gtk.StackTransitionType.CROSSFADE) + self.forecast_stack.set_transition_type(Gtk.StackTransitionType.CROSSFADE) self.attach(self.forecast_stack, 0, 1, 1, 1) tab_box.append(style_buttons_box) - self.page_stacks('tomorrow') + self.page_stacks("tomorrow") # ============= Button Click Methods ============== def _on_tomorrow_forecast_btn_clicked(self, widget): - page_name = 'tomorrow' + page_name = "tomorrow" if self.forecast_stack.get_child_by_name(page_name): self.forecast_stack.set_visible_child_name(page_name) return - self.page_stacks('tomorrow') + self.page_stacks("tomorrow") def _on_weekly_btn_forecast_btn_clicked(self, widget): - page_name = 'weekly' + page_name = "weekly" if self.forecast_stack.get_child_by_name(page_name): self.forecast_stack.set_visible_child_name(page_name) return - self.page_stacks('weekly') + self.page_stacks("weekly") # ============ Add items to Stack [Tomorrow/Week] ============= + def page_stacks(self, page_name): from .weatherData import daily_forecast_data as daily_data from .weatherData import hourly_forecast_data as hourly_data @@ -82,68 +82,75 @@ def page_stacks(self, page_name): self.forecast_stack.set_visible_child_name(page_name) # Create scrolled window , add it to stack-box - scrolled_window = Gtk.ScrolledWindow(margin_top=8,margin_bottom=8) - scrolled_window.set_policy( - Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) - scrolled_window.set_size_request(300, 535) + scrolled_window = Gtk.ScrolledWindow(margin_top=4, margin_bottom=4) + scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) + scrolled_window.set_size_request(260, 500) scrolled_window.set_kinetic_scrolling(True) box.append(scrolled_window) # Forecast card container forecast_container = Gtk.Box( - orientation=Gtk.Orientation.VERTICAL, margin_top=0, margin_bottom=0) + orientation=Gtk.Orientation.VERTICAL, margin_top=0, margin_bottom=0 + ) scrolled_window.set_child(forecast_container) items_range = 7 idx_offset = 0 - if page_name != 'weekly': + if page_name != "weekly": items_range = 24 idx_offset = self.get_idx_offset(hourly_data) # -------- Plot items ------- - for idx in range(items_range): - forecast_item_grid = Gtk.Grid(hexpand=True,margin_top=6) + for idx in range(items_range): + forecast_item_grid = Gtk.Grid(hexpand=True, margin_top=6) forecast_item_grid.set_css_classes( - ['bg_light_grey', 'custom_card_forecast_item']) + ["bg_light_grey", "custom_card_forecast_item"] + ) forecast_container.append(forecast_item_grid) - - ts = hourly_data.time.get('data')[idx+idx_offset] + 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_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] + weather_code = hourly_data.weathercode.get("data")[idx + idx_offset] - if page_name == 'weekly': - ts = daily_data.time.get("data")[idx+idx_offset] + if page_name == "weekly": + ts = daily_data.time.get("data")[idx + idx_offset] date_time = datetime.fromtimestamp(ts) dt_label = date_time.strftime("%A") - temp_min_text = daily_data.temperature_2m_min.get("data")[idx+idx_offset] - temp_max_text = daily_data.temperature_2m_max.get("data")[idx+idx_offset] - weather_code = daily_data.weathercode.get("data")[idx+idx_offset] + temp_min_text = daily_data.temperature_2m_min.get("data")[ + idx + idx_offset + ] + temp_max_text = daily_data.temperature_2m_max.get("data")[ + idx + idx_offset + ] + weather_code = daily_data.weathercode.get("data")[idx + idx_offset] if date_time.date().day == datetime.today().date().day: - dt_label = _('Today') - elif date_time.date().day == (datetime.today()+timedelta(days=1)).date().day: - dt_label = _('Tomorrow') + dt_label = _("Today") + elif ( + date_time.date().day + == (datetime.today() + timedelta(days=1)).date().day + ): + dt_label = _("Tomorrow") # Add dt_label Label label_box = Gtk.Box() label_box.set_size_request(80, 68) label_day_time = Gtk.Label(label=dt_label, halign=Gtk.Align.START) - label_day_time.set_css_classes(['text-4', 'bold-2','light-2']) + label_day_time.set_css_classes(["text-5", "bold-2", "light-2"]) label_box.append(label_day_time) forecast_item_grid.attach(label_box, 0, 0, 1, 1) # Condition Icon (if night) - if hourly_data.is_day.get("data")[idx+idx_offset] == 0: - weather_code = str(weather_code)+"n" + if hourly_data.is_day.get("data")[idx + idx_offset] == 0: + weather_code = str(weather_code) + "n" # Condition icon ===== condition_icon = Gtk.Image().new_from_file(icons[str(weather_code)]) @@ -152,7 +159,7 @@ def page_stacks(self, page_name): condition_icon.set_pixel_size(50) forecast_item_grid.attach(condition_icon, 1, 0, 1, 1) - forecast_cond_grid = Gtk.Grid(valign=Gtk.Align.CENTER,margin_end = 20) + forecast_cond_grid = Gtk.Grid(valign=Gtk.Align.CENTER, margin_end=20) forecast_item_grid.attach(forecast_cond_grid, 2, 0, 1, 1) # Temp label grid ===== @@ -160,17 +167,19 @@ def page_stacks(self, page_name): forecast_item_grid.attach(temp_label_grid, 3, 0, 1, 1) # Max temp label ====== - temp_max = Gtk.Label(label=f"{temp_max_text:.0f}° ", margin_start=10,) - temp_max.set_css_classes(['text-3', 'bold-2']) + temp_max = Gtk.Label( + label=f"{temp_max_text:.0f}° ", + margin_start=10, + ) + temp_max.set_css_classes(["text-4", "bold-2"]) temp_label_grid.attach(temp_max, 1, 0, 1, 1) # Min temp label ====== - if page_name == 'weekly': + if page_name == "weekly": temp_min = Gtk.Label(label=f" {temp_min_text:.0f}°", margin_top=5) - temp_min.set_css_classes(['light-4']) + temp_min.set_css_classes(["light-5"]) temp_label_grid.attach(temp_min, 1, 1, 1, 1) - # ============ get timestamp of upcomming 12:00 AM ==================== def get_upcomming_12am(self): # Get current date and time @@ -187,10 +196,10 @@ def get_upcomming_12am(self): return upcoming_12am.timestamp() # =========== Return index offset from hourly forecast to get tomorrow's weather condition ==================== - def get_idx_offset(self,hourly_data): + def get_idx_offset(self, hourly_data): idx_off = 0 upcomming_12am = self.get_upcomming_12am() for t in hourly_data.time.get("data"): if t > upcomming_12am: return idx_off - idx_off+=1 \ No newline at end of file + idx_off += 1 diff --git a/src/frontendHourlyDetails.py b/src/frontendHourlyDetails.py index a139365..631478b 100644 --- a/src/frontendHourlyDetails.py +++ b/src/frontendHourlyDetails.py @@ -2,11 +2,7 @@ import random import time import gi -import gettext from gi.repository import Gtk - -gi.require_version("Gtk", "4.0") -gi.require_version("Adw", "1") from gettext import gettext as _, pgettext as C_ from .constants import icons, icon_loc @@ -14,6 +10,9 @@ from .frontendUiDrawbarLine import DrawBar from .config import settings +gi.require_version("Gtk", "4.0") +gi.require_version("Adw", "1") + icon_loc += "arrow.svg" @@ -26,7 +25,7 @@ def __init__(self, *args, **kwargs): if settings.is_using_dynamic_bg: self.add_css_class("transparent_5") - self.set_margin_top(20) + self.set_margin_top(10) self.set_margin_start(5) self.paint_ui() self.daily_forecast = None @@ -51,7 +50,7 @@ def paint_ui(self): # Temperature Button ------------- temp_btn = Gtk.ToggleButton.new_with_label(_("Hourly")) - temp_btn.set_size_request(100, 20) + temp_btn.set_size_request(80, 16) temp_btn.set_css_classes(["btn_sm"]) temp_btn.do_clicked(temp_btn) style_buttons_box.append(temp_btn) @@ -59,7 +58,7 @@ def paint_ui(self): # Wind Button ------------- wind_btn = Gtk.ToggleButton.new_with_label(_("Wind")) - wind_btn.set_size_request(100, 20) + wind_btn.set_size_request(80, 16) wind_btn.set_css_classes(["btn_sm"]) wind_btn.set_group(temp_btn) style_buttons_box.append(wind_btn) @@ -67,7 +66,7 @@ def paint_ui(self): # Precipitation Button ------------- prec_btn = Gtk.ToggleButton.new_with_label(_("Precipitation")) - prec_btn.set_size_request(100, 20) + prec_btn.set_size_request(80, 16) prec_btn.set_css_classes(["btn_sm"]) prec_btn.set_group(temp_btn) style_buttons_box.append(prec_btn) @@ -85,33 +84,35 @@ def _on_btn_clicked(self, widget, page_name): # ---------- Create page stack -------------- def create_stack_page(self, page_name): - from .weatherData import daily_forecast_data as daily_data from .weatherData import hourly_forecast_data as hourly_data page_grid = Gtk.Grid() self.hourly_stack.add_named(page_grid, page_name) self.hourly_stack.set_visible_child_name(page_name) - info_grid = Gtk.Grid(margin_start=20, margin_top=10) + info_grid = Gtk.Grid( + margin_start=10, margin_top=15, margin_bottom=5, column_spacing=5 + ) + info_grid.set_css_classes(["card_infos"]) page_grid.attach(info_grid, 0, 1, 1, 1) - desc_label = Gtk.Label(label=C_("wind", "Day High"), halign=Gtk.Align.START) - desc_label.set_css_classes(["text-4", "light-2", "bold-2"]) - info_grid.attach(desc_label, 0, 0, 3, 1) + desc_label = Gtk.Label(label=C_("wind", "Day High •")) + desc_label.set_css_classes(["text-4", "light-3", "bold-3"]) + info_grid.attach(desc_label, 0, 0, 1, 2) val_label = Gtk.Label( label=str(max(hourly_data.windspeed_10m.get("data")[:24])), halign=Gtk.Align.START, ) - val_label.set_css_classes(["text-l5", "light-3", "bold-1"]) - info_grid.attach(val_label, 0, 1, 2, 2) + val_label.set_css_classes(["text-3", "light-3", "bold-1"]) + info_grid.attach(val_label, 1, 0, 2, 2) unit_label = Gtk.Label(label=hourly_data.windspeed_10m.get("unit")) unit_label.set_css_classes(["text-5", "light-2", "bold-3"]) - info_grid.attach(unit_label, 2, 2, 1, 1) + info_grid.attach(unit_label, 3, 0, 1, 2) # Hourly Page if page_name == "hourly": - desc_label.set_text(C_("temperature", "Day Max")) + desc_label.set_text(C_("temperature", "Day Max •")) val_label.set_text(str(max(hourly_data.temperature_2m.get("data"))) + "°") unit_label.set_text("") @@ -123,7 +124,7 @@ def create_stack_page(self, page_name): unit = "inch" if page_name == "prec": - desc_label.set_text(C_("precipitation", "Day High")) + desc_label.set_text(C_("precipitation", "Day High •")) val_label.set_text(f"{max_prec:.2f}") unit_label.set_text(unit) @@ -174,8 +175,8 @@ def create_stack_page(self, page_name): ) no_prec_label.set_css_classes(["text-3a", "bold-3", "light-2"]) no_prec_label.set_halign(Gtk.Align.CENTER) - no_prec_label.set_margin_top(40) - no_prec_label.set_margin_bottom(40) + no_prec_label.set_margin_top(20) + no_prec_label.set_margin_bottom(20) graphic_box.set_css_classes(["custom_card_hourly", "bg_light_grey"]) graphic_box.append(no_prec_label) graphic_container.append(graphic_box) @@ -190,7 +191,7 @@ def create_stack_page(self, page_name): graphic_container.append(graphic_box) label_timestamp = Gtk.Label(label="") - label_timestamp.set_css_classes(["text-6", "bold-2", "light-6"]) + label_timestamp.set_css_classes(["text-7", "bold-2", "light-6"]) time_stamp = datetime.datetime.fromtimestamp( hourly_data.time.get("data")[i] ) @@ -212,7 +213,7 @@ def create_stack_page(self, page_name): graphic_box.append(icon_box) label_val = Gtk.Label(label="") - label_val.set_css_classes(["text-4", "bold-2", "light-3"]) + label_val.set_css_classes(["text-5", "bold-2", "light-3"]) graphic_box.append(label_val) if page_name == "wind": diff --git a/src/frontendUiDrawBar.py b/src/frontendUiDrawBar.py index a071ab4..28cfb6f 100644 --- a/src/frontendUiDrawBar.py +++ b/src/frontendUiDrawBar.py @@ -1,15 +1,15 @@ import gi +from gi.repository import Gtk +import cairo gi.require_version("Gtk", "4.0") gi.require_version("Adw", "1") -from gi.repository import Gtk -import cairo class DrawLevelBar: def __init__( self, - fill_fr: float = .5, + fill_fr: float = 0.5, rounded_cap=False, width=40, height=70, @@ -28,15 +28,14 @@ def __init__( self.fill_fr = 1 - fill_fr self.rgb = rgb_color # [r,g,b] (between 0 to 1) - def draw(self, area, ctx, h, w, data): - x,y1 = (self.width)/2,10 - x,y2 = (self.width)/2,self.height-10 + x, y1 = (self.width) / 2, 10 + x, y2 = (self.width) / 2, self.height - 10 filled = self.fill_fr # filled = 1-filled - lev = y1+(y2-y1)*filled + lev = y1 + (y2 - y1) * filled ctx.set_source_rgba(*self.rgb, 0.4) # Set the line width @@ -50,16 +49,15 @@ def draw(self, area, ctx, h, w, data): # Stroke the line with the gradient ctx.stroke() - ctx.set_source_rgba(*self.rgb, 1) - ctx.move_to(x,lev) - ctx.rel_line_to(0,0) + ctx.move_to(x, lev) + ctx.rel_line_to(0, 0) ctx.stroke() # Draw a triangle using move_to and line_to - ctx.move_to(x-15, lev) + ctx.move_to(x - 15, lev) ctx.rel_line_to(-10, -6) # Draw the first side - ctx.rel_line_to(0,12) # Draw the second side - ctx.close_path() # Close the path to complete the triangle + ctx.rel_line_to(0, 12) # Draw the second side + ctx.close_path() # Close the path to complete the triangle ctx.fill() diff --git a/src/frontendUiDrawDayNight.py b/src/frontendUiDrawDayNight.py index f72f11c..5da4b34 100644 --- a/src/frontendUiDrawDayNight.py +++ b/src/frontendUiDrawDayNight.py @@ -1,18 +1,18 @@ import gi import math -gi.require_version("Gtk", "4.0") -gi.require_version("Adw", "1") from gi.repository import Gtk import cairo from datetime import datetime from .utils import get_cords, get_time_difference from .config import settings +gi.require_version("Gtk", "4.0") +gi.require_version("Adw", "1") + class DrawDayNight: def __init__(self, angle, width, height): - self.angle_degrees = angle # Specify the rotation angle in degrees self.width = width self.height = height @@ -28,7 +28,7 @@ def __init__(self, angle, width, height): def on_draw(self, widget, cr, width, height, data): # Create a Cairo surface context = cr - outer_radius = 43 + outer_radius = 38 num_rays = 8 sun_angle = self.angle_degrees # Degree @@ -75,12 +75,12 @@ def on_draw(self, widget, cr, width, height, data): # 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") + formatted_date_time = date_time.strftime("%I:%M %p") if settings.is_using_24h_clock: - formatted_date_time= date_time.strftime("%H:%M") + formatted_date_time = date_time.strftime("%H:%M") text_x += 7 text = formatted_date_time @@ -93,17 +93,6 @@ def on_draw(self, widget, cr, width, height, data): context.set_font_size(13) - # Horizon text - text = _("Horizon") - # Calculate the position for text placement - text_x = center_x + outer_radius * 1.3 - text_y = center_y - 10 - # Move the text cursor to the calculated position - context.move_to(text_x, text_y) - - # Display the text along the circular path - context.show_text(text) - text2 = _("Night") # Calculate the position for text placement text_x = center_x - 20 @@ -121,7 +110,9 @@ def on_draw(self, widget, cr, width, height, data): upper_limit = abs(1.2 - (1 - (360 - 170) / 90)) lower_limit = abs(1.2 - (1 - (180 - 170) / 90)) yellow = upper_limit - yellow + lower_limit - context.set_source_rgba(1, yellow, 0, 1.5) # color = function of y (height of sun) + context.set_source_rgba( + 1, yellow, 0, 1.5 + ) # color = function of y (height of sun) else: context.set_source_rgba(0.9, 0.9, 0.9, 1.0) # Whitish(for moon) @@ -155,9 +146,9 @@ def on_draw(self, widget, cr, width, height, data): context.set_line_width(1) context.set_source_rgba(0.8, 0.8, 0.8, 1) # Red context.set_line_cap(cairo.LINE_CAP_ROUND) - context.move_to(width / 6, height // 2) + context.move_to(width / 10, height // 2) context.line_to(width, height // 2) - dash_length = 12 - gap_length = 5 + dash_length = 6 + gap_length = 3 context.set_dash([dash_length, gap_length]) context.stroke() diff --git a/src/frontendUiDrawPollutionBar.py b/src/frontendUiDrawPollutionBar.py index 2e344aa..b44f5d6 100644 --- a/src/frontendUiDrawPollutionBar.py +++ b/src/frontendUiDrawPollutionBar.py @@ -1,8 +1,9 @@ import gi +import cairo +from gi.repository import Gtk + gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') -from gi.repository import Gtk -import cairo class PollutionBar(Gtk.DrawingArea): def __init__(self,pos): @@ -18,7 +19,7 @@ def on_draw(self, area, cr, h, w, data): width = self.get_width() height = 40 - gradient = cairo.LinearGradient(0, 0, 400, 0) + gradient = cairo.LinearGradient(0, 0, 250, 0) # Add color stops to the gradient (position, R, G, B, A) gradient.add_color_stop_rgba(0, 0, 1, 0, 1) # Green gradient.add_color_stop_rgba(0.3, 1, 1, 0, 1) # Yellow @@ -29,7 +30,7 @@ def on_draw(self, area, cr, h, w, data): # cr.set_source_rgba(0.8, 0.8, 0.8, 1) cr.set_line_width(6) cr.move_to(10, height / 2) - cr.line_to(width - 10, height / 2) + cr.line_to(width - 5, height / 2) cr.set_line_cap(cairo.LINE_CAP_ROUND) cr.stroke() diff --git a/src/mousam.py b/src/mousam.py index 1d0a37d..7778acc 100644 --- a/src/mousam.py +++ b/src/mousam.py @@ -1,10 +1,7 @@ import gi import time import threading -import gettext -gi.require_version("Gtk", "4.0") -gi.require_version("Adw", "1") from gi.repository import Gtk, Adw, Gio,Gdk,GLib from gettext import gettext as _, pgettext as C_ @@ -29,6 +26,8 @@ fetch_daily_forecast, fetch_current_air_pollution, ) +gi.require_version("Gtk", "4.0") +gi.require_version("Adw", "1") global updated_at updated_at = time.time() @@ -137,7 +136,7 @@ def show_loader(self): container_loader = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) container_loader.set_margin_top(220) - container_loader.set_margin_bottom(300) + container_loader.set_margin_bottom(200) # Create loader loader = Gtk.Spinner()