Added Weather Widgets

This commit is contained in:
tr1x_em committed 2025-08-03 17:54:53 +05:30
1 parent 59a48c374e
commit a8cf797c1c
2 files changed
+154 -17

No files matched your search

+57 -5
View File
@@ -82,6 +82,56 @@ menu > menuitem:hover > label {
#weather-widget label{
font-family: "SF Pro Rounded";
/* font-size: 20px; */
font-weight: 600;
margin-left: 10px;
}
#city {
margin-top: 10px;
font-size: 20px;
}
#temperature {
font-size: 50px;
}
#condition-emoji{
margin-top: 10px;
font-size: 16px;
}
#condition {
font-size: 15px;
}
#feels-like {
font-size: 15px;
}
/* # */
#date-widget label {
font-family: "SF Pro Rounded";
margin-top: 10px;
}
#day label, #day label,
#month label{ #month label{
color: var(--foreground); color: var(--foreground);
@@ -89,7 +139,6 @@ menu > menuitem:hover > label {
margin-top: 10px; margin-top: 10px;
font-size: 30px; font-size: 30px;
color: alpha(#fff, 0.7); color: alpha(#fff, 0.7);
font-family: "SF Pro Rounded";
font-weight: 600; font-weight: 600;
} }
@@ -98,16 +147,19 @@ menu > menuitem:hover > label {
margin-top: -10px; margin-top: -10px;
font-size: 90px; font-size: 90px;
font-weight: 600; font-weight: 600;
font-family: "SF Pro Rounded";
} }
#day label{ #day label{
color: alpha(#FF0000, 0.7); color: alpha(#FF0000, 0.7);
} }
#date{
}
#box-widget{ #box-widget{
background-color: alpha(#232323, 1); background-color: alpha(#232323, 1);
margin-top: 20px; margin: 20px 20px 20px 20px;
min-width: 170px;
min-height: 170px;
border-radius: 16px;
}
#box-widget-2{
background-color: alpha(#425D8A, 1);
min-width: 170px; min-width: 170px;
min-height: 170px; min-height: 170px;
border-radius: 16px; border-radius: 16px;
+97 -12
View File
@@ -79,14 +79,26 @@ def get_weather(callback):
condition = responseinfo["current_condition"][0]["weatherDesc"][0][ condition = responseinfo["current_condition"][0]["weatherDesc"][0][
"value" "value"
] ]
maxtemp = responseinfo["weather"][0]["maxtempC"] + "°"
mintemp = responseinfo["weather"][0]["mintempC"] + "°"
location = responseinfo["nearest_area"][0]["areaName"][0]["value"] location = responseinfo["nearest_area"][0]["areaName"][0]["value"]
emoji = response.text.strip() emoji = response.text.strip()
update_time = datetime.datetime.now().strftime("%I:%M:%S %p") update_time = datetime.datetime.now().strftime("%I:%M:%S %p")
GLib.idle_add( GLib.idle_add(
callback, callback,
[emoji, temp, condition, feels_like, location, update_time], [
emoji,
temp,
condition,
feels_like,
location,
update_time,
maxtemp,
mintemp,
],
) )
print(emoji, temp, condition, feels_like, location, update_time)
return return
except requests.RequestException as e: except requests.RequestException as e:
print(f"Error fetching weather (attempt {attempt + 1}): {e}") print(f"Error fetching weather (attempt {attempt + 1}): {e}")
@@ -448,9 +460,67 @@ def create_widgets(config):
return widgets return widgets
# if data.DESKTOP_WIDGETS: class Weather(Box):
# if config.get("widgets_displaytype_visible", True): def __init__(self, parent, **kwargs):
super().__init__(
name="weather-widget",
h_expand=True,
v_expand=True,
justification="right",
orientation="v",
all_visible=False,
**kwargs,
)
self.parent = parent
self.city = Label(
name="city", label="New York", justification="right", h_align="start"
)
self.temperature = Label(name="temperature", label="36", h_align="start")
self.condition_em = Label(name="condition-emoji", label="☁️", h_align="start")
self.condition = Label(name="condition", label="Cloudy", h_align="start")
self.feels_like = Label(name="feels-like", label="H:28 L:20", h_align="start")
self.add(self.city)
self.add(self.temperature)
self.add(self.condition_em)
self.add(self.condition)
self.add(self.feels_like)
update_weather(self)
def update_labels(self, weather_info):
if not self.weatherinfo:
return
# Unpack weather info into variables for better readability
emoji, temp, condition, feels_like, location, update_time, maxtemp, mintemp = (
self.weatherinfo
)
maxmin = f"H:{maxtemp} L:{mintemp}"
# Store references to deeply nested children to avoid repeated lookups
self.city.set_label(location)
self.feels_like.set_label(maxmin)
self.condition.set_label(condition)
self.temperature.set_label(temp)
self.condition_em.set_label(emoji)
self.parent.set_visible(True)
class WeatherContainer(Box):
def __init__(self, **kwargs):
super().__init__(
orientation="v",
name="box-widget-2",
v_expand=True,
v_align="center",
visible=False,
h_align="center",
children=[
Weather(),
],
**kwargs,
)
self.add(WeatherWidget())
class Date(Box): class Date(Box):
def __init__(self, **kwargs): def __init__(self, **kwargs):
@@ -475,6 +545,8 @@ class Date(Box):
self.add(self.datethree) self.add(self.datethree)
class Deskwidgets(Window): class Deskwidgets(Window):
def __init__(self, **kwargs): def __init__(self, **kwargs):
config = load_config() config = load_config()
@@ -482,24 +554,37 @@ class Deskwidgets(Window):
name="desktop", name="desktop",
layer="bottom", layer="bottom",
title="desktop-widgets", title="desktop-widgets",
orientation="v",
exclusivity="none", exclusivity="none",
child=[ child=[
Window( Window(
anchor="top left", anchor="top left",
orientation="h",
layer="bottom", layer="bottom",
child=[ child=[
Box( Box(
orientation="v", name="desktop-widgets-container",
name="box-widget", children=[
v_expand=True, Box(
v_align="center", orientation="v",
h_align="center", name="box-widget",
children=[Date()], v_expand=True,
) v_align="center",
h_align="center",
children=[Date()],
),
WeatherContainer(),
],
),
], ],
) ),
Window(
anchor="bottom left",
orientation="h",
layer="bottom",
child=[],
),
], ],
all_visible=True,
**kwargs, **kwargs,
) )