From 7d618eb116c33edd24c84c24e71131a28ba5bf92 Mon Sep 17 00:00:00 2001 From: Xiang Date: Thu, 11 Jul 2024 17:50:46 +0800 Subject: [PATCH] 1.15.0 update --- docs/changelog.txt | 4 ++-- tinypedal/const.py | 2 +- tinypedal/weather.py | 6 ++++-- tinypedal/widget/weather_forecast.py | 19 +++++++++++++------ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 74c37c05..ad6ccd03 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,7 +1,7 @@ -WIP +2.15.0 (2024-07-11) ----------------------------- * General - - Added new weather icon set in "images" folder. + - Added new weather icon set (by S.Victor) in "images" folder. * Fuel Calculator - Add Battery charge drain & regen (%) per lap to history log. diff --git a/tinypedal/const.py b/tinypedal/const.py index d63ec191..b865d1e5 100644 --- a/tinypedal/const.py +++ b/tinypedal/const.py @@ -27,7 +27,7 @@ from PySide2.QtCore import qVersion -VERSION = "2.14.1" +VERSION = "2.15.0" APP_NAME = "TinyPedal" PLATFORM = platform.system() APP_ICON = "images/icon.png" diff --git a/tinypedal/weather.py b/tinypedal/weather.py index ac94043e..57dafcf4 100644 --- a/tinypedal/weather.py +++ b/tinypedal/weather.py @@ -26,18 +26,18 @@ MAX_MINUTES = 9999 MIN_TEMPERATURE = -273 DEFAULT = [(MAX_MINUTES, -1, MIN_TEMPERATURE, -1)] +WEATHER_NODES = ("START", "NODE_25", "NODE_50", "NODE_75", "FINISH") def forecast_rf2(data: dict) -> list[tuple]: """Get value from weather forecast dictionary, output 5 api data + 5 padding data""" - weather_nodes = ("START", "NODE_25", "NODE_50", "NODE_75", "FINISH") try: output = [ (round(index * 0.2, 1), # 0 - fraction start time data[weather]["WNV_SKY"]["currentValue"], # 1 - sky type index round(data[weather]["WNV_TEMPERATURE"]["currentValue"]), # 2 - temperature round(data[weather]["WNV_RAIN_CHANCE"]["currentValue"]), # 3 - rain chance - ) for index, weather in enumerate(weather_nodes)] + ) for index, weather in enumerate(WEATHER_NODES)] output.extend(DEFAULT * 5) except (KeyError, TypeError): output = DEFAULT * 10 @@ -65,6 +65,8 @@ def sky_type_correction(sky_type, raininess): 10 Overcast & Storm """ if raininess <= 0: + if sky_type > 4: + return 4 return sky_type if 0 < raininess <= 10: return 5 diff --git a/tinypedal/widget/weather_forecast.py b/tinypedal/widget/weather_forecast.py index 7cba989a..e48e6882 100644 --- a/tinypedal/widget/weather_forecast.py +++ b/tinypedal/widget/weather_forecast.py @@ -48,15 +48,14 @@ def __init__(self, config): text_def = "n/a" bar_padx = round(self.wcfg["font_size"] * self.wcfg["bar_padding"]) * 2 bar_gap = self.wcfg["bar_gap"] - bar_width = font_m.width * 4 + bar_padx self.icon_size = int(max(self.wcfg["icon_size"], 16) * 0.5) * 2 + bar_width = max(font_m.width * 4 + bar_padx, self.icon_size) # Base style self.setStyleSheet( f"font-family: {self.wcfg['font_name']};" f"font-size: {self.wcfg['font_size']}px;" f"font-weight: {self.wcfg['font_weight']};" - f"min-width: {bar_width}px;" ) # Create layout @@ -84,6 +83,7 @@ def __init__(self, config): bar_style_time = ( f"color: {self.wcfg['font_color_estimated_time']};" f"background: {self.wcfg['bkg_color_estimated_time']};" + f"min-width: {bar_width}px;" ) self.bar_time_0 = QLabel("now") self.bar_time_0.setAlignment(Qt.AlignCenter) @@ -115,6 +115,7 @@ def __init__(self, config): bar_style_temp = ( f"color: {self.wcfg['font_color_ambient_temperature']};" f"background: {self.wcfg['bkg_color_ambient_temperature']};" + f"min-width: {bar_width}px;" ) self.bar_temp_0 = QLabel(text_def) self.bar_temp_0.setAlignment(Qt.AlignCenter) @@ -143,8 +144,11 @@ def __init__(self, config): # Rain chance if self.wcfg["show_rain_chance_bar"]: - bar_style_rain = f"background: {self.wcfg['rain_chance_bar_bkg_color']};" - self.bar_rain_width = max(bar_width, self.icon_size) + bar_style_rain = ( + f"background: {self.wcfg['rain_chance_bar_bkg_color']};" + f"min-width: {bar_width}px;" + ) + self.bar_rain_width = bar_width self.bar_rain_height = max(self.wcfg["rain_chance_bar_height"], 1) self.pixmap_rainchance = QPixmap(self.bar_rain_width, self.bar_rain_height) @@ -174,7 +178,10 @@ def __init__(self, config): layout_4.addWidget(self.bar_rain_4, 3, 0) # Forecast icon - bar_style_icon = f"background: {self.wcfg['bkg_color']};" + bar_style_icon = ( + f"background: {self.wcfg['bkg_color']};" + f"min-width: {bar_width}px;" + ) self.bar_icon_0 = QLabel() self.bar_icon_0.setAlignment(Qt.AlignCenter) self.bar_icon_0.setStyleSheet(bar_style_icon) @@ -295,7 +302,7 @@ def update_weather_forecast_restapi(self): def update_estimated_time(self, curr, last, index): """Estimated time""" if curr != last: - if curr >= wthr.MAX_MINUTES: + if curr >= wthr.MAX_MINUTES or curr < 0: time_text = "n/a" elif curr >= 60: time_text = f"{curr / 60:.1f}h"