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

Improved the behavior of threading in networking.py when an error occurs.

Fixed typo in the wpa_supplicant string in networking.py.
Changed formatting in dapper.py, edgy.py, and networking.py to conform closer to python coding conventions (and hopefully improve readability in general)
This commit is contained in:
imdano
2007-08-14 16:01:30 +00:00
parent 8c3a97d572
commit 2ed0c5cf75
4 changed files with 608 additions and 403 deletions

View File

@@ -1029,7 +1029,6 @@ class ConnectionWizard(dbus.service.Object):
self.SetWPADriver(config.get("Settings","wpa_driver")) self.SetWPADriver(config.get("Settings","wpa_driver"))
self.SetAlwaysShowWiredInterface(0) self.SetAlwaysShowWiredInterface(0)
self.SetAutoReconnect(1) self.SetAutoReconnect(1)
self.SetHideDupeAPs(0)
self.SetDebugMode(0) self.SetDebugMode(0)
self.SetWiredAutoConnectMethod(1) self.SetWiredAutoConnectMethod(1)
self.SetUseGlobalDNS(False) self.SetUseGlobalDNS(False)

142
dapper.py
View File

@@ -14,9 +14,9 @@ import gobject, dbus, dbus.service
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
############# #############
#declare the connections to our daemon. # Declare the connections to our daemon.
#without them nothing useful will happen # Without them nothing useful will happen.
#the daemon should be running as root # The daemon should be running as root.
bus = dbus.SystemBus() bus = dbus.SystemBus()
try: try:
print 'attempting to connect daemon...' print 'attempting to connect daemon...'
@@ -61,87 +61,109 @@ pic = gtk.Image()
def set_signal_image(): def set_signal_image():
global LastStrength global LastStrength
global stillWired #keeps us from resetting the wired info over and over global stillWired # Keeps us from resetting the wired info over and over
global network #declared as global so it is initialized once before it gets used in the if statement below global network # Declared as global so it gets initialized before first use
# Disable logging if debugging isn't on to prevent log spam
if not daemon.GetDebugMode(): if not daemon.GetDebugMode():
config.DisableLogging() config.DisableLogging()
#Check if wired profile chooser should be launched # Check if wired profile chooser should be launched
if daemon.GetNeedWiredProfileChooser() == True: if daemon.GetNeedWiredProfileChooser() == True:
wired_profile_chooser() wired_profile_chooser()
daemon.SetNeedWiredProfileChooser(False) daemon.SetNeedWiredProfileChooser(False)
#Are we using a wired connection? # Check for active wired connection
wired_ip = wired.GetWiredIP() wired_ip = wired.GetWiredIP()
if wired.CheckPluggedIn() == True and wired_ip: if wired.CheckPluggedIn() == True and wired_ip != None:
if stillWired == False: # Only set image/tooltip if it hasn't been set already
pic.set_from_file("images/wired.png") if stillWired == False:
tooltip.set_tip(eb,language['connected_to_wired'].replace('$A',wired_ip)) pic.set_from_file("images/wired.png")
stillWired = True tooltip.set_tip(eb,language['connected_to_wired'].replace('$A',
lock = '' wired_ip))
#Check for wireless or no connection stillWired = True
lock = ''
else: else:
if stillWired == True: #wire must have gotten unplugged # Check to see if we were using a wired connection that has now become
# unplugged or disabled.
if stillWired == True:
pic.set_from_file("images/no-signal.png") pic.set_from_file("images/no-signal.png")
tooltip.set_tip(eb,language['not_connected']) tooltip.set_tip(eb,language['not_connected'])
stillWired = False stillWired = False
wireless_ip = wireless.GetWirelessIP() wireless_ip = wireless.GetWirelessIP()
#If ip returns as None, we are probably returning from hibernation and need to force signal to 0 to avoid crashing # If ip returns as None, we are probably returning from hibernation
# and need to force signal to 0 to avoid crashing.
if wireless_ip != None: if wireless_ip != None:
signal = int(wireless.GetCurrentSignalStrength()) wireless_signal = int(wireless.GetCurrentSignalStrength())
else: else:
signal = 0 wireless_signal = 0
#only update if the signal strength has changed because doing I/O calls is expensive, # Only update if the signal strength has changed because doing I/O
#and the icon flickers # calls is expensive, and the icon flickers
if (signal != LastStrength or network != wireless.GetCurrentNetwork()) and wireless_ip != None: if (wireless_signal != LastStrength or
LastStrength = signal network != wireless.GetCurrentNetwork() or wireless_signal == 0) \
lock = '' #set the string to '' so that when it is put in "high-signal" + lock + ".png", there will be nothing and wireless_ip != None:
curNetID = wireless.GetCurrentNetworkID() #the network ID needs to be checked because a negative value here will break the tray LastStrength = wireless_signal
if signal > 0 and curNetID > -1 and wireless.GetWirelessProperty(curNetID,"encryption"): # Set the string to '' so that when it is put in "high-signal" +
lock = '-lock' #set the string to '-lock' so that it will display the lock picture # lock + ".png", there will be nothing
lock = ''
# curNetID needs to be checked because a negative value
# will break the tray when passed to GetWirelessProperty.
curNetID = wireless.GetCurrentNetworkID()
if wireless_signal > 0 and curNetID > -1 and \
wireless.GetWirelessProperty(curNetID,"encryption"):
# Set the string to '-lock' so that it will display the
# lock picture
lock = '-lock'
network = str(wireless.GetCurrentNetwork()) network = str(wireless.GetCurrentNetwork())
tooltip.set_tip(eb,language['connected_to_wireless'].replace('$A',network).replace('$B',str(signal)).replace('$C',str(wireless_ip))) tooltip.set_tip(eb,language['connected_to_wireless'].replace
if signal > 75: ('$A',network).replace('$B',str(wireless_signal)).
replace('$C',str(wireless_ip)))
if wireless_signal > 75:
pic.set_from_file("images/high-signal" + lock + ".png") pic.set_from_file("images/high-signal" + lock + ".png")
elif signal > 50: elif wireless_signal > 50:
pic.set_from_file("images/good-signal" + lock + ".png") pic.set_from_file("images/good-signal" + lock + ".png")
elif signal > 25: elif wireless_signal > 25:
pic.set_from_file("images/low-signal" + lock + ".png") pic.set_from_file("images/low-signal" + lock + ".png")
elif signal > 0: elif wireless_signal > 0:
pic.set_from_file("images/bad-signal" + lock + ".png") pic.set_from_file("images/bad-signal" + lock + ".png")
elif signal == 0: elif wireless_signal == 0:
pic.set_from_file("images/no-signal.png") pic.set_from_file("images/no-signal.png")
autoreconnect() autoreconnect()
elif wireless_ip == None and wired_ip == None: elif wireless_ip is None and wired_ip is None:
pic.set_from_file("images/no-signal") pic.set_from_file("images/no-signal")
tooltip.set_tip(eb,language['not_connected']) tooltip.set_tip(eb,language['not_connected'])
auto_reconnect() auto_reconnect()
if not daemon.GetDebugMode(): if not daemon.GetDebugMode():
config.EnableLogging() config.EnableLogging()
return True return True
def auto_reconnect(): def auto_reconnect():
#Auto-reconnect code - not sure how well this works. I know that without the ForcedDisconnect check it reconnects you when # Auto-reconnect code - not sure how well this works. I know that
#a disconnect is forced. People who have disconnection problems need to test it to determine if it actually works. # without the ForcedDisconnect check it reconnects you when a
#First it will attempt to reconnect to the last known wireless network, and if that fails it should run a scan and try to # disconnect is forced. People who have disconnection problems need
#connect to any network set to autoconnect. # to test it to determine if it actually works.
if wireless.GetAutoReconnect() == True and daemon.CheckIfConnecting() == False and wireless.GetForcedDisconnect() == False: #
# First it will attempt to reconnect to the last known wireless network
# and if that fails it should run a scan and try to connect to a wired
# network or any wireless network set to autoconnect.
global triedReconnect
if wireless.GetAutoReconnect() == True and \
daemon.CheckIfConnecting() == False:
curNetID = wireless.GetCurrentNetworkID() curNetID = wireless.GetCurrentNetworkID()
print 'Trying to autoreconnect' if curNetID > -1: # Needs to be a valid network to try to connect to
if curNetID > -1: if triedReconnect == False:
wireless.ConnectWireless(wireless.GetCurrentNetworkID()) print 'Trying to autoreconnect to last used network'
while wireless.CheckIfWirelessConnecting() == True: wireless.ConnectWireless(curNetID)
time.sleep(1) triedReconnect = True
if wireless.GetCurrentSignalStrength() != 0: elif wireless.CheckIfWirelessConnecting() == False:
print "Successfully autoreconnected." print "Couldn't reconnect to last used network,\
else: scanning for an autoconnect network..."
print "Couldn't reconnect to last used network, scanning for an autoconnect network..." daemon.AutoConnect(True)
print wireless.AutoConnect(True)
else: else:
daemon.AutoConnect(True) daemon.AutoConnect(True)
@@ -174,12 +196,14 @@ def on_about(data):
dialog.set_comments('an icon that shows your network connectivity') dialog.set_comments('an icon that shows your network connectivity')
dialog.set_website('http://wicd.sourceforge.net') dialog.set_website('http://wicd.sourceforge.net')
dialog.run() dialog.run()
dialog.destroy() dialog.destroy()
LastStrength = -2 LastStrength = -2
stillWired = False stillWired = False
network = '' network = ''
lastWinId = 0 lastWinId = 0
triedReconnect = False
menu = ''' menu = '''
<ui> <ui>
<menubar name="Menubar"> <menubar name="Menubar">
@@ -194,10 +218,12 @@ menu = '''
''' '''
actions = [ actions = [
('Menu', None, 'Menu'), ('Menu', None, 'Menu'),
('Connect', gtk.STOCK_CONNECT, '_Connect...', None, 'Connect to network', on_preferences), ('Connect', gtk.STOCK_CONNECT, '_Connect...', None,
('About', gtk.STOCK_ABOUT, '_About...', None, 'About wicd-tray-icon', on_about), 'Connect to network', on_preferences),
('About', gtk.STOCK_ABOUT, '_About...', None,
'About wicd-tray-icon', on_about),
('Quit',gtk.STOCK_QUIT,'_Quit',None,'Quit wicd-tray-icon', on_quit), ('Quit',gtk.STOCK_QUIT,'_Quit',None,'Quit wicd-tray-icon', on_quit),
] ]
ag = gtk.ActionGroup('Actions') ag = gtk.ActionGroup('Actions')
ag.add_actions(actions) ag.add_actions(actions)

143
edgy.py
View File

@@ -24,10 +24,10 @@ if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib import dbus.glib
############# #############
#declare the connections to our daemon. # Declare the connections to our daemon.
#without them nothing useful will happen # Without them nothing useful will happen.
#the daemon should be running as root # The daemon should be running as root.
#some connections aren't used so they are commented # Some connections aren't used so they are commented.
bus = dbus.SystemBus() bus = dbus.SystemBus()
try: try:
print 'attempting to connect daemon...' print 'attempting to connect daemon...'
@@ -37,12 +37,8 @@ except:
print 'daemon not running...' print 'daemon not running...'
import misc import misc
misc.PromptToStartDaemon() misc.PromptToStartDaemon()
time.sleep(5) sys.exit(0)
try: daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon')
proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon')
except:
print 'daemon still not running, aborting.'
daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon') # Had to uncomment it
wireless = dbus.Interface(proxy_obj, 'org.wicd.daemon.wireless') wireless = dbus.Interface(proxy_obj, 'org.wicd.daemon.wireless')
wired = dbus.Interface(proxy_obj, 'org.wicd.daemon.wired') wired = dbus.Interface(proxy_obj, 'org.wicd.daemon.wired')
config = dbus.Interface(proxy_obj, 'org.wicd.daemon.config') config = dbus.Interface(proxy_obj, 'org.wicd.daemon.config')
@@ -82,66 +78,82 @@ def open_wicd_gui():
def wired_profile_chooser(): def wired_profile_chooser():
print 'profile chooser is running' print 'profile chooser is running'
os.spawnlpe(os.P_WAIT, './gui.py', os.environ) os.spawnlpe(os.P_WAIT, './gui.py', os.environ)
def set_signal_image(): def set_signal_image():
global LastStrength global LastStrength
global stillWired #keeps us from resetting the wired info over and over global stillWired # Keeps us from resetting the wired info over and over
global network #declared as global so it gets initialized before initial use global network # Declared as global so it gets initialized before first use
#Disable logging if debugging isn't on to prevent log spam # Disable logging if debugging isn't on to prevent log spam
if not daemon.GetDebugMode(): if not daemon.GetDebugMode():
config.DisableLogging() config.DisableLogging()
#Check if wired profile chooser should be launched # Check if wired profile chooser should be launched
if daemon.GetNeedWiredProfileChooser() == True: if daemon.GetNeedWiredProfileChooser() == True:
wired_profile_chooser() wired_profile_chooser()
daemon.SetNeedWiredProfileChooser(False) daemon.SetNeedWiredProfileChooser(False)
#Check for active wired connection # Check for active wired connection
wired_ip = wired.GetWiredIP() wired_ip = wired.GetWiredIP()
if wired.CheckPluggedIn() == True and wired_ip != None: if wired.CheckPluggedIn() == True and wired_ip != None:
if stillWired == False: # Only set image/tooltip if it hasn't been set already # Only set image/tooltip if it hasn't been set already
if stillWired == False:
tr.set_from_file("images/wired.png") tr.set_from_file("images/wired.png")
tr.set_tooltip(language['connected_to_wired'].replace('$A',wired_ip)) tr.set_tooltip(language['connected_to_wired'].replace('$A',
wired_ip))
stillWired = True stillWired = True
lock = '' lock = ''
#Check if using wireless/not-connected
else: else:
if stillWired == True: #this only occurs when we were previously using wired but it became unplugged # Check to see if we were using a wired connection that has now become
# unplugged or disabled.
if stillWired == True:
tr.set_from_file("images/no-signal.png") tr.set_from_file("images/no-signal.png")
tr.set_tooltip(language['not_connected']) tr.set_tooltip(language['not_connected'])
stillWired = False stillWired = False
wireless_ip = wireless.GetWirelessIP() wireless_ip = wireless.GetWirelessIP()
#If ip returns as None, we are probably returning from hibernation and need to force signal to 0 to avoid crashing # If ip returns as None, we are probably returning from hibernation
# and need to force signal to 0 to avoid crashing.
if wireless_ip != None: if wireless_ip != None:
signal = int(wireless.GetCurrentSignalStrength()) wireless_signal = int(wireless.GetCurrentSignalStrength())
else: else:
signal = 0 wireless_signal = 0
#only update if the signal strength has changed because doing I/O calls is expensive, # Only update if the signal strength has changed because doing I/O
#and the icon flickers # calls is expensive, and the icon flickers
if (signal != LastStrength or network != wireless.GetCurrentNetwork() or signal == 0) and wireless_ip != None: if (wireless_signal != LastStrength or
LastStrength = signal network != wireless.GetCurrentNetwork() or wireless_signal == 0) \
lock = '' #set the string to '' so that when it is put in "high-signal" + lock + ".png", there will be nothing and wireless_ip != None:
curNetID = wireless.GetCurrentNetworkID() #this needs to be checked because a negative value will break the tray LastStrength = wireless_signal
if signal > 0 and curNetID > -1 and wireless.GetWirelessProperty(curNetID,"encryption"): # Set the string to '' so that when it is put in "high-signal" +
lock = '-lock' #set the string to '-lock' so that it will display the lock picture # lock + ".png", there will be nothing
network = str(wireless.GetCurrentNetwork()) lock = ''
tr.set_tooltip(language['connected_to_wireless'].replace('$A',network).replace('$B',str(signal)).replace('$C',str(wireless_ip))) # curNetID needs to be checked because a negative value
if signal > 75: # will break the tray when passed to GetWirelessProperty.
curNetID = wireless.GetCurrentNetworkID()
if wireless_signal > 0 and curNetID > -1 and \
wireless.GetWirelessProperty(curNetID,"encryption"):
# Set the string to '-lock' so that it will display the
# lock picture
lock = '-lock'
network = str(wireless.GetCurrentNetwork())
tr.set_tooltip(language['connected_to_wireless'].replace
('$A',network).replace
('$B',str(wireless_signal)).replace
('$C',str(wireless_ip)))
if wireless_signal > 75:
tr.set_from_file("images/high-signal" + lock + ".png") tr.set_from_file("images/high-signal" + lock + ".png")
elif signal > 50: elif wireless_signal > 50:
tr.set_from_file("images/good-signal" + lock + ".png") tr.set_from_file("images/good-signal" + lock + ".png")
elif signal > 25: elif wireless_signal > 25:
tr.set_from_file("images/low-signal" + lock + ".png") tr.set_from_file("images/low-signal" + lock + ".png")
elif signal > 0: elif wireless_signal > 0:
tr.set_from_file("images/bad-signal" + lock + ".png") tr.set_from_file("images/bad-signal" + lock + ".png")
elif signal == 0: elif wireless_signal == 0:
tr.set_from_file("images/no-signal.png") tr.set_from_file("images/no-signal.png")
auto_reconnect() auto_reconnect()
elif wireless_ip == None and wired_ip == None: elif wireless_ip is None and wired_ip is None:
tr.set_from_file("images/no-signal.png") tr.set_from_file("images/no-signal.png")
tr.set_tooltip(language['not_connected']) tr.set_tooltip(language['not_connected'])
auto_reconnect() auto_reconnect()
@@ -152,24 +164,31 @@ def set_signal_image():
return True return True
def auto_reconnect(): def auto_reconnect():
#Auto-reconnect code - not sure how well this works. I know that without the ForcedDisconnect check it reconnects you when # Auto-reconnect code - not sure how well this works. I know that
#a disconnect is forced. People who have disconnection problems need to test it to determine if it actually works. # without the ForcedDisconnect check it reconnects you when a
#First it will attempt to reconnect to the last known wireless network, and if that fails it should run a scan and try to # disconnect is forced. People who have disconnection problems need
#connect to a wired network or any wireless network set to autoconnect. # to test it to determine if it actually works.
#
# First it will attempt to reconnect to the last known wireless network
# and if that fails it should run a scan and try to connect to a wired
# network or any wireless network set to autoconnect.
global triedReconnect global triedReconnect
if wireless.GetAutoReconnect() == True and daemon.CheckIfConnecting() == False and wireless.GetForcedDisconnect() == False:
if wireless.GetAutoReconnect() == True and \
daemon.CheckIfConnecting() == False:
curNetID = wireless.GetCurrentNetworkID() curNetID = wireless.GetCurrentNetworkID()
print 'Trying to autoreconnect to last used network' if curNetID > -1: # Needs to be a valid network to try to connect to
if curNetID > -1: #needs to be a valid network to try to connect to
if triedReconnect == False: if triedReconnect == False:
print 'Trying to autoreconnect to last used network'
wireless.ConnectWireless(curNetID) wireless.ConnectWireless(curNetID)
triedReconnect = True triedReconnect = True
elif triedReconnect == True and wireless.CheckIfWirelessConnecting() == False: elif wireless.CheckIfWirelessConnecting() == False:
print "Couldn't reconnect to last used network, scanning for an autoconnect network..." print "Couldn't reconnect to last used network,\
scanning for an autoconnect network..."
daemon.AutoConnect(True) daemon.AutoConnect(True)
else: else:
daemon.AutoConnect(True) daemon.AutoConnect(True)
class TrackerStatusIcon(gtk.StatusIcon): class TrackerStatusIcon(gtk.StatusIcon):
def __init__(self): def __init__(self):
gtk.StatusIcon.__init__(self) gtk.StatusIcon.__init__(self)
@@ -187,10 +206,12 @@ class TrackerStatusIcon(gtk.StatusIcon):
''' '''
actions = [ actions = [
('Menu', None, 'Menu'), ('Menu', None, 'Menu'),
('Connect', gtk.STOCK_CONNECT, '_Connect...', None, 'Connect to network', self.on_preferences), ('Connect', gtk.STOCK_CONNECT, '_Connect...', None,
('About', gtk.STOCK_ABOUT, '_About...', None, 'About wicd-tray-icon', self.on_about), 'Connect to network', self.on_preferences),
('Quit',gtk.STOCK_QUIT,'_Quit',None,'Quit wicd-tray-icon', self.on_quit), ('About', gtk.STOCK_ABOUT, '_About...', None,
'About wicd-tray-icon', self.on_about),
('Quit',gtk.STOCK_QUIT,'_Quit',None,'Quit wicd-tray-icon',
self.on_quit),
] ]
ag = gtk.ActionGroup('Actions') ag = gtk.ActionGroup('Actions')
ag.add_actions(actions) ag.add_actions(actions)
@@ -205,7 +226,7 @@ class TrackerStatusIcon(gtk.StatusIcon):
self.connect('popup-menu', self.on_popup_menu) self.connect('popup-menu', self.on_popup_menu)
self.set_from_file("images/no-signal.png") self.set_from_file("images/no-signal.png")
self.set_tooltip("Initializing wicd...") self.set_tooltip("Initializing wicd...")
wireless.SetForcedDisconnect(False) wireless.SetForcedDisconnect(False)
def on_activate(self, data): def on_activate(self, data):
@@ -223,7 +244,7 @@ class TrackerStatusIcon(gtk.StatusIcon):
def on_about(self, data): def on_about(self, data):
dialog = gtk.AboutDialog() dialog = gtk.AboutDialog()
dialog.set_name('wicd tray icon') dialog.set_name('wicd tray icon')
dialog.set_version('0.2') #Might be time to move the version number up? dialog.set_version('0.2') # Might be time to move the version number up?
dialog.set_comments('an icon that shows your network connectivity') dialog.set_comments('an icon that shows your network connectivity')
dialog.set_website('http://wicd.sourceforge.net') dialog.set_website('http://wicd.sourceforge.net')
dialog.run() dialog.run()

File diff suppressed because it is too large Load Diff