diff --git a/wicd/gui.py b/wicd/gui.py index 88ef245..a74b009 100644 --- a/wicd/gui.py +++ b/wicd/gui.py @@ -38,6 +38,7 @@ from wicd import misc from wicd import wpath from wicd import dbusmanager from wicd import prefs +from wicd import netentry from wicd.misc import noneToString from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry from wicd.prefs import PreferencesDialog @@ -67,6 +68,7 @@ def setup_dbus(force=True): else: return False prefs.setup_dbus() + netentry.setup_dbus() bus = dbusmanager.get_bus() dbus_ifaces = dbusmanager.get_dbus_ifaces() daemon = dbus_ifaces['daemon'] @@ -91,7 +93,7 @@ class WiredProfileChooser: """ Initializes and runs the wired profile chooser. """ # Import and init WiredNetworkEntry to steal some of the # functions and widgets it uses. - wired_net_entry = WiredNetworkEntry(dbusmanager.get_dbus_ifaces()) + wired_net_entry = WiredNetworkEntry() dialog = gtk.Dialog(title = language['wired_network_found'], flags = gtk.DIALOG_MODAL, @@ -213,14 +215,17 @@ class appGui(object): 'ConnectResultsSent', 'org.wicd.daemon') bus.add_signal_receiver(lambda: setup_dbus(force=False), "DaemonStarting", "org.wicd.daemon") + bus.add_signal_receiver(self._do_statusbar_update, 'StatusChanged', + 'org.wicd.daemon') if standalone: bus.add_signal_receiver(handle_no_dbus, "DaemonClosing", "org.wicd.daemon") - try: - gobject.timeout_add_seconds(2, self.update_statusbar) - except: - gobject.timeout_add(2000, self.update_statusbar) + if hasattr(gobject, "timeout_add_seconds"): + self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar) + else: + self.update_cb = gobject.timeout_add(2000, self.update_statusbar) + self._do_statusbar_update(*daemon.GetConnectionStatus()) self.refresh_clicked() def handle_connection_results(self, results): @@ -349,18 +354,17 @@ class appGui(object): return True def update_statusbar(self): - """ Updates the status bar - - Queries the daemon for network connection information and - updates the GUI status bar based on the results. - - """ + """ Triggers a status update in wicd-monitor. """ if not self.is_visible or self.refreshing: return True daemon.UpdateState() - [state, info] = daemon.GetConnectionStatus() - + return True + + def _do_statusbar_update(self, state, info): + if not self.is_visible or self.refreshing: + return True + if state == misc.WIRED: return self.set_wired_state(info) elif state == misc.WIRELESS: @@ -485,7 +489,7 @@ class appGui(object): if wired.CheckPluggedIn() or daemon.GetAlwaysShowWiredInterface(): printLine = True # In this case we print a separator. - wirednet = WiredNetworkEntry(dbusmanager.get_dbus_ifaces()) + wirednet = WiredNetworkEntry() self.network_list.pack_start(wirednet, False, False) wirednet.connect_button.connect("button-press-event", self.connect, "wired", 0, wirednet) @@ -499,7 +503,6 @@ class appGui(object): instruct_label = self.wTree.get_widget("label_instructions") if num_networks > 0: instruct_label.show() - dbus_ifaces = dbusmanager.get_dbus_ifaces() for x in range(0, num_networks): if printLine: sep = gtk.HSeparator() @@ -508,7 +511,7 @@ class appGui(object): sep.show() else: printLine = True - tempnet = WirelessNetworkEntry(x, dbus_ifaces) + tempnet = WirelessNetworkEntry(x) self.network_list.pack_start(tempnet, False, False) tempnet.connect_button.connect("button-press-event", self.connect, "wireless", x, @@ -676,6 +679,9 @@ class appGui(object): """ self.window.hide() + gobject.source_remove(self.update_cb) + bus.remove_signal_receiver(self._do_statusbar_update, 'StatusChanged', + 'org.wicd.daemon') [width, height] = self.window.get_size() try: daemon.WriteWindowSize(width, height, "main") @@ -702,6 +708,12 @@ class appGui(object): daemon.SetGUIOpen(True) self.wait_for_events(0.1) gobject.idle_add(self.refresh_clicked) + bus.add_signal_receiver(self._do_statusbar_update, 'StatusChanged', + 'org.wicd.daemon') + if hasattr(gobject, "timeout_add_seconds"): + self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar) + else: + self.update_cb = gobject.timeout_add(2000, self.update_statusbar) if __name__ == '__main__': diff --git a/wicd/monitor.py b/wicd/monitor.py index 2e4bac7..048e686 100755 --- a/wicd/monitor.py +++ b/wicd/monitor.py @@ -311,12 +311,12 @@ def err_handle(error): def add_poll_callback(): global monitor, to_time, update_callback - try: + if hasattr(gobject, "timeout_add_seconds"): update_callback = gobject.timeout_add_seconds(to_time, monitor.update_connection_status) - except: + else: update_callback = gobject.timeout_add(to_time * 1000, - monitor.update_connection_status) + monitor.update_connection_status) def main(): """ Starts the connection monitor. diff --git a/wicd/netentry.py b/wicd/netentry.py index 8b4f541..ca92dc4 100644 --- a/wicd/netentry.py +++ b/wicd/netentry.py @@ -20,6 +20,7 @@ import os import misc import wpath +import dbusmanager from misc import noneToString, stringToNone, noneToBlankString, to_bool from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel, string_input @@ -30,6 +31,12 @@ daemon = None wired = None wireless = None +def setup_dbus(): + global daemon, wireless, wired + daemon = dbusmanager.get_interface('daemon') + wireless = dbusmanager.get_interface('wireless') + wired = dbusmanager.get_interface('wired') + class AdvancedSettingsDialog(gtk.Dialog): def __init__(self): """ Build the base advanced settings dialog. @@ -466,17 +473,14 @@ class WirelessSettingsDialog(AdvancedSettingsDialog): class NetworkEntry(gtk.HBox): - def __init__(self, dbus_ifaces): + def __init__(self): """ Base network entry class. Provides gtk objects used by both the WiredNetworkEntry and WirelessNetworkEntry classes. """ - global daemon, wired, wireless - daemon = dbus_ifaces["daemon"] - wired = dbus_ifaces["wired"] - wireless = dbus_ifaces["wireless"] + setup_dbus() gtk.HBox.__init__(self, False, 2) self.image = gtk.Image() self.pack_start(self.image, False, False) @@ -533,9 +537,9 @@ class NetworkEntry(gtk.HBox): class WiredNetworkEntry(NetworkEntry): - def __init__(self, dbus_ifaces): + def __init__(self): """ Load the wired network entry. """ - NetworkEntry.__init__(self, dbus_ifaces) + NetworkEntry.__init__(self) # Center the picture and pad it a bit self.image.set_padding(0, 0) self.image.set_alignment(.5, .5) @@ -718,9 +722,9 @@ class WiredNetworkEntry(NetworkEntry): class WirelessNetworkEntry(NetworkEntry): - def __init__(self, networkID, dbus_ifaces): + def __init__(self, networkID): """ Build the wireless network entry. """ - NetworkEntry.__init__(self, dbus_ifaces) + NetworkEntry.__init__(self) self.networkID = networkID self.image.set_padding(0, 0)