feat(modules/desktop): Refactor weather widget layout with header/footer and dynamic gradient styling
The update reorganizes the weather widget UI, adds a header for city and icon, a body for values, adjusts alignment and sizing, and applies a gradient class to the parent container. - New Features: Structured header/footer layout for weather information - Enhancements: Realigned text order, increased max_chars_width, resized icon, improved spacing- Bug Fixes: None
This commit is contained in:
1 file changed
+31
-14
+31
-14
@@ -227,17 +227,20 @@ class Weather(Box):
|
|||||||
update_weather(self)
|
update_weather(self)
|
||||||
|
|
||||||
def _create_labels(self):
|
def _create_labels(self):
|
||||||
|
self.header = Box(orientation="h", h_expand=True)
|
||||||
|
self.body = Box(orientation="v", v_expand=True, valign="end")
|
||||||
|
|
||||||
self.city = Label(
|
self.city = Label(
|
||||||
name="city",
|
name="city",
|
||||||
label="Loading...",
|
label="Loading...",
|
||||||
justification="right",
|
justification="left",
|
||||||
h_align="start",
|
h_align="start",
|
||||||
max_chars_width=12,
|
max_chars_width=15,
|
||||||
ellipsization="end",
|
ellipsization="end",
|
||||||
)
|
)
|
||||||
self.temperature = Label(name="temperature", label="--°", h_align="start")
|
self.temperature = Label(name="temperature", label="--°", h_align="start")
|
||||||
self.condition_em = svg_file(
|
self.condition_em = svg_file(
|
||||||
"weather/weather-none-available.svg", size=(48, 48), name="condition-emoji"
|
"weather/weather-none-available.svg", size=(35, 35), name="condition-emoji"
|
||||||
)
|
)
|
||||||
self.condition = Label(
|
self.condition = Label(
|
||||||
name="condition",
|
name="condition",
|
||||||
@@ -246,23 +249,28 @@ class Weather(Box):
|
|||||||
ellipsization="end",
|
ellipsization="end",
|
||||||
h_align="start",
|
h_align="start",
|
||||||
)
|
)
|
||||||
self.feels_like = Label(name="feels-like", label="H:-- L:--", h_align="start")
|
self.feels_like = Label(name="feels-like", label="L:-- H:--", h_align="start")
|
||||||
|
|
||||||
def _layout_labels(self):
|
def _layout_labels(self):
|
||||||
for label in [
|
# Header: City (left) and Icon (right)
|
||||||
self.city,
|
self.header.add(self.city)
|
||||||
self.temperature,
|
self.header.pack_end(self.condition_em, False, False, 0)
|
||||||
self.condition_em,
|
|
||||||
self.condition,
|
# Body: Temp, Condition, High/Low
|
||||||
self.feels_like,
|
self.body.add(self.temperature)
|
||||||
]:
|
self.body.add(self.condition)
|
||||||
self.add(label)
|
self.body.add(self.feels_like)
|
||||||
|
|
||||||
|
self.add(self.header)
|
||||||
|
self.add(self.body)
|
||||||
|
|
||||||
def update_labels(self, weather_info: List[str]):
|
def update_labels(self, weather_info: List[str]):
|
||||||
if not weather_info or len(weather_info) != 7:
|
if not weather_info or len(weather_info) != 7:
|
||||||
return
|
return
|
||||||
icon_name, temp, condition, location, maxtemp, mintemp, _ = weather_info
|
icon_name, temp, condition, location, maxtemp, mintemp, gradient_class = (
|
||||||
maxmin = f"H:{maxtemp} L:{mintemp}"
|
weather_info
|
||||||
|
)
|
||||||
|
maxmin = f"L:{mintemp} H:{maxtemp}"
|
||||||
|
|
||||||
self.city.set_label(location)
|
self.city.set_label(location)
|
||||||
self.temperature.set_label(temp)
|
self.temperature.set_label(temp)
|
||||||
@@ -273,6 +281,15 @@ class Weather(Box):
|
|||||||
self.condition.set_label(condition)
|
self.condition.set_label(condition)
|
||||||
self.feels_like.set_label(maxmin)
|
self.feels_like.set_label(maxmin)
|
||||||
|
|
||||||
|
# Apply gradient class to container
|
||||||
|
if hasattr(self, "parent") and self.parent:
|
||||||
|
# Remove old weather classes
|
||||||
|
for cls in self.parent.get_style_context().list_classes():
|
||||||
|
if cls.startswith("weather-"):
|
||||||
|
self.parent.remove_style_class(cls)
|
||||||
|
# Add new one
|
||||||
|
self.parent.add_style_class(gradient_class)
|
||||||
|
|
||||||
self.parent.set_visible(True)
|
self.parent.set_visible(True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user