Skip to content

Commit 254cd0f

Browse files
committed
Tweaks
1 parent fb069ee commit 254cd0f

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

modules/bar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def __init__(self, **kwargs):
171171

172172
self.hidden = False
173173

174-
self.show_all()
174+
# self.show_all()
175175
self.systray._update_visibility()
176176

177177
def on_button_enter(self, widget, event):

modules/buttons.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self):
2424
self._animation_timeout_id = None
2525
self._animation_step = 0
2626
self._animation_direction = 1
27-
27+
2828
self.network_icon = Label(
2929
name="network-icon",
3030
markup=None,
@@ -51,7 +51,7 @@ def __init__(self):
5151
h_align="start",
5252
v_align="center",
5353
spacing=10,
54-
54+
5555
children=[self.network_icon, self.network_text],
5656
)
5757
self.network_status_button = Button(
@@ -83,16 +83,20 @@ def __init__(self):
8383
children=[self.network_status_button, self.network_menu_button],
8484
)
8585

86-
self.widgets = [self, self.network_icon, self.network_label,
87-
self.network_ssid, self.network_status_button,
86+
self.widgets = [self, self.network_icon, self.network_label,
87+
self.network_ssid, self.network_status_button,
8888
self.network_menu_button, self.network_menu_label]
8989

9090
# Connect to wifi device signals when ready
9191
self.network_client.connect('device-ready', self._on_wifi_ready)
92-
93-
# Check initial state if wifi device is already available
94-
if self.network_client.wifi_device:
95-
self.update_state()
92+
93+
# Check initial state using idle_add to defer until GTK loop is running
94+
GLib.idle_add(self._initial_update)
95+
96+
97+
def _initial_update(self):
98+
self.update_state()
99+
return False # Run only once
96100

97101
def _on_wifi_ready(self, *args):
98102
if self.network_client.wifi_device:
@@ -103,23 +107,23 @@ def _on_wifi_ready(self, *args):
103107
def _animate_searching(self):
104108
"""Animate wifi icon when searching for networks"""
105109
wifi_icons = [icons.wifi_0, icons.wifi_1, icons.wifi_2, icons.wifi_3, icons.wifi_2, icons.wifi_1]
106-
110+
107111
# Si el widget no existe o el WiFi está desactivado, detener la animación
108112
wifi = self.network_client.wifi_device
109113
if not self.network_icon or not wifi or not wifi.enabled:
110114
self._stop_animation()
111115
return False
112-
116+
113117
# Si estamos conectados, detener la animación
114118
if wifi.state == "activated" and wifi.ssid != "Disconnected":
115119
self._stop_animation()
116120
return False
117-
121+
118122
GLib.idle_add(self.network_icon.set_markup, wifi_icons[self._animation_step])
119-
123+
120124
# Reiniciar al principio cuando llegamos al final
121125
self._animation_step = (self._animation_step + 1) % len(wifi_icons)
122-
126+
123127
return True # Mantener la animación activa
124128

125129
def _start_animation(self):
@@ -140,7 +144,7 @@ def update_state(self, *args):
140144
wifi = self.network_client.wifi_device
141145
ethernet = self.network_client.ethernet_device
142146

143-
# Primero actualizamos el estado enabled/disabled
147+
# Update enabled/disabled state
144148
if wifi and not wifi.enabled:
145149
self._stop_animation()
146150
self.network_icon.set_markup(icons.wifi_off)
@@ -149,16 +153,16 @@ def update_state(self, *args):
149153
self.network_ssid.set_label("Disabled")
150154
return
151155

152-
# Removemos la clase disabled si llegamos aquí
156+
# Remove disabled class if we got here
153157
for widget in self.widgets:
154158
widget.remove_style_class("disabled")
155159

156-
# Actualizar el texto y la animación según el estado
160+
# Update text and animation based on state
157161
if wifi and wifi.enabled:
158162
if wifi.state == "activated" and wifi.ssid != "Disconnected":
159163
self._stop_animation()
160164
self.network_ssid.set_label(wifi.ssid)
161-
# Actualizar icono según la intensidad de la señal
165+
# Update icon based on signal strength
162166
if wifi.strength > 0:
163167
strength = wifi.strength
164168
if strength < 25:
@@ -173,8 +177,14 @@ def update_state(self, *args):
173177
self.network_ssid.set_label("Enabled")
174178
self._start_animation()
175179

176-
# Manejar el caso de conexión por cable
177-
if self.network_client.primary_device == "wired":
180+
# Handle primary device check safely
181+
try:
182+
primary_device = self.network_client.primary_device
183+
except AttributeError:
184+
primary_device = "wireless" # Default to wireless if error occurs
185+
186+
# Handle wired connection case
187+
if primary_device == "wired":
178188
self._stop_animation()
179189
if ethernet and ethernet.internet == "activated":
180190
self.network_icon.set_markup(icons.world)

modules/weather.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def _fetch_weather_thread(self):
5252
GLib.idle_add(self.label.set_label, weather_data.replace(" ", ""))
5353
else:
5454
GLib.idle_add(self.label.set_markup, f"{icons.cloud_off} Unavailable")
55+
self.set_visible(False)
5556
except Exception as e:
56-
print(f"Error al obtener clima: {e}")
57+
print(f"Error fetching weather: {e}")
5758
GLib.idle_add(self.label.set_markup, f"{icons.cloud_off} Error")
59+
self.set_visible(False)

0 commit comments

Comments
 (0)