Added Weather Widgets
This commit is contained in:
1 parent
59a48c374e
commit
a8cf797c1c
2 files changed
+154
-17
No files matched your search
@@ -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,
|
||||
#month label{
|
||||
color: var(--foreground);
|
||||
@@ -89,7 +139,6 @@ menu > menuitem:hover > label {
|
||||
margin-top: 10px;
|
||||
font-size: 30px;
|
||||
color: alpha(#fff, 0.7);
|
||||
font-family: "SF Pro Rounded";
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@@ -98,16 +147,19 @@ menu > menuitem:hover > label {
|
||||
margin-top: -10px;
|
||||
font-size: 90px;
|
||||
font-weight: 600;
|
||||
font-family: "SF Pro Rounded";
|
||||
}
|
||||
#day label{
|
||||
color: alpha(#FF0000, 0.7);
|
||||
}
|
||||
#date{
|
||||
}
|
||||
#box-widget{
|
||||
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-height: 170px;
|
||||
border-radius: 16px;
|
||||
|
||||
+97
-12
@@ -79,14 +79,26 @@ def get_weather(callback):
|
||||
condition = responseinfo["current_condition"][0]["weatherDesc"][0][
|
||||
"value"
|
||||
]
|
||||
maxtemp = responseinfo["weather"][0]["maxtempC"] + "°"
|
||||
mintemp = responseinfo["weather"][0]["mintempC"] + "°"
|
||||
location = responseinfo["nearest_area"][0]["areaName"][0]["value"]
|
||||
emoji = response.text.strip()
|
||||
update_time = datetime.datetime.now().strftime("%I:%M:%S %p")
|
||||
|
||||
GLib.idle_add(
|
||||
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
|
||||
except requests.RequestException as e:
|
||||
print(f"Error fetching weather (attempt {attempt + 1}): {e}")
|
||||
@@ -448,9 +460,67 @@ def create_widgets(config):
|
||||
return widgets
|
||||
|
||||
|
||||
# if data.DESKTOP_WIDGETS:
|
||||
# if config.get("widgets_displaytype_visible", True):
|
||||
class Weather(Box):
|
||||
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):
|
||||
def __init__(self, **kwargs):
|
||||
@@ -475,6 +545,8 @@ class Date(Box):
|
||||
self.add(self.datethree)
|
||||
|
||||
|
||||
|
||||
|
||||
class Deskwidgets(Window):
|
||||
def __init__(self, **kwargs):
|
||||
config = load_config()
|
||||
@@ -482,24 +554,37 @@ class Deskwidgets(Window):
|
||||
name="desktop",
|
||||
layer="bottom",
|
||||
title="desktop-widgets",
|
||||
orientation="v",
|
||||
exclusivity="none",
|
||||
child=[
|
||||
Window(
|
||||
anchor="top left",
|
||||
orientation="h",
|
||||
layer="bottom",
|
||||
child=[
|
||||
Box(
|
||||
orientation="v",
|
||||
name="box-widget",
|
||||
v_expand=True,
|
||||
v_align="center",
|
||||
h_align="center",
|
||||
children=[Date()],
|
||||
)
|
||||
name="desktop-widgets-container",
|
||||
children=[
|
||||
Box(
|
||||
orientation="v",
|
||||
name="box-widget",
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user