1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-20 04:48:00 +01:00

Refactored several files (especially gui.py) to be more in line with python conventions and make the code easier to understand.

Added a bunch of docstrings.
Fixed an invalid function call in wnettools.py.
This commit is contained in:
imdano
2008-01-25 14:12:32 +00:00
parent f6d480d89b
commit 6599b7ce0a
5 changed files with 159 additions and 119 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
""" Configure the scripts for a particular network """ Configure the scripts for a particular network.
Script for configuring the scripts for a network passed in as a Script for configuring the scripts for a network passed in as a
command line argument. This needs to run a separate process because command line argument. This needs to run a separate process because
@@ -26,13 +26,11 @@ run as the current user.
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import os
import sys import sys
import gtk import gtk
import ConfigParser import ConfigParser
import dbus import dbus
import dbus.service import dbus.service
import pygtk
import gtk.glade import gtk.glade
import wpath import wpath
@@ -67,21 +65,26 @@ wired_conf = wpath.etc + 'wired-settings.conf'
def none_to_blank(text): def none_to_blank(text):
"""if text is None, 'None', or '' then return '', otherwise return str(text)""" """ Converts special string cases to a blank string.
If text is None, 'None', or '' then this method will
return '', otherwise it will just return str(text).
"""
if text == None or text == "None" or text == "": if text == None or text == "None" or text == "":
return "" return ""
else: else:
return str(text) return str(text)
def blank_to_none(text): def blank_to_none(text):
"""Convert an empty or null string to 'None'""" """ Convert an empty or null string to 'None'. """
if text == "" or text == None: if text == "" or text == None:
return "None" return "None"
else: else:
return str(text) return str(text)
def get_script_info(network, network_type): def get_script_info(network, network_type):
"""Reads script info from disk and load it into the configuration dialog""" """ Read script info from disk and load it into the configuration dialog """
info = {} info = {}
con = ConfigParser.ConfigParser() con = ConfigParser.ConfigParser()
if network_type == "wired": if network_type == "wired":
@@ -101,7 +104,7 @@ def get_script_info(network, network_type):
return info return info
def write_scripts(network, network_type, script_info): def write_scripts(network, network_type, script_info):
"""Writes script info to disk and loads it into the daemon""" """ Writes script info to disk and loads it into the daemon. """
con = ConfigParser.ConfigParser() con = ConfigParser.ConfigParser()
print "writing scripts, type",network_type print "writing scripts, type",network_type
if network_type == "wired": if network_type == "wired":
@@ -110,7 +113,8 @@ def write_scripts(network, network_type, script_info):
con.add_section(network) con.add_section(network)
con.set(network, "beforescript", script_info["pre_entry"]) con.set(network, "beforescript", script_info["pre_entry"])
con.set(network, "afterscript", script_info["post_entry"]) con.set(network, "afterscript", script_info["post_entry"])
con.set(network, "disconnectscript", script_info["disconnect_entry"]) con.set(network, "disconnectscript",
script_info["disconnect_entry"])
con.write(open(wired_conf, "w")) con.write(open(wired_conf, "w"))
config.ReadWiredNetworkProfile(network) config.ReadWiredNetworkProfile(network)
config.SaveWiredNetworkProfile(network) config.SaveWiredNetworkProfile(network)

246
gui.py
View File

@@ -19,9 +19,17 @@
import os import os
import sys import sys
import wpath
import signal import signal
import time import time
import gettext
import locale
import gobject
import dbus
import dbus.service
import pango
import misc
import wpath
if __name__ == '__main__': if __name__ == '__main__':
wpath.chdir(__file__) wpath.chdir(__file__)
@@ -36,8 +44,6 @@ except:
print 'Missing GTK and gtk.glade. Aborting.' print 'Missing GTK and gtk.glade. Aborting.'
sys.exit(1) sys.exit(1)
import time, os, misc, gettext, locale, gobject, dbus, dbus.service,pango
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0): if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib import dbus.glib
@@ -65,42 +71,7 @@ wired = dbus.Interface(proxy_obj, 'org.wicd.daemon.wired')
vpn_session = dbus.Interface(proxy_obj, 'org.wicd.daemon.vpn') vpn_session = dbus.Interface(proxy_obj, 'org.wicd.daemon.vpn')
config = dbus.Interface(proxy_obj, 'org.wicd.daemon.config') config = dbus.Interface(proxy_obj, 'org.wicd.daemon.config')
#Translation stuff _ = misc.get_gettext()
#borrowed from an excellent post on how to do this on
#http://www.learningpython.com/2006/12/03/translating-your-pythonpygtk-application/
#which is also under GPLv2
# Get the local directory since we are not installing anything.
local_path = os.path.realpath(os.path.dirname(sys.argv[0])) + '/translations'
# Init the list of languages to support.
langs = list()
# Check the default locale.
lc, encoding = locale.getdefaultlocale()
if (lc):
# If we have a default, it's the first in the list.
langs = [lc]
# Now lets get all of the supported languages on the system
osLanguage = os.environ.get('LANGUAGE', None)
if (osLanguage):
# Language comes back something like en_CA:en_US:en_GB:en
#on linuxy systems, on Win32 it's nothing, so we need to
#split it up into a list
langs += osLanguage.split(":")
#Now add on to the back of the list the translations that we
#know that we have, our defaults
langs += ["en_US"] # I add english because a lot of people can read it
#Now langs is a list of all of the languages that we are going
#to try to use. First we check the default, then what the system
#told us, and finally the 'known' list
gettext.bindtextdomain('wicd', local_path)
gettext.textdomain('wicd')
# Get the language to use
lang = gettext.translation('wicd', local_path, languages=langs, fallback = True)
#map _() to self.lang.gettext() which will translate them.
_ = lang.gettext
# Keep all the language strings in a dictionary # Keep all the language strings in a dictionary
# by the english words. # by the english words.
@@ -171,6 +142,7 @@ language['wired_network_found'] = _('Wired connection detected')
language['stop_showing_chooser'] = _('Stop Showing Autoconnect pop-up temporarily') language['stop_showing_chooser'] = _('Stop Showing Autoconnect pop-up temporarily')
language['display_type_dialog'] = _('Use dBm to measure signal strength') language['display_type_dialog'] = _('Use dBm to measure signal strength')
language['scripts'] = _('Scripts') language['scripts'] = _('Scripts')
language['invalid_address'] = _('Invalid address in $A entry.')
language['0'] = _('0') language['0'] = _('0')
language['1'] = _('1') language['1'] = _('1')
@@ -691,9 +663,10 @@ class WiredNetworkEntry(NetworkEntry):
self.profileHelp.hide() self.profileHelp.hide()
def toggleDefaultProfile(self,widget): def toggleDefaultProfile(self,widget):
if self.checkboxDefaultProfile.get_active() == True: if self.checkboxDefaultProfile.get_active():
print 'unsetting previous default profile...' print 'unsetting previous default profile...'
config.UnsetWiredDefault() # Makes sure there is only one default profile at a time # Make sure there is only one default profile at a time
config.UnsetWiredDefault()
wired.SetWiredProperty("default",self.checkboxDefaultProfile.get_active()) wired.SetWiredProperty("default",self.checkboxDefaultProfile.get_active())
config.SaveWiredNetworkProfile(self.comboProfileNames.get_active_text()) config.SaveWiredNetworkProfile(self.comboProfileNames.get_active_text())
@@ -707,18 +680,21 @@ class WiredNetworkEntry(NetworkEntry):
print profileName print profileName
config.ReadWiredNetworkProfile(profileName) config.ReadWiredNetworkProfile(profileName)
self.txtIP.set_text(noneToBlankString(wired.GetWiredProperty("ip"))) self.txtIP.set_text(self.format_entry("ip"))
self.txtNetmask.set_text(noneToBlankString(wired.GetWiredProperty("netmask"))) self.txtNetmask.set_text(self.format_entry("netmask"))
self.txtGateway.set_text(noneToBlankString(wired.GetWiredProperty("gateway"))) self.txtGateway.set_text(self.format_entry("gateway"))
self.txtDNS1.set_text(noneToBlankString(wired.GetWiredProperty("dns1"))) self.txtDNS1.set_text(self.format_entry("dns1"))
self.txtDNS2.set_text(noneToBlankString(wired.GetWiredProperty("dns2"))) self.txtDNS2.set_text(self.format_entry("dns2"))
self.txtDNS3.set_text(noneToBlankString(wired.GetWiredProperty("dns3"))) self.txtDNS3.set_text(self.format_entry("dns3"))
self.checkboxDefaultProfile.set_active(stringToBoolean(wired.GetWiredProperty("default")))
is_default = wired.GetWiredProperty("default")
self.checkboxDefaultProfile.set_active(stringToBoolean(is_default))
self.resetStaticCheckboxes() self.resetStaticCheckboxes()
def format_entry(self, label):
return noneToBlankString(wired.GetWiredProperty(label))
class WirelessNetworkEntry(NetworkEntry): class WirelessNetworkEntry(NetworkEntry):
# This class is respsponsible for creating the expander # This class is respsponsible for creating the expander
# in each wirelessnetwork entry. # in each wirelessnetwork entry.
@@ -750,26 +726,28 @@ class WirelessNetworkEntry(NetworkEntry):
self.hboxStatus.pack_start(self.lblMode,fill=False,expand=True) self.hboxStatus.pack_start(self.lblMode,fill=False,expand=True)
self.hboxStatus.pack_start(self.lblChannel,fill=False,expand=True) self.hboxStatus.pack_start(self.lblChannel,fill=False,expand=True)
self.vboxTop.pack_start(self.checkboxAutoConnect,fill=False,expand=False) self.vboxTop.pack_start(self.checkboxAutoConnect, fill=False,
expand=False)
self.vboxTop.pack_start(self.hboxStatus,fill=True,expand=True) self.vboxTop.pack_start(self.hboxStatus,fill=True,expand=True)
self.vboxAdvanced.pack_start(self.checkboxEncryption,fill=False,expand=False) self.vboxAdvanced.pack_start(self.checkboxEncryption, fill=False,
expand=False)
self.txtIP.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"ip"))) self.txtIP.set_text(self.format_entry(networkID,"ip"))
self.txtNetmask.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"netmask"))) self.txtNetmask.set_text(self.format_entry(networkID,"netmask"))
self.txtGateway.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"gateway"))) self.txtGateway.set_text(self.format_entry(networkID,"gateway"))
if wireless.GetWirelessProperty(networkID,'use_global_dns'): if wireless.GetWirelessProperty(networkID,'use_global_dns'):
self.checkboxGlobalDNS.set_active(True) self.checkboxGlobalDNS.set_active(True)
if wireless.GetWirelessProperty(networkID,"dns1") != None: if wireless.GetWirelessProperty(networkID,"dns1") != None:
self.txtDNS1.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"dns1"))) self.txtDNS1.set_text(self.format_entry(networkID,"dns1"))
if wireless.GetWirelessProperty(networkID,'dns2') != None: if wireless.GetWirelessProperty(networkID,'dns2') != None:
self.txtDNS2.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"dns2"))) self.txtDNS2.set_text(self.format_entry(networkID,"dns2"))
if wireless.GetWirelessProperty(networkID,'dns3') != None: if wireless.GetWirelessProperty(networkID,'dns3') != None:
self.txtDNS3.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"dns3"))) self.txtDNS3.set_text(self.format_entry(networkID,"dns3"))
self.resetStaticCheckboxes() self.resetStaticCheckboxes()
encryptionTypes = misc.LoadEncryptionMethods() encryptionTypes = misc.LoadEncryptionMethods()
@@ -777,7 +755,7 @@ class WirelessNetworkEntry(NetworkEntry):
self.checkboxEncryption.set_active(False) self.checkboxEncryption.set_active(False)
self.comboEncryption.set_sensitive(False) self.comboEncryption.set_sensitive(False)
if stringToBoolean(wireless.GetWirelessProperty(networkID,"automatic")): if stringToBoolean(self.format_entry(networkID, "automatic")):
self.checkboxAutoConnect.set_active(True) self.checkboxAutoConnect.set_active(True)
else: else:
self.checkboxAutoConnect.set_active(False) self.checkboxAutoConnect.set_active(False)
@@ -788,7 +766,8 @@ class WirelessNetworkEntry(NetworkEntry):
activeID = -1 #set the menu to this item when we are done activeID = -1 #set the menu to this item when we are done
for x in encryptionTypes: for x in encryptionTypes:
self.comboEncryption.append_text(encryptionTypes[x][0]) self.comboEncryption.append_text(encryptionTypes[x][0])
if encryptionTypes[x][1] == wireless.GetWirelessProperty(networkID,"enctype"): if encryptionTypes[x][1] == wireless.GetWirelessProperty(networkID,
"enctype"):
activeID = x activeID = x
self.comboEncryption.set_active(activeID) self.comboEncryption.set_active(activeID)
@@ -807,12 +786,15 @@ class WirelessNetworkEntry(NetworkEntry):
self.comboEncryption.connect("changed",self.changeEncryptionMethod) self.comboEncryption.connect("changed",self.changeEncryptionMethod)
self.show_all() self.show_all()
def format_entry(self, networkid, label):
return noneToBlankString(wireless.GetWirelessProperty(networkid, label))
def editScripts(self, widget=None, event=None): def editScripts(self, widget=None, event=None):
result = os.spawnlpe(os.P_WAIT, "gksudo", "gksudo", "./configscript.py", result = os.spawnlpe(os.P_WAIT, "gksudo", "gksudo", "./configscript.py",
str(self.networkID), "wireless", os.environ) str(self.networkID), "wireless", os.environ)
print result print result
def updateAutoConnect(self,widget): def updateAutoConnect(self, widget=None):
wireless.SetWirelessProperty(self.networkID,"automatic", wireless.SetWirelessProperty(self.networkID,"automatic",
noneToString(self.checkboxAutoConnect.get_active())) noneToString(self.checkboxAutoConnect.get_active()))
@@ -878,7 +860,9 @@ class WirelessNetworkEntry(NetworkEntry):
self.lblMode.set_label(str(mode)) self.lblMode.set_label(str(mode))
class WiredProfileChooser: class WiredProfileChooser:
""" Class for displaying the wired profile chooser. """
def __init__(self): def __init__(self):
""" Initializes and runs the wired profile chooser. """
# Import and init WiredNetworkEntry to steal some of the # Import and init WiredNetworkEntry to steal some of the
# functions and widgets it uses. # functions and widgets it uses.
wiredNetEntry = WiredNetworkEntry() wiredNetEntry = WiredNetworkEntry()
@@ -904,14 +888,17 @@ class WiredProfileChooser:
wiredNetEntry.vboxTop.remove(wiredNetEntry.profileHelp) wiredNetEntry.vboxTop.remove(wiredNetEntry.profileHelp)
dialog.vbox.pack_start(instructLabel,fill=False,expand=False) dialog.vbox.pack_start(instructLabel,fill=False,expand=False)
dialog.vbox.pack_start(wiredNetEntry.profileHelp,fill=False,expand=False) dialog.vbox.pack_start(wiredNetEntry.profileHelp, fill=False,
dialog.vbox.pack_start(wiredNetEntry.hboxTemp,fill=False,expand=False) expand=False)
dialog.vbox.pack_start(wiredNetEntry.hboxTemp, fill=False,
expand=False)
dialog.vbox.pack_start(stoppopcheckbox,fill=False,expand=False) dialog.vbox.pack_start(stoppopcheckbox,fill=False,expand=False)
dialog.show_all() dialog.show_all()
wired_profiles = wiredNetEntry.comboProfileNames
wiredNetEntry.profileHelp.hide() wiredNetEntry.profileHelp.hide()
if wiredNetEntry.profileList != None: if wiredNetEntry.profileList != None:
wiredNetEntry.comboProfileNames.set_active(0) wired_profiles.set_active(0)
print "wired profiles found" print "wired profiles found"
else: else:
print "no wired profiles found" print "no wired profiles found"
@@ -919,17 +906,19 @@ class WiredProfileChooser:
response = dialog.run() response = dialog.run()
if response == 1: if response == 1:
print 'reading profile ', wiredNetEntry.comboProfileNames.get_active_text() print 'reading profile ', wired_profiles.get_active_text()
config.ReadWiredNetworkProfile(wiredNetEntry.comboProfileNames.get_active_text()) config.ReadWiredNetworkProfile(wired_profiles.get_active_text())
wired.ConnectWired() wired.ConnectWired()
else: else:
if stoppopcheckbox.get_active() == True: if stoppopcheckbox.get_active():
daemon.SetForcedDisconnect(True) daemon.SetForcedDisconnect(True)
dialog.destroy() dialog.destroy()
class appGui: class appGui:
""" The main wicd GUI class. """
def __init__(self): def __init__(self):
""" Initializes everything needed for the GUI. """
gladefile = "data/wicd.glade" gladefile = "data/wicd.glade"
self.windowname = "gtkbench" self.windowname = "gtkbench"
self.wTree = gtk.glade.XML(gladefile) self.wTree = gtk.glade.XML(gladefile)
@@ -946,11 +935,8 @@ class appGui:
self.wTree.signal_autoconnect(dic) self.wTree.signal_autoconnect(dic)
# Set some strings in the GUI - they may be translated # Set some strings in the GUI - they may be translated
label_instruct = self.wTree.get_widget("label_instructions")
self.wTree.get_widget("label_instructions").set_label(language['select_a_network']) label_instruct.set_label(language['select_a_network'])
# I don't know how to translate a menu entry.
# More specifically, I don't know how to set a menu entry's text
# self.wTree.get_widget("connect_button").modify_text(language['_network'])
probar = self.wTree.get_widget("progressbar") probar = self.wTree.get_widget("progressbar")
probar.set_text(language['connecting']) probar.set_text(language['connecting'])
@@ -982,7 +968,7 @@ class appGui:
gobject.timeout_add(100, self.pulse_progress_bar) gobject.timeout_add(100, self.pulse_progress_bar)
def create_adhoc_network(self,widget=None): def create_adhoc_network(self,widget=None):
'''shows a dialog that creates a new adhoc network''' """ Shows a dialog that creates a new adhoc network. """
print "Starting the Ad-Hoc Network Creation Process..." print "Starting the Ad-Hoc Network Creation Process..."
dialog = gtk.Dialog(title = language['create_adhoc_network'], dialog = gtk.Dialog(title = language['create_adhoc_network'],
flags = gtk.DIALOG_MODAL, flags = gtk.DIALOG_MODAL,
@@ -1027,12 +1013,15 @@ class appGui:
dialog.destroy() dialog.destroy()
def toggleEncryptionCheck(self,widget=None): def toggleEncryptionCheck(self,widget=None):
""" Toggles the encryption key entry box for the ad-hoc dialog. """
self.keyEntry.set_sensitive(self.useEncryptionCheckbox.get_active()) self.keyEntry.set_sensitive(self.useEncryptionCheckbox.get_active())
def disconnect(self,widget=None): def disconnect(self,widget=None):
""" Disconnects from any active network. """
daemon.Disconnect() daemon.Disconnect()
def about_dialog(self,widget,event=None): def about_dialog(self,widget,event=None):
""" Displays an about dialog. """
dialog = gtk.AboutDialog() dialog = gtk.AboutDialog()
dialog.set_name("Wicd") dialog.set_name("Wicd")
dialog.set_version(daemon.Hello()) dialog.set_version(daemon.Hello())
@@ -1042,7 +1031,9 @@ class appGui:
dialog.destroy() dialog.destroy()
def settings_dialog(self,widget,event=None): def settings_dialog(self,widget,event=None):
dialog = gtk.Dialog(title=language['preferences'], flags=gtk.DIALOG_MODAL, """ Displays a general settings dialog. """
dialog = gtk.Dialog(title=language['preferences'],
flags=gtk.DIALOG_MODAL,
buttons=(gtk.STOCK_OK,1,gtk.STOCK_CANCEL,2)) buttons=(gtk.STOCK_OK,1,gtk.STOCK_CANCEL,2))
dialog.set_has_separator(False) dialog.set_has_separator(False)
dialog.set_size_request(465,-1) dialog.set_size_request(465,-1)
@@ -1055,9 +1046,15 @@ class appGui:
displaytypecheckbox = gtk.CheckButton(language['display_type_dialog']) displaytypecheckbox = gtk.CheckButton(language['display_type_dialog'])
displaytypecheckbox.set_active(daemon.GetSignalDisplayType()) displaytypecheckbox.set_active(daemon.GetSignalDisplayType())
sepline = gtk.HSeparator() sepline = gtk.HSeparator()
usedefaultradiobutton = gtk.RadioButton(None,language['use_default_profile'],False) usedefaultradiobutton = gtk.RadioButton(None,
showlistradiobutton = gtk.RadioButton(usedefaultradiobutton,language['show_wired_list'],False) language['use_default_profile'],
lastusedradiobutton = gtk.RadioButton(usedefaultradiobutton,language['use_last_used_profile'],False) False)
showlistradiobutton = gtk.RadioButton(usedefaultradiobutton,
language['show_wired_list'],
False)
lastusedradiobutton = gtk.RadioButton(usedefaultradiobutton,
language['use_last_used_profile'],
False)
if wired.GetWiredAutoConnectMethod() == 1: if wired.GetWiredAutoConnectMethod() == 1:
usedefaultradiobutton.set_active(True) usedefaultradiobutton.set_active(True)
print 'use default profile' print 'use default profile'
@@ -1105,7 +1102,8 @@ class appGui:
dns2Entry = LabelEntry(language['dns'] + ' ' + language['2']) dns2Entry = LabelEntry(language['dns'] + ' ' + language['2'])
dns3Entry = LabelEntry(language['dns'] + ' ' + language['3']) dns3Entry = LabelEntry(language['dns'] + ' ' + language['3'])
useGlobalDNSCheckbox.connect("toggled",checkboxTextboxToggle,(dns1Entry, dns2Entry, dns3Entry)) useGlobalDNSCheckbox.connect("toggled", checkboxTextboxToggle,
(dns1Entry, dns2Entry, dns3Entry))
dns_addresses = daemon.GetGlobalDNSAddresses() dns_addresses = daemon.GetGlobalDNSAddresses()
@@ -1169,6 +1167,7 @@ class appGui:
dialog.destroy() dialog.destroy()
def connect_hidden(self,widget): def connect_hidden(self,widget):
""" Prompts the user for a hidden network, then scans for it. """
# Should display a dialog asking # Should display a dialog asking
# for the ssid of a hidden network # for the ssid of a hidden network
# and displaying connect/cancel buttons # and displaying connect/cancel buttons
@@ -1189,6 +1188,7 @@ class appGui:
dialog.destroy() dialog.destroy()
def cancel_connect(self,widget): def cancel_connect(self,widget):
""" Alerts the daemon to cancel the connection process. """
#should cancel a connection if there #should cancel a connection if there
#is one in progress #is one in progress
cancelButton = self.wTree.get_widget("cancel_button") cancelButton = self.wTree.get_widget("cancel_button")
@@ -1198,6 +1198,7 @@ class appGui:
daemon.SetForcedDisconnect(True) daemon.SetForcedDisconnect(True)
def pulse_progress_bar(self): def pulse_progress_bar(self):
""" Pulses the progress bar while connecting to a network. """
try: try:
self.wTree.get_widget("progressbar").pulse() self.wTree.get_widget("progressbar").pulse()
except: except:
@@ -1205,24 +1206,25 @@ class appGui:
return True return True
def update_statusbar(self): def update_statusbar(self):
#should update the status bar """ Updates the status bar. """
#every couple hundred milliseconds # Update the status bar every couple hundred milliseconds.
if self.is_visible == False: if self.is_visible == False:
return True return True
iwconfig = wireless.GetIwconfig() iwconfig = wireless.GetIwconfig()
wireless_ip = wireless.GetWirelessIP() wireless_ip = wireless.GetWirelessIP()
wiredConnecting = wired.CheckIfWiredConnecting() wiredConnecting = wired.CheckIfWiredConnecting()
wirelessConnecting = wireless.CheckIfWirelessConnecting() wirelessConnecting = wireless.CheckIfWirelessConnecting()
if wirelessConnecting or wiredConnecting: if wirelessConnecting or wiredConnecting:
self.network_list.set_sensitive(False) self.network_list.set_sensitive(False)
self.status_area.show_all() self.status_area.show_all()
if self.statusID: if self.statusID:
self.status_bar.remove(1,self.statusID) self.status_bar.remove(1,self.statusID)
if wirelessConnecting: if wirelessConnecting:
self.statusID = self.status_bar.push(1,wireless.GetCurrentNetwork(iwconfig) + ': ' + self.set_status(wireless.GetCurrentNetwork(iwconfig) + ': ' +
language[str(wireless.CheckWirelessConnectingMessage())]) language[str(wireless.CheckWirelessConnectingMessage())])
if wiredConnecting: if wiredConnecting:
self.statusID = self.status_bar.push(1,language['wired_network'] + ': ' + self.set_status(language['wired_network'] + ': ' +
language[str(wired.CheckWiredConnectingMessage())]) language[str(wired.CheckWiredConnectingMessage())])
else: else:
self.network_list.set_sensitive(True) self.network_list.set_sensitive(True)
@@ -1243,7 +1245,7 @@ class appGui:
else: else:
strength = str(dbm_strength) strength = str(dbm_strength)
ip = str(wireless_ip) ip = str(wireless_ip)
self.statusID=self.status_bar.push(1, language['connected_to_wireless'].replace self.set_status(language['connected_to_wireless'].replace
('$A',network).replace ('$A',network).replace
('$B',daemon.FormatSignalForPrinting(strength)).replace ('$B',daemon.FormatSignalForPrinting(strength)).replace
('$C',wireless_ip)) ('$C',wireless_ip))
@@ -1251,13 +1253,26 @@ class appGui:
wired_ip = wired.GetWiredIP() wired_ip = wired.GetWiredIP()
if wired_ip: if wired_ip:
if wired.CheckPluggedIn(): if wired.CheckPluggedIn():
self.statusID = self.status_bar.push(1, language['connected_to_wired']. self.set_status(language['connected_to_wired'].replace('$A',
replace('$A', wired_ip)) wired_ip))
return True return True
self.statusID = self.status_bar.push(1,language['not_connected']) self.set_status(language['not_connected'])
return True return True
def set_status(self, msg):
""" Sets the status bar message for the GUI. """
self.statusID = self.status_bar.push(1, msg)
def refresh_networks(self,widget=None,fresh=True,hidden=None): def refresh_networks(self,widget=None,fresh=True,hidden=None):
""" Refreshes the network list.
If fresh=True, scans for wireless networks and displays the results.
If a ethernet connection is available, or the user has chosen to,
displays a Wired Network entry as well.
If hidden isn't None, will scan for networks after running
iwconfig <wireless interface> essid <hidden>.
"""
print "refreshing..." print "refreshing..."
printLine = False # We don't print a separator by default. printLine = False # We don't print a separator by default.
@@ -1267,14 +1282,13 @@ class appGui:
if wired.CheckPluggedIn() or wired.GetAlwaysShowWiredInterface(): if wired.CheckPluggedIn() or wired.GetAlwaysShowWiredInterface():
printLine = True # In this case we print a separator. printLine = True # In this case we print a separator.
wiredNetwork = PrettyWiredNetworkEntry() wirednet = PrettyWiredNetworkEntry()
self.network_list.pack_start(wiredNetwork,fill=False,expand=False) self.network_list.pack_start(wirednet, fill=False, expand=False)
wiredNetwork.connectButton.connect("button-press-event", wirednet.connectButton.connect("button-press-event", self.connect,
self.connect, "wired", 0, "wired", 0, wirednet)
wiredNetwork) wirednet.expander.advancedButton.connect("button-press-event",
wiredNetwork.expander.advancedButton.connect("button-press-event", self.edit_advanced,
self.editAdvanced, "wired", 0, wirednet)
"wired", 0, wiredNetwork)
# Scan # Scan
if fresh: if fresh:
# Even if it is None, it can still be passed. # Even if it is None, it can still be passed.
@@ -1294,17 +1308,15 @@ class appGui:
sep.show() sep.show()
else: else:
printLine = True printLine = True
tempNetwork = PrettyWirelessNetworkEntry(x) tempnet = PrettyWirelessNetworkEntry(x)
tempNetwork.show_all() tempnet.show_all()
self.network_list.pack_start(tempNetwork, expand=False, self.network_list.pack_start(tempnet, expand=False, fill=False)
fill=False) tempnet.connectButton.connect("button-press-event",
tempNetwork.connectButton.connect("button-press-event",
self.connect, "wireless", x, self.connect, "wireless", x,
tempNetwork) tempnet)
tempNetwork.expander.advancedButton.connect("button-press-event", tempnet.expander.advancedButton.connect("button-press-event",
self.editAdvanced, self.edit_advanced,
"wireless", x, "wireless", x, tempnet)
tempNetwork)
else: else:
instructLabel.hide() instructLabel.hide()
if wireless.GetKillSwitchEnabled(): if wireless.GetKillSwitchEnabled():
@@ -1315,6 +1327,7 @@ class appGui:
label.show() label.show()
def save_settings(self, type, networkid, networkentry): def save_settings(self, type, networkid, networkentry):
""" Verifies and saves the settings for the network entry. """
entry = networkentry.expander entry = networkentry.expander
entlist = [] entlist = []
@@ -1333,8 +1346,8 @@ class appGui:
for lblent in entlist: for lblent in entlist:
if not misc.IsValidIP(lblent.get_text()): if not misc.IsValidIP(lblent.get_text()):
misc.error(self.window, "Invalid address in " + misc.error(self.window, language['invalid_address'].
lblent.label.get_label() + " entry.") replace('$A', lblent.label.get_label()))
return False return False
# Now save the settings. # Now save the settings.
@@ -1381,7 +1394,8 @@ class appGui:
encryptionInfo = entry.encryptionInfo encryptionInfo = entry.encryptionInfo
encrypt_methods = misc.LoadEncryptionMethods() encrypt_methods = misc.LoadEncryptionMethods()
wireless.SetWirelessProperty(networkid, "enctype", wireless.SetWirelessProperty(networkid, "enctype",
encrypt_methods[entry.comboEncryption.get_active()][1]) encrypt_methods[entry.comboEncryption.
get_active()][1])
for x in encryptionInfo: for x in encryptionInfo:
wireless.SetWirelessProperty(networkid,x, wireless.SetWirelessProperty(networkid,x,
noneToString(encryptionInfo[x].get_text())) noneToString(encryptionInfo[x].get_text()))
@@ -1421,7 +1435,15 @@ class appGui:
config.SaveWiredNetworkProfile(entry.comboProfileNames.get_active_text()) config.SaveWiredNetworkProfile(entry.comboProfileNames.get_active_text())
return True return True
def editAdvanced(self, widget, event, type, networkid, networkentry): def edit_advanced(self, widget, event, ttype, networkid, networkentry):
""" Display the advanced settings dialog.
Displays the advanced settings dialog and saves any changes made.
If errors occur in the settings, an error message will be displayed
and the user won't be able to save the changes until the errors
are fixed.
"""
dialog = gtk.Dialog(title=language['advanced_settings'], dialog = gtk.Dialog(title=language['advanced_settings'],
flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_OK, flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_OK,
gtk.RESPONSE_ACCEPT, gtk.RESPONSE_ACCEPT,
@@ -1430,12 +1452,18 @@ class appGui:
dialog.vbox.pack_start(networkentry.expander.vboxAdvanced) dialog.vbox.pack_start(networkentry.expander.vboxAdvanced)
dialog.show_all() dialog.show_all()
while True: while True:
if self.run_advanced(dialog, networkid, networkentry): if self.run_settings_dialog(dialog, networkid, networkentry):
break break
dialog.vbox.remove(networkentry.expander.vboxAdvanced) dialog.vbox.remove(networkentry.expander.vboxAdvanced)
dialog.destroy() dialog.destroy()
def run_advanced(self, dialog, networkid, networkentry): def run_settings_dialog(self, dialog, networkid, networkentry):
""" Runs the settings dialog.
Runs the settings dialog and returns True if settings are saved
successfully, and false otherwise.
"""
result = dialog.run() result = dialog.run()
if result == gtk.RESPONSE_ACCEPT: if result == gtk.RESPONSE_ACCEPT:
if self.save_settings(type, networkid, networkentry): if self.save_settings(type, networkid, networkentry):

View File

@@ -228,6 +228,10 @@ def noneToString(text):
return str(text) return str(text)
def get_gettext(): def get_gettext():
""" Set up gettext for translations. """
# Translation stuff
# borrowed from an excellent post on how to do this on
# http://www.learningpython.com/2006/12/03/translating-your-pythonpygtk-application/
local_path = os.path.realpath(os.path.dirname(sys.argv[0])) + '/translations' local_path = os.path.realpath(os.path.dirname(sys.argv[0])) + '/translations'
langs = [] langs = []
lc, encoding = locale.getdefaultlocale() lc, encoding = locale.getdefaultlocale()

View File

@@ -1,5 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
""" Suspends the wicd daemon.
Sets a flag in the daemon that will stop it from monitoring networkg status.
Used for when a laptop enters hibernation/suspension. """
# #
# Copyright (C) 2007 Adam Blackburn # Copyright (C) 2007 Adam Blackburn
# Copyright (C) 2007 Dan O'Reilly # Copyright (C) 2007 Dan O'Reilly
@@ -17,7 +22,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import os
import dbus import dbus
import dbus.service import dbus.service

View File

@@ -361,7 +361,7 @@ class WirelessInterface(Interface):
# Get available network info from iwpriv get_site_survey # Get available network info from iwpriv get_site_survey
# if we're using a ralink card (needed to get encryption info) # if we're using a ralink card (needed to get encryption info)
if self.wpa_driver == RALINK_DRIVER: if self.wpa_driver == RALINK_DRIVER:
ralink_info = self._GetRalinkScanInfo() ralink_info = self._GetRalinkInfo()
else: else:
ralink_info = None ralink_info = None