mirror of
https://github.com/gryf/wicd.git
synced 2025-12-23 06:37:59 +01:00
Fix some issues with the GUI statusbar being incorrect.
Make wicd-client more tolerant of dbus exceptions. Disconnect from both managed interfaces before making a connection.
This commit is contained in:
20
wicd/gui.py
20
wicd/gui.py
@@ -221,11 +221,12 @@ class appGui(object):
|
|||||||
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing",
|
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing",
|
||||||
"org.wicd.daemon")
|
"org.wicd.daemon")
|
||||||
|
|
||||||
|
self._do_statusbar_update(*daemon.GetConnectionStatus())
|
||||||
|
self.wait_for_events(0.1)
|
||||||
if hasattr(gobject, "timeout_add_seconds"):
|
if hasattr(gobject, "timeout_add_seconds"):
|
||||||
self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar)
|
self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar)
|
||||||
else:
|
else:
|
||||||
self.update_cb = gobject.timeout_add(2000, self.update_statusbar)
|
self.update_cb = gobject.timeout_add(2000, self.update_statusbar)
|
||||||
self._do_statusbar_update(*daemon.GetConnectionStatus())
|
|
||||||
self.refresh_clicked()
|
self.refresh_clicked()
|
||||||
|
|
||||||
def handle_connection_results(self, results):
|
def handle_connection_results(self, results):
|
||||||
@@ -355,14 +356,17 @@ class appGui(object):
|
|||||||
|
|
||||||
def update_statusbar(self):
|
def update_statusbar(self):
|
||||||
""" Triggers a status update in wicd-monitor. """
|
""" Triggers a status update in wicd-monitor. """
|
||||||
if not self.is_visible or self.refreshing:
|
if not self.is_visible:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
daemon.UpdateState()
|
if self.connecting:
|
||||||
|
self._do_statusbar_update(*daemon.GetConnectionStatus())
|
||||||
|
else:
|
||||||
|
daemon.UpdateState()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _do_statusbar_update(self, state, info):
|
def _do_statusbar_update(self, state, info):
|
||||||
if not self.is_visible or self.refreshing:
|
if not self.is_visible:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if state == misc.WIRED:
|
if state == misc.WIRED:
|
||||||
@@ -373,14 +377,15 @@ class appGui(object):
|
|||||||
return self.set_connecting_state(info)
|
return self.set_connecting_state(info)
|
||||||
elif state in (misc.SUSPENDED, misc.NOT_CONNECTED):
|
elif state in (misc.SUSPENDED, misc.NOT_CONNECTED):
|
||||||
return self.set_not_connected_state(info)
|
return self.set_not_connected_state(info)
|
||||||
|
return True
|
||||||
|
|
||||||
def set_wired_state(self, info):
|
def set_wired_state(self, info):
|
||||||
self._set_connected_state()
|
self._set_not_connecting_state()
|
||||||
self.set_status(language['connected_to_wired'].replace('$A', info[0]))
|
self.set_status(language['connected_to_wired'].replace('$A', info[0]))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def set_wireless_state(self, info):
|
def set_wireless_state(self, info):
|
||||||
self._set_connected_state()
|
self._set_not_connecting_state()
|
||||||
self.set_status(language['connected_to_wireless'].replace
|
self.set_status(language['connected_to_wireless'].replace
|
||||||
('$A', info[1]).replace
|
('$A', info[1]).replace
|
||||||
('$B', daemon.FormatSignalForPrinting(info[2])).replace
|
('$B', daemon.FormatSignalForPrinting(info[2])).replace
|
||||||
@@ -389,10 +394,11 @@ class appGui(object):
|
|||||||
|
|
||||||
def set_not_connected_state(self, info):
|
def set_not_connected_state(self, info):
|
||||||
self.connecting = False
|
self.connecting = False
|
||||||
|
self._set_not_connecting_state()
|
||||||
self.set_status(language['not_connected'])
|
self.set_status(language['not_connected'])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _set_connected_state(self):
|
def _set_not_connecting_state(self):
|
||||||
self.connecting = False
|
self.connecting = False
|
||||||
if self.pulse_active:
|
if self.pulse_active:
|
||||||
self.pulse_active = False
|
self.pulse_active = False
|
||||||
|
|||||||
@@ -647,5 +647,6 @@ def threaded(f):
|
|||||||
wrapper.__name__ = f.__name__
|
wrapper.__name__ = f.__name__
|
||||||
wrapper.__dict__ = f.__dict__
|
wrapper.__dict__ = f.__dict__
|
||||||
wrapper.__doc__ = f.__doc__
|
wrapper.__doc__ = f.__doc__
|
||||||
|
wrapper.__module__ = f.__module__
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|||||||
@@ -69,15 +69,16 @@ class ConnectionStatus(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
""" Initialize variables needed for the connection status methods. """
|
""" Initialize variables needed for the connection status methods. """
|
||||||
self.last_strength = -2
|
self.last_strength = -2
|
||||||
|
self.last_state = misc.NOT_CONNECTED
|
||||||
|
self.last_reconnect_time = time.time()
|
||||||
|
self.last_network = ""
|
||||||
self.displayed_strength = -1
|
self.displayed_strength = -1
|
||||||
self.still_wired = False
|
self.still_wired = False
|
||||||
self.network = ''
|
self.network = ''
|
||||||
self.tried_reconnect = False
|
self.tried_reconnect = False
|
||||||
self.connection_lost_counter = 0
|
self.connection_lost_counter = 0
|
||||||
self.last_state = misc.NOT_CONNECTED
|
|
||||||
self.reconnecting = False
|
self.reconnecting = False
|
||||||
self.reconnect_tries = 0
|
self.reconnect_tries = 0
|
||||||
self.last_reconnect_time = time.time()
|
|
||||||
self.signal_changed = False
|
self.signal_changed = False
|
||||||
self.iwconfig = ""
|
self.iwconfig = ""
|
||||||
self.trigger_reconnect = False
|
self.trigger_reconnect = False
|
||||||
@@ -155,8 +156,9 @@ class ConnectionStatus(object):
|
|||||||
self.connection_lost_counter = 0
|
self.connection_lost_counter = 0
|
||||||
|
|
||||||
if (wifi_signal != self.last_strength or
|
if (wifi_signal != self.last_strength or
|
||||||
self.network != wireless.GetCurrentNetwork(self.iwconfig)):
|
self.network != self.last_network):
|
||||||
self.last_strength = wifi_signal
|
self.last_strength = wifi_signal
|
||||||
|
self.last_network = self.network
|
||||||
self.signal_changed = True
|
self.signal_changed = True
|
||||||
daemon.SetCurrentInterface(daemon.GetWirelessInterface())
|
daemon.SetCurrentInterface(daemon.GetWirelessInterface())
|
||||||
|
|
||||||
@@ -262,8 +264,8 @@ class ConnectionStatus(object):
|
|||||||
daemon.SetConnectionStatus(state, info)
|
daemon.SetConnectionStatus(state, info)
|
||||||
|
|
||||||
# Send a D-Bus signal announcing status has changed if necessary.
|
# Send a D-Bus signal announcing status has changed if necessary.
|
||||||
if state != self.last_state or \
|
if (state != self.last_state or (state == misc.WIRELESS and
|
||||||
(state == misc.WIRELESS and self.signal_changed):
|
self.signal_changed)):
|
||||||
daemon.EmitStatusChanged(state, info)
|
daemon.EmitStatusChanged(state, info)
|
||||||
self.last_state = state
|
self.last_state = state
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ def abortable(func):
|
|||||||
wrapper.__name__ = func.__name__
|
wrapper.__name__ = func.__name__
|
||||||
wrapper.__dict__ = func.__dict__
|
wrapper.__dict__ = func.__dict__
|
||||||
wrapper.__doc__ = func.__doc__
|
wrapper.__doc__ = func.__doc__
|
||||||
|
wrapper.__module = func.__module__
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
def get_backend_list():
|
def get_backend_list():
|
||||||
|
|||||||
@@ -74,6 +74,21 @@ DBUS_AVAIL = False
|
|||||||
|
|
||||||
language = misc.get_language_list_tray()
|
language = misc.get_language_list_tray()
|
||||||
|
|
||||||
|
|
||||||
|
def catchdbus(func):
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
try:
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
except DBusException, e:
|
||||||
|
print "warning: ignoring exception %s" % egg
|
||||||
|
return None
|
||||||
|
wrapper.__name__ = func.__name__
|
||||||
|
wrapper.__module__ = func.__module__
|
||||||
|
wrapper.__dict__ = func.__dict__
|
||||||
|
wrapper.__doc__ = func.__doc__
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class NetworkMenuItem(gtk.ImageMenuItem):
|
class NetworkMenuItem(gtk.ImageMenuItem):
|
||||||
def __init__(self, lbl, is_active=False):
|
def __init__(self, lbl, is_active=False):
|
||||||
gtk.ImageMenuItem.__init__(self)
|
gtk.ImageMenuItem.__init__(self)
|
||||||
@@ -130,6 +145,7 @@ class TrayIcon(object):
|
|||||||
handle_no_dbus()
|
handle_no_dbus()
|
||||||
self.set_not_connected_state()
|
self.set_not_connected_state()
|
||||||
|
|
||||||
|
@catchdbus
|
||||||
def wired_profile_chooser(self):
|
def wired_profile_chooser(self):
|
||||||
""" Launch the wired profile chooser. """
|
""" Launch the wired profile chooser. """
|
||||||
gui.WiredProfileChooser()
|
gui.WiredProfileChooser()
|
||||||
@@ -142,6 +158,7 @@ class TrayIcon(object):
|
|||||||
self.tr.set_tooltip(language['connected_to_wired'].replace('$A',
|
self.tr.set_tooltip(language['connected_to_wired'].replace('$A',
|
||||||
wired_ip))
|
wired_ip))
|
||||||
|
|
||||||
|
@catchdbus
|
||||||
def set_wireless_state(self, info):
|
def set_wireless_state(self, info):
|
||||||
""" Sets the icon info for a wireless state. """
|
""" Sets the icon info for a wireless state. """
|
||||||
lock = ''
|
lock = ''
|
||||||
@@ -170,6 +187,7 @@ class TrayIcon(object):
|
|||||||
cur_network + "...")
|
cur_network + "...")
|
||||||
self.tr.set_from_file(os.path.join(wpath.images, "no-signal.png"))
|
self.tr.set_from_file(os.path.join(wpath.images, "no-signal.png"))
|
||||||
|
|
||||||
|
@catchdbus
|
||||||
def set_not_connected_state(self, info=None):
|
def set_not_connected_state(self, info=None):
|
||||||
""" Set the icon info for the not connected state. """
|
""" Set the icon info for the not connected state. """
|
||||||
self.tr.set_from_file(wpath.images + "no-signal.png")
|
self.tr.set_from_file(wpath.images + "no-signal.png")
|
||||||
@@ -182,6 +200,7 @@ class TrayIcon(object):
|
|||||||
status = language['not_connected']
|
status = language['not_connected']
|
||||||
self.tr.set_tooltip(status)
|
self.tr.set_tooltip(status)
|
||||||
|
|
||||||
|
@catchdbus
|
||||||
def update_tray_icon(self, state=None, info=None):
|
def update_tray_icon(self, state=None, info=None):
|
||||||
""" Updates the tray icon and current connection status. """
|
""" Updates the tray icon and current connection status. """
|
||||||
if not self.use_tray or not DBUS_AVAIL: return False
|
if not self.use_tray or not DBUS_AVAIL: return False
|
||||||
@@ -202,6 +221,7 @@ class TrayIcon(object):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@catchdbus
|
||||||
def set_signal_image(self, wireless_signal, lock):
|
def set_signal_image(self, wireless_signal, lock):
|
||||||
""" Sets the tray icon image for an active wireless connection. """
|
""" Sets the tray icon image for an active wireless connection. """
|
||||||
if self.animate:
|
if self.animate:
|
||||||
@@ -230,6 +250,7 @@ class TrayIcon(object):
|
|||||||
img_file = ''.join([wpath.images, prefix, signal_img, lock, ".png"])
|
img_file = ''.join([wpath.images, prefix, signal_img, lock, ".png"])
|
||||||
self.tr.set_from_file(img_file)
|
self.tr.set_from_file(img_file)
|
||||||
|
|
||||||
|
@catchdbus
|
||||||
def get_bandwidth_state(self):
|
def get_bandwidth_state(self):
|
||||||
""" Determines what network activity state we are in. """
|
""" Determines what network activity state we are in. """
|
||||||
transmitting = False
|
transmitting = False
|
||||||
@@ -408,6 +429,7 @@ class TrayIcon(object):
|
|||||||
item.set_sensitive(False)
|
item.set_sensitive(False)
|
||||||
del item
|
del item
|
||||||
|
|
||||||
|
@catchdbus
|
||||||
def _get_img(self, net_id):
|
def _get_img(self, net_id):
|
||||||
""" Determines which image to use for the wireless entries. """
|
""" Determines which image to use for the wireless entries. """
|
||||||
def fix_strength(val, default):
|
def fix_strength(val, default):
|
||||||
@@ -441,6 +463,7 @@ class TrayIcon(object):
|
|||||||
signal_img = 'signal-25.png'
|
signal_img = 'signal-25.png'
|
||||||
return wpath.images + signal_img
|
return wpath.images + signal_img
|
||||||
|
|
||||||
|
@catchdbus
|
||||||
def on_net_menu_activate(self, item):
|
def on_net_menu_activate(self, item):
|
||||||
""" Trigger a background scan to populate the network menu.
|
""" Trigger a background scan to populate the network menu.
|
||||||
|
|
||||||
@@ -464,6 +487,7 @@ class TrayIcon(object):
|
|||||||
return True
|
return True
|
||||||
wireless.Scan(False)
|
wireless.Scan(False)
|
||||||
|
|
||||||
|
@catchdbus
|
||||||
def populate_network_menu(self, data=None):
|
def populate_network_menu(self, data=None):
|
||||||
""" Populates the network list submenu. """
|
""" Populates the network list submenu. """
|
||||||
def get_prop(net_id, prop):
|
def get_prop(net_id, prop):
|
||||||
|
|||||||
@@ -1120,6 +1120,7 @@ class WirelessDaemon(dbus.service.Object):
|
|||||||
self.wifi.disconnect_script = self.GetWirelessProperty(id,
|
self.wifi.disconnect_script = self.GetWirelessProperty(id,
|
||||||
'disconnectscript')
|
'disconnectscript')
|
||||||
print 'Connecting to wireless network ' + self.LastScan[id]['essid']
|
print 'Connecting to wireless network ' + self.LastScan[id]['essid']
|
||||||
|
self.daemon.wired_bus.DisconnectWired()
|
||||||
conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode)
|
conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode)
|
||||||
self.daemon.UpdateState()
|
self.daemon.UpdateState()
|
||||||
|
|
||||||
@@ -1424,6 +1425,7 @@ class WiredDaemon(dbus.service.Object):
|
|||||||
self.wired.before_script = self.GetWiredProperty("beforescript")
|
self.wired.before_script = self.GetWiredProperty("beforescript")
|
||||||
self.wired.after_script = self.GetWiredProperty("afterscript")
|
self.wired.after_script = self.GetWiredProperty("afterscript")
|
||||||
self.wired.disconnect_script = self.GetWiredProperty("disconnectscript")
|
self.wired.disconnect_script = self.GetWiredProperty("disconnectscript")
|
||||||
|
self.daemon.wireless_bus.DisconnectWireless()
|
||||||
self.wired.Connect(self.WiredNetwork, debug=self.debug_mode)
|
self.wired.Connect(self.WiredNetwork, debug=self.debug_mode)
|
||||||
self.daemon.UpdateState()
|
self.daemon.UpdateState()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user