From 7d7b943ee75ad2d2973161de9f434f7bf5d3d076 Mon Sep 17 00:00:00 2001 From: imdano <> Date: Sat, 22 Dec 2007 22:09:00 +0000 Subject: [PATCH] Make sure daemon alerts tray to change status during connection process. Specify which network is being connected to in both the tray tooltip and gui statusbar Clean up code in wicd.py. Refactor Edgy/DapperTrayIcon class names to something less Ubuntu-specific. Fix typo in EggTrayIcon that would keep gui from opening. --- daemon.py | 6 ++-- gui.py | 23 ++++++++------ wicd.py | 91 ++++++++++++++++++++++++++++++++++++------------------- 3 files changed, 75 insertions(+), 45 deletions(-) diff --git a/daemon.py b/daemon.py index 2da17e2..a8ce2df2 100644 --- a/daemon.py +++ b/daemon.py @@ -434,7 +434,6 @@ class ConnectionWizard(dbus.service.Object): Scans for wireless networks and also for hidden networks defined in wireless-settings.conf - ''' hidden_network_list = self.GetHiddenNetworkList() master_scan = self.Scan() @@ -1471,6 +1470,8 @@ class ConnectionStatus(): if not wireless_found: # No connection at all if not conn.CheckIfConnecting(): self.auto_reconnect() + else: + self.status_changed = True # Send a D-Bus signal announcing status has changed if necessary. if self.status_changed: conn.StatusChanged() @@ -1489,8 +1490,7 @@ class ConnectionStatus(): conn.SetCurrentInterface('') self.status_changed = True - if conn.GetAutoReconnect() and \ - not conn.CheckIfConnecting() and \ + if conn.GetAutoReconnect() and not conn.CheckIfConnecting() and \ not conn.GetForcedDisconnect(): print 'Starting automatic reconnect process' # First try connecting through ethernet diff --git a/gui.py b/gui.py index a87cda2..78db261 100644 --- a/gui.py +++ b/gui.py @@ -318,10 +318,10 @@ class PrettyNetworkEntry(gtk.HBox): '''adds an image and a connect button to a NetworkEntry''' def __init__(self,expander): gtk.HBox.__init__(self) - #add the stuff to the hbox (self) + # Add the stuff to the hbox (self) self.expander = expander self.expander.show() - self.expander.higherLevel = self #do this so that the expander can access the stuff inside me + self.expander.higherLevel = self # Do this so that the expander can access the stuff inside me self.tempVBox = gtk.VBox(False,1) self.tempVBox.show() self.connectButton = LinkButton() @@ -362,7 +362,7 @@ class PrettyWirelessNetworkEntry(PrettyNetworkEntry): self.setChannel(wireless.GetWirelessProperty(networkID,'channel')) self.setEncryption(wireless.GetWirelessProperty(networkID,'encryption'), wireless.GetWirelessProperty(networkID,'encryption_method')) - #show everything + # Show everything self.show_all() def setSignalStrength(self,strength, dbm_strength): @@ -460,7 +460,7 @@ class NetworkEntry(gtk.Expander): self.vboxTop.pack_end(self.expanderAdvanced,fill=False,expand=False) self.expanderAdvanced.add(self.vboxAdvanced) self.expanderScripts.add(self.vboxScripts) - #connect the events to the actions + # Connect the events to the actions self.checkboxStaticIP.connect("toggled",self.toggleIPCheckbox) self.checkboxStaticDNS.connect("toggled",self.toggleDNSCheckbox) self.checkboxGlobalDNS.connect("toggled",self.toggleGlobalDNSCheckbox) @@ -481,8 +481,8 @@ class NetworkEntry(gtk.Expander): #fill it in with a .1 at the end gateway.set_text('.'.join(ip_parts[0:3]) + '.1') - if stringToNone(netmask.get_text()) == None: #make sure the netmask is blank - netmask.set_text('255.255.255.0') #fill in the most common one + if stringToNone(netmask.get_text()) == None: # Make sure the netmask is blank + netmask.set_text('255.255.255.0') # Fill in the most common one def resetStaticCheckboxes(self): #enable the right stuff @@ -885,12 +885,13 @@ class WiredProfileChooser: print 'reading profile ', wiredNetEntry.comboProfileNames.get_active_text() config.ReadWiredNetworkProfile(wiredNetEntry.comboProfileNames.get_active_text()) wired.ConnectWired() - dialog.destroy() else: if stoppopcheckbox.get_active() == True: # Stops the pop-up from reappearing if cancelled wired.use_default_profile = 1 - dialog.destroy() + dialog.destroy() + + class appGui: def __init__(self): gladefile = "data/wicd.glade" @@ -1181,9 +1182,11 @@ class appGui: if self.statusID: self.status_bar.remove(1,self.statusID) if wirelessConnecting: - self.statusID = self.status_bar.push(1,language[str(wireless.CheckWirelessConnectingMessage())]) + self.statusID = self.status_bar.push(1,wireless.GetCurrentNetwork() + ': ' + + language[str(wireless.CheckWirelessConnectingMessage())]) if wiredConnecting: - self.statusID = self.status_bar.push(1,language[str(wired.CheckWiredConnectingMessage())]) + self.statusID = self.status_bar.push(1,language['wired_network'] + ': ' + + language[str(wired.CheckWiredConnectingMessage())]) else: self.network_list.set_sensitive(True) self.status_area.hide_all() diff --git a/wicd.py b/wicd.py index f51b639..542fff2 100755 --- a/wicd.py +++ b/wicd.py @@ -10,9 +10,10 @@ class TrayIcon() -- Parent class of TrayIconGUI and IconConnectionInfo. class TrayConnectionInfo() -- Child class of TrayIcon which provides and updates connection status. class TrayIconGUI() -- Child class of TrayIcon which implements the tray. - icon itself. Parent class of EdgyTrayIconGUI and DapperTrayIconGUI. - class EdgyTrayIconGUI() -- Implements the tray icon using a gtk.StatusIcon. - class DapperTrayIconGUI() -- Implements the tray icon using egg.trayicon. + icon itself. Parent class of StatusTrayIconGUI and EggTrayIconGUI. + class StatusTrayIconGUI() -- Implements the tray icon using a + gtk.StatusIcon. + class EggTrayIconGUI() -- Implements the tray icon using egg.trayicon. def usage() -- Prints usage information. def main() -- Runs the wicd frontend main loop. @@ -35,15 +36,11 @@ def main() -- Runs the wicd frontend main loop. # along with this program. If not, see . # -import os import sys import gtk import gobject import dbus import dbus.service -import locale -import gettext -import signal import getopt # Import egg.trayicon if we're using an older gtk version @@ -67,7 +64,8 @@ if sys.platform == 'linux2': import dl libc = dl.open('/lib/libc.so.6') libc.call('prctl', 15, 'wicd\0', 0, 0, 0) # 15 is PR_SET_NAME - except: + except Exception: + print 'Failed to rename wicd process' pass if __name__ == '__main__': @@ -81,7 +79,7 @@ try: print 'Attempting to connect tray to daemon...' proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon') print 'Success.' -except: +except Exception: print 'Daemon not running...' misc.PromptToStartDaemon() sys.exit(1) @@ -96,14 +94,20 @@ language = {} language['connected_to_wireless'] = _('Connected to $A at $B (IP: $C)') language['connected_to_wired'] = _('Connected to wired network (IP: $A)') language['not_connected'] = _('Not connected') -language['connecting'] = _('Connecting...') +language['connecting'] = _('Connecting') +language['wired'] = _('wired network') class TrayIcon(): + """Base Tray Icon class + + Base Class for implementing a tray icon to display network status. + + """ def __init__(self, use_tray): if USE_EGG: - self.tr = self.DapperTrayIconGUI(use_tray) + self.tr = self.EggTrayIconGUI(use_tray) else: - self.tr = self.EdgyTrayIconGUI(use_tray) + self.tr = self.StatusTrayIconGUI(use_tray) self.icon_info = self.TrayConnectionInfo(self.tr) @@ -122,14 +126,19 @@ class TrayIcon(): def wired_profile_chooser(self): """Launch the wired profile chooser.""" daemon.SetNeedWiredProfileChooser(False) - chooser = gui.WiredProfileChooser() + gui.WiredProfileChooser() def update_tray_icon(self): """Updates the tray icon and current connection status""" # If we're currently connecting, we can shortcut all other checks if daemon.CheckIfConnecting(): - self.tr.set_tooltip(language['connecting']) + if wireless.CheckIfWirelessConnecting(): + cur_network = wireless.GetCurrentNetwork() + else: + cur_network = language['wired_network'] + self.tr.set_tooltip(language['connecting'] + " to " + + cur_network + "...") self.tr.set_from_file(wpath.images + "no-signal.png") return True @@ -141,7 +150,8 @@ class TrayIcon(): if cur_iface == wire_iface: wired_ip = wired.GetWiredIP() self.tr.set_from_file(wpath.images + "wired.png") - self.tr.set_tooltip(language['connected_to_wired'].replace('$A', + self.tr.set_tooltip(language['connected_to_wired']. + replace('$A', wired_ip)) # Check for a wireless connection @@ -193,7 +203,11 @@ class TrayIcon(): class TrayIconGUI(): - def __init__(self): + """Base Tray Icon class + + Implements methods and variables used by both egg/StatusIcon tray icons. + """ + def __init__(self, use_tray): menu = """ @@ -220,8 +234,11 @@ class TrayIcon(): self.manager = gtk.UIManager() self.manager.insert_action_group(actg, 0) self.manager.add_ui_from_string(menu) - self.menu = self.manager.get_widget('/Menubar/Menu/About').props.parent + self.menu = (self.manager.get_widget('/Menubar/Menu/About'). + props.parent) self.gui_win = None + self.current_icon_path = None + self.use_tray = use_tray def on_activate(self, data=None): """Opens the wicd GUI""" @@ -239,8 +256,8 @@ class TrayIcon(): """Opens the About Dialog""" dialog = gtk.AboutDialog() dialog.set_name('wicd tray icon') - dialog.set_version('0.4') - dialog.set_comments('an icon that shows your network connectivity') + dialog.set_version('1.0') + dialog.set_comments('An icon that shows your network connectivity') dialog.set_website('http://wicd.sourceforge.net') dialog.run() dialog.destroy() @@ -263,10 +280,15 @@ class TrayIcon(): return True - class DapperTrayIconGUI(TrayIconGUI): + class EggTrayIconGUI(TrayIconGUI): + """Tray Icon for gtk < 2.10 + + Uses the deprecated egg.trayicon module to implement the tray icon. + + """ def __init__(self, use_tray=True): """Initializes the tray icon""" - TrayIcon.TrayIconGUI.__init__(self) + TrayIcon.TrayIconGUI.__init__(self, use_tray) self.use_tray = use_tray if not use_tray: self.toggle_wicd_gui() @@ -287,16 +309,16 @@ class TrayIcon(): def tray_clicked(self, widget, event): """Handles tray mouse click events""" if event.button == 1: - self.open_wicd_gui() + self.toggle_wicd_gui() if event.button == 3: self.menu.popup(None, None, None, event.button, event.time) - def set_from_file(self, str): + def set_from_file(self, val): """Calls set_from_file on the gtk.Image for the tray icon""" if not self.use_tray: return - self.pic.set_from_file(str) + self.pic.set_from_file(val) - def set_tooltip(self, str): + def set_tooltip(self, val): """ Sets the tooltip for the gtk.ToolTips associated with this @@ -304,13 +326,17 @@ class TrayIcon(): """ if not self.use_tray: return - self.tooltip.set_tip(self.eb, str) + self.tooltip.set_tip(self.eb, val) - class EdgyTrayIconGUI(gtk.StatusIcon, TrayIconGUI): - """Class for creating the wicd tray icon""" + class StatusTrayIconGUI(gtk.StatusIcon, TrayIconGUI): + """Class for creating the wicd tray icon on gtk > 2.10 + + Uses gtk.StatusIcon to implement a tray icon. + + """ def __init__(self, use_tray=True): - TrayIcon.TrayIconGUI.__init__(self) + TrayIcon.TrayIconGUI.__init__(self, use_tray) self.use_tray = use_tray if not use_tray: self.toggle_wicd_gui() @@ -339,6 +365,7 @@ class TrayIcon(): def usage(): + """Print usage information.""" print """ wicd 1.40 wireless (and wired) connection daemon front-end. @@ -365,11 +392,11 @@ def main(argv): usage() sys.exit(2) - for o, a in opts: - if o in ('-h', '--help'): + for opt, a in opts: + if opt in ('-h', '--help'): usage() sys.exit() - if o in ('-n', '--no-tray'): + if opt in ('-n', '--no-tray'): use_tray = False # Redirect stderr and stdout for logging purposes