mirror of
https://github.com/gryf/wicd.git
synced 2026-02-14 12:55:49 +01:00
More pylint fixes
This commit is contained in:
@@ -47,10 +47,10 @@ wired_conf = wpath.etc + 'wired-settings.conf'
|
||||
|
||||
def none_to_blank(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 in (None, "None", ""):
|
||||
return ""
|
||||
@@ -63,7 +63,7 @@ def blank_to_none(text):
|
||||
return "None"
|
||||
else:
|
||||
return str(text)
|
||||
|
||||
|
||||
def get_script_info(network, network_type):
|
||||
""" Read script info from disk and load it into the configuration dialog """
|
||||
info = {}
|
||||
@@ -72,16 +72,20 @@ def get_script_info(network, network_type):
|
||||
if con.has_section(network):
|
||||
info["pre_entry"] = con.get(network, "beforescript", None)
|
||||
info["post_entry"] = con.get(network, "afterscript", None)
|
||||
info["pre_disconnect_entry"] = con.get(network, "predisconnectscript", None)
|
||||
info["post_disconnect_entry"] = con.get(network, "postdisconnectscript", None)
|
||||
info["pre_disconnect_entry"] = con.get(network,
|
||||
"predisconnectscript", None)
|
||||
info["post_disconnect_entry"] = con.get(network,
|
||||
"postdisconnectscript", None)
|
||||
else:
|
||||
bssid = wireless.GetWirelessProperty(int(network), "bssid")
|
||||
con = ConfigManager(wireless_conf)
|
||||
if con.has_section(bssid):
|
||||
info["pre_entry"] = con.get(bssid, "beforescript", None)
|
||||
info["post_entry"] = con.get(bssid, "afterscript", None)
|
||||
info["pre_disconnect_entry"] = con.get(bssid, "predisconnectscript", None)
|
||||
info["post_disconnect_entry"] = con.get(bssid, "postdisconnectscript", None)
|
||||
info["pre_disconnect_entry"] = con.get(bssid,
|
||||
"predisconnectscript", None)
|
||||
info["post_disconnect_entry"] = con.get(bssid,
|
||||
"postdisconnectscript", None)
|
||||
return info
|
||||
|
||||
def write_scripts(network, network_type, script_info):
|
||||
@@ -90,8 +94,10 @@ def write_scripts(network, network_type, script_info):
|
||||
con = ConfigManager(wired_conf)
|
||||
con.set(network, "beforescript", script_info["pre_entry"])
|
||||
con.set(network, "afterscript", script_info["post_entry"])
|
||||
con.set(network, "predisconnectscript", script_info["pre_disconnect_entry"])
|
||||
con.set(network, "postdisconnectscript", script_info["post_disconnect_entry"])
|
||||
con.set(network, "predisconnectscript",
|
||||
script_info["pre_disconnect_entry"])
|
||||
con.set(network, "postdisconnectscript",
|
||||
script_info["post_disconnect_entry"])
|
||||
con.write()
|
||||
wired.ReloadConfig()
|
||||
wired.ReadWiredNetworkProfile(network)
|
||||
@@ -101,8 +107,10 @@ def write_scripts(network, network_type, script_info):
|
||||
con = ConfigManager(wireless_conf)
|
||||
con.set(bssid, "beforescript", script_info["pre_entry"])
|
||||
con.set(bssid, "afterscript", script_info["post_entry"])
|
||||
con.set(bssid, "predisconnectscript", script_info["pre_disconnect_entry"])
|
||||
con.set(bssid, "postdisconnectscript", script_info["post_disconnect_entry"])
|
||||
con.set(bssid, "predisconnectscript",
|
||||
script_info["pre_disconnect_entry"])
|
||||
con.set(bssid, "postdisconnectscript",
|
||||
script_info["post_disconnect_entry"])
|
||||
con.write()
|
||||
wireless.ReloadConfig()
|
||||
wireless.ReadWirelessNetworkProfile(int(network))
|
||||
@@ -114,12 +122,12 @@ def main (argv):
|
||||
if len(argv) < 2:
|
||||
print 'Network id to configure is missing, aborting.'
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
network = argv[1]
|
||||
network_type = argv[2]
|
||||
|
||||
|
||||
script_info = get_script_info(network, network_type)
|
||||
|
||||
|
||||
gladefile = os.path.join(wpath.gtk, "wicd.ui")
|
||||
wTree = gtk.Builder()
|
||||
wTree.set_translation_domain('wicd')
|
||||
@@ -127,33 +135,39 @@ def main (argv):
|
||||
dialog = wTree.get_object("configure_script_dialog")
|
||||
wTree.get_object("pre_label").set_label(_('Pre-connection Script') + ":")
|
||||
wTree.get_object("post_label").set_label(_('Post-connection Script') + ":")
|
||||
wTree.get_object("pre_disconnect_label").set_label(_('Pre-disconnection Script')
|
||||
+ ":")
|
||||
wTree.get_object("post_disconnect_label").set_label(_('Post-disconnection Script')
|
||||
+ ":")
|
||||
wTree.get_object("pre_disconnect_label").\
|
||||
set_label(_('Pre-disconnection Script') + ":")
|
||||
wTree.get_object("post_disconnect_label").\
|
||||
set_label(_('Post-disconnection Script') + ":")
|
||||
wTree.get_object("window1").hide()
|
||||
|
||||
|
||||
pre_entry = wTree.get_object("pre_entry")
|
||||
post_entry = wTree.get_object("post_entry")
|
||||
pre_disconnect_entry = wTree.get_object("pre_disconnect_entry")
|
||||
post_disconnect_entry = wTree.get_object("post_disconnect_entry")
|
||||
|
||||
|
||||
pre_entry.set_text(none_to_blank(script_info.get("pre_entry")))
|
||||
post_entry.set_text(none_to_blank(script_info.get("post_entry")))
|
||||
pre_disconnect_entry.set_text(none_to_blank(script_info.get("pre_disconnect_entry")))
|
||||
post_disconnect_entry.set_text(none_to_blank(script_info.get("post_disconnect_entry")))
|
||||
pre_disconnect_entry.set_text(
|
||||
none_to_blank(script_info.get("pre_disconnect_entry"))
|
||||
)
|
||||
post_disconnect_entry.set_text(
|
||||
none_to_blank(script_info.get("post_disconnect_entry"))
|
||||
)
|
||||
|
||||
dialog.show_all()
|
||||
|
||||
|
||||
result = dialog.run()
|
||||
if result == 1:
|
||||
script_info["pre_entry"] = blank_to_none(pre_entry.get_text())
|
||||
script_info["post_entry"] = blank_to_none(post_entry.get_text())
|
||||
script_info["pre_disconnect_entry"] = blank_to_none(pre_disconnect_entry.get_text())
|
||||
script_info["post_disconnect_entry"] = blank_to_none(post_disconnect_entry.get_text())
|
||||
script_info["pre_disconnect_entry"] = \
|
||||
blank_to_none(pre_disconnect_entry.get_text())
|
||||
script_info["post_disconnect_entry"] = \
|
||||
blank_to_none(post_disconnect_entry.get_text())
|
||||
write_scripts(network, network_type, script_info)
|
||||
dialog.destroy()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if os.getuid() != 0:
|
||||
|
||||
335
gtk/gui.py
335
gtk/gui.py
@@ -27,7 +27,6 @@ import os
|
||||
import sys
|
||||
import time
|
||||
import gobject
|
||||
import pango
|
||||
import gtk
|
||||
from itertools import chain
|
||||
from dbus import DBusException
|
||||
@@ -49,22 +48,30 @@ if __name__ == '__main__':
|
||||
proxy_obj = daemon = wireless = wired = bus = None
|
||||
DBUS_AVAIL = False
|
||||
|
||||
|
||||
def setup_dbus(force=True):
|
||||
""" Initialize DBus. """
|
||||
global bus, daemon, wireless, wired, DBUS_AVAIL
|
||||
try:
|
||||
dbusmanager.connect_to_dbus()
|
||||
except DBusException:
|
||||
if force:
|
||||
print "Can't connect to the daemon, trying to start it automatically..."
|
||||
print "Can't connect to the daemon, ' + \
|
||||
'trying to start it automatically..."
|
||||
if not misc.PromptToStartDaemon():
|
||||
print "Failed to find a graphical sudo program, cannot continue."
|
||||
print "Failed to find a graphical sudo program, ' + \
|
||||
'cannot continue."
|
||||
return False
|
||||
try:
|
||||
dbusmanager.connect_to_dbus()
|
||||
except DBusException:
|
||||
error(None, _("Could not connect to wicd's D-Bus interface. Check the wicd log for error messages."))
|
||||
error(
|
||||
None,
|
||||
_("Could not connect to wicd's D-Bus interface. "
|
||||
"Check the wicd log for error messages.")
|
||||
)
|
||||
return False
|
||||
else:
|
||||
else:
|
||||
return False
|
||||
prefs.setup_dbus()
|
||||
netentry.setup_dbus()
|
||||
@@ -74,18 +81,26 @@ def setup_dbus(force=True):
|
||||
wireless = dbus_ifaces['wireless']
|
||||
wired = dbus_ifaces['wired']
|
||||
DBUS_AVAIL = True
|
||||
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def handle_no_dbus(from_tray=False):
|
||||
""" Handle the case where no DBus is available. """
|
||||
global DBUS_AVAIL
|
||||
DBUS_AVAIL = False
|
||||
if from_tray: return False
|
||||
if from_tray:
|
||||
return False
|
||||
print "Wicd daemon is shutting down!"
|
||||
error(None, _('The wicd daemon has shut down. The UI will not function properly until it is restarted.'), block=False)
|
||||
error(
|
||||
None,
|
||||
_('The wicd daemon has shut down. The UI will not function '
|
||||
'properly until it is restarted.'),
|
||||
block=False
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
|
||||
class WiredProfileChooser:
|
||||
""" Class for displaying the wired profile chooser. """
|
||||
def __init__(self):
|
||||
@@ -94,14 +109,19 @@ class WiredProfileChooser:
|
||||
# functions and widgets it uses.
|
||||
wired_net_entry = WiredNetworkEntry()
|
||||
|
||||
dialog = gtk.Dialog(title = _('Wired connection detected'),
|
||||
flags = gtk.DIALOG_MODAL,
|
||||
buttons = (gtk.STOCK_CONNECT, 1,
|
||||
gtk.STOCK_CANCEL, 2))
|
||||
dialog = gtk.Dialog(
|
||||
title=_('Wired connection detected'),
|
||||
flags=gtk.DIALOG_MODAL,
|
||||
buttons=(gtk.STOCK_CONNECT, 1, gtk.STOCK_CANCEL, 2)
|
||||
)
|
||||
dialog.set_has_separator(False)
|
||||
dialog.set_size_request(400, 150)
|
||||
instruct_label = gtk.Label(_('Select or create a wired profile to connect with') + ':\n')
|
||||
stoppopcheckbox = gtk.CheckButton(_('Stop Showing Autoconnect pop-up temporarily'))
|
||||
instruct_label = gtk.Label(
|
||||
_('Select or create a wired profile to connect with') + ':\n'
|
||||
)
|
||||
stoppopcheckbox = gtk.CheckButton(
|
||||
_('Stop Showing Autoconnect pop-up temporarily')
|
||||
)
|
||||
|
||||
wired_net_entry.is_full_gui = False
|
||||
instruct_label.set_alignment(0, 0)
|
||||
@@ -112,15 +132,19 @@ class WiredProfileChooser:
|
||||
wired_net_entry.vbox_top.remove(wired_net_entry.hbox_temp)
|
||||
wired_net_entry.vbox_top.remove(wired_net_entry.profile_help)
|
||||
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_start(instruct_label, fill=False, expand=False)
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_start(wired_net_entry.profile_help, False, False)
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_start(wired_net_entry.hbox_temp, False, False)
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_start(stoppopcheckbox, False, False)
|
||||
dialog.show_all()
|
||||
|
||||
wired_profiles = wired_net_entry.combo_profile_names
|
||||
wired_net_entry.profile_help.hide()
|
||||
if wired_net_entry.profile_list != None:
|
||||
if wired_net_entry.profile_list is not None:
|
||||
wired_profiles.set_active(0)
|
||||
print "wired profiles found"
|
||||
else:
|
||||
@@ -139,6 +163,7 @@ class WiredProfileChooser:
|
||||
|
||||
|
||||
def get_wireless_prop(net_id, prop):
|
||||
""" Get wireless property. """
|
||||
return wireless.GetWirelessProperty(net_id, prop)
|
||||
|
||||
class appGui(object):
|
||||
@@ -170,18 +195,19 @@ class appGui(object):
|
||||
width = 530
|
||||
self.window.resize(width, int(gtk.gdk.screen_height() / 1.7))
|
||||
|
||||
dic = { "refresh_clicked" : self.refresh_clicked,
|
||||
"quit_clicked" : self.exit,
|
||||
"rfkill_clicked" : self.switch_rfkill,
|
||||
"disconnect_clicked" : self.disconnect_all,
|
||||
"main_exit" : self.exit,
|
||||
"cancel_clicked" : self.cancel_connect,
|
||||
"hidden_clicked" : self.connect_hidden,
|
||||
"preferences_clicked" : self.settings_dialog,
|
||||
"about_clicked" : self.about_dialog,
|
||||
"create_adhoc_clicked" : self.create_adhoc_network,
|
||||
"forget_network_clicked" : self.forget_network,
|
||||
}
|
||||
dic = {
|
||||
"refresh_clicked": self.refresh_clicked,
|
||||
"quit_clicked": self.exit,
|
||||
"rfkill_clicked": self.switch_rfkill,
|
||||
"disconnect_clicked": self.disconnect_all,
|
||||
"main_exit": self.exit,
|
||||
"cancel_clicked": self.cancel_connect,
|
||||
"hidden_clicked": self.connect_hidden,
|
||||
"preferences_clicked": self.settings_dialog,
|
||||
"about_clicked": self.about_dialog,
|
||||
"create_adhoc_clicked": self.create_adhoc_network,
|
||||
"forget_network_clicked": self.forget_network,
|
||||
}
|
||||
self.wTree.connect_signals(dic)
|
||||
|
||||
# Set some strings in the GUI - they may be translated
|
||||
@@ -207,7 +233,9 @@ class appGui(object):
|
||||
self.status_area.hide_all()
|
||||
|
||||
if os.path.exists(os.path.join(wpath.images, "wicd.png")):
|
||||
self.window.set_icon_from_file(os.path.join(wpath.images, "wicd.png"))
|
||||
self.window.set_icon_from_file(
|
||||
os.path.join(wpath.images, "wicd.png")
|
||||
)
|
||||
self.statusID = None
|
||||
self.first_dialog_load = True
|
||||
self.is_visible = True
|
||||
@@ -236,32 +264,36 @@ class appGui(object):
|
||||
'org.wicd.daemon')
|
||||
bus.add_signal_receiver(self.handle_connection_results,
|
||||
'ConnectResultsSent', 'org.wicd.daemon')
|
||||
bus.add_signal_receiver(lambda: setup_dbus(force=False),
|
||||
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",
|
||||
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing",
|
||||
"org.wicd.daemon")
|
||||
|
||||
|
||||
self._do_statusbar_update(*daemon.GetConnectionStatus())
|
||||
self.wait_for_events(0.1)
|
||||
self.update_cb = misc.timeout_add(2, self.update_statusbar)
|
||||
self.refresh_clicked()
|
||||
|
||||
|
||||
def handle_connection_results(self, results):
|
||||
""" Handle connection results. """
|
||||
if results not in ['success', 'aborted'] and self.is_visible:
|
||||
error(self.window, language[results], block=False)
|
||||
|
||||
def create_adhoc_network(self, widget=None):
|
||||
""" Shows a dialog that creates a new adhoc network. """
|
||||
print "Starting the Ad-Hoc Network Creation Process..."
|
||||
dialog = gtk.Dialog(title = _('Create an Ad-Hoc Network'),
|
||||
flags = gtk.DIALOG_MODAL,
|
||||
buttons=(gtk.STOCK_CANCEL, 2, gtk.STOCK_OK, 1))
|
||||
dialog = gtk.Dialog(
|
||||
title=_('Create an Ad-Hoc Network'),
|
||||
flags=gtk.DIALOG_MODAL,
|
||||
buttons=(gtk.STOCK_CANCEL, 2, gtk.STOCK_OK, 1)
|
||||
)
|
||||
dialog.set_has_separator(False)
|
||||
dialog.set_size_request(400, -1)
|
||||
self.chkbox_use_encryption = gtk.CheckButton(_('Use Encryption (WEP only)'))
|
||||
self.chkbox_use_encryption = \
|
||||
gtk.CheckButton(_('Use Encryption (WEP only)'))
|
||||
self.chkbox_use_encryption.set_active(False)
|
||||
ip_entry = LabelEntry(_('IP') + ':')
|
||||
essid_entry = LabelEntry(_('ESSID') + ':')
|
||||
@@ -270,7 +302,8 @@ class appGui(object):
|
||||
self.key_entry.set_auto_hidden(True)
|
||||
self.key_entry.set_sensitive(False)
|
||||
|
||||
chkbox_use_ics = gtk.CheckButton( _('Activate Internet Connection Sharing'))
|
||||
chkbox_use_ics = \
|
||||
gtk.CheckButton(_('Activate Internet Connection Sharing'))
|
||||
|
||||
self.chkbox_use_encryption.connect("toggled",
|
||||
self.toggle_encrypt_check)
|
||||
@@ -283,22 +316,30 @@ class appGui(object):
|
||||
vbox_ah.pack_start(self.chkbox_use_encryption, False, False)
|
||||
vbox_ah.pack_start(self.key_entry, False, False)
|
||||
vbox_ah.show()
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_start(essid_entry)
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_start(ip_entry)
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_start(channel_entry)
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_start(chkbox_use_ics)
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_start(vbox_ah)
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.set_spacing(5)
|
||||
dialog.show_all()
|
||||
response = dialog.run()
|
||||
if response == 1:
|
||||
wireless.CreateAdHocNetwork(essid_entry.entry.get_text(),
|
||||
channel_entry.entry.get_text(),
|
||||
ip_entry.entry.get_text().strip(),
|
||||
"WEP",
|
||||
self.key_entry.entry.get_text(),
|
||||
self.chkbox_use_encryption.get_active(),
|
||||
False) #chkbox_use_ics.get_active())
|
||||
wireless.CreateAdHocNetwork(
|
||||
essid_entry.entry.get_text(),
|
||||
channel_entry.entry.get_text(),
|
||||
ip_entry.entry.get_text().strip(),
|
||||
"WEP",
|
||||
self.key_entry.entry.get_text(),
|
||||
self.chkbox_use_encryption.get_active(),
|
||||
False # chkbox_use_ics.get_active())
|
||||
)
|
||||
dialog.destroy()
|
||||
|
||||
def forget_network(self, widget=None):
|
||||
@@ -307,9 +348,11 @@ class appGui(object):
|
||||
delete them.
|
||||
"""
|
||||
wireless.ReloadConfig()
|
||||
dialog = gtk.Dialog(title = _('List of saved networks'),
|
||||
flags = gtk.DIALOG_MODAL,
|
||||
buttons=(gtk.STOCK_DELETE, 1, gtk.STOCK_OK, 2))
|
||||
dialog = gtk.Dialog(
|
||||
title=_('List of saved networks'),
|
||||
flags=gtk.DIALOG_MODAL,
|
||||
buttons=(gtk.STOCK_DELETE, 1, gtk.STOCK_OK, 2)
|
||||
)
|
||||
dialog.set_has_separator(True)
|
||||
dialog.set_size_request(400, 200)
|
||||
|
||||
@@ -324,16 +367,18 @@ class appGui(object):
|
||||
|
||||
cell = gtk.CellRendererText()
|
||||
|
||||
column = gtk.TreeViewColumn(_('ESSID'), cell, text = 0)
|
||||
column = gtk.TreeViewColumn(_('ESSID'), cell, text=0)
|
||||
tree.append_column(column)
|
||||
|
||||
column = gtk.TreeViewColumn(_('BSSID'), cell, text = 1)
|
||||
column = gtk.TreeViewColumn(_('BSSID'), cell, text=1)
|
||||
tree.append_column(column)
|
||||
|
||||
scroll = gtk.ScrolledWindow()
|
||||
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||
scroll.add(tree)
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_start(scroll)
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.set_spacing(5)
|
||||
dialog.show_all()
|
||||
response = dialog.run()
|
||||
@@ -342,21 +387,24 @@ class appGui(object):
|
||||
to_remove = dict(essid=[], bssid=[])
|
||||
if pathlist:
|
||||
for row in pathlist:
|
||||
iter = model.get_iter(path=row)
|
||||
to_remove['essid'].append(misc.noneToString(model.get_value(iter, 0)))
|
||||
to_remove['bssid'].append(model.get_value(iter, 1))
|
||||
it = model.get_iter(path=row)
|
||||
to_remove['essid'].append(
|
||||
misc.noneToString(model.get_value(it, 0))
|
||||
)
|
||||
to_remove['bssid'].append(model.get_value(it, 1))
|
||||
|
||||
confirm = gtk.MessageDialog(
|
||||
flags = gtk.DIALOG_MODAL,
|
||||
type = gtk.MESSAGE_INFO,
|
||||
buttons = gtk.BUTTONS_YES_NO,
|
||||
message_format = _('Are you sure you want to discard' +
|
||||
' settings for the selected networks?')
|
||||
)
|
||||
flags=gtk.DIALOG_MODAL,
|
||||
type=gtk.MESSAGE_INFO,
|
||||
buttons=gtk.BUTTONS_YES_NO,
|
||||
message_format=_('Are you sure you want to discard' +
|
||||
' settings for the selected networks?')
|
||||
)
|
||||
confirm.format_secondary_text('\n'.join(to_remove['essid']))
|
||||
response = confirm.run()
|
||||
if response == gtk.RESPONSE_YES:
|
||||
map(wireless.DeleteWirelessNetwork, to_remove['bssid'])
|
||||
for x in to_remove['bssid']:
|
||||
wireless.DeleteWirelessNetwork(x)
|
||||
wireless.ReloadConfig()
|
||||
confirm.destroy()
|
||||
dialog.destroy()
|
||||
@@ -379,7 +427,7 @@ class appGui(object):
|
||||
""" Disconnects from any active network. """
|
||||
def handler(*args):
|
||||
gobject.idle_add(self.all_network_list.set_sensitive, True)
|
||||
|
||||
|
||||
self.all_network_list.set_sensitive(False)
|
||||
daemon.Disconnect(reply_handler=handler, error_handler=handler)
|
||||
|
||||
@@ -388,17 +436,22 @@ class appGui(object):
|
||||
dialog = gtk.AboutDialog()
|
||||
dialog.set_name("Wicd")
|
||||
dialog.set_version(daemon.Hello())
|
||||
dialog.set_authors([ "Adam Blackburn", "Dan O'Reilly", "Andrew Psaltis", "David Paleino"])
|
||||
dialog.set_authors([
|
||||
"Adam Blackburn",
|
||||
"Dan O'Reilly",
|
||||
"Andrew Psaltis",
|
||||
"David Paleino"
|
||||
])
|
||||
dialog.set_website("http://wicd.sourceforge.net")
|
||||
dialog.run()
|
||||
dialog.destroy()
|
||||
|
||||
def key_event (self, widget, event=None):
|
||||
|
||||
def key_event(self, widget, event=None):
|
||||
""" Handle key-release-events. """
|
||||
if event.state & gtk.gdk.CONTROL_MASK and \
|
||||
gtk.gdk.keyval_name(event.keyval) in ["w", "q"]:
|
||||
self.exit()
|
||||
|
||||
|
||||
def settings_dialog(self, widget, event=None):
|
||||
""" Displays a general settings dialog. """
|
||||
if not self.pref:
|
||||
@@ -411,13 +464,17 @@ class appGui(object):
|
||||
|
||||
def connect_hidden(self, widget):
|
||||
""" Prompts the user for a hidden network, then scans for it. """
|
||||
dialog = gtk.Dialog(title=('Hidden Network'),
|
||||
flags=gtk.DIALOG_MODAL,
|
||||
buttons=(gtk.STOCK_CONNECT, 1, gtk.STOCK_CANCEL, 2))
|
||||
dialog = gtk.Dialog(
|
||||
title=('Hidden Network'),
|
||||
flags=gtk.DIALOG_MODAL,
|
||||
buttons=(gtk.STOCK_CONNECT, 1, gtk.STOCK_CANCEL, 2)
|
||||
)
|
||||
dialog.set_has_separator(False)
|
||||
lbl = gtk.Label(_('Hidden Network ESSID'))
|
||||
textbox = gtk.Entry()
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_start(lbl)
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_start(textbox)
|
||||
dialog.show_all()
|
||||
button = dialog.run()
|
||||
@@ -454,18 +511,19 @@ class appGui(object):
|
||||
""" Triggers a status update in wicd-monitor. """
|
||||
if not self.is_visible:
|
||||
return True
|
||||
|
||||
|
||||
daemon.UpdateState()
|
||||
if self.connecting:
|
||||
# If we're connecting, don't wait for the monitor to send
|
||||
# us a signal, since it won't until the connection is made.
|
||||
self._do_statusbar_update(*daemon.GetConnectionStatus())
|
||||
return True
|
||||
|
||||
|
||||
def _do_statusbar_update(self, state, info):
|
||||
""" Actually perform the statusbar update. """
|
||||
if not self.is_visible:
|
||||
return True
|
||||
|
||||
|
||||
if state == misc.WIRED:
|
||||
return self.set_wired_state(info)
|
||||
elif state == misc.WIRELESS:
|
||||
@@ -475,15 +533,19 @@ class appGui(object):
|
||||
elif state in (misc.SUSPENDED, misc.NOT_CONNECTED):
|
||||
return self.set_not_connected_state(info)
|
||||
return True
|
||||
|
||||
|
||||
def set_wired_state(self, info):
|
||||
""" Set wired state. """
|
||||
if self.connecting:
|
||||
# Adjust our state from connecting->connected.
|
||||
self._set_not_connecting_state()
|
||||
self.set_status(_('Connected to wired network (IP: $A)').replace('$A', info[0]))
|
||||
self.set_status(
|
||||
_('Connected to wired network (IP: $A)').replace('$A', info[0])
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
def set_wireless_state(self, info):
|
||||
""" Set wireless state. """
|
||||
if self.connecting:
|
||||
# Adjust our state from connecting->connected.
|
||||
self._set_not_connecting_state()
|
||||
@@ -492,15 +554,17 @@ class appGui(object):
|
||||
('$B', daemon.FormatSignalForPrinting(info[2])).replace
|
||||
('$C', info[0]))
|
||||
return True
|
||||
|
||||
|
||||
def set_not_connected_state(self, info):
|
||||
""" Set not connected state. """
|
||||
if self.connecting:
|
||||
# Adjust our state from connecting->not-connected.
|
||||
self._set_not_connecting_state()
|
||||
self.set_status(_('Not connected'))
|
||||
return True
|
||||
|
||||
|
||||
def _set_not_connecting_state(self):
|
||||
""" Set not-connecting state. """
|
||||
if self.connecting:
|
||||
if self.update_cb:
|
||||
gobject.source_remove(self.update_cb)
|
||||
@@ -512,12 +576,13 @@ class appGui(object):
|
||||
gobject.idle_add(self.status_area.hide_all)
|
||||
if self.statusID:
|
||||
gobject.idle_add(self.status_bar.remove_message, 1, self.statusID)
|
||||
|
||||
|
||||
def set_connecting_state(self, info):
|
||||
""" Set connecting state. """
|
||||
if not self.connecting:
|
||||
if self.update_cb:
|
||||
gobject.source_remove(self.update_cb)
|
||||
self.update_cb = misc.timeout_add(500, self.update_statusbar,
|
||||
self.update_cb = misc.timeout_add(500, self.update_statusbar,
|
||||
milli=True)
|
||||
self.connecting = True
|
||||
if not self.pulse_active:
|
||||
@@ -531,56 +596,60 @@ class appGui(object):
|
||||
stat = wireless.CheckWirelessConnectingMessage()
|
||||
gobject.idle_add(self.set_status, "%s: %s" % (info[1], stat))
|
||||
elif info[0] == "wired":
|
||||
gobject.idle_add(self.set_status, _('Wired Network') + ': ' \
|
||||
gobject.idle_add(self.set_status, _('Wired Network') + ': '
|
||||
+ wired.CheckWiredConnectingMessage())
|
||||
return True
|
||||
|
||||
|
||||
def update_connect_buttons(self, state=None, x=None, force_check=False):
|
||||
""" Updates the connect/disconnect buttons for each network entry.
|
||||
|
||||
If force_check is given, update the buttons even if the
|
||||
current network state is the same as the previous.
|
||||
|
||||
|
||||
"""
|
||||
if not DBUS_AVAIL: return
|
||||
if not DBUS_AVAIL:
|
||||
return
|
||||
if not state:
|
||||
state, x = daemon.GetConnectionStatus()
|
||||
|
||||
|
||||
if self.prev_state != state or force_check:
|
||||
apbssid = wireless.GetApBssid()
|
||||
for entry in chain(self.network_list, self.wired_network_box):
|
||||
if hasattr(entry, "update_connect_button"):
|
||||
entry.update_connect_button(state, apbssid)
|
||||
self.prev_state = state
|
||||
|
||||
|
||||
def set_status(self, msg):
|
||||
""" Sets the status bar message for the GUI. """
|
||||
self.statusID = self.status_bar.push(1, msg)
|
||||
|
||||
|
||||
def dbus_scan_finished(self):
|
||||
""" Calls for a non-fresh update of the gui window.
|
||||
|
||||
|
||||
This method is called after a wireless scan is completed.
|
||||
|
||||
|
||||
"""
|
||||
if not DBUS_AVAIL: return
|
||||
if not DBUS_AVAIL:
|
||||
return
|
||||
gobject.idle_add(self.refresh_networks, None, False, None)
|
||||
|
||||
|
||||
def dbus_scan_started(self):
|
||||
""" Called when a wireless scan starts. """
|
||||
if not DBUS_AVAIL: return
|
||||
if not DBUS_AVAIL:
|
||||
return
|
||||
self.network_list.set_sensitive(False)
|
||||
|
||||
def _remove_items_from_vbox(self, vbox):
|
||||
""" Remove items fro a VBox. """
|
||||
for z in vbox:
|
||||
vbox.remove(z)
|
||||
z.destroy()
|
||||
del z
|
||||
|
||||
|
||||
def refresh_clicked(self, widget=None):
|
||||
""" Kick off an asynchronous wireless scan. """
|
||||
if not DBUS_AVAIL or self.connecting: return
|
||||
if not DBUS_AVAIL or self.connecting:
|
||||
return
|
||||
self.refreshing = True
|
||||
|
||||
# Remove stuff already in there.
|
||||
@@ -598,7 +667,7 @@ class appGui(object):
|
||||
wirednet.disconnect_button.connect("clicked", self.disconnect,
|
||||
"wired", 0, wirednet)
|
||||
wirednet.advanced_button.connect("clicked",
|
||||
self.edit_advanced, "wired", 0,
|
||||
self.edit_advanced, "wired", 0,
|
||||
wirednet)
|
||||
state, x = daemon.GetConnectionStatus()
|
||||
wirednet.update_connect_button(state)
|
||||
@@ -611,13 +680,13 @@ class appGui(object):
|
||||
|
||||
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>.
|
||||
|
||||
|
||||
"""
|
||||
if fresh:
|
||||
if hidden:
|
||||
@@ -637,7 +706,9 @@ class appGui(object):
|
||||
skip_never_connect = not daemon.GetShowNeverConnect()
|
||||
instruct_label.show()
|
||||
for x in xrange(0, num_networks):
|
||||
if skip_never_connect and misc.to_bool(get_wireless_prop(x,'never')): continue
|
||||
if skip_never_connect and \
|
||||
misc.to_bool(get_wireless_prop(x, 'never')):
|
||||
continue
|
||||
if printLine:
|
||||
sep = gtk.HSeparator()
|
||||
self.network_list.pack_start(sep, padding=10, fill=False,
|
||||
@@ -673,17 +744,17 @@ class appGui(object):
|
||||
entry = networkentry.advanced_dialog
|
||||
opt_entlist = []
|
||||
req_entlist = []
|
||||
|
||||
|
||||
# First make sure all the Addresses entered are valid.
|
||||
if entry.chkbox_static_ip.get_active():
|
||||
req_entlist = [entry.txt_ip, entry.txt_netmask]
|
||||
opt_entlist = [entry.txt_gateway]
|
||||
|
||||
|
||||
if entry.chkbox_static_dns.get_active() and \
|
||||
not entry.chkbox_global_dns.get_active():
|
||||
for ent in [entry.txt_dns_1, entry.txt_dns_2, entry.txt_dns_3]:
|
||||
opt_entlist.append(ent)
|
||||
|
||||
|
||||
# Required entries.
|
||||
for lblent in req_entlist:
|
||||
lblent.set_text(lblent.get_text().strip())
|
||||
@@ -691,7 +762,7 @@ class appGui(object):
|
||||
error(self.window, _('Invalid address in $A entry.').
|
||||
replace('$A', lblent.label.get_label()))
|
||||
return False
|
||||
|
||||
|
||||
# Optional entries, only check for validity if they're entered.
|
||||
for lblent in opt_entlist:
|
||||
lblent.set_text(lblent.get_text().strip())
|
||||
@@ -708,17 +779,17 @@ class appGui(object):
|
||||
elif nettype == "wired":
|
||||
if not networkentry.save_wired_settings():
|
||||
return False
|
||||
|
||||
|
||||
return True
|
||||
|
||||
def edit_advanced(self, widget, 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 = networkentry.advanced_dialog
|
||||
dialog.set_values()
|
||||
@@ -727,13 +798,13 @@ class appGui(object):
|
||||
if self.run_settings_dialog(dialog, ttype, networkid, networkentry):
|
||||
break
|
||||
dialog.hide()
|
||||
|
||||
|
||||
def run_settings_dialog(self, dialog, nettype, networkid, networkentry):
|
||||
""" Runs the settings dialog.
|
||||
|
||||
|
||||
Runs the settings dialog and returns True if settings are saved
|
||||
successfully, and false otherwise.
|
||||
|
||||
|
||||
"""
|
||||
result = dialog.run()
|
||||
if result == gtk.RESPONSE_ACCEPT:
|
||||
@@ -742,7 +813,7 @@ class appGui(object):
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def check_encryption_valid(self, networkid, entry):
|
||||
""" Make sure that encryption settings are properly filled in. """
|
||||
# Make sure no entries are left blank
|
||||
@@ -751,18 +822,25 @@ class appGui(object):
|
||||
for entry_info in encryption_info.itervalues():
|
||||
if entry_info[0].entry.get_text() == "" and \
|
||||
entry_info[1] == 'required':
|
||||
error(self.window, "%s (%s)" % (_('Required encryption information is missing.'),
|
||||
entry_info[0].label.get_label())
|
||||
)
|
||||
error(
|
||||
self.window,
|
||||
"%s (%s)" %
|
||||
(_('Required encryption information is missing.'),
|
||||
entry_info[0].label.get_label())
|
||||
)
|
||||
return False
|
||||
# Make sure the checkbox is checked when it should be
|
||||
elif not entry.chkbox_encryption.get_active() and \
|
||||
wireless.GetWirelessProperty(networkid, "encryption"):
|
||||
error(self.window, _('This network requires encryption to be enabled.'))
|
||||
error(
|
||||
self.window,
|
||||
_('This network requires encryption to be enabled.')
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
||||
def _wait_for_connect_thread_start(self):
|
||||
""" Wait for the connect thread to start. """
|
||||
self.wTree.get_object("progressbar").pulse()
|
||||
if not self._connect_thread_started:
|
||||
return True
|
||||
@@ -770,19 +848,22 @@ class appGui(object):
|
||||
misc.timeout_add(2, self.update_statusbar)
|
||||
self.update_statusbar()
|
||||
return False
|
||||
|
||||
|
||||
def connect(self, widget, nettype, networkid, networkentry):
|
||||
""" Initiates the connection process in the daemon. """
|
||||
def handler(*args):
|
||||
self._connect_thread_started = True
|
||||
|
||||
def setup_interface_for_connection():
|
||||
""" Initialize interface for connection. """
|
||||
cancel_button = self.wTree.get_object("cancel_button")
|
||||
cancel_button.set_sensitive(True)
|
||||
self.all_network_list.set_sensitive(False)
|
||||
if self.statusID:
|
||||
gobject.idle_add(self.status_bar.remove_message, 1, self.statusID)
|
||||
gobject.idle_add(self.set_status, _('Disconnecting active connections...'))
|
||||
gobject.idle_add(
|
||||
self.status_bar.remove_message, 1, self.statusID)
|
||||
gobject.idle_add(
|
||||
self.set_status, _('Disconnecting active connections...'))
|
||||
gobject.idle_add(self.status_area.show_all)
|
||||
self.wait_for_events()
|
||||
self._connect_thread_started = False
|
||||
@@ -798,25 +879,25 @@ class appGui(object):
|
||||
elif nettype == "wired":
|
||||
setup_interface_for_connection()
|
||||
wired.ConnectWired(reply_handler=handler, error_handler=handler)
|
||||
|
||||
|
||||
gobject.source_remove(self.update_cb)
|
||||
misc.timeout_add(100, self._wait_for_connect_thread_start, milli=True)
|
||||
|
||||
|
||||
def disconnect(self, widget, nettype, networkid, networkentry):
|
||||
""" Disconnects from the given network.
|
||||
|
||||
|
||||
Keyword arguments:
|
||||
widget -- The disconnect button that was pressed.
|
||||
event -- unused
|
||||
nettype -- "wired" or "wireless", depending on the network entry type.
|
||||
networkid -- unused
|
||||
networkentry -- The NetworkEntry containing the disconnect button.
|
||||
|
||||
|
||||
"""
|
||||
def handler(*args):
|
||||
gobject.idle_add(self.all_network_list.set_sensitive, True)
|
||||
gobject.idle_add(self.network_list.set_sensitive, True)
|
||||
|
||||
|
||||
widget.hide()
|
||||
networkentry.connect_button.show()
|
||||
daemon.SetForcedDisconnect(True)
|
||||
@@ -824,16 +905,16 @@ class appGui(object):
|
||||
if nettype == "wired":
|
||||
wired.DisconnectWired(reply_handler=handler, error_handler=handler)
|
||||
else:
|
||||
wireless.DisconnectWireless(reply_handler=handler,
|
||||
wireless.DisconnectWireless(reply_handler=handler,
|
||||
error_handler=handler)
|
||||
|
||||
|
||||
def wait_for_events(self, amt=0):
|
||||
""" Wait for any pending gtk events to finish before moving on.
|
||||
""" Wait for any pending gtk events to finish before moving on.
|
||||
|
||||
Keyword arguments:
|
||||
amt -- a number specifying the number of ms to wait before checking
|
||||
for pending events.
|
||||
|
||||
|
||||
"""
|
||||
time.sleep(amt)
|
||||
while gtk.events_pending():
|
||||
@@ -843,7 +924,7 @@ class appGui(object):
|
||||
""" Hide the wicd GUI.
|
||||
|
||||
This method hides the wicd GUI and writes the current window size
|
||||
to disc for later use. This method normally does NOT actually
|
||||
to disc for later use. This method normally does NOT actually
|
||||
destroy the GUI, it just hides it.
|
||||
|
||||
"""
|
||||
@@ -864,11 +945,11 @@ class appGui(object):
|
||||
return True
|
||||
|
||||
def show_win(self):
|
||||
""" Brings the GUI out of the hidden state.
|
||||
|
||||
""" Brings the GUI out of the hidden state.
|
||||
|
||||
Method to show the wicd GUI, alert the daemon that it is open,
|
||||
and refresh the network list.
|
||||
|
||||
|
||||
"""
|
||||
self.window.present()
|
||||
self.window.deiconify()
|
||||
|
||||
@@ -30,22 +30,27 @@ try:
|
||||
except ImportError:
|
||||
print "Importing pynotify failed, notifications disabled."
|
||||
HAS_NOTIFY = False
|
||||
|
||||
|
||||
print "Has notifications support", HAS_NOTIFY
|
||||
|
||||
if wpath.no_use_notifications:
|
||||
print 'Notifications disabled during setup.py configure'
|
||||
|
||||
|
||||
|
||||
def can_use_notify():
|
||||
""" Check whether WICD is allowed to use notifications. """
|
||||
use_notify = os.path.exists(os.path.join(os.path.expanduser('~/.wicd'),
|
||||
'USE_NOTIFICATIONS')
|
||||
)
|
||||
return use_notify and HAS_NOTIFY and not wpath.no_use_notifications
|
||||
|
||||
def error(parent, message, block=True):
|
||||
|
||||
|
||||
def error(parent, message, block=True):
|
||||
""" Shows an error dialog. """
|
||||
def delete_event(dialog, id):
|
||||
def delete_event(dialog, i):
|
||||
""" Handle dialog destroy. """
|
||||
dialog.destroy()
|
||||
|
||||
if can_use_notify() and not block:
|
||||
notification = pynotify.Notification("ERROR", message, "error")
|
||||
notification.show()
|
||||
@@ -59,11 +64,14 @@ def error(parent, message, block=True):
|
||||
else:
|
||||
dialog.run()
|
||||
dialog.destroy()
|
||||
|
||||
def alert(parent, message, block=True):
|
||||
|
||||
|
||||
def alert(parent, message, block=True):
|
||||
""" Shows an warning dialog. """
|
||||
def delete_event(dialog, id):
|
||||
def delete_event(dialog, i):
|
||||
""" Handle dialog destroy. """
|
||||
dialog.destroy()
|
||||
|
||||
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING,
|
||||
gtk.BUTTONS_OK)
|
||||
dialog.set_markup(message)
|
||||
@@ -74,11 +82,14 @@ def alert(parent, message, block=True):
|
||||
dialog.run()
|
||||
dialog.destroy()
|
||||
|
||||
|
||||
def string_input(prompt, secondary, textbox_label):
|
||||
""" Dialog with a label and an entry. """
|
||||
# based on a version of a PyGTK text entry from
|
||||
# http://ardoris.wordpress.com/2008/07/05/pygtk-text-entry-dialog/
|
||||
|
||||
def dialog_response(entry, dialog, response):
|
||||
""" Handle dialog response. """
|
||||
dialog.response(response)
|
||||
|
||||
dialog = gtk.MessageDialog(
|
||||
@@ -103,6 +114,7 @@ def string_input(prompt, secondary, textbox_label):
|
||||
hbox.pack_start(entry)
|
||||
|
||||
# pack the boxes and show the dialog
|
||||
# pylint: disable-msg=E1101
|
||||
dialog.vbox.pack_end(hbox, True, True, 0)
|
||||
dialog.show_all()
|
||||
|
||||
@@ -114,19 +126,24 @@ def string_input(prompt, secondary, textbox_label):
|
||||
dialog.destroy()
|
||||
return None
|
||||
|
||||
|
||||
class SmallLabel(gtk.Label):
|
||||
""" Small GtkLabel. """
|
||||
def __init__(self, text=''):
|
||||
gtk.Label.__init__(self, text)
|
||||
self.set_size_request(50, -1)
|
||||
|
||||
|
||||
|
||||
class LeftAlignedLabel(gtk.Label):
|
||||
"""GtkLabel with text aligned to left. """
|
||||
def __init__(self, label=None):
|
||||
gtk.Label.__init__(self, label)
|
||||
self.set_alignment(0.0, 0.5)
|
||||
|
||||
|
||||
class LabelEntry(gtk.HBox):
|
||||
""" A label on the left with a textbox on the right. """
|
||||
def __init__(self,text):
|
||||
def __init__(self, text):
|
||||
gtk.HBox.__init__(self)
|
||||
self.entry = gtk.Entry()
|
||||
self.entry.set_size_request(200, -1)
|
||||
@@ -143,27 +160,31 @@ class LabelEntry(gtk.HBox):
|
||||
self.show()
|
||||
|
||||
def set_text(self, text):
|
||||
""" Set text of the GtkEntry. """
|
||||
# For compatibility...
|
||||
self.entry.set_text(text)
|
||||
|
||||
def get_text(self):
|
||||
""" Get text of the GtkEntry. """
|
||||
return self.entry.get_text()
|
||||
|
||||
def set_auto_hidden(self, value):
|
||||
""" Set auto-hide of the text of GtkEntry. """
|
||||
self.entry.set_visibility(False)
|
||||
self.auto_hide_text = value
|
||||
|
||||
def show_characters(self, widget=None, event=None):
|
||||
# When the box has focus, show the characters
|
||||
""" When the box has focus, show the characters. """
|
||||
if self.auto_hide_text and widget:
|
||||
self.entry.set_visibility(True)
|
||||
|
||||
def set_sensitive(self, value):
|
||||
""" Set sensitivity of the widget. """
|
||||
self.entry.set_sensitive(value)
|
||||
self.label.set_sensitive(value)
|
||||
|
||||
def hide_characters(self, widget=None, event=None):
|
||||
# When the box looses focus, hide them
|
||||
""" When the box looses focus, hide them. """
|
||||
if self.auto_hide_text and widget:
|
||||
self.entry.set_visibility(False)
|
||||
|
||||
@@ -202,24 +223,30 @@ class ProtectedLabelEntry(gtk.HBox):
|
||||
self.show()
|
||||
|
||||
def set_entry_text(self, text):
|
||||
""" Set text of the GtkEntry. """
|
||||
# For compatibility...
|
||||
self.entry.set_text(text)
|
||||
|
||||
def get_entry_text(self):
|
||||
""" Get text of the GtkEntry. """
|
||||
return self.entry.get_text()
|
||||
|
||||
def set_sensitive(self, value):
|
||||
""" Set sensitivity of the widget. """
|
||||
self.entry.set_sensitive(value)
|
||||
self.label.set_sensitive(value)
|
||||
self.check.set_sensitive(value)
|
||||
|
||||
def click_handler(self, widget=None, event=None):
|
||||
""" Handle clicks. """
|
||||
active = self.check.get_active()
|
||||
self.entry.set_visibility(active)
|
||||
|
||||
|
||||
class LabelCombo(gtk.HBox):
|
||||
""" A label on the left with a combobox on the right. """
|
||||
def __init__(self,text):
|
||||
|
||||
def __init__(self, text):
|
||||
gtk.HBox.__init__(self)
|
||||
self.combo = gtk.ComboBox()
|
||||
self.combo.set_size_request(200, -1)
|
||||
@@ -236,20 +263,26 @@ class LabelCombo(gtk.HBox):
|
||||
self.show()
|
||||
|
||||
def get_active(self):
|
||||
""" Return the selected item in the GtkComboBox. """
|
||||
return self.combo.get_active()
|
||||
|
||||
def set_active(self, index):
|
||||
""" Set given item in the GtkComboBox. """
|
||||
self.combo.set_active(index)
|
||||
|
||||
def get_active_text(self):
|
||||
""" Return the selected item's text in the GtkComboBox. """
|
||||
return self.combo.get_active_text()
|
||||
|
||||
def get_model(self):
|
||||
""" Return the GtkComboBox's model. """
|
||||
return self.combo.get_model()
|
||||
|
||||
def set_model(self, model=None):
|
||||
""" Set the GtkComboBox's model. """
|
||||
self.combo.set_model(model)
|
||||
|
||||
def set_sensitive(self, value):
|
||||
""" Set sensitivity of the widget. """
|
||||
self.combo.set_sensitive(value)
|
||||
self.label.set_sensitive(value)
|
||||
|
||||
532
gtk/netentry.py
532
gtk/netentry.py
File diff suppressed because it is too large
Load Diff
234
gtk/prefs.py
234
gtk/prefs.py
@@ -26,7 +26,6 @@ handles recieving/sendings the settings from/to the daemon.
|
||||
|
||||
import gtk
|
||||
import gobject
|
||||
#import pango
|
||||
import os
|
||||
|
||||
from wicd import misc
|
||||
@@ -39,25 +38,75 @@ daemon = None
|
||||
wireless = None
|
||||
wired = None
|
||||
|
||||
from wicd.translations import language
|
||||
|
||||
USER_SETTINGS_DIR = os.path.expanduser('~/.wicd/')
|
||||
|
||||
|
||||
def setup_dbus():
|
||||
""" Initialize DBus. """
|
||||
global daemon, wireless, wired
|
||||
daemon = dbusmanager.get_interface('daemon')
|
||||
wireless = dbusmanager.get_interface('wireless')
|
||||
wired = dbusmanager.get_interface('wired')
|
||||
|
||||
|
||||
class PreferencesDialog(object):
|
||||
""" Class for handling the wicd preferences dialog window. """
|
||||
def __init__(self, parent, wTree):
|
||||
setup_dbus()
|
||||
self.parent = parent
|
||||
self.wTree = wTree
|
||||
|
||||
self.ethtoolradio = None
|
||||
self.miitoolradio = None
|
||||
|
||||
self.wpadrivercombo = None
|
||||
self.wpadrivers = None
|
||||
self.backends = None
|
||||
self.backendcombo = None
|
||||
self.be_descriptions = None
|
||||
self.preferwiredcheckbox = None
|
||||
self.useGlobalDNSCheckbox = None
|
||||
self.displaytypecheckbox = None
|
||||
self.verifyapcheckbox = None
|
||||
self.debugmodecheckbox = None
|
||||
self.wiredcheckbox = None
|
||||
self.showneverconnectcheckbox = None
|
||||
self.reconnectcheckbox = None
|
||||
self.notificationscheckbox = None
|
||||
|
||||
self.usedefaultradiobutton = None
|
||||
self.lastusedradiobutton = None
|
||||
self.showlistradiobutton = None
|
||||
|
||||
self.kdesuradio = None
|
||||
self.gksudoradio = None
|
||||
self.sudoautoradio = None
|
||||
self.ktsussradio = None
|
||||
|
||||
self.dhclientradio = None
|
||||
self.dhcpautoradio = None
|
||||
self.pumpradio = None
|
||||
self.udhcpcradio = None
|
||||
self.dhcpcdradio = None
|
||||
|
||||
self.linkautoradio = None
|
||||
self.routeflushradio = None
|
||||
self.ipflushradio = None
|
||||
self.flushautoradio = None
|
||||
|
||||
self.dialog = None
|
||||
self.entryWiredInterface = None
|
||||
self.entryWirelessInterface = None
|
||||
|
||||
self.dns1Entry = None
|
||||
self.dns2Entry = None
|
||||
self.dns3Entry = None
|
||||
self.searchDomEntry = None
|
||||
self.dnsDomEntry = None
|
||||
|
||||
self.prep_settings_diag()
|
||||
self.load_preferences_diag()
|
||||
|
||||
|
||||
def _setup_external_app_radios(self, radio_list, get_method, set_method):
|
||||
""" Generic function for setting up external app radios. """
|
||||
# Disable radios for apps that aren't installed.
|
||||
@@ -71,10 +120,10 @@ class PreferencesDialog(object):
|
||||
# If it isn't, default to Automatic.
|
||||
set_method(misc.AUTO)
|
||||
radio_list[misc.AUTO].set_active(True)
|
||||
|
||||
|
||||
def load_preferences_diag(self):
|
||||
""" Loads data into the preferences Dialog. """
|
||||
|
||||
|
||||
self.wiredcheckbox.set_active(daemon.GetAlwaysShowWiredInterface())
|
||||
self.reconnectcheckbox.set_active(daemon.GetAutoReconnect())
|
||||
self.debugmodecheckbox.set_active(daemon.GetDebugMode())
|
||||
@@ -82,28 +131,30 @@ class PreferencesDialog(object):
|
||||
self.verifyapcheckbox.set_active(daemon.GetShouldVerifyAp())
|
||||
self.preferwiredcheckbox.set_active(daemon.GetPreferWiredNetwork())
|
||||
self.showneverconnectcheckbox.set_active(daemon.GetShowNeverConnect())
|
||||
|
||||
dhcp_list = [self.dhcpautoradio, self.dhclientradio, self.dhcpcdradio,
|
||||
|
||||
dhcp_list = [self.dhcpautoradio, self.dhclientradio, self.dhcpcdradio,
|
||||
self.pumpradio, self.udhcpcradio]
|
||||
self._setup_external_app_radios(dhcp_list, daemon.GetDHCPClient,
|
||||
daemon.SetDHCPClient)
|
||||
|
||||
self._setup_external_app_radios(
|
||||
dhcp_list, daemon.GetDHCPClient, daemon.SetDHCPClient)
|
||||
|
||||
wired_link_list = [self.linkautoradio, self.ethtoolradio,
|
||||
self.miitoolradio]
|
||||
self._setup_external_app_radios(wired_link_list,
|
||||
daemon.GetLinkDetectionTool,
|
||||
daemon.SetLinkDetectionTool)
|
||||
self._setup_external_app_radios(
|
||||
wired_link_list,
|
||||
daemon.GetLinkDetectionTool,
|
||||
daemon.SetLinkDetectionTool
|
||||
)
|
||||
|
||||
flush_list = [self.flushautoradio, self.ipflushradio,
|
||||
self.routeflushradio]
|
||||
self._setup_external_app_radios(flush_list, daemon.GetFlushTool,
|
||||
daemon.SetFlushTool)
|
||||
|
||||
self._setup_external_app_radios(
|
||||
flush_list, daemon.GetFlushTool, daemon.SetFlushTool)
|
||||
|
||||
sudo_list = [self.sudoautoradio, self.gksudoradio, self.kdesuradio,
|
||||
self.ktsussradio]
|
||||
self._setup_external_app_radios(sudo_list, daemon.GetSudoApp,
|
||||
daemon.SetSudoApp)
|
||||
|
||||
self._setup_external_app_radios(
|
||||
sudo_list, daemon.GetSudoApp, daemon.SetSudoApp)
|
||||
|
||||
auto_conn_meth = daemon.GetWiredAutoConnectMethod()
|
||||
if auto_conn_meth == 1:
|
||||
self.usedefaultradiobutton.set_active(True)
|
||||
@@ -111,7 +162,7 @@ class PreferencesDialog(object):
|
||||
self.showlistradiobutton.set_active(True)
|
||||
elif auto_conn_meth == 3:
|
||||
self.lastusedradiobutton.set_active(True)
|
||||
|
||||
|
||||
self.entryWirelessInterface.set_text(daemon.GetWirelessInterface())
|
||||
self.entryWiredInterface.set_text(daemon.GetWiredInterface())
|
||||
|
||||
@@ -121,10 +172,14 @@ class PreferencesDialog(object):
|
||||
except ValueError:
|
||||
self.wpadrivercombo.set_active(0)
|
||||
|
||||
self.useGlobalDNSCheckbox.connect("toggled", checkboxTextboxToggle,
|
||||
(self.dns1Entry, self.dns2Entry,
|
||||
self.dns3Entry, self.dnsDomEntry,
|
||||
self.searchDomEntry))
|
||||
self.useGlobalDNSCheckbox.connect(
|
||||
"toggled",
|
||||
checkboxTextboxToggle,
|
||||
(
|
||||
self.dns1Entry, self.dns2Entry, self.dns3Entry,
|
||||
self.dnsDomEntry, self.searchDomEntry
|
||||
)
|
||||
)
|
||||
|
||||
dns_addresses = daemon.GetGlobalDNSAddresses()
|
||||
self.useGlobalDNSCheckbox.set_active(daemon.GetUseGlobalDNS())
|
||||
@@ -140,7 +195,7 @@ class PreferencesDialog(object):
|
||||
self.dns1Entry.set_sensitive(False)
|
||||
self.dns2Entry.set_sensitive(False)
|
||||
self.dns3Entry.set_sensitive(False)
|
||||
|
||||
|
||||
cur_backend = daemon.GetSavedBackend()
|
||||
try:
|
||||
self.backendcombo.set_active(self.backends.index(cur_backend))
|
||||
@@ -164,24 +219,25 @@ class PreferencesDialog(object):
|
||||
self.notificationscheckbox.set_active(False)
|
||||
self.notificationscheckbox.hide()
|
||||
self.wTree.get_object('label2').hide()
|
||||
|
||||
|
||||
self.wTree.get_object("notebook2").set_current_page(0)
|
||||
|
||||
|
||||
def run(self):
|
||||
""" Runs the preferences dialog window. """
|
||||
return self.dialog.run()
|
||||
|
||||
|
||||
def hide(self):
|
||||
""" Hides the preferences dialog window. """
|
||||
self.dialog.hide()
|
||||
|
||||
|
||||
def destroy(self):
|
||||
""" Destroy dialog. """
|
||||
self.dialog.destroy()
|
||||
|
||||
|
||||
def show_all(self):
|
||||
""" Shows the preferences dialog window. """
|
||||
self.dialog.show()
|
||||
|
||||
|
||||
def save_results(self):
|
||||
""" Pushes the selected settings to the daemon. """
|
||||
daemon.SetUseGlobalDNS(self.useGlobalDNSCheckbox.get_active())
|
||||
@@ -189,9 +245,13 @@ class PreferencesDialog(object):
|
||||
for i in [self.dns1Entry, self.dns2Entry, self.dns3Entry,
|
||||
self.dnsDomEntry, self.searchDomEntry]:
|
||||
i.set_text(i.get_text().strip())
|
||||
daemon.SetGlobalDNS(self.dns1Entry.get_text(), self.dns2Entry.get_text(),
|
||||
self.dns3Entry.get_text(), self.dnsDomEntry.get_text(),
|
||||
self.searchDomEntry.get_text())
|
||||
daemon.SetGlobalDNS(
|
||||
self.dns1Entry.get_text(),
|
||||
self.dns2Entry.get_text(),
|
||||
self.dns3Entry.get_text(),
|
||||
self.dnsDomEntry.get_text(),
|
||||
self.searchDomEntry.get_text()
|
||||
)
|
||||
daemon.SetWirelessInterface(self.entryWirelessInterface.get_text())
|
||||
daemon.SetWiredInterface(self.entryWiredInterface.get_text())
|
||||
daemon.SetWPADriver(self.wpadrivers[self.wpadrivercombo.get_active()])
|
||||
@@ -200,8 +260,10 @@ class PreferencesDialog(object):
|
||||
daemon.SetDebugMode(self.debugmodecheckbox.get_active())
|
||||
daemon.SetSignalDisplayType(int(self.displaytypecheckbox.get_active()))
|
||||
daemon.SetShouldVerifyAp(bool(self.verifyapcheckbox.get_active()))
|
||||
daemon.SetPreferWiredNetwork(bool(self.preferwiredcheckbox.get_active()))
|
||||
daemon.SetShowNeverConnect(bool(self.showneverconnectcheckbox.get_active()))
|
||||
daemon.SetPreferWiredNetwork(
|
||||
bool(self.preferwiredcheckbox.get_active()))
|
||||
daemon.SetShowNeverConnect(
|
||||
bool(self.showneverconnectcheckbox.get_active()))
|
||||
if self.showlistradiobutton.get_active():
|
||||
daemon.SetWiredAutoConnectMethod(2)
|
||||
elif self.lastusedradiobutton.get_active():
|
||||
@@ -210,7 +272,7 @@ class PreferencesDialog(object):
|
||||
daemon.SetWiredAutoConnectMethod(1)
|
||||
|
||||
daemon.SetBackend(self.backends[self.backendcombo.get_active()])
|
||||
|
||||
|
||||
# External Programs Tab
|
||||
if self.dhcpautoradio.get_active():
|
||||
dhcp_client = misc.AUTO
|
||||
@@ -223,7 +285,7 @@ class PreferencesDialog(object):
|
||||
else:
|
||||
dhcp_client = misc.UDHCPC
|
||||
daemon.SetDHCPClient(dhcp_client)
|
||||
|
||||
|
||||
if self.linkautoradio.get_active():
|
||||
link_tool = misc.AUTO
|
||||
elif self.ethtoolradio.get_active():
|
||||
@@ -231,7 +293,7 @@ class PreferencesDialog(object):
|
||||
else:
|
||||
link_tool = misc.MIITOOL
|
||||
daemon.SetLinkDetectionTool(link_tool)
|
||||
|
||||
|
||||
if self.flushautoradio.get_active():
|
||||
flush_tool = misc.AUTO
|
||||
elif self.ipflushradio.get_active():
|
||||
@@ -239,7 +301,7 @@ class PreferencesDialog(object):
|
||||
else:
|
||||
flush_tool = misc.ROUTE
|
||||
daemon.SetFlushTool(flush_tool)
|
||||
|
||||
|
||||
if self.sudoautoradio.get_active():
|
||||
sudo_tool = misc.AUTO
|
||||
elif self.gksudoradio.get_active():
|
||||
@@ -251,7 +313,7 @@ class PreferencesDialog(object):
|
||||
daemon.SetSudoApp(sudo_tool)
|
||||
|
||||
[width, height] = self.dialog.get_size()
|
||||
|
||||
|
||||
not_path = os.path.join(USER_SETTINGS_DIR, 'USE_NOTIFICATIONS')
|
||||
if self.notificationscheckbox.get_active():
|
||||
if not os.path.exists(not_path):
|
||||
@@ -268,7 +330,7 @@ class PreferencesDialog(object):
|
||||
def set_label(self, glade_str, label):
|
||||
""" Sets the label for the given widget in wicd.glade. """
|
||||
self.wTree.get_object(glade_str).set_label(label)
|
||||
|
||||
|
||||
def prep_settings_diag(self):
|
||||
""" Set up anything that doesn't have to be persisted later. """
|
||||
def build_combobox(lbl):
|
||||
@@ -281,7 +343,7 @@ class PreferencesDialog(object):
|
||||
combobox.pack_start(cell, True)
|
||||
combobox.add_attribute(cell, 'text', 0)
|
||||
return combobox
|
||||
|
||||
|
||||
def setup_label(name, lbl=""):
|
||||
""" Sets up a label for the given widget name. """
|
||||
widget = self.wTree.get_object(name)
|
||||
@@ -290,7 +352,7 @@ class PreferencesDialog(object):
|
||||
if widget is None:
|
||||
raise ValueError('widget %s does not exist' % name)
|
||||
return widget
|
||||
|
||||
|
||||
# External Programs tab
|
||||
# self.wTree.get_object("gen_settings_label").set_label(_('General Settings'))
|
||||
# self.wTree.get_object("ext_prog_label").set_label(_('External Programs'))
|
||||
@@ -298,14 +360,14 @@ class PreferencesDialog(object):
|
||||
# self.wTree.get_object("wired_detect_label").set_label(_('Wired Link Detection'))
|
||||
# self.wTree.get_object("route_flush_label").set_label(_('Route Table Flushing'))
|
||||
# self.wTree.get_object("pref_backend_label").set_label(_('Backend') + ":")
|
||||
|
||||
|
||||
# entryWiredAutoMethod = self.wTree.get_object("pref_wired_auto_label")
|
||||
# entryWiredAutoMethod.set_label('Wired Autoconnect Setting:')
|
||||
# entryWiredAutoMethod.set_alignment(0, 0)
|
||||
# atrlist = pango.AttrList()
|
||||
# atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, 50))
|
||||
# entryWiredAutoMethod.set_attributes(atrlist)
|
||||
|
||||
|
||||
# self.set_label("pref_dns1_label", "%s 1" % _('DNS server'))
|
||||
# self.set_label("pref_dns2_label", "%s 2" % _('DNS server'))
|
||||
# self.set_label("pref_dns3_label", "%s 3" % _('DNS server'))
|
||||
@@ -313,62 +375,82 @@ class PreferencesDialog(object):
|
||||
# self.set_label("pref_wifi_label", "%s:" % _('Wireless Interface'))
|
||||
# self.set_label("pref_wired_label", "%s:" % _('Wired Interface'))
|
||||
# self.set_label("pref_driver_label", "%s:" % _('WPA Supplicant Driver'))
|
||||
|
||||
|
||||
self.dialog = self.wTree.get_object("pref_dialog")
|
||||
self.dialog.set_title(_('Preferences'))
|
||||
if os.path.exists(os.path.join(wpath.images, "wicd.png")):
|
||||
self.dialog.set_icon_from_file(os.path.join(wpath.images, "wicd.png"))
|
||||
self.dialog.set_icon_from_file(
|
||||
os.path.join(wpath.images, "wicd.png"))
|
||||
width = int(gtk.gdk.screen_width() / 2.4)
|
||||
if width > 450:
|
||||
width = 450
|
||||
self.dialog.resize(width, int(gtk.gdk.screen_height() / 2))
|
||||
|
||||
self.wiredcheckbox = setup_label("pref_always_check", _('''Always show wired interface'''))
|
||||
|
||||
self.wiredcheckbox = setup_label(
|
||||
"pref_always_check",
|
||||
_('''Always show wired interface''')
|
||||
)
|
||||
self.preferwiredcheckbox = setup_label("pref_prefer_wired_check",
|
||||
"prefer_wired")
|
||||
|
||||
self.reconnectcheckbox = setup_label("pref_auto_check",
|
||||
_('Automatically reconnect on connection loss'))
|
||||
self.showneverconnectcheckbox = setup_label("pref_show_never_connect_check",
|
||||
_('Show never connect networks'))
|
||||
self.showneverconnectcheckbox = setup_label(
|
||||
"pref_show_never_connect_check",
|
||||
_('Show never connect networks')
|
||||
)
|
||||
self.debugmodecheckbox = setup_label("pref_debug_check",
|
||||
_('Enable debug mode'))
|
||||
self.displaytypecheckbox = setup_label("pref_dbm_check",
|
||||
_('Use dBm to measure signal strength'))
|
||||
self.verifyapcheckbox = setup_label("pref_verify_ap_check",
|
||||
_('Ping static gateways after connecting to verify association'))
|
||||
self.usedefaultradiobutton = setup_label("pref_use_def_radio",
|
||||
_('Use default profile on wired autoconnect'))
|
||||
self.showlistradiobutton = setup_label("pref_prompt_radio",
|
||||
_('Prompt for profile on wired autoconnect'))
|
||||
self.lastusedradiobutton = setup_label("pref_use_last_radio",
|
||||
_('Use last used profile on wired autoconnect'))
|
||||
self.displaytypecheckbox = setup_label(
|
||||
"pref_dbm_check",
|
||||
_('Use dBm to measure signal strength')
|
||||
)
|
||||
self.verifyapcheckbox = setup_label(
|
||||
"pref_verify_ap_check",
|
||||
_('Ping static gateways after connecting to verify association')
|
||||
)
|
||||
self.usedefaultradiobutton = setup_label(
|
||||
"pref_use_def_radio",
|
||||
_('Use default profile on wired autoconnect')
|
||||
)
|
||||
self.showlistradiobutton = setup_label(
|
||||
"pref_prompt_radio",
|
||||
_('Prompt for profile on wired autoconnect')
|
||||
)
|
||||
self.lastusedradiobutton = setup_label(
|
||||
"pref_use_last_radio",
|
||||
_('Use last used profile on wired autoconnect')
|
||||
)
|
||||
|
||||
|
||||
self.notificationscheckbox = setup_label("pref_use_libnotify",
|
||||
_('Display notifications about connection status'))
|
||||
self.notificationscheckbox = setup_label(
|
||||
"pref_use_libnotify",
|
||||
_('Display notifications about connection status')
|
||||
)
|
||||
|
||||
# DHCP Clients
|
||||
self.dhcpautoradio = setup_label("dhcp_auto_radio", _('Automatic (recommended)'))
|
||||
self.dhcpautoradio = setup_label(
|
||||
"dhcp_auto_radio", _('Automatic (recommended)'))
|
||||
self.dhclientradio = self.wTree.get_object("dhclient_radio")
|
||||
self.pumpradio = self.wTree.get_object("pump_radio")
|
||||
self.dhcpcdradio = self.wTree.get_object("dhcpcd_radio")
|
||||
self.udhcpcradio = self.wTree.get_object("udhcpc_radio")
|
||||
|
||||
|
||||
# Wired Link Detection Apps
|
||||
self.linkautoradio = setup_label("link_auto_radio", _('Automatic (recommended)'))
|
||||
self.linkautoradio = setup_label(
|
||||
"link_auto_radio", _('Automatic (recommended)'))
|
||||
self.linkautoradio = setup_label("link_auto_radio")
|
||||
self.ethtoolradio = setup_label("ethtool_radio")
|
||||
self.miitoolradio = setup_label("miitool_radio")
|
||||
|
||||
|
||||
# Route Flushing Apps
|
||||
self.flushautoradio = setup_label("flush_auto_radio",
|
||||
_('Automatic (recommended)'))
|
||||
self.ipflushradio = setup_label("ip_flush_radio")
|
||||
self.routeflushradio = setup_label("route_flush_radio")
|
||||
|
||||
|
||||
# Graphical Sudo Apps
|
||||
self.sudoautoradio = setup_label("sudo_auto_radio", _('Automatic (recommended)'))
|
||||
self.sudoautoradio = setup_label(
|
||||
"sudo_auto_radio", _('Automatic (recommended)'))
|
||||
self.gksudoradio = setup_label("gksudo_radio")
|
||||
self.kdesuradio = setup_label("kdesu_radio")
|
||||
self.ktsussradio = setup_label("ktsuss_radio")
|
||||
@@ -384,7 +466,7 @@ class PreferencesDialog(object):
|
||||
|
||||
self.entryWirelessInterface = self.wTree.get_object("pref_wifi_entry")
|
||||
self.entryWiredInterface = self.wTree.get_object("pref_wired_entry")
|
||||
|
||||
|
||||
# Set up global DNS stuff
|
||||
self.useGlobalDNSCheckbox = setup_label("pref_global_check",
|
||||
'use_global_dns')
|
||||
@@ -393,19 +475,19 @@ class PreferencesDialog(object):
|
||||
self.dns1Entry = self.wTree.get_object("pref_dns1_entry")
|
||||
self.dns2Entry = self.wTree.get_object("pref_dns2_entry")
|
||||
self.dns3Entry = self.wTree.get_object("pref_dns3_entry")
|
||||
|
||||
|
||||
self.backendcombo = build_combobox("pref_backend_combobox")
|
||||
self.backendcombo.connect("changed", self.be_combo_changed)
|
||||
# Load backend combobox
|
||||
self.backends = daemon.GetBackendList()
|
||||
self.be_descriptions = daemon.GetBackendDescriptionDict()
|
||||
|
||||
|
||||
for x in self.backends:
|
||||
if x:
|
||||
if x == 'ioctl':
|
||||
x = 'ioctl NOT SUPPORTED'
|
||||
self.backendcombo.append_text(x)
|
||||
|
||||
|
||||
def be_combo_changed(self, combo):
|
||||
""" Update the description label for the given backend. """
|
||||
self.backendcombo.set_tooltip_text(
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
""" wicd - wireless connection daemon frontend implementation
|
||||
|
||||
This module implements a usermode frontend for wicd. It updates connection
|
||||
information, provides an (optional) tray icon, and allows for launching of
|
||||
information, provides an (optional) tray icon, and allows for launching of
|
||||
the wicd GUI and Wired Profile Chooser.
|
||||
|
||||
class TrayIcon() -- Parent class of TrayIconGUI and IconConnectionInfo.
|
||||
@@ -11,7 +11,7 @@ class TrayIcon() -- Parent class of TrayIconGUI and IconConnectionInfo.
|
||||
and updates connection status.
|
||||
class TrayIconGUI() -- Child class of TrayIcon which implements the tray.
|
||||
icon itself. Parent class of StatusTrayIconGUI and EggTrayIconGUI.
|
||||
class StatusTrayIconGUI() -- Implements the tray icon using a
|
||||
class StatusTrayIconGUI() -- Implements the tray icon using a
|
||||
gtk.StatusIcon.
|
||||
class EggTrayIconGUI() -- Implements the tray icon using egg.trayicon.
|
||||
def usage() -- Prints usage information.
|
||||
@@ -42,7 +42,6 @@ import gobject
|
||||
import getopt
|
||||
import os
|
||||
import pango
|
||||
import time
|
||||
import atexit
|
||||
from dbus import DBusException
|
||||
|
||||
@@ -74,27 +73,37 @@ if not hasattr(gtk, "StatusIcon"):
|
||||
import egg.trayicon
|
||||
USE_EGG = True
|
||||
except ImportError:
|
||||
print 'Unable to load tray icon: Missing both egg.trayicon and gtk.StatusIcon modules.'
|
||||
print 'Unable to load tray icon: Missing both egg.trayicon and ' + \
|
||||
'gtk.StatusIcon modules.'
|
||||
ICON_AVAIL = False
|
||||
|
||||
misc.RenameProcess("wicd-client")
|
||||
|
||||
if __name__ == '__main__':
|
||||
wpath.chdir(__file__)
|
||||
|
||||
|
||||
daemon = wireless = wired = lost_dbus_id = None
|
||||
DBUS_AVAIL = False
|
||||
|
||||
theme = gtk.icon_theme_get_default()
|
||||
theme.append_search_path(wpath.images)
|
||||
|
||||
|
||||
def catchdbus(func):
|
||||
""" Decorator to catch DBus exceptions. """
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except DBusException, e:
|
||||
if e.get_dbus_name() != None and "DBus.Error.AccessDenied" in e.get_dbus_name():
|
||||
error(None, _('Unable to contact the Wicd daemon due to an access denied error from DBus. Please check that your user is in the $A group.').replace("$A","<b>"+wpath.wicd_group+"</b>"))
|
||||
if e.get_dbus_name() is not None and \
|
||||
"DBus.Error.AccessDenied" in e.get_dbus_name():
|
||||
error(
|
||||
None,
|
||||
_('Unable to contact the Wicd daemon due to an access '
|
||||
'denied error from DBus. Please check that your user is '
|
||||
'in the $A group.').
|
||||
replace("$A", "<b>" + wpath.wicd_group + "</b>")
|
||||
)
|
||||
#raise
|
||||
raise DBusException(e)
|
||||
else:
|
||||
@@ -105,9 +114,10 @@ def catchdbus(func):
|
||||
wrapper.__dict__ = func.__dict__
|
||||
wrapper.__doc__ = func.__doc__
|
||||
return wrapper
|
||||
|
||||
|
||||
|
||||
class NetworkMenuItem(gtk.ImageMenuItem):
|
||||
""" Network menu item. """
|
||||
def __init__(self, lbl, is_active=False):
|
||||
gtk.ImageMenuItem.__init__(self)
|
||||
self.label = gtk.Label(lbl)
|
||||
@@ -119,13 +129,13 @@ class NetworkMenuItem(gtk.ImageMenuItem):
|
||||
self.label.set_alignment(0, 0)
|
||||
self.add(self.label)
|
||||
self.label.show()
|
||||
|
||||
|
||||
|
||||
class TrayIcon(object):
|
||||
""" Base Tray Icon class.
|
||||
|
||||
|
||||
Base Class for implementing a tray icon to display network status.
|
||||
|
||||
|
||||
"""
|
||||
def __init__(self, animate, displaytray=True, displayapp=False):
|
||||
self.cur_sndbytes = -1
|
||||
@@ -145,13 +155,13 @@ class TrayIcon(object):
|
||||
self.tr.icon_info = self.icon_info
|
||||
print 'displaytray %s' % displaytray
|
||||
self.tr.visible(displaytray)
|
||||
|
||||
|
||||
def is_embedded(self):
|
||||
if USE_EGG:
|
||||
raise NotImplementedError()
|
||||
else:
|
||||
return self.tr.is_embedded()
|
||||
|
||||
return self.tr.is_embedded() # pylint: disable-msg=E1103
|
||||
|
||||
def get_bandwidth_bytes(self):
|
||||
""" Gets the amount of byte sent sine the last time I checked """
|
||||
dev_dir = '/sys/class/net/'
|
||||
@@ -161,13 +171,15 @@ class TrayIcon(object):
|
||||
if fldr == iface:
|
||||
dev_dir = dev_dir + fldr + "/statistics/"
|
||||
break
|
||||
|
||||
|
||||
try:
|
||||
self.cur_rcvbytes = int(open(dev_dir + "rx_bytes", "r").read().strip())
|
||||
self.cur_sndbytes = int(open(dev_dir + "tx_bytes", "r").read().strip())
|
||||
except:
|
||||
self.cur_sndbytes = -1
|
||||
self.cur_rcvbytes = -1
|
||||
self.cur_rcvbytes = int(
|
||||
open(dev_dir + "rx_bytes", "r").read().strip())
|
||||
self.cur_sndbytes = int(
|
||||
open(dev_dir + "tx_bytes", "r").read().strip())
|
||||
except (IOError, OSError, ValueError):
|
||||
self.cur_sndbytes = -1
|
||||
self.cur_rcvbytes = -1
|
||||
|
||||
class TrayConnectionInfo(object):
|
||||
""" Class for updating the tray icon status. """
|
||||
@@ -234,8 +246,8 @@ class TrayIcon(object):
|
||||
if self.should_notify:
|
||||
try:
|
||||
if not self._last_bubble:
|
||||
self._last_bubble = pynotify.Notification(title, details,
|
||||
image)
|
||||
self._last_bubble = pynotify.Notification(
|
||||
title, details, image)
|
||||
self._last_bubble.show()
|
||||
else:
|
||||
self._last_bubble.clear_actions()
|
||||
@@ -258,20 +270,20 @@ class TrayIcon(object):
|
||||
""" Launch the wired profile chooser. """
|
||||
gui.WiredProfileChooser()
|
||||
daemon.SetNeedWiredProfileChooser(False)
|
||||
|
||||
|
||||
def set_wired_state(self, info):
|
||||
""" Sets the icon info for a wired state. """
|
||||
wired_ip = info[0]
|
||||
self.network_addr = str(info[0])
|
||||
self.network_type = "wired"
|
||||
self.tr.set_from_name('wired')
|
||||
# status_string = _('Connected to wired network (IP: $A)').replace('$A',
|
||||
#wired_ip)
|
||||
# self.tr.set_tooltip(status_string)
|
||||
#status_string = _('Connected to wired network (IP: $A)'). \
|
||||
# replace('$A',wired_ip)
|
||||
#self.tr.set_tooltip(status_string)
|
||||
self._show_notification(_('Wired Network'),
|
||||
_('Connection established'),
|
||||
'network-wired')
|
||||
|
||||
|
||||
self.update_tooltip()
|
||||
|
||||
@catchdbus
|
||||
@@ -289,22 +301,21 @@ class TrayIcon(object):
|
||||
self.network_str = sig_string
|
||||
self.network_br = info[4]
|
||||
self.set_signal_image(int(info[2]), lock)
|
||||
|
||||
|
||||
if wireless.GetWirelessProperty(cur_net_id, "encryption"):
|
||||
lock = "-lock"
|
||||
# status_string = (_('Connected to $A at $B (IP: $C)')
|
||||
#.replace('$A', self.network)
|
||||
# .replace('$B', sig_string)
|
||||
# .replace('$C', str(wireless_ip)))
|
||||
# .replace('$C', str(wireless_ip)))
|
||||
#self.tr.set_tooltip(status_string)
|
||||
self.set_signal_image(int(strength), lock)
|
||||
self._show_notification(self.network,
|
||||
_('Connection established'),
|
||||
'network-wireless')
|
||||
|
||||
|
||||
|
||||
self.update_tooltip()
|
||||
|
||||
|
||||
def set_connecting_state(self, info):
|
||||
""" Sets the icon info for a connecting state. """
|
||||
wired = False
|
||||
@@ -327,7 +338,6 @@ class TrayIcon(object):
|
||||
_('Establishing connection...'),
|
||||
'network-wireless')
|
||||
|
||||
|
||||
@catchdbus
|
||||
def set_not_connected_state(self, info=None):
|
||||
""" Set the icon info for the not connected state. """
|
||||
@@ -335,7 +345,7 @@ class TrayIcon(object):
|
||||
if not DBUS_AVAIL:
|
||||
status = _('Wicd daemon unreachable')
|
||||
elif wireless.GetKillSwitchEnabled():
|
||||
status = (_('Not connected') + " (" +
|
||||
status = (_('Not connected') + " (" +
|
||||
_('Wireless Kill Switch Enabled') + ")")
|
||||
else:
|
||||
status = _('Not connected')
|
||||
@@ -346,17 +356,18 @@ class TrayIcon(object):
|
||||
@catchdbus
|
||||
def update_tray_icon(self, state=None, info=None):
|
||||
""" Updates the tray icon and current connection status. """
|
||||
if not DBUS_AVAIL: return False
|
||||
if not DBUS_AVAIL:
|
||||
return False
|
||||
|
||||
if not state or not info:
|
||||
[state, info] = daemon.GetConnectionStatus()
|
||||
|
||||
# should this state change display a notification?
|
||||
self.should_notify = (can_use_notify() and
|
||||
self.should_notify = (can_use_notify() and
|
||||
self.last_state != state)
|
||||
|
||||
self.last_state = state
|
||||
|
||||
|
||||
if state == misc.WIRED:
|
||||
self.set_wired_state(info)
|
||||
elif state == misc.WIRELESS:
|
||||
@@ -398,13 +409,13 @@ class TrayIcon(object):
|
||||
signal_img = "bad-signal"
|
||||
img_name = ''.join([prefix, signal_img, lock])
|
||||
self.tr.set_from_name(img_name)
|
||||
|
||||
|
||||
@catchdbus
|
||||
def get_bandwidth_activity(self):
|
||||
""" Determines what network activity state we are in. """
|
||||
transmitting = False
|
||||
receiving = False
|
||||
|
||||
|
||||
dev_dir = '/sys/class/net/'
|
||||
wiface = daemon.GetWirelessInterface()
|
||||
for fldr in os.listdir(dev_dir):
|
||||
@@ -417,26 +428,26 @@ class TrayIcon(object):
|
||||
except IOError:
|
||||
sndbytes = None
|
||||
rcvbytes = None
|
||||
|
||||
|
||||
if not rcvbytes or not sndbytes:
|
||||
return 'idle-'
|
||||
|
||||
|
||||
# Figure out receiving data info.
|
||||
activity = self.is_network_active(self.parent.cur_rcvbytes,
|
||||
activity = self.is_network_active(self.parent.cur_rcvbytes,
|
||||
self.parent.max_rcv_gain,
|
||||
self.parent.last_rcvbytes)
|
||||
receiving = activity[0]
|
||||
self.parent.max_rcv_gain = activity[1]
|
||||
self.parent.last_rcvbytes = activity[2]
|
||||
|
||||
|
||||
# Figure out out transmitting data info.
|
||||
activity = self.is_network_active(self.parent.cur_sndbytes,
|
||||
activity = self.is_network_active(self.parent.cur_sndbytes,
|
||||
self.parent.max_snd_gain,
|
||||
self.parent.last_sndbytes)
|
||||
transmitting = activity[0]
|
||||
self.parent.max_snd_gain = activity[1]
|
||||
self.parent.last_sndbytes = activity[2]
|
||||
|
||||
|
||||
if transmitting and receiving:
|
||||
return 'both-'
|
||||
elif transmitting:
|
||||
@@ -445,21 +456,21 @@ class TrayIcon(object):
|
||||
return 'receiving-'
|
||||
else:
|
||||
return 'idle-'
|
||||
|
||||
|
||||
def is_network_active(self, bytes, max_gain, last_bytes):
|
||||
""" Determines if a network is active.
|
||||
|
||||
|
||||
Determines if a network is active by looking at the
|
||||
number of bytes sent since the previous check. This method
|
||||
is generic, and can be used to determine activity in both
|
||||
the sending and receiving directions.
|
||||
|
||||
|
||||
Returns:
|
||||
A tuple containing three elements:
|
||||
1) a boolean specifying if the network is active.
|
||||
2) an int specifying the maximum gain the network has had.
|
||||
3) an int specifying the last recorded number of bytes sent.
|
||||
|
||||
|
||||
"""
|
||||
active = False
|
||||
if last_bytes == -1:
|
||||
@@ -467,21 +478,24 @@ class TrayIcon(object):
|
||||
elif bytes > (last_bytes + float(max_gain / 20.0)):
|
||||
last_bytes = bytes
|
||||
active = True
|
||||
|
||||
|
||||
gain = bytes - last_bytes
|
||||
if gain > max_gain:
|
||||
max_gain = gain
|
||||
return (active, max_gain, last_bytes)
|
||||
|
||||
|
||||
class TrayIconGUI(object):
|
||||
""" Base Tray Icon UI class.
|
||||
|
||||
|
||||
Implements methods and variables used by both egg/StatusIcon
|
||||
tray icons.
|
||||
|
||||
"""
|
||||
def __init__(self, parent):
|
||||
self.list = []
|
||||
self.label = None
|
||||
self.data = None
|
||||
|
||||
menu = """
|
||||
<ui>
|
||||
<menubar name="Menubar">
|
||||
@@ -496,13 +510,13 @@ class TrayIcon(object):
|
||||
</ui>
|
||||
"""
|
||||
actions = [
|
||||
('Menu', None, 'Menu'),
|
||||
('Menu', None, 'Menu'),
|
||||
('Connect', gtk.STOCK_CONNECT, _('Connect')),
|
||||
('Info', gtk.STOCK_INFO, _('_Connection Info'), None,
|
||||
_('Information about the current connection'),
|
||||
self.on_conn_info),
|
||||
('Quit',gtk.STOCK_QUIT,_('_Quit'),None,_('Quit wicd-tray-icon'),
|
||||
self.on_quit),
|
||||
_('Information about the current connection'),
|
||||
self.on_conn_info),
|
||||
('Quit', gtk.STOCK_QUIT, _('_Quit'), None,
|
||||
_('Quit wicd-tray-icon'), self.on_quit),
|
||||
]
|
||||
actg = gtk.ActionGroup('Actions')
|
||||
actg.add_actions(actions)
|
||||
@@ -516,30 +530,34 @@ class TrayIcon(object):
|
||||
self._is_scanning = False
|
||||
net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/")
|
||||
net_menuitem.connect("activate", self.on_net_menu_activate)
|
||||
|
||||
|
||||
self.parent = parent
|
||||
self.time = 2 # Time between updates
|
||||
self.cont = 'Stop'
|
||||
self.conn_info_txt = ''
|
||||
|
||||
|
||||
def tray_scan_started(self):
|
||||
""" Callback for when a wireless scan is started. """
|
||||
if not DBUS_AVAIL: return
|
||||
if not DBUS_AVAIL:
|
||||
return
|
||||
self._is_scanning = True
|
||||
self.init_network_menu()
|
||||
|
||||
|
||||
def tray_scan_ended(self):
|
||||
""" Callback for when a wireless scan finishes. """
|
||||
if not DBUS_AVAIL: return
|
||||
if not DBUS_AVAIL:
|
||||
return
|
||||
self._is_scanning = False
|
||||
self.populate_network_menu()
|
||||
|
||||
|
||||
def on_activate(self, data=None):
|
||||
""" Opens the wicd GUI. """
|
||||
if DBUS_AVAIL:
|
||||
self.toggle_wicd_gui()
|
||||
else:
|
||||
# error(None, _('The wicd daemon is unavailable, so your request cannot be completed'))
|
||||
#error(None,
|
||||
#_('The wicd daemon is unavailable, so your request '
|
||||
# 'cannot be completed'))
|
||||
pass
|
||||
|
||||
def on_quit(self, widget=None):
|
||||
@@ -558,8 +576,13 @@ class TrayIcon(object):
|
||||
|
||||
def on_conn_info(self, data=None):
|
||||
""" Opens the Connection Information Dialog """
|
||||
window = gtk.Dialog("Wicd Connection Info", None, 0, (gtk.STOCK_OK, gtk.RESPONSE_CLOSE))
|
||||
|
||||
window = gtk.Dialog(
|
||||
"Wicd Connection Info",
|
||||
None,
|
||||
0,
|
||||
(gtk.STOCK_OK, gtk.RESPONSE_CLOSE)
|
||||
)
|
||||
|
||||
# Create labels
|
||||
self.label = gtk.Label()
|
||||
self.data = gtk.Label()
|
||||
@@ -571,43 +594,43 @@ class TrayIcon(object):
|
||||
self.list.append(self.label)
|
||||
|
||||
# Setup table
|
||||
table = gtk.Table(1,2)
|
||||
table = gtk.Table(1, 2)
|
||||
table.set_col_spacings(12)
|
||||
table.attach(self.label, 0, 1, 0, 1)
|
||||
table.attach(self.data, 1, 2, 0 ,1)
|
||||
table.attach(self.data, 1, 2, 0, 1)
|
||||
|
||||
# Setup Window
|
||||
content = window.get_content_area()
|
||||
content.pack_start(table, True, True, 0)
|
||||
content.show_all()
|
||||
|
||||
|
||||
# Start updates
|
||||
self.cont = 'Go'
|
||||
gobject.timeout_add(5000, self.update_conn_info_win, self.list)
|
||||
self.update_conn_info_win(self.list)
|
||||
|
||||
|
||||
window.run()
|
||||
|
||||
|
||||
# Destroy window and stop updates
|
||||
window.destroy()
|
||||
self.cont = 'Stop'
|
||||
|
||||
def update_conn_info_win(self, list):
|
||||
|
||||
def update_conn_info_win(self, l):
|
||||
""" Updates the information in the connection summary window """
|
||||
if (self.cont == "Stop"):
|
||||
return False
|
||||
|
||||
|
||||
[state, info] = daemon.GetConnectionStatus()
|
||||
[rx, tx] = self.get_current_bandwidth()
|
||||
|
||||
|
||||
# Choose info for the data
|
||||
if state == misc.WIRED:
|
||||
text = (_('''$A
|
||||
$B KB/s
|
||||
$C KB/s''')
|
||||
.replace('$A', str(info[0])) #IP
|
||||
.replace('$B', str(rx)) #RX
|
||||
.replace('$C', str(tx))) #TX
|
||||
.replace('$A', str(info[0])) # IP
|
||||
.replace('$B', str(rx)) # RX
|
||||
.replace('$C', str(tx))) # TX
|
||||
elif state == misc.WIRELESS:
|
||||
text = (_('''$A
|
||||
$B
|
||||
@@ -615,10 +638,11 @@ $C
|
||||
$D
|
||||
$E KB/s
|
||||
$F KB/s''')
|
||||
.replace('$A', str(info[1])) #SSID
|
||||
.replace('$B', str(info[4])) #Speed
|
||||
.replace('$C', str(info[0])) #IP
|
||||
.replace('$D', daemon.FormatSignalForPrinting(str(info[2])))
|
||||
.replace('$A', str(info[1])) # SSID
|
||||
.replace('$B', str(info[4])) # Speed
|
||||
.replace('$C', str(info[0])) # IP
|
||||
.replace('$D',
|
||||
daemon.FormatSignalForPrinting(str(info[2])))
|
||||
.replace('$E', str(rx))
|
||||
.replace('$F', str(tx)))
|
||||
else:
|
||||
@@ -643,11 +667,11 @@ TX:'''))
|
||||
self.list[1].set_text(_('Connecting'))
|
||||
elif state in (misc.SUSPENDED, misc.NOT_CONNECTED):
|
||||
self.list[1].set_text(_('Disconnected'))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
return True
|
||||
|
||||
def get_current_bandwidth(self):
|
||||
"""
|
||||
"""
|
||||
Calculates the current bandwidth based on sent/received bytes
|
||||
divided over time. Unit is in KB/s
|
||||
"""
|
||||
@@ -660,10 +684,10 @@ TX:'''))
|
||||
|
||||
rx_rate = float(rxb / (self.time * 1024))
|
||||
tx_rate = float(txb / (self.time * 1024))
|
||||
|
||||
|
||||
return (rx_rate, tx_rate)
|
||||
|
||||
def _add_item_to_menu(self, net_menu, lbl, type_, n_id, is_connecting,
|
||||
|
||||
def _add_item_to_menu(self, net_menu, lbl, type_, n_id, is_connecting,
|
||||
is_active):
|
||||
""" Add an item to the network list submenu. """
|
||||
def network_selected(widget, net_type, net_id):
|
||||
@@ -672,10 +696,10 @@ TX:'''))
|
||||
wired.ConnectWired()
|
||||
else:
|
||||
wireless.ConnectWireless(net_id)
|
||||
|
||||
|
||||
item = NetworkMenuItem(lbl, is_active)
|
||||
image = gtk.Image()
|
||||
|
||||
|
||||
if type_ == "__wired__":
|
||||
image.set_from_icon_name("network-wired", 2)
|
||||
else:
|
||||
@@ -686,19 +710,19 @@ TX:'''))
|
||||
net_menu.append(item)
|
||||
item.show()
|
||||
if is_connecting:
|
||||
item.set_sensitive(False)
|
||||
item.set_sensitive(False)
|
||||
del item
|
||||
|
||||
|
||||
@catchdbus
|
||||
def _get_img(self, net_id):
|
||||
""" Determines which image to use for the wireless entries. """
|
||||
def fix_strength(val, default):
|
||||
""" Assigns given strength to a default value if needed. """
|
||||
return val and int(val) or default
|
||||
|
||||
|
||||
def get_prop(prop):
|
||||
return wireless.GetWirelessProperty(net_id, prop)
|
||||
|
||||
|
||||
strength = fix_strength(get_prop("quality"), -1)
|
||||
dbm_strength = fix_strength(get_prop('strength'), -100)
|
||||
|
||||
@@ -722,26 +746,27 @@ TX:'''))
|
||||
else:
|
||||
signal_img = 'signal-25'
|
||||
return signal_img
|
||||
|
||||
|
||||
@catchdbus
|
||||
def on_net_menu_activate(self, item):
|
||||
""" Trigger a background scan to populate the network menu.
|
||||
|
||||
""" Trigger a background scan to populate the network menu.
|
||||
|
||||
Called when the network submenu is moused over. We
|
||||
sleep briefly, clear pending gtk events, and if
|
||||
we're still being moused over we trigger a scan.
|
||||
This is to prevent scans when the user is just
|
||||
mousing past the menu to select another menu item.
|
||||
|
||||
|
||||
"""
|
||||
def dummy(x=None): pass
|
||||
|
||||
def dummy(x=None):
|
||||
pass
|
||||
|
||||
if self._is_scanning:
|
||||
return True
|
||||
|
||||
|
||||
self.init_network_menu()
|
||||
gobject.timeout_add(800, self._trigger_scan_if_needed, item)
|
||||
|
||||
|
||||
@catchdbus
|
||||
def _trigger_scan_if_needed(self, item):
|
||||
""" Trigger a scan if the network menu is being hovered over. """
|
||||
@@ -751,7 +776,7 @@ TX:'''))
|
||||
return True
|
||||
wireless.Scan(False)
|
||||
return False
|
||||
|
||||
|
||||
@catchdbus
|
||||
def populate_network_menu(self, data=None):
|
||||
""" Populates the network list submenu. """
|
||||
@@ -768,7 +793,7 @@ TX:'''))
|
||||
is_connecting = daemon.CheckIfConnecting()
|
||||
num_networks = wireless.GetNumberOfNetworks()
|
||||
[status, info] = daemon.GetConnectionStatus()
|
||||
|
||||
|
||||
if daemon.GetAlwaysShowWiredInterface() or \
|
||||
wired.CheckPluggedIn():
|
||||
if status == misc.WIRED:
|
||||
@@ -780,11 +805,13 @@ TX:'''))
|
||||
sep = gtk.SeparatorMenuItem()
|
||||
submenu.append(sep)
|
||||
sep.show()
|
||||
|
||||
|
||||
if num_networks > 0:
|
||||
skip_never_connect = not daemon.GetShowNeverConnect()
|
||||
for x in xrange(0, num_networks):
|
||||
if skip_never_connect and misc.to_bool(get_prop(x,"never")): continue
|
||||
if skip_never_connect and \
|
||||
misc.to_bool(get_prop(x,"never")):
|
||||
continue
|
||||
essid = get_prop(x, "essid")
|
||||
if status == misc.WIRELESS and info[1] == essid:
|
||||
is_active = True
|
||||
@@ -800,7 +827,7 @@ TX:'''))
|
||||
|
||||
submenu.reposition()
|
||||
net_menuitem.show()
|
||||
|
||||
|
||||
def init_network_menu(self):
|
||||
""" Set the right-click network menu to the scanning state. """
|
||||
net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/")
|
||||
@@ -812,13 +839,13 @@ TX:'''))
|
||||
loading_item.show()
|
||||
submenu.append(loading_item)
|
||||
net_menuitem.show()
|
||||
|
||||
|
||||
def _clear_menu(self, menu):
|
||||
""" Clear the right-click menu. """
|
||||
for item in menu.get_children():
|
||||
menu.remove(item)
|
||||
item.destroy()
|
||||
|
||||
|
||||
def toggle_wicd_gui(self):
|
||||
""" Toggles the wicd GUI. """
|
||||
if not self.gui_win:
|
||||
@@ -828,16 +855,15 @@ TX:'''))
|
||||
else:
|
||||
self.gui_win.exit()
|
||||
return True
|
||||
|
||||
|
||||
if USE_EGG:
|
||||
class EggTrayIconGUI(TrayIconGUI):
|
||||
""" Tray Icon for gtk < 2.10.
|
||||
|
||||
|
||||
Uses the deprecated egg.trayicon module to implement the tray icon.
|
||||
Since it relies on a deprecated module, this class is only used
|
||||
for machines running versions of GTK < 2.10.
|
||||
|
||||
|
||||
"""
|
||||
def __init__(self, parent):
|
||||
"""Initializes the tray icon"""
|
||||
@@ -864,11 +890,15 @@ TX:'''))
|
||||
|
||||
def set_from_file(self, val=None):
|
||||
""" Calls set_from_file on the gtk.Image for the tray icon. """
|
||||
self.pic.set_from_file(os.path.join(wpath.images, 'hicolor/22x22/status/%s.png' % val))
|
||||
self.pic.set_from_file(
|
||||
os.path.join(
|
||||
wpath.images, 'hicolor/22x22/status/%s.png' % val
|
||||
)
|
||||
)
|
||||
|
||||
def set_tooltip(self, val):
|
||||
""" Set the tooltip for this tray icon.
|
||||
|
||||
|
||||
Sets the tooltip for the gtk.ToolTips associated with this
|
||||
tray icon.
|
||||
|
||||
@@ -887,13 +917,12 @@ TX:'''))
|
||||
else:
|
||||
self.tray.hide_all()
|
||||
|
||||
|
||||
if hasattr(gtk, "StatusIcon"):
|
||||
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, parent):
|
||||
TrayIcon.TrayIconGUI.__init__(self, parent)
|
||||
@@ -930,7 +959,7 @@ TX:'''))
|
||||
def usage():
|
||||
""" Print usage information. """
|
||||
print """
|
||||
wicd %s
|
||||
wicd %s
|
||||
wireless (and wired) connection daemon front-end.
|
||||
|
||||
Arguments:
|
||||
@@ -941,23 +970,29 @@ Arguments:
|
||||
\t-o\t--only-notifications\tDon't display anything except notifications.
|
||||
""" % wpath.version
|
||||
|
||||
|
||||
def setup_dbus(force=True):
|
||||
""" Initialize DBus. """
|
||||
global daemon, wireless, wired, DBUS_AVAIL, lost_dbus_id
|
||||
print "Connecting to daemon..."
|
||||
try:
|
||||
dbusmanager.connect_to_dbus()
|
||||
except DBusException:
|
||||
if force:
|
||||
print "Can't connect to the daemon, trying to start it automatically..."
|
||||
print "Can't connect to the daemon, trying to start it " + \
|
||||
"automatically..."
|
||||
misc.PromptToStartDaemon()
|
||||
try:
|
||||
dbusmanager.connect_to_dbus()
|
||||
except DBusException:
|
||||
error(None, _("Could not connect to wicd's D-Bus interface. Check the wicd log for error messages."))
|
||||
error(None,
|
||||
_("Could not connect to wicd's D-Bus interface. Check "
|
||||
"the wicd log for error messages.")
|
||||
)
|
||||
return False
|
||||
else:
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
if lost_dbus_id:
|
||||
gobject.source_remove(lost_dbus_id)
|
||||
lost_dbus_id = None
|
||||
@@ -969,23 +1004,32 @@ def setup_dbus(force=True):
|
||||
print "Connected."
|
||||
return True
|
||||
|
||||
|
||||
def on_exit():
|
||||
""" Handle GUI exit. """
|
||||
if DBUS_AVAIL:
|
||||
try:
|
||||
daemon.SetGUIOpen(False)
|
||||
except DBusException:
|
||||
pass
|
||||
|
||||
|
||||
def handle_no_dbus():
|
||||
""" Called when dbus announces its shutting down. """
|
||||
global DBUS_AVAIL, lost_dbus_id
|
||||
DBUS_AVAIL = False
|
||||
gui.handle_no_dbus(from_tray=True)
|
||||
print "Wicd daemon is shutting down!"
|
||||
lost_dbus_id = misc.timeout_add(5, lambda:error(None, _('The wicd daemon has shut down. The UI will not function properly until it is restarted.'),
|
||||
block=False))
|
||||
lost_dbus_id = misc.timeout_add(5,
|
||||
lambda: error(None,
|
||||
_('The wicd daemon has shut down. The UI will not function '
|
||||
'properly until it is restarted.'),
|
||||
block=False
|
||||
)
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
@catchdbus
|
||||
def main(argv):
|
||||
""" The main frontend program.
|
||||
@@ -995,10 +1039,11 @@ def main(argv):
|
||||
|
||||
"""
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], 'tnhao', ['help', 'no-tray',
|
||||
'tray',
|
||||
'no-animate',
|
||||
'only-notifications'])
|
||||
opts, args = getopt.getopt(
|
||||
sys.argv[1:],
|
||||
'tnhao',
|
||||
['help', 'no-tray', 'tray', 'no-animate', 'only-notifications']
|
||||
)
|
||||
except getopt.GetoptError:
|
||||
# Print help information and exit
|
||||
usage()
|
||||
@@ -1024,13 +1069,13 @@ def main(argv):
|
||||
else:
|
||||
usage()
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
print 'Loading...'
|
||||
setup_dbus()
|
||||
atexit.register(on_exit)
|
||||
|
||||
if display_app and not use_tray or not ICON_AVAIL:
|
||||
the_gui = gui.appGui(standalone=True)
|
||||
gui.appGui(standalone=True)
|
||||
mainloop = gobject.MainLoop()
|
||||
mainloop.run()
|
||||
sys.exit(0)
|
||||
@@ -1043,7 +1088,7 @@ def main(argv):
|
||||
if DBUS_AVAIL and daemon.GetNeedWiredProfileChooser():
|
||||
daemon.SetNeedWiredProfileChooser(False)
|
||||
tray_icon.icon_info.wired_profile_chooser()
|
||||
|
||||
|
||||
bus = dbusmanager.get_bus()
|
||||
bus.add_signal_receiver(tray_icon.icon_info.wired_profile_chooser,
|
||||
'LaunchChooser', 'org.wicd.daemon')
|
||||
@@ -1053,9 +1098,13 @@ def main(argv):
|
||||
'org.wicd.daemon.wireless')
|
||||
bus.add_signal_receiver(tray_icon.tr.tray_scan_started,
|
||||
'SendStartScanSignal', 'org.wicd.daemon.wireless')
|
||||
bus.add_signal_receiver(lambda: (handle_no_dbus() or
|
||||
tray_icon.icon_info.set_not_connected_state()),
|
||||
"DaemonClosing", 'org.wicd.daemon')
|
||||
bus.add_signal_receiver(
|
||||
lambda: (
|
||||
handle_no_dbus() or tray_icon.icon_info.set_not_connected_state()
|
||||
),
|
||||
"DaemonClosing",
|
||||
'org.wicd.daemon'
|
||||
)
|
||||
bus.add_signal_receiver(lambda: setup_dbus(force=False), "DaemonStarting",
|
||||
"org.wicd.daemon")
|
||||
print 'Done loading.'
|
||||
|
||||
Reference in New Issue
Block a user