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:
@@ -1029,7 +1029,6 @@ class ConnectionWizard(dbus.service.Object):
|
||||
self.SetWPADriver(config.get("Settings","wpa_driver"))
|
||||
self.SetAlwaysShowWiredInterface(0)
|
||||
self.SetAutoReconnect(1)
|
||||
self.SetHideDupeAPs(0)
|
||||
self.SetDebugMode(0)
|
||||
self.SetWiredAutoConnectMethod(1)
|
||||
self.SetUseGlobalDNS(False)
|
||||
|
||||
116
dapper.py
116
dapper.py
@@ -14,9 +14,9 @@ import gobject, dbus, dbus.service
|
||||
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
|
||||
import dbus.glib
|
||||
#############
|
||||
#declare the connections to our daemon.
|
||||
#without them nothing useful will happen
|
||||
#the daemon should be running as root
|
||||
# Declare the connections to our daemon.
|
||||
# Without them nothing useful will happen.
|
||||
# The daemon should be running as root.
|
||||
bus = dbus.SystemBus()
|
||||
try:
|
||||
print 'attempting to connect daemon...'
|
||||
@@ -61,9 +61,10 @@ pic = gtk.Image()
|
||||
|
||||
def set_signal_image():
|
||||
global LastStrength
|
||||
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 stillWired # Keeps us from resetting the wired info over and over
|
||||
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():
|
||||
config.DisableLogging()
|
||||
|
||||
@@ -72,50 +73,65 @@ def set_signal_image():
|
||||
wired_profile_chooser()
|
||||
daemon.SetNeedWiredProfileChooser(False)
|
||||
|
||||
#Are we using a wired connection?
|
||||
# Check for active wired connection
|
||||
wired_ip = wired.GetWiredIP()
|
||||
if wired.CheckPluggedIn() == True and wired_ip:
|
||||
if wired.CheckPluggedIn() == True and wired_ip != None:
|
||||
# Only set image/tooltip if it hasn't been set already
|
||||
if stillWired == False:
|
||||
pic.set_from_file("images/wired.png")
|
||||
tooltip.set_tip(eb,language['connected_to_wired'].replace('$A',wired_ip))
|
||||
tooltip.set_tip(eb,language['connected_to_wired'].replace('$A',
|
||||
wired_ip))
|
||||
stillWired = True
|
||||
lock = ''
|
||||
#Check for wireless or no connection
|
||||
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")
|
||||
tooltip.set_tip(eb,language['not_connected'])
|
||||
stillWired = False
|
||||
|
||||
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:
|
||||
signal = int(wireless.GetCurrentSignalStrength())
|
||||
wireless_signal = int(wireless.GetCurrentSignalStrength())
|
||||
else:
|
||||
signal = 0
|
||||
wireless_signal = 0
|
||||
|
||||
#only update if the signal strength has changed because doing I/O calls is expensive,
|
||||
#and the icon flickers
|
||||
if (signal != LastStrength or network != wireless.GetCurrentNetwork()) and wireless_ip != None:
|
||||
LastStrength = signal
|
||||
lock = '' #set the string to '' so that when it is put in "high-signal" + lock + ".png", there will be nothing
|
||||
curNetID = wireless.GetCurrentNetworkID() #the network ID needs to be checked because a negative value here will break the tray
|
||||
if signal > 0 and curNetID > -1 and wireless.GetWirelessProperty(curNetID,"encryption"):
|
||||
lock = '-lock' #set the string to '-lock' so that it will display the lock picture
|
||||
# Only update if the signal strength has changed because doing I/O
|
||||
# calls is expensive, and the icon flickers
|
||||
if (wireless_signal != LastStrength or
|
||||
network != wireless.GetCurrentNetwork() or wireless_signal == 0) \
|
||||
and wireless_ip != None:
|
||||
LastStrength = wireless_signal
|
||||
# Set the string to '' so that when it is put in "high-signal" +
|
||||
# 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())
|
||||
tooltip.set_tip(eb,language['connected_to_wireless'].replace('$A',network).replace('$B',str(signal)).replace('$C',str(wireless_ip)))
|
||||
if signal > 75:
|
||||
tooltip.set_tip(eb,language['connected_to_wireless'].replace
|
||||
('$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")
|
||||
elif signal > 50:
|
||||
elif wireless_signal > 50:
|
||||
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")
|
||||
elif signal > 0:
|
||||
elif wireless_signal > 0:
|
||||
pic.set_from_file("images/bad-signal" + lock + ".png")
|
||||
elif signal == 0:
|
||||
elif wireless_signal == 0:
|
||||
pic.set_from_file("images/no-signal.png")
|
||||
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")
|
||||
tooltip.set_tip(eb,language['not_connected'])
|
||||
auto_reconnect()
|
||||
@@ -126,22 +142,28 @@ def set_signal_image():
|
||||
return True
|
||||
|
||||
def auto_reconnect():
|
||||
#Auto-reconnect code - not sure how well this works. I know that without the ForcedDisconnect check it reconnects you when
|
||||
#a disconnect is forced. People who have disconnection problems need 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 any network set to autoconnect.
|
||||
if wireless.GetAutoReconnect() == True and daemon.CheckIfConnecting() == False and wireless.GetForcedDisconnect() == False:
|
||||
# Auto-reconnect code - not sure how well this works. I know that
|
||||
# without the ForcedDisconnect check it reconnects you when a
|
||||
# disconnect is forced. People who have disconnection problems need
|
||||
# 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
|
||||
|
||||
if wireless.GetAutoReconnect() == True and \
|
||||
daemon.CheckIfConnecting() == False:
|
||||
curNetID = wireless.GetCurrentNetworkID()
|
||||
print 'Trying to autoreconnect'
|
||||
if curNetID > -1:
|
||||
wireless.ConnectWireless(wireless.GetCurrentNetworkID())
|
||||
while wireless.CheckIfWirelessConnecting() == True:
|
||||
time.sleep(1)
|
||||
if wireless.GetCurrentSignalStrength() != 0:
|
||||
print "Successfully autoreconnected."
|
||||
else:
|
||||
print "Couldn't reconnect to last used network, scanning for an autoconnect network..."
|
||||
print wireless.AutoConnect(True)
|
||||
if curNetID > -1: # Needs to be a valid network to try to connect to
|
||||
if triedReconnect == False:
|
||||
print 'Trying to autoreconnect to last used network'
|
||||
wireless.ConnectWireless(curNetID)
|
||||
triedReconnect = True
|
||||
elif wireless.CheckIfWirelessConnecting() == False:
|
||||
print "Couldn't reconnect to last used network,\
|
||||
scanning for an autoconnect network..."
|
||||
daemon.AutoConnect(True)
|
||||
else:
|
||||
daemon.AutoConnect(True)
|
||||
|
||||
@@ -180,6 +202,8 @@ LastStrength = -2
|
||||
stillWired = False
|
||||
network = ''
|
||||
lastWinId = 0
|
||||
triedReconnect = False
|
||||
|
||||
menu = '''
|
||||
<ui>
|
||||
<menubar name="Menubar">
|
||||
@@ -194,8 +218,10 @@ menu = '''
|
||||
'''
|
||||
actions = [
|
||||
('Menu', None, 'Menu'),
|
||||
('Connect', gtk.STOCK_CONNECT, '_Connect...', None, 'Connect to network', on_preferences),
|
||||
('About', gtk.STOCK_ABOUT, '_About...', None, 'About wicd-tray-icon', on_about),
|
||||
('Connect', gtk.STOCK_CONNECT, '_Connect...', None,
|
||||
'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),
|
||||
|
||||
]
|
||||
|
||||
115
edgy.py
115
edgy.py
@@ -24,10 +24,10 @@ if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
|
||||
import dbus.glib
|
||||
|
||||
#############
|
||||
#declare the connections to our daemon.
|
||||
#without them nothing useful will happen
|
||||
#the daemon should be running as root
|
||||
#some connections aren't used so they are commented
|
||||
# Declare the connections to our daemon.
|
||||
# Without them nothing useful will happen.
|
||||
# The daemon should be running as root.
|
||||
# Some connections aren't used so they are commented.
|
||||
bus = dbus.SystemBus()
|
||||
try:
|
||||
print 'attempting to connect daemon...'
|
||||
@@ -37,12 +37,8 @@ except:
|
||||
print 'daemon not running...'
|
||||
import misc
|
||||
misc.PromptToStartDaemon()
|
||||
time.sleep(5)
|
||||
try:
|
||||
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
|
||||
sys.exit(0)
|
||||
daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon')
|
||||
wireless = dbus.Interface(proxy_obj, 'org.wicd.daemon.wireless')
|
||||
wired = dbus.Interface(proxy_obj, 'org.wicd.daemon.wired')
|
||||
config = dbus.Interface(proxy_obj, 'org.wicd.daemon.config')
|
||||
@@ -85,8 +81,8 @@ def wired_profile_chooser():
|
||||
|
||||
def set_signal_image():
|
||||
global LastStrength
|
||||
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 stillWired # Keeps us from resetting the wired info over and over
|
||||
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():
|
||||
@@ -100,48 +96,64 @@ def set_signal_image():
|
||||
# Check for active wired connection
|
||||
wired_ip = wired.GetWiredIP()
|
||||
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_tooltip(language['connected_to_wired'].replace('$A',wired_ip))
|
||||
tr.set_tooltip(language['connected_to_wired'].replace('$A',
|
||||
wired_ip))
|
||||
stillWired = True
|
||||
lock = ''
|
||||
#Check if using wireless/not-connected
|
||||
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_tooltip(language['not_connected'])
|
||||
stillWired = False
|
||||
|
||||
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:
|
||||
signal = int(wireless.GetCurrentSignalStrength())
|
||||
wireless_signal = int(wireless.GetCurrentSignalStrength())
|
||||
else:
|
||||
signal = 0
|
||||
wireless_signal = 0
|
||||
|
||||
#only update if the signal strength has changed because doing I/O calls is expensive,
|
||||
#and the icon flickers
|
||||
if (signal != LastStrength or network != wireless.GetCurrentNetwork() or signal == 0) and wireless_ip != None:
|
||||
LastStrength = signal
|
||||
lock = '' #set the string to '' so that when it is put in "high-signal" + lock + ".png", there will be nothing
|
||||
curNetID = wireless.GetCurrentNetworkID() #this needs to be checked because a negative value will break the tray
|
||||
if signal > 0 and curNetID > -1 and wireless.GetWirelessProperty(curNetID,"encryption"):
|
||||
lock = '-lock' #set the string to '-lock' so that it will display the lock picture
|
||||
# Only update if the signal strength has changed because doing I/O
|
||||
# calls is expensive, and the icon flickers
|
||||
if (wireless_signal != LastStrength or
|
||||
network != wireless.GetCurrentNetwork() or wireless_signal == 0) \
|
||||
and wireless_ip != None:
|
||||
LastStrength = wireless_signal
|
||||
# Set the string to '' so that when it is put in "high-signal" +
|
||||
# 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())
|
||||
tr.set_tooltip(language['connected_to_wireless'].replace('$A',network).replace('$B',str(signal)).replace('$C',str(wireless_ip)))
|
||||
if signal > 75:
|
||||
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")
|
||||
elif signal > 50:
|
||||
elif wireless_signal > 50:
|
||||
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")
|
||||
elif signal > 0:
|
||||
elif wireless_signal > 0:
|
||||
tr.set_from_file("images/bad-signal" + lock + ".png")
|
||||
elif signal == 0:
|
||||
elif wireless_signal == 0:
|
||||
tr.set_from_file("images/no-signal.png")
|
||||
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_tooltip(language['not_connected'])
|
||||
auto_reconnect()
|
||||
@@ -152,20 +164,27 @@ def set_signal_image():
|
||||
return True
|
||||
|
||||
def auto_reconnect():
|
||||
#Auto-reconnect code - not sure how well this works. I know that without the ForcedDisconnect check it reconnects you when
|
||||
#a disconnect is forced. People who have disconnection problems need 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.
|
||||
# Auto-reconnect code - not sure how well this works. I know that
|
||||
# without the ForcedDisconnect check it reconnects you when a
|
||||
# disconnect is forced. People who have disconnection problems need
|
||||
# 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
|
||||
if wireless.GetAutoReconnect() == True and daemon.CheckIfConnecting() == False and wireless.GetForcedDisconnect() == False:
|
||||
|
||||
if wireless.GetAutoReconnect() == True and \
|
||||
daemon.CheckIfConnecting() == False:
|
||||
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:
|
||||
print 'Trying to autoreconnect to last used network'
|
||||
wireless.ConnectWireless(curNetID)
|
||||
triedReconnect = True
|
||||
elif triedReconnect == True and wireless.CheckIfWirelessConnecting() == False:
|
||||
print "Couldn't reconnect to last used network, scanning for an autoconnect network..."
|
||||
elif wireless.CheckIfWirelessConnecting() == False:
|
||||
print "Couldn't reconnect to last used network,\
|
||||
scanning for an autoconnect network..."
|
||||
daemon.AutoConnect(True)
|
||||
else:
|
||||
daemon.AutoConnect(True)
|
||||
@@ -187,10 +206,12 @@ class TrackerStatusIcon(gtk.StatusIcon):
|
||||
'''
|
||||
actions = [
|
||||
('Menu', None, 'Menu'),
|
||||
('Connect', gtk.STOCK_CONNECT, '_Connect...', None, 'Connect to network', self.on_preferences),
|
||||
('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),
|
||||
|
||||
('Connect', gtk.STOCK_CONNECT, '_Connect...', None,
|
||||
'Connect to network', self.on_preferences),
|
||||
('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.add_actions(actions)
|
||||
|
||||
541
networking.py
541
networking.py
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user