1
0
mirror of https://github.com/gryf/wicd.git synced 2026-03-28 06:53:32 +01:00

Merged latest changes from NaCl's branch.

This commit is contained in:
Robby Workman
2009-01-21 22:12:51 -06:00
24 changed files with 999 additions and 516 deletions

View File

@@ -22,11 +22,13 @@ D : disconnect from all active networks
ESC : if connecting to a network, stop doing so ESC : if connecting to a network, stop doing so
ENTER : Attempt connection to selected network ENTER : Attempt connection to selected network
P : Display preferences dialog P : Display preferences dialog
C : Display network configuration for selected network (only works for C : Display network configuration for selected network
wireless at the moment)
A : Display "About" dialog A : Display "About" dialog
I : Raise the "Scan for hidden networks" dialog I : Raise the "Scan for hidden networks" dialog
H : Raise help dialog H : Raise help dialog
S : Provide instructions for configuring scripts
delete : Delete selected wired network profile (from the wired ComboBox)
F2 : Rename selected wired network profile (from the wired ComboBox)
IN DIALOGS (Meta usually is "Alt"): IN DIALOGS (Meta usually is "Alt"):
ESC or Q: Quit dialog without saving information (if present) ESC or Q: Quit dialog without saving information (if present)

View File

@@ -1,6 +1,5 @@
Things to do (in no particular order): Things to do (in no particular order):
* Make a network config dialog for wired interfaces
* Implement a keyhandler function for the overall frame * Implement a keyhandler function for the overall frame
* Make keystrokes customizable * Make keystrokes customizable
* Make color schemes customizable * Make color schemes customizable

139
curses/configscript_curses.py Executable file
View File

@@ -0,0 +1,139 @@
#!/usr/bin/env python
"""configscript_curses.py
Kind of like configscript.py, except writtwn using urwid.
Also recycles a lot of configscript.py, too. :-)
"""
# Copyright (C) 2009 Andrew Psaltis
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
from wicd import misc
import configscript
from configscript import write_scripts,get_script_info,get_val,none_to_blank,blank_to_none
import urwid
import urwid.curses_display
import sys
import os
_ = misc.get_gettext()
language = {}
language['configure_scripts'] = _("Configure Scripts")
language['before_script'] = _("Pre-connection Script")
language['after_script'] = _("Post-connection Script")
language['disconnect_script'] = _("Disconnection Script")
def main(argv):
global ui,frame
if len(argv) < 2:
print 'Network id to configure is missing, aborting.'
sys.exit(1)
ui = urwid.curses_display.Screen()
ui.register_palette( [
('body','default','default'),
('focus','dark magenta','light gray'),
('editcp', 'default', 'default', 'standout'),
('editbx', 'light gray', 'dark blue'),
('editfc', 'white','dark blue', 'bold')] )
network = argv[1]
network_type = argv[2]
script_info = get_script_info(network, network_type)
blank = urwid.Text('')
pre_entry_t = ('body',language['before_script']+': ')
post_entry_t = ('body',language['after_script']+': ')
disconnect_entry_t = ('body',language['disconnect_script']+': ')
global pre_entry,post_entry,disconnect_entry
pre_entry = urwid.AttrWrap(urwid.Edit(pre_entry_t,
none_to_blank(script_info.get('pre_entry'))),'editbx','editfc' )
post_entry = urwid.AttrWrap(urwid.Edit(post_entry_t,
none_to_blank(script_info.get('post_entry'))),'editbx','editfc' )
disconnect_entry = urwid.AttrWrap(urwid.Edit(disconnect_entry_t,
none_to_blank(script_info.get('disconnect_entry'))),'editbx','editfc' )
# The buttons
ok_button = urwid.AttrWrap(urwid.Button('OK',ok_callback),'body','focus')
cancel_button = urwid.AttrWrap(urwid.Button('Cancel',cancel_callback),'body','focus')
button_cols = urwid.Columns([ok_button,cancel_button],dividechars=1)
lbox = urwid.Pile([('fixed',2,urwid.Filler(pre_entry)),
#('fixed',urwid.Filler(blank),1),
('fixed',2,urwid.Filler(post_entry)),
('fixed',2,urwid.Filler(disconnect_entry)),
#blank,blank,blank,blank,blank,
urwid.Filler(button_cols,'bottom')
])
frame = urwid.Frame(lbox)
result = ui.run_wrapper(run)
if result == True:
script_info["pre_entry"] = blank_to_none(pre_entry.get_edit_text())
script_info["post_entry"] = blank_to_none(post_entry.get_edit_text())
script_info["disconnect_entry"] = blank_to_none(disconnect_entry.get_edit_text())
write_scripts(network, network_type, script_info)
OK_PRESSED = False
CANCEL_PRESSED = False
def ok_callback(button_object,user_data=None):
global OK_PRESSED
OK_PRESSED = True
def cancel_callback(button_object,user_data=None):
global CANCEL_PRESSED
CANCEL_PRESSED = True
def run():
dim = ui.get_cols_rows()
ui.set_mouse_tracking()
keys = True
while True:
if keys:
ui.draw_screen(dim, frame.render(dim, True))
keys = ui.get_input()
if "window resize" in keys:
dim = ui.get_cols_rows()
if "esc" in keys or 'Q' in keys:
return False
for k in keys:
#Send key to underlying widget:
if urwid.is_mouse_event(k):
event, button, col, row = k
frame.mouse_event( dim,
event, button, col, row,
focus=True)
else:
frame.keypress(dim, k)
# Check if buttons are pressed.
if CANCEL_PRESSED:
return False
if OK_PRESSED or 'meta enter' in keys:
return True
if __name__ == '__main__':
if os.getuid() != 0:
print "Root privileges are required to configure scripts. Exiting."
sys.exit(0)
main(sys.argv)

View File

@@ -24,6 +24,15 @@ wicd-curses.
import urwid import urwid
# Uses code that is towards the bottom
def error(ui,parent,message):
"""Shows an error dialog (or something that resembles one)"""
# /\
# /!!\
# /____\
dialog = TextDialog(message,6,40,('important',"ERROR"))
return dialog.run(ui,parent)
# My savior. :-) # My savior. :-)
# Although I could have made this myself pretty easily, just want to give credit where # Although I could have made this myself pretty easily, just want to give credit where
# its due. # its due.
@@ -295,30 +304,44 @@ class ComboBox(urwid.WidgetWrap):
self.use_enter = use_enter self.use_enter = use_enter
# The Focus # The Focus
self.focus = focus self.focus = focus
# The callback and friends # The callback and friends
self.callback = callback self.callback = callback
self.user_args = user_args self.user_args = user_args
# Widget references to simplify some things
self.parent = None
self.ui = None
self.row = None
def set_list(self,list): def set_list(self,list):
self.list = list self.list = list
def set_focus(self,index): def set_focus(self,index):
self.focus = index self.focus = index
self.cbox.set_w(SelText(self.list[index]+' vvv'))
if self.overlay:
self.overlay._listbox.set_focus(index)
def build_combobox(self,body,ui,row): def rebuild_combobox(self):
self.build_combobox(self.parent,self.ui,self.row)
def build_combobox(self,parent,ui,row):
str,trash = self.label.get_text() str,trash = self.label.get_text()
self.cbox = DynWrap(SelText([self.list[self.focus]+' vvv']),attrs=self.attrs,focus_attr=self.focus_attr) self.cbox = DynWrap(SelText([self.list[self.focus]+' vvv']),attrs=self.attrs,focus_attr=self.focus_attr)
if str != '': if str != '':
w = urwid.Columns([('fixed',len(str),self.label),self.cbox],dividechars=1) w = urwid.Columns([('fixed',len(str),self.label),self.cbox],dividechars=1)
self.overlay = self.ComboSpace(self.list,body,ui,self.focus, self.overlay = self.ComboSpace(self.list,parent,ui,self.focus,
pos=(len(str)+1,row)) pos=(len(str)+1,row))
else: else:
w = urwid.Columns([self.cbox]) w = urwid.Columns([self.cbox])
self.overlay = self.ComboSpace(self.list,body,ui,self.focus, self.overlay = self.ComboSpace(self.list,parent,ui,self.focus,
pos=(0,row)) pos=(0,row))
self.set_w(w) self.set_w(w)
self.body = body self.parent = parent
self.ui = ui self.ui = ui
self.row = row
# If we press space or enter, be a combo box! # If we press space or enter, be a combo box!
def keypress(self,size,key): def keypress(self,size,key):
@@ -329,9 +352,10 @@ class ComboBox(urwid.WidgetWrap):
# Die if the user didn't prepare the combobox overlay # Die if the user didn't prepare the combobox overlay
if self.overlay == None: if self.overlay == None:
raise ComboBoxException('ComboBox must be built before use!') raise ComboBoxException('ComboBox must be built before use!')
retval = self.overlay.show(self.ui,self.body) retval = self.overlay.show(self.ui,self.parent)
if retval != None: if retval != None:
self.cbox.set_w(SelText(retval+' vvv')) self.set_focus(self.list.index(retval))
#self.cbox.set_w(SelText(retval+' vvv'))
if self.callback != None: if self.callback != None:
self.callback(self,self.overlay._listbox.get_focus()[1],self.user_args) self.callback(self,self.overlay._listbox.get_focus()[1],self.user_args)
return self._w.keypress(size,key) return self._w.keypress(size,key)
@@ -431,9 +455,9 @@ class Dialog2(urwid.WidgetWrap):
# Simple dialog with text in it and "OK" # Simple dialog with text in it and "OK"
class TextDialog(Dialog2): class TextDialog(Dialog2):
def __init__(self, text, height, width, header=None,align='left'): def __init__(self, text, height, width, header=None,align='left'):
l = [] l = [urwid.Text(text)]
for line in text: #for line in text:
l.append( urwid.Text( line,align=align)) # l.append( urwid.Text( line,align=align))
body = urwid.ListBox(l) body = urwid.ListBox(l)
body = urwid.AttrWrap(body, 'body') body = urwid.AttrWrap(body, 'body')
@@ -448,8 +472,8 @@ class TextDialog(Dialog2):
self.frame.set_focus('footer') self.frame.set_focus('footer')
class InputDialog(Dialog2): class InputDialog(Dialog2):
def __init__(self, text, height, width,ok_name='OK'): def __init__(self, text, height, width,ok_name='OK',edit_text=''):
self.edit = urwid.Edit(wrap='clip') self.edit = urwid.Edit(wrap='clip',edit_text=edit_text)
body = urwid.ListBox([self.edit]) body = urwid.ListBox([self.edit])
body = urwid.AttrWrap(body, 'editbx','editfc') body = urwid.AttrWrap(body, 'editbx','editfc')
@@ -470,3 +494,8 @@ class InputDialog(Dialog2):
def on_exit(self, exitcode): def on_exit(self, exitcode):
return exitcode, self.edit.get_edit_text() return exitcode, self.edit.get_edit_text()
# Pile that has an edit and a label saying that the file at the path specified
# does not exist
#class FileGuessEdit(urwid.WidgetWrap):
# def __init__(self,caption='',

View File

@@ -22,17 +22,10 @@
# MA 02110-1301, USA. # MA 02110-1301, USA.
import urwid import urwid
from curses_misc import TextDialog,DynWrap,MaskingEdit,ComboBox from curses_misc import TextDialog,DynWrap,MaskingEdit,ComboBox,error
import wicd.misc as misc import wicd.misc as misc
from wicd.misc import noneToString, stringToNone, noneToBlankString, to_bool from wicd.misc import noneToString, stringToNone, noneToBlankString, to_bool
def error(ui,parent,message):
"""Shows an error dialog (or something that resembles one)"""
# /\
# /!!\
# /____\
dialog = TextDialog(message,40,6,('important',"ERROR"))
return dialog.run(ui,parent)
language = misc.get_language_list_gui() language = misc.get_language_list_gui()
@@ -136,7 +129,7 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
self.global_dns_cb.set_sensitive(new_state) self.global_dns_cb.set_sensitive(new_state)
# use_global_dns_cb is DynWrapped # use_global_dns_cb is DynWrapped
if checkb == self.global_dns_cb.get_w(): if checkb == self.global_dns_cb.get_w():
for w in [ self.dns_dom_edit,self.search_dom_edit, for w in [self.dns_dom_edit,self.search_dom_edit,
self.dns1,self.dns2,self.dns3 ]: self.dns1,self.dns2,self.dns3 ]:
w.set_sensitive(not new_state) w.set_sensitive(not new_state)
@@ -174,31 +167,93 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
self.set_net_prop("dns2", '') self.set_net_prop("dns2", '')
self.set_net_prop("dns3", '') self.set_net_prop("dns3", '')
def prerun(self,ui,dim,display):
pass
def run(self,ui,dim,display): def run(self,ui,dim,display):
self.ui = ui
self.parent = display
width,height = ui.get_cols_rows() width,height = ui.get_cols_rows()
overlay = urwid.Overlay(self, display, ('fixed left', 0),width self.overlay = urwid.Overlay(self, display, ('fixed left', 0),width
, ('fixed top',1), height-3) , ('fixed top',1), height-3)
self.prerun(ui,dim,display)
#self.ready_comboboxes(ui,overlay) #self.ready_comboboxes(ui,overlay)
keys = True keys = True
while True: while True:
if keys: if keys:
ui.draw_screen(dim, overlay.render(dim, True)) ui.draw_screen(dim, self.overlay.render(dim, True))
keys = ui.get_input() keys = ui.get_input()
for k in keys:
#Send key to underlying widget:
if urwid.is_mouse_event(k):
event, button, col, row = k
self.overlay.mouse_event( dim,
event, button, col, row,
focus=True)
self.overlay.keypress(dim, k)
if "window resize" in keys: if "window resize" in keys:
dim = ui.get_cols_rows() dim = ui.get_cols_rows()
if "esc" in keys or 'Q' in keys: if "esc" in keys or 'Q' in keys:
return False return False
for k in keys: if "meta enter" in keys or self.OK_PRESSED:
#Send key to underlying widget: self.OK_PRESSED = False
overlay.keypress(dim, k) if self.save_settings():
# Check if buttons are pressed. return True
#if self.CANCEL_PRESSED: if self.CANCEL_PRESSED:
# return False return False
#if self.OK_PRESSED or 'meta enter' in keys:
# return True class WiredSettingsDialog(AdvancedSettingsDialog):
def __init__(self,name):
global wired, daemon
AdvancedSettingsDialog.__init__(self)
self.set_default = urwid.CheckBox(language['default_wired'])
#self.cur_default =
# Add widgets to listbox
self._w.body.body.append(self.set_default)
self._w.body.body.append(self.button_cols)
self.prof_name = name
self._w.header = urwid.Text( ('header',">Configuring preferences for wired profile \"%s\"" % self.prof_name),align='right' )
self.set_values()
def set_net_prop(self,option,value):
wired.SetWiredProperty(option,value)
def set_values(self):
self.ip_edit.set_edit_text(self.format_entry("ip"))
self.netmask_edit.set_edit_text(self.format_entry("netmask"))
self.gateway_edit.set_edit_text(self.format_entry("gateway"))
self.global_dns_cb.set_state(bool(wired.GetWiredProperty('use_global_dns')))
self.static_dns_cb.set_state(bool(wired.GetWiredProperty('use_static_dns')))
self.dns1.set_edit_text(self.format_entry( "dns1"))
self.dns2.set_edit_text(self.format_entry( "dns2"))
self.dns3.set_edit_text(self.format_entry( "dns3"))
self.dns_dom_edit.set_edit_text(self.format_entry("dns_domain"))
self.search_dom_edit.set_edit_text(self.format_entry("search_domain"))
self.set_default.set_state(to_bool(wired.GetWiredProperty("default")))
def save_settings(self):
AdvancedSettingsDialog.save_settings(self)
if self.set_default.get_state():
wired.UnsetWiredDefault()
print self.set_default.get_state()
if self.set_default.get_state():
bool = True
else:
bool = False
wired.SetWiredProperty("default",bool)
wired.SaveWiredNetworkProfile(self.prof_name)
return True
def format_entry(self, label):
""" Helper method to fetch and format wired properties. """
return noneToBlankString(wired.GetWiredProperty(label))
def prerun(self,ui,dim,display):
pass
######################################## ########################################
@@ -257,6 +312,13 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
self.global_settings_chkbox.set_state(bool(wireless.GetWirelessProperty(networkID self.global_settings_chkbox.set_state(bool(wireless.GetWirelessProperty(networkID
,'use_settings_globally'))) ,'use_settings_globally')))
# Throw the encryption stuff into a list
list = []
for x, enc_type in enumerate(self.encrypt_types):
list.append(enc_type[0])
self.encryption_combo.set_list(list)
self.change_encrypt_method()
activeID = -1 # Set the menu to this item when we are done activeID = -1 # Set the menu to this item when we are done
user_enctype = wireless.GetWirelessProperty(networkID, "enctype") user_enctype = wireless.GetWirelessProperty(networkID, "enctype")
for x, enc_type in enumerate(self.encrypt_types): for x, enc_type in enumerate(self.encrypt_types):
@@ -270,12 +332,6 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
#self.lbox_encrypt_info.set_sensitive(True) #self.lbox_encrypt_info.set_sensitive(True)
else: else:
self.encryption_combo.set_focus(0) self.encryption_combo.set_focus(0)
# Throw the encryption stuff into a list
list = []
for x, enc_type in enumerate(self.encrypt_types):
list.append(enc_type[0])
self.encryption_combo.set_list(list)
self.change_encrypt_method()
def set_net_prop(self, option, value): def set_net_prop(self, option, value):
""" Sets the given option to the given value for this network. """ """ Sets the given option to the given value for this network. """
@@ -363,7 +419,7 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
self.overlay = urwid.Overlay(self, display, ('fixed left', 0),width self.overlay = urwid.Overlay(self, display, ('fixed left', 0),width
, ('fixed top',1), height-3) , ('fixed top',1), height-3)
self.encryption_combo.build_combobox(self.overlay,ui,14) self.encryption_combo.build_combobox(self.overlay,ui,14)
#self.change_encrypt_method() self.change_encrypt_method()
#self._w.body.body.append(self.pile_encrypt) #self._w.body.body.append(self.pile_encrypt)
keys = True keys = True

View File

@@ -45,7 +45,8 @@ from dbus import version as dbus_version
import gobject import gobject
# Other important wicd-related stuff # Other important wicd-related stuff
import wicd.misc as misc from wicd import wpath
from wicd import misc
from wicd import dbusmanager from wicd import dbusmanager
# Internal Python stuff # Internal Python stuff
@@ -53,10 +54,14 @@ import sys
from time import sleep from time import sleep
# Curses UIs for other stuff # Curses UIs for other stuff
from curses_misc import SelText,ComboBox,TextDialog,InputDialog from curses_misc import SelText,ComboBox,TextDialog,InputDialog,error
from prefs_curses import PrefsDialog from prefs_curses import PrefsDialog
import netentry_curses import netentry_curses
from netentry_curses import WirelessSettingsDialog, error from netentry_curses import WirelessSettingsDialog, WiredSettingsDialog
# Stuff about getting the script configurer running
from grp import getgrgid
from os import getgroups,system
language = misc.get_language_list_gui() language = misc.get_language_list_gui()
@@ -104,6 +109,7 @@ class wrap_exceptions:
# Zap the screen # Zap the screen
ui.stop() ui.stop()
# Print out standard notification: # Print out standard notification:
print "\nEXCEPTION!" print "\nEXCEPTION!"
print "Please report this to the maintainer and/or file a bug report with the backtrace below:" print "Please report this to the maintainer and/or file a bug report with the backtrace below:"
print redraw_tag print redraw_tag
@@ -180,10 +186,10 @@ def gen_network_list():
id = 0 id = 0
wiredL = [] wiredL = []
is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None #is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None
# This one makes a list of strings to put in a combo box. # This one makes a list of strings to put in a combo box.
for profile in wired.GetWiredProfileList(): #for profile in wired.GetWiredProfileList():
theString = '%4s %25s' % (id, profile) #theString = '%4s %25s' % (id, profile)
#### THIS IS wired.blah() in experimental #### THIS IS wired.blah() in experimental
#print config.GetLastUsedWiredNetwork() #print config.GetLastUsedWiredNetwork()
# Tag if no wireless IP present, and wired one is # Tag if no wireless IP present, and wired one is
@@ -194,9 +200,9 @@ def gen_network_list():
# 'connected focus')) # 'connected focus'))
#else: #else:
#wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus')) #wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus'))
wiredL.append(theString) #wiredL.append(theString)
id+=1 #id+=1
wiredL = wired.GetWiredProfileList()
wlessL = [] wlessL = []
# This one makes a list of NetLabels # This one makes a list of NetLabels
for network_id in range(0, wireless.GetNumberOfNetworks()): for network_id in range(0, wireless.GetNumberOfNetworks()):
@@ -211,39 +217,88 @@ def about_dialog(body):
# The ASCII Art "Wicd" was made from the "smslant" font on one of those # The ASCII Art "Wicd" was made from the "smslant" font on one of those
# online ASCII big text generators. # online ASCII big text generators.
theText = [ theText = [
[('green'," /// \\\\\\")," _ ___ __"], ('green'," /// \\\\\\")," _ ___ __\n",
[('green'," /// \\\\\\")," | | /| / (_)______/ /"], ('green'," /// \\\\\\")," | | /| / (_)______/ /\n",
[('green'," /// \\\\\\")," | |/ |/ / / __/ _ / "], ('green'," /// \\\\\\")," | |/ |/ / / __/ _ / \n",
[('green',"/|| // \\\\ ||\\")," |__/|__/_/\__/\_,_/ "], ('green',"/|| // \\\\ ||\\")," |__/|__/_/\__/\_,_/ \n",
[('green',"||| ||"),"(|^|)",('green',"|| |||"), ('green',"||| ||"),"(|^|)",('green',"|| |||"),
" ($VERSION) ".replace("$VERSION",daemon.Hello())], " ($VERSION) \n".replace("$VERSION",daemon.Hello()),
[('green',"\\|| \\\\")," |+| ",('green',"// ||/ ")], ('green',"\\|| \\\\")," |+| ",('green',"// ||/ \n"),
[('green'," \\\\\\")," |+| ",('green',"///")," http://wicd.net"], ('green'," \\\\\\")," |+| ",('green',"///")," http://wicd.net\n",
[('green'," \\\\\\")," |+| ",('green',"///")," Brought to you by:"], ('green'," \\\\\\")," |+| ",('green',"///")," Brought to you by:\n",
[('green'," \\\\\\")," |+| ",('green',"///")," Adam Blackburn (wicd)"], ('green'," \\\\\\")," |+| ",('green',"///")," Adam Blackburn (wicd)\n",
" ___|+|___ Dan O'Reilly (wicd)", " ___|+|___ Dan O'Reilly (wicd)\n",
" |---------| Andrew Psaltis (this ui)", " |---------| Andrew Psaltis (this ui)\n",
"-----------------------------------------------------"] "-----------------------------------------------------"]
about = TextDialog(theText,16,55,header=('header','About Wicd')) about = TextDialog(theText,16,55,header=('header','About Wicd'))
about.run(ui,body) about.run(ui,body)
def help_dialog(body): def help_dialog(body):
theText = [ theText = [
"For more detailed help, consult the wicd-curses(8) man page.", "For more detailed help, consult the wicd-curses(8) man page.\n",
"", "All controls are case sensitive", "\n", "All controls are case sensitive\n",
[('bold','H')," Display this help dialog"], ('bold','H')," Display this help dialog\n",
[('bold','enter')," Connect to selected network"], ('bold','enter')," Connect to selected network\n",
[('bold','D')," Disconnect from all networks"], ('bold','D')," Disconnect from all networks\n",
[('bold','ESC')," Stop a network connection in progress"], ('bold','ESC')," Stop a network connection in progress\n",
[('bold','F5')," or ", ('bold','R')," Refresh network list"], ('bold','F5')," or ", ('bold','R')," Refresh network list\n",
[('bold','P')," Prefrences dialog"], ('bold','P')," Prefrences dialog\n",
[('bold','I')," Scan for hidden networks"], ('bold','I')," Scan for hidden networks\n",
[('bold','S')," Select scripts"] ('bold','S')," Select scripts\n"
] ]
help = TextDialog(theText,15,62,header=('header',"Wicd-Curses Help")) help = TextDialog(theText,15,62,header=('header',"Wicd-Curses Help"))
help.run(ui,body) help.run(ui,body)
def run_configscript(parent,netname,nettype):
configfile = wpath.etc+netname+'-settings.conf'
header = 'profile' if nettype == 'wired' else 'BSSID'
profname = netname if nettype == 'wired' else wireless.GetWirelessProperty(
netname,'bssid')
theText = [
"""To avoid various complications, wicd-curses does not support directly editing the scripts directly. However, you can edit them manually. First, (as root)", open the "%s" config file, and look for the section labeled by the %s in question. In this case, this is:
[%s]
Once here, you can adjust (or add) the "beforescript", "afterscript", and "disconnectscript" variables as needed, to change the preconnect, postconnect, and disconnect scripts respectively.
Alternatively, you can configure the wireless networks by ESSID, by looking for the "[<ESSID>]" field in the config file.""" % (configfile,header,profname)]
dialog = TextDialog(theText,16,80)
dialog.run(ui,parent)
# This code works with many distributions, but not all of them. So, to
# limit complications, it has been deactivated. If you want to run it,
# be my guest. Be sure to deactivate the above stuff first.
"""
loop.quit()
ui.stop()
argv = netname + ' ' +nettype
#cmd = '/usr/lib/configscript_curses.py '+argv
cmd = wpath.lib+'configscript_curses.py '+argv
# Check whether we can sudo. Hopefully this is complete
glist = []
for i in getgroups():
glist.append(getgrgid(i)[0])
if 'root' in glist:
precmd = ''
precmdargv = ''
postcmd = ''
elif 'admin' in glist or 'wheel' in glist or 'sudo' in glist:
precmd = 'sudo'
precmdargv = ''
postcmd = ''
else:
precmd = 'su'
precmdargv = ' -c "'
postcmd = '"'
print "Calling command: " + precmd + precmdargv + cmd + postcmd
sys.stdout.flush()
system(precmd+precmdargv+cmd+postcmd)
raw_input("Press enter!")
main()
"""
######################################## ########################################
##### URWID SUPPORT CLASSES ##### URWID SUPPORT CLASSES
######################################## ########################################
@@ -297,10 +352,16 @@ class WiredComboBox(ComboBox):
""" """
list : the list of wired network profiles. The rest is self-explanitory. list : the list of wired network profiles. The rest is self-explanitory.
""" """
def init(self,list): def __init__(self,list):
self.ADD_PROFILE = '---Add a new profile---'
self.__super.__init__(use_enter=False)
self.set_list(list)
#self.set_focus(self.theList.index(wired.GetDefaultProfile()))
def set_list(self,list):
self.theList = list self.theList = list
id = 0 id=0
wiredL = [] wiredL=[]
is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None
for profile in list: for profile in list:
theString = '%4s %25s' % (id, profile) theString = '%4s %25s' % (id, profile)
@@ -316,11 +377,59 @@ class WiredComboBox(ComboBox):
# wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus')) # wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus'))
wiredL.append(theString) wiredL.append(theString)
id+=1 id+=1
self.__super.__init__(list=wiredL,use_enter=False) wiredL.append(self.ADD_PROFILE)
self.set_focus(theList.index(wired.GetDefaultWiredProfile())) if is_active:
self.attrs = ('connected','editnfc')
self.focus_attr = 'connected focus'
else :
self.attrs = ('body','editnfc')
self.focus_attr = 'focus'
self.list = wiredL
if self.theList != []:
wired.ReadWiredNetworkProfile(self.get_selected_profile())
#def rebuild_combobox(self):
# pass
def keypress(self,size,key): def keypress(self,size,key):
self.__super.keypress(size,key) prev_focus = self.get_focus()[1]
key = self.__super.keypress(size,key)
if self.get_focus()[1] == len(self.list)-1:
dialog = InputDialog(('header',"Add new wired profile"),7,30)
exitcode,name = dialog.run(ui,self.parent)
if exitcode == 0:
wired.CreateWiredNetworkProfile(name,False)
self.set_list(wired.GetWiredProfileList())
self.rebuild_combobox()
self.set_focus(prev_focus)
else:
wired.ReadWiredNetworkProfile(self.get_selected_profile())
if key == 'delete':
if len(self.theList) == 1:
error(self.ui,self.parent,"Cannot delete the last wired profile. Try renaming it ('F2')")
return key
wired.DeleteWiredNetworkProfile(self.get_selected_profile())
# Return to the top of the list if something is deleted.
if wired.GetDefaultWiredNetwork() != None:
self.set_focus(self.theList.index(wired.GetDefaultWiredNetwork()))
else:
prev_focus -= 1
self.set_focus(prev_focus)
self.set_list(wired.GetWiredProfileList())
self.rebuild_combobox()
if key == 'f2':
dialog = InputDialog(('header',"Rename wired profile"),7,30,
edit_text=unicode(self.get_selected_profile()))
exitcode,name = dialog.run(ui,self.parent)
if exitcode == 0:
# Save the new one, then kill the old one
wired.SaveWiredNetworkProfile(name)
wired.DeleteWiredNetworkProfile(self.get_selected_profile())
self.set_list(wired.GetWiredProfileList())
self.set_focus(self.theList.index(name))
self.rebuild_combobox()
return key
#if key == 'C': #if key == 'C':
# Configure the network # Configure the network
# pass # pass
@@ -331,11 +440,10 @@ class WiredComboBox(ComboBox):
# self.connect() # self.connect()
#return key #return key
def connect(self):
wired.ConnectWired()
def get_selected_profile(self): def get_selected_profile(self):
"""Get the selected wired profile""" """Get the selected wired profile"""
return self.theList[self._w.get_selected()[1]] loc = self.get_focus()[1]
return self.theList[loc]
######################################## ########################################
##### APPLICATION INTERFACE CLASS ##### APPLICATION INTERFACE CLASS
@@ -369,7 +477,7 @@ class appGUI():
wiredL,wlessL = [],[]# = gen_network_list() wiredL,wlessL = [],[]# = gen_network_list()
self.frame = None self.frame = None
self.wiredCB = urwid.Filler(ComboBox(list=wiredL,use_enter=False)) self.wiredCB = urwid.Filler(WiredComboBox(wiredL))
self.wlessLB = urwid.ListBox(wlessL) self.wlessLB = urwid.ListBox(wlessL)
self.update_netlist(force_check=True,firstrun=True) self.update_netlist(force_check=True,firstrun=True)
@@ -400,7 +508,6 @@ class appGUI():
self.screen_locked = False self.screen_locked = False
#self.always_show_wired = daemon.GetAlwaysShowWiredInterface() #self.always_show_wired = daemon.GetAlwaysShowWiredInterface()
self.pref = None self.pref = None
self.update_status() self.update_status()
@@ -411,11 +518,12 @@ class appGUI():
def lock_screen(self): def lock_screen(self):
self.frame.set_body(self.screen_locker) self.frame.set_body(self.screen_locker)
self.screen_locked = True self.screen_locked = True
self.update_ui()
def unlock_screen(self): def unlock_screen(self):
self.update_netlist(force_check=True)
self.frame.set_body(self.thePile) self.frame.set_body(self.thePile)
self.screen_locked = False self.screen_locked = False
self.update_netlist(force_check=True)
self.update_ui() self.update_ui()
def raise_hidden_network_dialog(self): def raise_hidden_network_dialog(self):
@@ -432,24 +540,24 @@ class appGUI():
# Location of last known focus is remapped to current location. # Location of last known focus is remapped to current location.
# This might need to be cleaned up later. # This might need to be cleaned up later.
if self.thePile.get_focus() is self.wiredCB: #self.set_status(str(self.frame.get_body().get_focus())+ ' '+ str(self.wiredCB))
if self.thePile.get_focus() == self.wiredCB:
wlessorwired = self.WIRED_IDX wlessorwired = self.WIRED_IDX
else :
wlessorwired = self.WLESS_IDX
if self.thePile.get_focus() == self.no_wlan:
where = 0
elif self.thePile.get_focus() == self.wiredCB:
where = self.thePile.get_focus().get_body().get_focus()[1] where = self.thePile.get_focus().get_body().get_focus()[1]
else: else: #self.thePile.get_focus() == self.wlessLB :
where = self.thePile.get_focus().get_focus()[1] wlessorwired = self.WLESS_IDX
if self.wlessLB == self.no_wlan:
where = None
else:
where = self.thePile.get_focus().get_focus()[1]
#where = self.wlessLB.get_focus()[1]
self.focusloc = (wlessorwired,where) self.focusloc = (wlessorwired,where)
# Be clunky until I get to a later stage of development. # Be clunky until I get to a later stage of development.
# Update the list of networks. Usually called by DBus. # Update the list of networks. Usually called by DBus.
# TODO: Preserve current focus when updating the list. # TODO: Preserve current focus when updating the list.
@wrap_exceptions() @wrap_exceptions()
def update_netlist(self,state=None, x=None, force_check=False,firstrun=False): def update_netlist(self,state=None, x=None, force_check=False,firstrun=False):
# Run focus-collecting code if we are not running this for the first time
if not firstrun: if not firstrun:
self.update_focusloc() self.update_focusloc()
""" Updates the overall network list.""" """ Updates the overall network list."""
@@ -462,31 +570,45 @@ class appGUI():
self.wiredCB.get_body().set_list(wiredL) self.wiredCB.get_body().set_list(wiredL)
self.wiredCB.get_body().build_combobox(self.frame,ui,3) self.wiredCB.get_body().build_combobox(self.frame,ui,3)
if len(wlessL) != 0: if len(wlessL) != 0:
self.wlessLB = urwid.ListBox(wlessL) if self.wlessLB == self.no_wlan:
#self.wlessLB.body = urwid.SimpleListWalker(wlessL) self.wlessLB = urwid.ListBox(wlessL)
else:
self.wlessLB.body = urwid.SimpleListWalker(wlessL)
else: else:
self.wlessLB = self.no_wlan self.wlessLB = self.no_wlan
#self.wlessLB.body = urwid.SimpleListWalker([self.no_wlan])
if daemon.GetAlwaysShowWiredInterface() or wired.CheckPluggedIn(): if daemon.GetAlwaysShowWiredInterface() or wired.CheckPluggedIn():
#if daemon.GetAlwaysShowWiredInterface(): #if daemon.GetAlwaysShowWiredInterface():
#if firstrun:
self.thePile = urwid.Pile([('fixed',1,self.wiredH), self.thePile = urwid.Pile([('fixed',1,self.wiredH),
('fixed',1,self.wiredCB), ('fixed',1,self.wiredCB),
('fixed',1,self.wlessH), ('fixed',1,self.wlessH),
self.wlessLB] ) self.wlessLB] )
if not firstrun:
self.frame.body = self.thePile
#self.focusloc = (self.thePile.get_focus(), #self.focusloc = (self.thePile.get_focus(),
# self.thePile.get_focus().get_focus()[1]) # self.thePile.get_focus().get_focus()[1])
self.thePile.set_focus(self.focusloc[0]) self.thePile.set_focus(self.focusloc[0])
if self.focusloc[0] == self.WIRED_IDX: if self.focusloc[0] == self.WIRED_IDX:
self.thePile.get_focus().get_body().set_focus(self.focusloc[1]) self.thePile.get_focus().get_body().set_focus(self.focusloc[1])
else: else:
self.thePile.get_focus().set_focus(self.focusloc[1]) if self.wlessLB is not self.no_wlan:
self.thePile.get_focus().set_focus(self.focusloc[1])
else:
self.thePile.set_focus(self.wiredCB)
else: else:
self.thePile = urwid.Pile([('fixed',1,self.wlessH),self.wlessLB] ) self.thePile = urwid.Pile([('fixed',1,self.wlessH),self.wlessLB] )
self.frame.body = self.thePile if not firstrun:
if self.focusloc[0] == self.wlessLB: self.frame.body = self.thePile
self.wlessLB.set_focus(self.focusloc[1]) #if self.focusloc[0] == self.wlessLB:
self.wlessLB.set_focus(self.focusloc[1])
#self.thePile.get_focus().set_focus(self.focusloc[1])
#self.always_show_wired = not self.always_show_wired #self.always_show_wired = not self.always_show_wired
self.prev_state = state self.prev_state = state
if not firstrun:
self.update_ui()
if firstrun:
if wired.GetDefaultWiredNetwork() != None:
self.wiredCB.get_body().set_focus(wired.GetWiredProfileList().index(wired.GetDefaultWiredNetwork()))
# Update the footer/status bar # Update the footer/status bar
@wrap_exceptions() @wrap_exceptions()
@@ -529,6 +651,7 @@ class appGUI():
return True return True
else: else:
self.set_status(language['not_connected']) self.set_status(language['not_connected'])
self.update_ui()
return True return True
@@ -542,6 +665,8 @@ class appGUI():
# something, and we aren't connecting to something, return False # something, and we aren't connecting to something, return False
# immediately. # immediately.
if from_idle and not self.connecting: if from_idle and not self.connecting:
self.update_netlist()
self.update_ui()
return False return False
toAppend = '' toAppend = ''
# If we are connecting and being called from the idle function, spin # If we are connecting and being called from the idle function, spin
@@ -558,12 +683,15 @@ class appGUI():
# Not necessary in the end, but I will be using footer1 for stuff in # Not necessary in the end, but I will be using footer1 for stuff in
# the long run, so I might as well put something there. # the long run, so I might as well put something there.
incr = 0 incr = 0
@wrap_exceptions()
def idle_incr(self): def idle_incr(self):
theText = "" theText = " "
#if self.special != None:
# theText += self.special
if self.connecting: if self.connecting:
theText = "-- Connecting -- Press ESC to cancel " theText += "-- Connecting -- Press ESC to cancel "
quit_note = "-- Press F8 or Q to quit." quit_note = "-- Press F8 or Q to quit."
self.footer1 = urwid.Text(str(self.incr) + ' '+theText+quit_note) self.footer1 = urwid.Text(str(self.incr) + theText+quit_note,wrap='clip')
self.incr+=1 self.incr+=1
return True return True
@@ -574,16 +702,11 @@ class appGUI():
#if not self.connecting: #if not self.connecting:
# gobject.idle_add(self.refresh_networks, None, False, None) # gobject.idle_add(self.refresh_networks, None, False, None)
self.unlock_screen() self.unlock_screen()
# I'm hoping that this will resolve Adam's problem with the screen lock
# remaining onscreen until a key is pressed. It goes away perfectly well
# here.
self.update_ui()
# Same, same, same, same, same, same # Same, same, same, same, same, same
#@wrap_exceptions() #@wrap_exceptions()
def dbus_scan_started(self): def dbus_scan_started(self):
self.lock_screen() self.lock_screen()
self.update_ui()
# Redraw the screen # Redraw the screen
@wrap_exceptions() @wrap_exceptions()
@@ -603,7 +726,8 @@ class appGUI():
if "f8" in keys or 'Q' in keys: if "f8" in keys or 'Q' in keys:
loop.quit() loop.quit()
return False return False
if "f5" in keys: if "f5" in keys or 'R' in keys:
self.lock_screen()
wireless.Scan() wireless.Scan()
if "D" in keys: if "D" in keys:
# Disconnect from all networks. # Disconnect from all networks.
@@ -612,8 +736,9 @@ class appGUI():
# Guess what! I actually need to put this here, else I'll have tons of # Guess what! I actually need to put this here, else I'll have tons of
# references to self.frame lying around. ^_^ # references to self.frame lying around. ^_^
if "enter" in keys: if "enter" in keys:
focus = self.thePile.get_focus() focus = self.frame.body.get_focus()
if focus is self.wiredCB: if focus == self.wiredCB:
self.special = focus
self.connect("wired",0) self.connect("wired",0)
else: else:
# wless list only other option # wless list only other option
@@ -638,7 +763,8 @@ class appGUI():
if "C" in keys: if "C" in keys:
focus = self.thePile.get_focus() focus = self.thePile.get_focus()
if focus == self.wiredCB: if focus == self.wiredCB:
pass WiredSettingsDialog(self.wiredCB.get_body().
get_selected_profile()).run(ui,self.size,self.frame)
else: else:
# wireless list only other option # wireless list only other option
wid,pos = self.thePile.get_focus().get_focus() wid,pos = self.thePile.get_focus().get_focus()
@@ -649,6 +775,16 @@ class appGUI():
self.raise_hidden_network_dialog() self.raise_hidden_network_dialog()
if "H" in keys: if "H" in keys:
help_dialog(self.frame) help_dialog(self.frame)
if "S" in keys:
focus = self.thePile.get_focus()
if focus == self.wiredCB:
nettype = 'wired'
netname = self.wiredCB.get_body().get_selected_profile()
else:
nettype = 'wireless'
netname = str(self.wiredLB.get_focus()[1])
run_configscript(self.frame,netname,nettype)
for k in keys: for k in keys:
if urwid.is_mouse_event(k): if urwid.is_mouse_event(k):
event, button, col, row = k event, button, col, row = k
@@ -659,18 +795,6 @@ class appGUI():
self.size = ui.get_cols_rows() self.size = ui.get_cols_rows()
continue continue
self.frame.keypress( self.size, k ) self.frame.keypress( self.size, k )
if " " in keys:
focus = self.thePile.get_focus()
if focus == self.wiredCB:
#self.set_status('space pressed on wiredCB!')
wid,pos = self.wiredCB.get_body().get_focus()
text,attr = wid.get_text()
wired.ReadWiredNetworkProfile(text)
# Make sure our internal reference to the combobox matches the
# one found in the pile.
#self.wiredCB = self.thePile.get_focus()
return True return True
# TODO: Update this to use the networkentry stuff # TODO: Update this to use the networkentry stuff
def connect(self, nettype, networkid, networkentry=None): def connect(self, nettype, networkid, networkentry=None):

View File

@@ -1,7 +1,7 @@
name = TTLS with WEP name = TTLS with WEP
author = Adam Blackburn author = Adam Blackburn
version = 1 version = 1
require anonymous_identity *Anonymous_Identity identity *Identity password *Password auth *Authentication require identity *Identity password *Password auth *Authentication
----- -----
ctrl_interface=/var/run/wpa_supplicant ctrl_interface=/var/run/wpa_supplicant
network={ network={
@@ -9,7 +9,7 @@ network={
scan_ssid=$_SCAN scan_ssid=$_SCAN
eap=TTLS eap=TTLS
key_mgmt=IEEE8021X key_mgmt=IEEE8021X
identity="$_USERNAME" identity="$_IDENTITY"
password="$_PASSWORD" password="$_PASSWORD"
phase2="auth=$_AUTH" phase2="auth=$_AUTH"
} }

View File

@@ -1,4 +1,5 @@
.TH WICD-CURSES "8" "January 2009" "wicd-curses" .\" First revision was r203
.TH WICD-CURSES "8" "January 2009" "wicd-curses-r250"
.SH NAME .SH NAME
.B wicd-curses .B wicd-curses
\- curses-based wicd(8) controller \- curses-based wicd(8) controller
@@ -39,17 +40,25 @@ Bring up hidden network scanning dialog
.TP .TP
.BR H .BR H
Bring up a rather simplistic help dialog. Of course, it mentions this man page first. :-) Bring up a rather simplistic help dialog. Of course, it mentions this man page first. :-)
.PP .\".PP
The following is a work in progress and might not be fully functional as of yet. .\"The following is a work in progress and might not be fully functional as of yet.
.TP .TP
.BR C .BR C
Bring up network configuration controller for the selected network Bring up network configuration controller for the selected network
.PP .TP
The following are not implemented yet: .BR delete
Delete the selected wired network profile (from the wired network combo box at the top)
.TP
.BR F2
Rename the selected wired network profile (from the wired network combo box at the top)
.\".PP
.\"The following are not implemented yet:
.TP .TP
.BR S .BR S
Bring up the script selector for the selected network (requires superuser privileges) .\"Bring up the script selector for the selected network (requires superuser privileges)
.SH "FILES" Bring up instructions on how to edit the scripts. I have implemented a way to do this in the interface itself, but making it function with all Linux distros would be difficult. Since you are reading this, you should know how to do what I suggest. ;-)
".SH "FILES"
These are not used yet. These are not used yet.
.TP .TP
.I ~/.wicd/WHEREAREMYFILES .I ~/.wicd/WHEREAREMYFILES

View File

@@ -1,8 +1,10 @@
If you are reading this, you are probably wondering why your Wicd configuration WHERE ARE MY FILES?!
files are not here. What follows is a summary of the folders that wicd uses.
For a more detailed (and complete) description what is in each directory, consult the If you are reading this, you are probably wondering why your Wicd configuration
man pages for wicd(8) and wicd-curses(8). files are not here. What follows is a summary of the folders that Wicd uses.
For a more detailed (and complete) description what is in each directory,
consult the man pages for wicd(8) and wicd-curses(8).
~/.wicd ~/.wicd
User-dependent configuration files, only used by wicd-curses User-dependent configuration files, only used by wicd-curses

View File

@@ -126,32 +126,32 @@ class configure(Command):
self.distro_detect_failed = False self.distro_detect_failed = False
self.initfile = 'init/default/wicd' self.initfile = 'init/default/wicd'
if os.access('/etc/redhat-release', os.F_OK): if os.path.exists('/etc/redhat-release'):
self.init = '/etc/rc.d/init.d/' self.init = '/etc/rc.d/init.d/'
self.initfile = 'init/redhat/wicd' self.initfile = 'init/redhat/wicd'
elif os.access('/etc/SuSE-release', os.F_OK): elif os.path.exists('/etc/SuSE-release'):
self.init = '/etc/init.d/' self.init = '/etc/init.d/'
self.initfile = 'init/suse/wicd' self.initfile = 'init/suse/wicd'
elif os.access('/etc/fedora-release', os.F_OK): elif os.path.exists('/etc/fedora-release'):
self.init = '/etc/rc.d/init.d/' self.init = '/etc/rc.d/init.d/'
self.initfile = 'init/redhat/wicd' self.initfile = 'init/redhat/wicd'
elif os.access('/etc/gentoo-release', os.F_OK): elif os.path.exists('/etc/gentoo-release'):
self.init = '/etc/init.d/' self.init = '/etc/init.d/'
self.initfile = 'init/gentoo/wicd' self.initfile = 'init/gentoo/wicd'
elif os.access('/etc/debian_version', os.F_OK): elif os.path.exists('/etc/debian_version'):
self.init = '/etc/init.d/' self.init = '/etc/init.d/'
self.initfile = 'init/debian/wicd' self.initfile = 'init/debian/wicd'
elif os.access('/etc/arch-release', os.F_OK): elif os.path.exists('/etc/arch-release'):
self.init = '/etc/rc.d/' self.init = '/etc/rc.d/'
self.initfile = 'init/arch/wicd' self.initfile = 'init/arch/wicd'
elif os.access('/etc/slackware-version', os.F_OK) or \ elif os.path.exists('/etc/slackware-version') or \
os.access('/etc/slamd64-version', os.F_OK): os.path.exists('/etc/slamd64-version'):
self.init = '/etc/rc.d/' self.init = '/etc/rc.d/'
self.initfile = 'init/slackware/rc.wicd' self.initfile = 'init/slackware/rc.wicd'
self.docdir = '/usr/doc/wicd-%s' % VERSION_NUM self.docdir = '/usr/doc/wicd-%s' % VERSION_NUM
self.mandir = '/usr/man/' self.mandir = '/usr/man/'
self.no_install_acpi = True self.no_install_acpi = True
elif os.access('/etc/pld-release', os.F_OK): elif os.path.exists('/etc/pld-release'):
self.init = '/etc/rc.d/init.d/' self.init = '/etc/rc.d/init.d/'
self.initfile = 'init/pld/wicd' self.initfile = 'init/pld/wicd'
else: else:
@@ -177,7 +177,7 @@ class configure(Command):
if len(pmutils_candidate) == 0 or returncode != 0 or not os.path.isabs(pmutils_candidate): if len(pmutils_candidate) == 0 or returncode != 0 or not os.path.isabs(pmutils_candidate):
raise ValueError raise ValueError
else: else:
self.pmutils = pmutils_candidate self.pmutils = pmutils_candidate
except (OSError, ValueError): except (OSError, ValueError):
pass # use our default pass # use our default
@@ -188,7 +188,7 @@ class configure(Command):
if len(kdedir_candidate) == 0 or returncode != 0 or not os.path.isabs(kdedir_candidate): if len(kdedir_candidate) == 0 or returncode != 0 or not os.path.isabs(kdedir_candidate):
raise ValueError raise ValueError
else: else:
self.kdedir = kdedir_candidate + '/share/autostart' self.kdedir = kdedir_candidate + '/share/autostart'
except (OSError, ValueError): except (OSError, ValueError):
# If kde-config isn't present, we'll check for kde-4.x # If kde-config isn't present, we'll check for kde-4.x
try: try:
@@ -409,6 +409,7 @@ try:
data.append(( wpath.lib, ['curses/prefs_curses.py'])) data.append(( wpath.lib, ['curses/prefs_curses.py']))
data.append(( wpath.lib, ['curses/wicd-curses.py'])) data.append(( wpath.lib, ['curses/wicd-curses.py']))
data.append(( wpath.lib, ['curses/netentry_curses.py'])) data.append(( wpath.lib, ['curses/netentry_curses.py']))
data.append(( wpath.lib, ['curses/configscript_curses.py']))
data.append(( wpath.bin, ['scripts/wicd-curses'])) data.append(( wpath.bin, ['scripts/wicd-curses']))
if not wpath.no_install_man: if not wpath.no_install_man:
data.append(( wpath.mandir + 'man8/', ['man/wicd-curses.8'])) data.append(( wpath.mandir + 'man8/', ['man/wicd-curses.8']))
@@ -474,7 +475,10 @@ connect at startup to any preferred network within range.
url="http://wicd.net", url="http://wicd.net",
license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html", license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
## scripts=['configscript.py', 'autoconnect.py', 'gui.py', 'wicd.py', 'daemon.py', 'suspend.py', 'monitor.py'], ## scripts=['configscript.py', 'autoconnect.py', 'gui.py', 'wicd.py', 'daemon.py', 'suspend.py', 'monitor.py'],
py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', 'wicd.wpath', 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', 'wicd.logfile', 'wicd.backend', 'wicd.configmanager'], ext_modules=[iwscan_ext, wpactrl_ext], py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', 'wicd.wpath',
'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', 'wicd.logfile', 'wicd.backend',
'wicd.configmanager', 'wicd.guiutil'],
ext_modules=[iwscan_ext, wpactrl_ext],
data_files=data data_files=data
) )
##print "Running post-install configuration..." ##print "Running post-install configuration..."

View File

@@ -17,6 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
from wicd import dbusmanager
import dbus import dbus
import time import time
import gobject import gobject
@@ -29,9 +31,9 @@ else:
DBusGMainLoop(set_as_default=True) DBusGMainLoop(set_as_default=True)
try: try:
bus = dbus.SystemBus() dbusmanager.connect_to_dbus()
proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon') daemon = dbusmanager.get_interface('daemon')
daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon') wireless = dbusmanager.get_interface('wireless')
except Exception, e: except Exception, e:
print>>sys.stderr, "Exception caught: %s" % str(e) print>>sys.stderr, "Exception caught: %s" % str(e)
print>>sys.stderr, 'Could not connect to daemon.' print>>sys.stderr, 'Could not connect to daemon.'
@@ -46,10 +48,10 @@ def error_handler(*args):
if __name__ == '__main__': if __name__ == '__main__':
try: try:
time.sleep(3) time.sleep(2)
wireless.Scan()
daemon.SetSuspend(False) daemon.SetSuspend(False)
if not daemon.CheckIfConnecting(): if not daemon.CheckIfConnecting():
daemon.SetForcedDisconnect(False)
daemon.AutoConnect(True, reply_handler=handler, error_handler=handler) daemon.AutoConnect(True, reply_handler=handler, error_handler=handler)
except Exception, e: except Exception, e:
print>>sys.stderr, "Exception caught: %s" % str(e) print>>sys.stderr, "Exception caught: %s" % str(e)

View File

@@ -316,7 +316,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
ap['hidden'] = False ap['hidden'] = False
if cell["channel"]: if cell["channel"]:
ap["channel"] = True ap["channel"] = cell["channel"]
else: else:
ap["channel"] = self._FreqToChannel(cell["frequency"]) ap["channel"] = self._FreqToChannel(cell["frequency"])

View File

@@ -26,14 +26,16 @@ reusable for other purposes as well.
from ConfigParser import RawConfigParser from ConfigParser import RawConfigParser
from wicd.misc import stringToNone, Noneify from wicd.misc import stringToNone, Noneify, to_unicode
class ConfigManager(RawConfigParser): class ConfigManager(RawConfigParser):
""" A class that can be used to manage a given configuration file. """ """ A class that can be used to manage a given configuration file. """
def __init__(self, path): def __init__(self, path, debug=False, mark_whitespace="`'`"):
RawConfigParser.__init__(self) RawConfigParser.__init__(self)
self.config_file = path self.config_file = path
self.debug = debug
self.mrk_ws = mark_whitespace
self.read(path) self.read(path)
def __repr__(self): def __repr__(self):
@@ -57,8 +59,12 @@ class ConfigManager(RawConfigParser):
""" """
if not self.has_section(section): if not self.has_section(section):
self.add_section(section) self.add_section(section)
if isinstance(value, basestring):
RawConfigParser.set(self, section, str(option), str(value)) value = to_unicode(value)
if value.startswith(' ') or value.endswith(' '):
value = "%(ws)s%(value)s%(ws)s" % {"value" : value,
"ws" : self.mrk_ws}
RawConfigParser.set(self, section, str(option), value)
if save: if save:
self.write() self.write()
@@ -75,16 +81,23 @@ class ConfigManager(RawConfigParser):
""" """
if not self.has_section(section): if not self.has_section(section):
self.add_section(section) if default != "__None__":
self.add_section(section)
else:
return None
if self.has_option(section, option): if self.has_option(section, option):
ret = RawConfigParser.get(self, section, option) ret = RawConfigParser.get(self, section, option)
if (isinstance(ret, basestring) and ret.startswith(self.mrk_ws)
and ret.endswith(self.mrk_ws)):
ret = ret[3:-3]
if default: if default:
print ''.join(['found ', option, ' in configuration ', ret]) if self.debug:
print ''.join(['found ', option, ' in configuration ',
str(ret)])
else: else:
if default != "__None__": if default != "__None__":
print ''.join(['did not find ', option, print 'did not find %s in configuration, setting default %s' % (option, str(default))
' in configuration, setting default ', str(default)])
self.set(section, option, str(default), save=True) self.set(section, option, str(default), save=True)
ret = default ret = default
else: else:

View File

@@ -24,6 +24,7 @@ A module for managing wicd's dbus interfaces.
# #
import dbus import dbus
from dbus import DBusException
if getattr(dbus, "version", (0, 0, 0)) < (0, 80, 0): if getattr(dbus, "version", (0, 0, 0)) < (0, 80, 0):
import dbus.glib import dbus.glib
else: else:

View File

@@ -40,6 +40,7 @@ from wicd import dbusmanager
from wicd.misc import noneToString from wicd.misc import noneToString
from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry
from wicd.prefs import PreferencesDialog from wicd.prefs import PreferencesDialog
from wicd.guiutil import error, GreyLabel, LabelEntry, SmallLabel
if __name__ == '__main__': if __name__ == '__main__':
wpath.chdir(__file__) wpath.chdir(__file__)
@@ -87,92 +88,6 @@ def handle_no_dbus(from_tray=False):
error(None, language['lost_dbus'], block=False) error(None, language['lost_dbus'], block=False)
return False return False
def error(parent, message, block=True):
""" Shows an error dialog """
def delete_event(dialog, id):
dialog.destroy()
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR,
gtk.BUTTONS_OK)
dialog.set_markup(message)
if not block:
dialog.present()
dialog.connect("response", delete_event)
else:
dialog.run()
dialog.destroy()
def alert(parent, message):
""" Shows an warning dialog """
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING,
gtk.BUTTONS_OK)
dialog.set_markup(message)
dialog.present()
dialog.connect("response", lambda *args: dialog.destroy())
def dummy(x=None):pass
########################################
##### GTK EXTENSION CLASSES
########################################
class SmallLabel(gtk.Label):
def __init__(self, text=''):
gtk.Label.__init__(self, text)
self.set_size_request(50, -1)
class LabelEntry(gtk.HBox):
""" A label on the left with a textbox on the right. """
def __init__(self,text):
gtk.HBox.__init__(self)
self.entry = gtk.Entry()
self.entry.set_size_request(200, -1)
self.label = SmallLabel()
self.label.set_text(text)
self.label.set_size_request(170, -1)
self.pack_start(self.label, fill=False, expand=False)
self.pack_start(self.entry, fill=False, expand=False)
self.label.show()
self.entry.show()
self.entry.connect('focus-out-event', self.hide_characters)
self.entry.connect('focus-in-event', self.show_characters)
self.auto_hide_text = False
self.show()
def set_text(self, text):
# For compatibility...
self.entry.set_text(text)
def get_text(self):
return self.entry.get_text()
def set_auto_hidden(self, value):
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
if self.auto_hide_text and widget:
self.entry.set_visibility(True)
def set_sensitive(self, value):
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
if self.auto_hide_text and widget:
self.entry.set_visibility(False)
class GreyLabel(gtk.Label):
""" Creates a grey gtk.Label. """
def __init__(self):
gtk.Label.__init__(self)
def set_label(self, text):
self.set_markup("<span color=\"#666666\"><i>" + text + "</i></span>")
self.set_alignment(0, 0)
class WiredProfileChooser: class WiredProfileChooser:
""" Class for displaying the wired profile chooser. """ """ Class for displaying the wired profile chooser. """
@@ -241,8 +156,10 @@ class appGui(object):
if width > -1 and height > -1: if width > -1 and height > -1:
self.window.resize(int(width), int(height)) self.window.resize(int(width), int(height))
else: else:
self.window.resize(gtk.gdk.screen_width() / 3, width = int(gtk.gdk.screen_width() / 2)
gtk.gdk.screen_height() / 2) if width > 530:
width = 530
self.window.resize(width, int(gtk.gdk.screen_height() / 1.7))
dic = { "refresh_clicked" : self.refresh_clicked, dic = { "refresh_clicked" : self.refresh_clicked,
"quit_clicked" : self.exit, "quit_clicked" : self.exit,
@@ -289,6 +206,7 @@ class appGui(object):
self.wait_for_events(0.2) self.wait_for_events(0.2)
self.window.connect('delete_event', self.exit) self.window.connect('delete_event', self.exit)
self.window.connect('key-release-event', self.key_event) self.window.connect('key-release-event', self.key_event)
daemon.SetGUIOpen(True)
bus.add_signal_receiver(self.dbus_scan_finished, 'SendEndScanSignal', bus.add_signal_receiver(self.dbus_scan_finished, 'SendEndScanSignal',
'org.wicd.daemon.wireless') 'org.wicd.daemon.wireless')
bus.add_signal_receiver(self.dbus_scan_started, 'SendStartScanSignal', bus.add_signal_receiver(self.dbus_scan_started, 'SendStartScanSignal',
@@ -643,25 +561,35 @@ class appGui(object):
def save_settings(self, nettype, networkid, networkentry): def save_settings(self, nettype, networkid, networkentry):
""" Verifies and saves the settings for the network entry. """ """ Verifies and saves the settings for the network entry. """
entry = networkentry.advanced_dialog entry = networkentry.advanced_dialog
entlist = [] opt_entlist = []
req_entlist = []
# First make sure all the Addresses entered are valid. # First make sure all the Addresses entered are valid.
if entry.chkbox_static_ip.get_active(): if entry.chkbox_static_ip.get_active():
entlist = [ent for ent in [entry.txt_ip, entry.txt_netmask, req_entlist = [entry.txt_ip, entry.txt_netmask]
entry.txt_gateway]] opt_entlist = [entry.txt_gateway]
if entry.chkbox_static_dns.get_active() and \ if entry.chkbox_static_dns.get_active() and \
not entry.chkbox_global_dns.get_active(): not entry.chkbox_global_dns.get_active():
entlist.append(entry.txt_dns_1) req_entlist.append(entry.txt_dns_1)
# Only append additional dns entries if they're entered. # Only append additional dns entries if they're entered.
for ent in [entry.txt_dns_2, entry.txt_dns_3]: for ent in [entry.txt_dns_2, entry.txt_dns_3]:
if ent.get_text() != "": if ent.get_text() != "":
entlist.append(ent) opt_entlist.append(ent)
for lblent in entlist:
# Required entries.
for lblent in req_entlist:
if not misc.IsValidIP(lblent.get_text()): if not misc.IsValidIP(lblent.get_text()):
error(self.window, language['invalid_address']. error(self.window, language['invalid_address'].
replace('$A', lblent.label.get_label())) replace('$A', lblent.label.get_label()))
return False return False
# Optional entries, only check for validity if they're entered.
for lblent in opt_entlist:
if lblent.get_text() and not misc.IsValidIP(lblent.get_text()):
error(self.window, language['invalid_address'].
replace('$A', lblent.label.get_label()))
return False
# Now save the settings. # Now save the settings.
if nettype == "wireless": if nettype == "wireless":

111
wicd/guiutil.py Normal file
View File

@@ -0,0 +1,111 @@
""" guiutil - A collection of commonly used gtk/gui functions and classes. """
#
# Copyright (C) 2007 - 2008 Adam Blackburn
# Copyright (C) 2007 - 2008 Dan O'Reilly
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License Version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import gtk
def error(parent, message, block=True):
""" Shows an error dialog. """
def delete_event(dialog, id):
dialog.destroy()
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR,
gtk.BUTTONS_OK)
dialog.set_markup(message)
if not block:
dialog.present()
dialog.connect("response", delete_event)
else:
dialog.run()
dialog.destroy()
def alert(parent, message, block=True):
""" Shows an warning dialog. """
def delete_event(dialog, id):
dialog.destroy()
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING,
gtk.BUTTONS_OK)
dialog.set_markup(message)
if not block:
dialog.present()
dialog.connect("response", delete_event)
else:
dialog.run()
dialog.destroy()
class SmallLabel(gtk.Label):
def __init__(self, text=''):
gtk.Label.__init__(self, text)
self.set_size_request(50, -1)
class LeftAlignedLabel(gtk.Label):
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):
gtk.HBox.__init__(self)
self.entry = gtk.Entry()
self.entry.set_size_request(200, -1)
self.label = SmallLabel()
self.label.set_text(text)
self.label.set_size_request(170, -1)
self.pack_start(self.label, fill=False, expand=False)
self.pack_start(self.entry, fill=False, expand=False)
self.label.show()
self.entry.show()
self.entry.connect('focus-out-event', self.hide_characters)
self.entry.connect('focus-in-event', self.show_characters)
self.auto_hide_text = False
self.show()
def set_text(self, text):
# For compatibility...
self.entry.set_text(text)
def get_text(self):
return self.entry.get_text()
def set_auto_hidden(self, value):
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
if self.auto_hide_text and widget:
self.entry.set_visibility(True)
def set_sensitive(self, value):
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
if self.auto_hide_text and widget:
self.entry.set_visibility(False)
class GreyLabel(gtk.Label):
""" Creates a grey gtk.Label. """
def __init__(self):
gtk.Label.__init__(self)
def set_label(self, text):
self.set_markup("<span color=\"#666666\"><i>" + text + "</i></span>")
self.set_alignment(0, 0)

View File

@@ -318,7 +318,7 @@ def get_gettext():
def to_unicode(x): def to_unicode(x):
""" Attempts to convert a string to utf-8. """ """ Attempts to convert a string to utf-8. """
# If this is a unicode string, encode it and return # If this is a unicode string, encode it and return
if type(x) not in [unicode, str]: if not isinstance(x, basestring):
return x return x
if isinstance(x, unicode): if isinstance(x, unicode):
return x.encode('utf-8') return x.encode('utf-8')
@@ -399,7 +399,7 @@ def choose_sudo_prog():
for p in env_path: for p in env_path:
paths.extend([p + '/gksudo', p + "/gksu", p + '/ktsuss']) paths.extend([p + '/gksudo', p + "/gksu", p + '/ktsuss'])
for path in paths: for path in paths:
if os.access(path, os.F_OK): if os.path.exists(path):
return path return path
return None return None
@@ -414,7 +414,7 @@ def find_path(cmd):
""" """
paths = os.getenv("PATH", default="/usr/bin:/usr/local/bin").split(':') paths = os.getenv("PATH", default="/usr/bin:/usr/local/bin").split(':')
for path in paths: for path in paths:
if os.access(os.path.join(path, cmd), os.F_OK): if os.path.exists(os.path.join(path, cmd)):
return os.path.join(path, cmd) return os.path.join(path, cmd)
return None return None
@@ -435,7 +435,7 @@ def get_language_list_gui():
language['use_static_ip'] = _('Use Static IPs') language['use_static_ip'] = _('Use Static IPs')
language['use_static_dns'] = _('Use Static DNS') language['use_static_dns'] = _('Use Static DNS')
language['use_encryption'] = _('Use Encryption') language['use_encryption'] = _('Use Encryption')
language['advanced_settings'] = _('Advanced Settings') language['advanced_settings'] = _('Properties')
language['wired_network'] = _('Wired Network') language['wired_network'] = _('Wired Network')
language['wired_network_instructions'] = _('To connect to a wired network,' language['wired_network_instructions'] = _('To connect to a wired network,'
' you must create a network profile. To create a network profile, type a' ' you must create a network profile. To create a network profile, type a'

View File

@@ -268,16 +268,16 @@ class ConnectionStatus(object):
error_handler=err_handle) error_handler=err_handle)
self.reconnecting = False self.reconnecting = False
def rescan_networks(self): #def rescan_networks(self):
""" Calls a wireless scan. """ # """ Calls a wireless scan. """
try: # try:
if daemon.GetSuspend() or daemon.CheckIfConnecting(): # if daemon.GetSuspend() or daemon.CheckIfConnecting():
return True # return True
wireless.Scan() # wireless.Scan()
except dbus.exceptions.DBusException, e: # except dbus.exceptions.DBusException, e:
print 'dbus exception while attempting rescan: %s' % str(e) # print 'dbus exception while attempting rescan: %s' % str(e)
finally: # finally:
return True # return True
def reply_handle(): def reply_handle():
""" Just a dummy function needed for asynchronous dbus calls. """ """ Just a dummy function needed for asynchronous dbus calls. """

View File

@@ -19,8 +19,9 @@ import gtk
import os import os
import misc import misc
from misc import noneToString, stringToNone, noneToBlankString, to_bool
import wpath import wpath
from misc import noneToString, stringToNone, noneToBlankString, to_bool
from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel
language = misc.get_language_list_gui() language = misc.get_language_list_gui()
@@ -28,73 +29,6 @@ language = misc.get_language_list_gui()
daemon = None daemon = None
wired = None wired = None
wireless = None wireless = None
def error(parent, message):
""" Shows an error dialog """
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR,
gtk.BUTTONS_OK)
dialog.set_markup(message)
dialog.run()
dialog.destroy()
class SmallLabel(gtk.Label):
def __init__(self, text=''):
gtk.Label.__init__(self, text)
self.set_size_request(50, -1)
class LabelEntry(gtk.HBox):
""" A label on the left with a textbox on the right. """
def __init__(self, text):
gtk.HBox.__init__(self)
self.entry = gtk.Entry()
self.entry.set_size_request(200, -1)
self.label = SmallLabel()
self.label.set_text(text)
self.label.set_size_request(170, -1)
self.pack_start(self.label, fill=False, expand=False)
self.pack_start(self.entry, fill=False, expand=False)
self.label.show()
self.entry.show()
self.entry.connect('focus-out-event', self.hide_characters)
self.entry.connect('focus-in-event', self.show_characters)
self.auto_hide_text = False
self.show()
def set_text(self, text):
# For compatibility...
self.entry.set_text(text)
def get_text(self):
return self.entry.get_text()
def set_auto_hidden(self, value):
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
if self.auto_hide_text and widget:
self.entry.set_visibility(True)
def set_sensitive(self, value):
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
if self.auto_hide_text and widget:
self.entry.set_visibility(False)
class GreyLabel(gtk.Label):
""" Creates a grey gtk.Label. """
def __init__(self):
gtk.Label.__init__(self)
def set_label(self, text):
self.set_markup("<span color=\"#666666\"><i>" + text + "</i></span>")
self.set_alignment(0, 0)
class AdvancedSettingsDialog(gtk.Dialog): class AdvancedSettingsDialog(gtk.Dialog):
def __init__(self): def __init__(self):
@@ -126,6 +60,19 @@ class AdvancedSettingsDialog(gtk.Dialog):
self.hbox_dns.pack_start(self.chkbox_static_dns) self.hbox_dns.pack_start(self.chkbox_static_dns)
self.hbox_dns.pack_start(self.chkbox_global_dns) self.hbox_dns.pack_start(self.chkbox_global_dns)
# Set up the script settings button
self.script_button = gtk.Button()
script_image = gtk.Image()
script_image.set_from_stock(gtk.STOCK_EXECUTE, 4)
script_image.set_padding(4, 0)
#self.script_button.set_alignment(.5, .5)
self.script_button.set_image(script_image)
self.script_button.set_label(language['scripts'])
self.button_hbox = gtk.HBox(False, 2)
self.button_hbox.pack_start(self.script_button, fill=False, expand=False)
self.button_hbox.show()
assert(isinstance(self.vbox, gtk.VBox)) assert(isinstance(self.vbox, gtk.VBox))
self.vbox.pack_start(self.chkbox_static_ip, fill=False, expand=False) self.vbox.pack_start(self.chkbox_static_ip, fill=False, expand=False)
self.vbox.pack_start(self.txt_ip, fill=False, expand=False) self.vbox.pack_start(self.txt_ip, fill=False, expand=False)
@@ -137,6 +84,7 @@ class AdvancedSettingsDialog(gtk.Dialog):
self.vbox.pack_start(self.txt_dns_1, fill=False, expand=False) self.vbox.pack_start(self.txt_dns_1, fill=False, expand=False)
self.vbox.pack_start(self.txt_dns_2, fill=False, expand=False) self.vbox.pack_start(self.txt_dns_2, fill=False, expand=False)
self.vbox.pack_start(self.txt_dns_3, fill=False, expand=False) self.vbox.pack_start(self.txt_dns_3, fill=False, expand=False)
self.vbox.pack_end(self.button_hbox, fill=False, expand=False, padding=5)
# Connect the events to the actions # Connect the events to the actions
@@ -277,12 +225,27 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
""" Build the wired settings dialog. """ """ Build the wired settings dialog. """
AdvancedSettingsDialog.__init__(self) AdvancedSettingsDialog.__init__(self)
self.des = self.connect("destroy", self.destroy_called) self.des = self.connect("destroy", self.destroy_called)
self.script_button.connect("button-press-event", self.edit_scripts)
self.prof_name = name self.prof_name = name
def set_net_prop(self, option, value): def set_net_prop(self, option, value):
""" Sets the given option to the given value for this network. """ """ Sets the given option to the given value for this network. """
wired.SetWiredProperty(option, value) wired.SetWiredProperty(option, value)
def edit_scripts(self, widget=None, event=None):
""" Launch the script editting dialog. """
profile = self.combo_profile_names.get_active_text()
cmdend = [os.path.join(wpath.lib, "configscript.py"), profile, "wired"]
if os.getuid() != 0:
cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'])
if not cmdbase:
error(None, language["no_sudo_prog"])
return
cmdbase.extend(cmdend)
misc.LaunchAndWait(cmdbase)
else:
misc.LaunchAndWait(cmdend)
def set_values(self): def set_values(self):
""" Fill in the Gtk.Entry objects with the correct values. """ """ Fill in the Gtk.Entry objects with the correct values. """
self.txt_ip.set_text(self.format_entry("ip")) self.txt_ip.set_text(self.format_entry("ip"))
@@ -330,12 +293,16 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
self.combo_encryption.set_sensitive(False) self.combo_encryption.set_sensitive(False)
self.encrypt_types = misc.LoadEncryptionMethods() self.encrypt_types = misc.LoadEncryptionMethods()
information_button = gtk.Button(stock=gtk.STOCK_INFO)
self.button_hbox.pack_start(information_button, False, False)
information_button.connect('clicked', lambda *a, **k: WirelessInformationDialog(networkID))
information_button.show()
# Build the encryption menu # Build the encryption menu
activeID = -1 # Set the menu to this item when we are done activeID = -1 # Set the menu to this item when we are done
for x, enc_type in enumerate(self.encrypt_types): for x, enc_type in enumerate(self.encrypt_types):
self.combo_encryption.append_text(enc_type[0]) self.combo_encryption.append_text(enc_type[0])
if enc_type[1] == wireless.GetWirelessProperty(networkID, if enc_type[1] == wireless.GetWirelessProperty(networkID, "enctype"):
"enctype"):
activeID = x activeID = x
self.combo_encryption.set_active(activeID) self.combo_encryption.set_active(activeID)
if activeID != -1: if activeID != -1:
@@ -354,6 +321,7 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
# Connect signals. # Connect signals.
self.chkbox_encryption.connect("toggled", self.toggle_encryption) self.chkbox_encryption.connect("toggled", self.toggle_encryption)
self.combo_encryption.connect("changed", self.change_encrypt_method) self.combo_encryption.connect("changed", self.change_encrypt_method)
self.script_button.connect("button-press-event", self.edit_scripts)
self.des = self.connect("destroy", self.destroy_called) self.des = self.connect("destroy", self.destroy_called)
def destroy_called(self, *args): def destroy_called(self, *args):
@@ -363,6 +331,20 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
self.destroy() self.destroy()
del self del self
def edit_scripts(self, widget=None, event=None):
""" Launch the script editting dialog. """
cmdend = [os.path.join(wpath.lib, "configscript.py"),
str(self.networkID), "wireless"]
if os.getuid() != 0:
cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'])
if not cmdbase:
error(None, language["no_sudo_prog"])
return
cmdbase.extend(cmdend)
misc.LaunchAndWait(cmdbase)
else:
misc.LaunchAndWait(cmdend)
def set_net_prop(self, option, value): def set_net_prop(self, option, value):
""" Sets the given option to the given value for this network. """ """ Sets the given option to the given value for this network. """
wireless.SetWirelessProperty(self.networkID, option, value) wireless.SetWirelessProperty(self.networkID, option, value)
@@ -418,17 +400,16 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
if encryption_info[x].get_text() == "": if encryption_info[x].get_text() == "":
error(self, language['encrypt_info_missing']) error(self, language['encrypt_info_missing'])
return False return False
self.set_net_prop(x, noneToString(encryption_info[x]. self.set_net_prop(x, noneToString(encryption_info[x].get_text()))
get_text()))
elif not self.chkbox_encryption.get_active() and \ elif not self.chkbox_encryption.get_active() and \
wireless.GetWirelessProperty(networkid, "encryption"): wireless.GetWirelessProperty(networkid, "encryption"):
error(self, language['enable_encryption']) error(self, language['enable_encryption'])
return False return False
else: else:
print 'encryption is ' + str(wireless.GetWirelessProperty(networkid,
"encryption"))
print "no encryption specified..." print "no encryption specified..."
self.set_net_prop("enctype", "None") self.set_net_prop("enctype", "None")
for x in self.encryption_info:
self.set_net_prop(x, "")
AdvancedSettingsDialog.save_settings(self) AdvancedSettingsDialog.save_settings(self)
if self.chkbox_global_settings.get_active(): if self.chkbox_global_settings.get_active():
@@ -479,7 +460,7 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
box.entry.set_text(noneToBlankString( box.entry.set_text(noneToBlankString(
wireless.GetWirelessProperty(self.networkID, opts[x][1]))) wireless.GetWirelessProperty(self.networkID, opts[x][1])))
self.vbox_encrypt_info.show_all() self.vbox_encrypt_info.show_all()
class NetworkEntry(gtk.HBox): class NetworkEntry(gtk.HBox):
@@ -500,15 +481,16 @@ class NetworkEntry(gtk.HBox):
# Create an HBox to hold the buttons # Create an HBox to hold the buttons
self.buttons_hbox = gtk.HBox(False, 6) self.buttons_hbox = gtk.HBox(False, 6)
# self.buttons_hbox.set_border_width(5)
# Set up the Connect button # Set up the Connect button
self.connect_button = gtk.Button(stock=gtk.STOCK_CONNECT) self.connect_button = gtk.Button(stock=gtk.STOCK_CONNECT)
self.buttons_hbox.pack_start(self.connect_button, False, False) self.connect_hbox = gtk.HBox(False, 2)
self.connect_hbox.pack_start(self.connect_button, False, False)
self.connect_hbox.show()
# Set up the Disconnect button # Set up the Disconnect button
self.disconnect_button = gtk.Button(stock=gtk.STOCK_DISCONNECT) self.disconnect_button = gtk.Button(stock=gtk.STOCK_DISCONNECT)
self.buttons_hbox.pack_start(self.disconnect_button, False, False) self.connect_hbox.pack_start(self.disconnect_button, False, False)
# Create a label to hold the name of the entry # Create a label to hold the name of the entry
self.name_label = gtk.Label() self.name_label = gtk.Label()
@@ -528,23 +510,18 @@ class NetworkEntry(gtk.HBox):
self.advanced_button.set_label(language['advanced_settings']) self.advanced_button.set_label(language['advanced_settings'])
self.advanced_button.set_image(self.advanced_image) self.advanced_button.set_image(self.advanced_image)
# Set up the script settings button #self.buttons_hbox.pack_start(self.script_button, False, False)
self.script_button = gtk.Button() self.buttons_hbox.pack_start(self.connect_hbox, False, False)
self.script_image = gtk.Image()
self.script_image.set_from_stock(gtk.STOCK_EXECUTE, 4)
self.script_image.set_padding(4, 0)
self.script_button.set_alignment(.5, .5)
self.script_button.set_image(self.script_image)
self.script_button.set_label(language['scripts'])
self.buttons_hbox.pack_start(self.script_button, False, False)
self.buttons_hbox.pack_start(self.advanced_button, False, False) self.buttons_hbox.pack_start(self.advanced_button, False, False)
self.vbox_top = gtk.VBox(False, 0) self.vbox_top = gtk.VBox(False, 0)
self.vbox_top.pack_end(self.buttons_hbox, False, False) #self.vbox_top.pack_end(self.buttons_hbox, False, False)
#self.vbox_top.pack_end(self.connect_hbox, False, False)
self.expander_vbox.pack_start(self.name_label) self.expander_vbox.pack_start(self.name_label)
self.expander_vbox.pack_start(self.vbox_top) self.expander_vbox.pack_start(self.vbox_top)
self.expander_vbox.pack_start(self.buttons_hbox)
def destroy_called(self, *args): def destroy_called(self, *args):
""" Clean up everything. """ """ Clean up everything. """
@@ -603,7 +580,6 @@ class WiredNetworkEntry(NetworkEntry):
self.chkbox_default_profile.connect("toggled", self.chkbox_default_profile.connect("toggled",
self.toggle_default_profile) self.toggle_default_profile)
self.combo_profile_names.connect("changed", self.change_profile) self.combo_profile_names.connect("changed", self.change_profile)
self.script_button.connect("button-press-event", self.edit_scripts)
# Toggle the default profile checkbox to the correct state. # Toggle the default profile checkbox to the correct state.
if to_bool(wired.GetWiredProperty("default")): if to_bool(wired.GetWiredProperty("default")):
@@ -645,20 +621,6 @@ class WiredNetworkEntry(NetworkEntry):
def save_wired_settings(self): def save_wired_settings(self):
""" Save wired network settings. """ """ Save wired network settings. """
return self.advanced_dialog.save_settings() return self.advanced_dialog.save_settings()
def edit_scripts(self, widget=None, event=None):
""" Launch the script editting dialog. """
profile = self.combo_profile_names.get_active_text()
cmdend = [os.path.join(wpath.lib, "configscript.py"), profile, "wired"]
if os.getuid() != 0:
cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'])
if not cmdbase:
error(None, language["no_sudo_prog"])
return
cmdbase.extend(cmdend)
misc.LaunchAndWait(cmdbase)
else:
misc.LaunchAndWait(cmdend)
def check_enable(self): def check_enable(self):
""" Disable objects if the profile list is empty. """ """ Disable objects if the profile list is empty. """
@@ -667,7 +629,6 @@ class WiredNetworkEntry(NetworkEntry):
self.button_delete.set_sensitive(False) self.button_delete.set_sensitive(False)
self.connect_button.set_sensitive(False) self.connect_button.set_sensitive(False)
self.advanced_button.set_sensitive(False) self.advanced_button.set_sensitive(False)
self.script_button.set_sensitive(False)
def update_connect_button(self, state, apbssid=None): def update_connect_button(self, state, apbssid=None):
""" Update the connection/disconnect button for this entry. """ """ Update the connection/disconnect button for this entry. """
@@ -696,7 +657,6 @@ class WiredNetworkEntry(NetworkEntry):
self.button_delete.set_sensitive(True) self.button_delete.set_sensitive(True)
self.connect_button.set_sensitive(True) self.connect_button.set_sensitive(True)
self.advanced_button.set_sensitive(True) self.advanced_button.set_sensitive(True)
self.script_button.set_sensitive(True)
def remove_profile(self, widget): def remove_profile(self, widget):
""" Remove a profile from the profile list. """ """ Remove a profile from the profile list. """
@@ -714,7 +674,6 @@ class WiredNetworkEntry(NetworkEntry):
if self.is_full_gui: if self.is_full_gui:
self.button_delete.set_sensitive(False) self.button_delete.set_sensitive(False)
self.advanced_button.set_sensitive(False) self.advanced_button.set_sensitive(False)
self.script_button.set_sensitive(False)
self.connect_button.set_sensitive(False) self.connect_button.set_sensitive(False)
else: else:
self.profile_help.hide() self.profile_help.hide()
@@ -761,47 +720,35 @@ class WirelessNetworkEntry(NetworkEntry):
self.networkID = networkID self.networkID = networkID
self.image.set_padding(0, 0) self.image.set_padding(0, 0)
self.image.set_alignment(0.5, 0.5) self.image.set_alignment(.5, .5)
self.image.set_size_request(60, -1) self.image.set_size_request(60, -1)
self.image.show()
#self.image.set_from_icon_name("network-wired", 6) #self.image.set_from_icon_name("network-wired", 6)
self.essid = noneToBlankString(wireless.GetWirelessProperty(networkID, self.essid = noneToBlankString(wireless.GetWirelessProperty(networkID,
"essid")) "essid"))
self.lbl_strength = GreyLabel()
self.lbl_encryption = GreyLabel()
self.lbl_channel = GreyLabel()
print "ESSID : " + self.essid print "ESSID : " + self.essid
# Make the combo box.
self.lbl_strength = gtk.Label()
self.lbl_strength.set_alignment(0, 0.5)
self.lbl_encryption = gtk.Label()
self.lbl_encryption.set_alignment(0, 0.5)
self.lbl_mac = gtk.Label()
self.lbl_mac.set_alignment(0, 0.5)
self.lbl_channel = gtk.Label()
self.lbl_channel.set_alignment(0, 0.5)
self.lbl_mode = gtk.Label()
self.lbl_mode.set_alignment(0, 0.5)
self.hbox_status = gtk.HBox(False, 5)
self.chkbox_autoconnect = gtk.CheckButton(language['automatic_connect']) self.chkbox_autoconnect = gtk.CheckButton(language['automatic_connect'])
# Set the values of the network info labels.
self.set_signal_strength(wireless.GetWirelessProperty(networkID, self.set_signal_strength(wireless.GetWirelessProperty(networkID,
'quality'), 'quality'),
wireless.GetWirelessProperty(networkID, wireless.GetWirelessProperty(networkID,
'strength')) 'strength'))
self.set_mac_address(wireless.GetWirelessProperty(networkID, 'bssid')) self.set_encryption(wireless.GetWirelessProperty(networkID,
self.set_mode(wireless.GetWirelessProperty(networkID, 'mode'))
self.set_channel(wireless.GetWirelessProperty(networkID, 'channel'))
self.set_encryption(wireless.GetWirelessProperty(networkID,
'encryption'), 'encryption'),
wireless.GetWirelessProperty(networkID, wireless.GetWirelessProperty(networkID,
'encryption_method')) 'encryption_method'))
self.set_channel(wireless.GetWirelessProperty(networkID, 'channel'))
self.name_label.set_markup(self._escape(self.essid)) self.name_label.set_use_markup(True)
self.name_label.set_label("%s %s %s %s" % (self._escape(self.essid),
information_button = gtk.Button(stock=gtk.STOCK_INFO) self.lbl_strength.get_label(),
self.lbl_encryption.get_label(),
self.buttons_hbox.pack_start(information_button, False, False) self.lbl_channel.get_label(),
)
information_button.connect('clicked', self.show_info_dialog) )
# Add the wireless network specific parts to the NetworkEntry # Add the wireless network specific parts to the NetworkEntry
# VBox objects. # VBox objects.
self.vbox_top.pack_start(self.chkbox_autoconnect, False, False) self.vbox_top.pack_start(self.chkbox_autoconnect, False, False)
@@ -813,55 +760,13 @@ class WirelessNetworkEntry(NetworkEntry):
self.chkbox_autoconnect.set_active(False) self.chkbox_autoconnect.set_active(False)
# Connect signals. # Connect signals.
self.chkbox_autoconnect.connect("toggled", self.update_autoconnect) self.chkbox_autoconnect.connect("toggled", self.update_autoconnect)
self.script_button.connect("button-press-event", self.edit_scripts)
# Show everything # Show everything
self.show_all() self.show_all()
self.advanced_dialog = WirelessSettingsDialog(networkID) self.advanced_dialog = WirelessSettingsDialog(networkID)
self.wifides = self.connect("destroy", self.destroy_called) self.wifides = self.connect("destroy", self.destroy_called)
def show_info_dialog(self, button=None):
dialog = gtk.Dialog()
dialog.set_title('Network Information')
vbox = dialog.vbox
dialog.set_has_separator(False)
# dialog.set_border_width(12)
table = gtk.Table(5, 2)
table.set_col_spacings(12)
vbox.pack_start(table)
class LeftAlignedLabel(gtk.Label):
def __init__(self, label=None):
gtk.Label.__init__(self, label)
self.set_alignment(0.0, 0.5)
# Pack the network status HBox.
table.attach(LeftAlignedLabel('Signal strength'), 0, 1, 0, 1)
table.attach(self.lbl_strength, 1, 2, 0, 1)
table.attach(LeftAlignedLabel('Encryption type'), 0, 1, 1, 2)
table.attach(self.lbl_encryption, 1, 2, 1, 2)
table.attach(LeftAlignedLabel('Access point address'), 0, 1, 2, 3)
table.attach(self.lbl_mac, 1, 2, 2, 3)
table.attach(LeftAlignedLabel('Mode'), 0, 1, 3, 4)
table.attach(self.lbl_mode, 1, 2, 3, 4)
table.attach(LeftAlignedLabel('Channel'), 0, 1, 4, 5)
table.attach(self.lbl_channel, 1, 2, 4, 5)
vbox.show_all()
dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
dialog.run()
dialog.destroy()
def _escape(self, val): def _escape(self, val):
""" Escapes special characters so they're displayed correctly. """ """ Escapes special characters so they're displayed correctly. """
return val.replace("&", "&amp;").replace("<", "&lt;").\ return val.replace("&", "&amp;").replace("<", "&lt;").\
@@ -870,7 +775,14 @@ class WirelessNetworkEntry(NetworkEntry):
def save_wireless_settings(self, networkid): def save_wireless_settings(self, networkid):
""" Save wireless network settings. """ """ Save wireless network settings. """
return self.advanced_dialog.save_settings(networkid) return self.advanced_dialog.save_settings(networkid)
def update_autoconnect(self, widget=None):
""" Called when the autoconnect checkbox is toggled. """
wireless.SetWirelessProperty(self.networkID, "automatic",
noneToString(self.chkbox_autoconnect.
get_active()))
wireless.SaveWirelessNetworkProperty(self.networkID, "automatic")
def destroy_called(self, *args): def destroy_called(self, *args):
""" Clean up everything. """ """ Clean up everything. """
self.disconnect(self.wifides) self.disconnect(self.wifides)
@@ -879,7 +791,19 @@ class WirelessNetworkEntry(NetworkEntry):
super(WirelessNetworkEntry, self).destroy_called() super(WirelessNetworkEntry, self).destroy_called()
self.destroy() self.destroy()
del self del self
def update_connect_button(self, state, apbssid):
""" Update the connection/disconnect button for this entry. """
if not apbssid:
apbssid = wireless.GetApBssid()
if state == misc.WIRELESS and \
apbssid == wireless.GetWirelessProperty(self.networkID, "bssid"):
self.disconnect_button.show()
self.connect_button.hide()
else:
self.disconnect_button.hide()
self.connect_button.show()
def set_signal_strength(self, strength, dbm_strength): def set_signal_strength(self, strength, dbm_strength):
""" Set the signal strength displayed in the WirelessNetworkEntry. """ """ Set the signal strength displayed in the WirelessNetworkEntry. """
if strength is not None: if strength is not None:
@@ -918,21 +842,127 @@ class WirelessNetworkEntry(NetworkEntry):
signal_img = 'signal-25.png' signal_img = 'signal-25.png'
ending = "%" ending = "%"
disp_strength = str(strength) disp_strength = str(strength)
self.image.set_from_file(wpath.images + signal_img) self.image.set_from_file(wpath.images + signal_img)
self.lbl_strength.set_label(disp_strength + ending) self.lbl_strength.set_label(disp_strength + ending)
self.image.show()
def update_connect_button(self, state, apbssid): def set_encryption(self, on, ttype):
""" Update the connection/disconnect button for this entry. """ """ Set the encryption value for the WirelessNetworkEntry. """
if not apbssid: if on and ttype:
apbssid = wireless.GetApBssid() self.lbl_encryption.set_label(str(ttype))
if state == misc.WIRELESS and \ if on and not ttype:
apbssid == wireless.GetWirelessProperty(self.networkID, "bssid"): self.lbl_encryption.set_label(language['secured'])
self.disconnect_button.show() if not on:
self.connect_button.hide() self.lbl_encryption.set_label(language['unsecured'])
def set_channel(self, channel):
""" Set the channel value for the WirelessNetworkEntry. """
self.lbl_channel.set_label(language['channel'] + ' ' + str(channel))
def format_entry(self, networkid, label):
""" Helper method for fetching/formatting wireless properties. """
return noneToBlankString(wireless.GetWirelessProperty(networkid, label))
class WirelessInformationDialog(gtk.Dialog):
def __init__(self, networkID):
gtk.Dialog.__init__(self)
# Make the combo box.
self.lbl_strength = gtk.Label()
self.lbl_strength.set_alignment(0, 0.5)
self.lbl_encryption = gtk.Label()
self.lbl_encryption.set_alignment(0, 0.5)
self.lbl_mac = gtk.Label()
self.lbl_mac.set_alignment(0, 0.5)
self.lbl_channel = gtk.Label()
self.lbl_channel.set_alignment(0, 0.5)
self.lbl_mode = gtk.Label()
self.lbl_mode.set_alignment(0, 0.5)
self.hbox_status = gtk.HBox(False, 5)
# Set the values of the network info labels.
self.set_signal_strength(wireless.GetWirelessProperty(networkID,
'quality'),
wireless.GetWirelessProperty(networkID,
'strength'))
self.set_mac_address(wireless.GetWirelessProperty(networkID, 'bssid'))
self.set_mode(wireless.GetWirelessProperty(networkID, 'mode'))
self.set_channel(wireless.GetWirelessProperty(networkID, 'channel'))
self.set_encryption(wireless.GetWirelessProperty(networkID,
'encryption'),
wireless.GetWirelessProperty(networkID,
'encryption_method'))
self.set_title('Network Information')
vbox = self.vbox
self.set_has_separator(False)
table = gtk.Table(5, 2)
table.set_col_spacings(12)
vbox.pack_start(table)
# Pack the network status HBox.
table.attach(LeftAlignedLabel('Signal strength:'), 0, 1, 0, 1)
table.attach(self.lbl_strength, 1, 2, 0, 1)
table.attach(LeftAlignedLabel('Encryption type:'), 0, 1, 1, 2)
table.attach(self.lbl_encryption, 1, 2, 1, 2)
table.attach(LeftAlignedLabel('Access point address:'), 0, 1, 2, 3)
table.attach(self.lbl_mac, 1, 2, 2, 3)
table.attach(LeftAlignedLabel('Mode:'), 0, 1, 3, 4)
table.attach(self.lbl_mode, 1, 2, 3, 4)
table.attach(LeftAlignedLabel('Channel:'), 0, 1, 4, 5)
table.attach(self.lbl_channel, 1, 2, 4, 5)
vbox.show_all()
self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
self.show()
self.run()
self.destroy()
def set_signal_strength(self, strength, dbm_strength):
""" Set the signal strength displayed in the WirelessNetworkEntry. """
if strength is not None:
strength = int(strength)
else: else:
self.disconnect_button.hide() strength = -1
self.connect_button.show() if dbm_strength is not None:
dbm_strength = int(dbm_strength)
else:
dbm_strength = -100
display_type = daemon.GetSignalDisplayType()
if daemon.GetWPADriver() == 'ralink legacy' or display_type == 1:
# Use the -xx dBm signal strength to display a signal icon
# I'm not sure how accurately the dBm strength is being
# "converted" to strength bars, so suggestions from people
# for a better way would be welcome.
if dbm_strength >= -60:
signal_img = 'signal-100.png'
elif dbm_strength >= -70:
signal_img = 'signal-75.png'
elif dbm_strength >= -80:
signal_img = 'signal-50.png'
else:
signal_img = 'signal-25.png'
ending = "dBm"
disp_strength = str(dbm_strength)
else:
# Uses normal link quality, should be fine in most cases
if strength > 75:
signal_img = 'signal-100.png'
elif strength > 50:
signal_img = 'signal-75.png'
elif strength > 25:
signal_img = 'signal-50.png'
else:
signal_img = 'signal-25.png'
ending = "%"
disp_strength = str(strength)
self.lbl_strength.set_label(disp_strength + ending)
def set_mac_address(self, address): def set_mac_address(self, address):
""" Set the MAC address for the WirelessNetworkEntry. """ """ Set the MAC address for the WirelessNetworkEntry. """
@@ -958,24 +988,3 @@ class WirelessNetworkEntry(NetworkEntry):
def format_entry(self, networkid, label): def format_entry(self, networkid, label):
""" Helper method for fetching/formatting wireless properties. """ """ Helper method for fetching/formatting wireless properties. """
return noneToBlankString(wireless.GetWirelessProperty(networkid, label)) return noneToBlankString(wireless.GetWirelessProperty(networkid, label))
def edit_scripts(self, widget=None, event=None):
""" Launch the script editting dialog. """
cmdend = [os.path.join(wpath.lib, "configscript.py"),
str(self.networkID), "wireless"]
if os.getuid() != 0:
cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'])
if not cmdbase:
error(None, language["no_sudo_prog"])
return
cmdbase.extend(cmdend)
misc.LaunchAndWait(cmdbase)
else:
misc.LaunchAndWait(cmdend)
def update_autoconnect(self, widget=None):
""" Called when the autoconnect checkbox is toggled. """
wireless.SetWirelessProperty(self.networkID, "automatic",
noneToString(self.chkbox_autoconnect.
get_active()))
wireless.SaveWirelessNetworkProperty(self.networkID, "automatic")

View File

@@ -393,8 +393,9 @@ class ConnectThread(threading.Thread):
self.SetStatus('setting_static_ip') self.SetStatus('setting_static_ip')
print 'Setting static IP : ' + self.network['ip'] print 'Setting static IP : ' + self.network['ip']
iface.SetAddress(self.network['ip'], self.network['netmask']) iface.SetAddress(self.network['ip'], self.network['netmask'])
print 'Setting default gateway : ' + self.network['gateway'] if self.network.get('gateway'):
iface.SetDefaultRoute(self.network['gateway']) print 'Setting default gateway : ' + self.network['gateway']
iface.SetDefaultRoute(self.network['gateway'])
else: else:
# Run dhcp... # Run dhcp...
self.SetStatus('running_dhcp') self.SetStatus('running_dhcp')

View File

@@ -40,14 +40,6 @@ wired = None
language = misc.get_language_list_gui() language = misc.get_language_list_gui()
def alert(parent, message):
""" Shows an alert dialog """
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING,
gtk.BUTTONS_OK)
dialog.set_markup(message)
dialog.run()
dialog.destroy()
class PreferencesDialog(object): class PreferencesDialog(object):
""" Class for handling the wicd preferences dialog window. """ """ Class for handling the wicd preferences dialog window. """
def __init__(self, wTree, dbus): def __init__(self, wTree, dbus):
@@ -254,8 +246,10 @@ class PreferencesDialog(object):
if width > -1 and height > -1: if width > -1 and height > -1:
self.dialog.resize(int(width), int(height)) self.dialog.resize(int(width), int(height))
else: else:
self.dialog.resize(gtk.gdk.screen_width() / 3, width = int(gtk.gdk.screen_width() / 2.4)
gtk.gdk.screen_height() / 2) if width > 450:
width = 450
self.dialog.resize(width, int(gtk.gdk.screen_height() / 2))
self.wiredcheckbox = setup_label("pref_always_check", self.wiredcheckbox = setup_label("pref_always_check",
'wired_always_on') 'wired_always_on')

View File

@@ -43,13 +43,14 @@ import getopt
import os import os
import pango import pango
import time import time
from dbus import DBusException import atexit
# Wicd specific imports # Wicd specific imports
from wicd import wpath from wicd import wpath
from wicd import misc from wicd import misc
from wicd import gui from wicd import gui
from wicd import dbusmanager from wicd import dbusmanager
from wicd.guiutil import error
ICON_AVAIL = True ICON_AVAIL = True
USE_EGG = False USE_EGG = False
@@ -364,7 +365,7 @@ class TrayIcon(object):
if DBUS_AVAIL: if DBUS_AVAIL:
self.toggle_wicd_gui() self.toggle_wicd_gui()
else: else:
# gui.error(None, language["daemon_unavailable"]) # error(None, language["daemon_unavailable"])
pass pass
def on_quit(self, widget=None): def on_quit(self, widget=None):
@@ -652,8 +653,8 @@ def setup_dbus(force=True):
misc.PromptToStartDaemon() misc.PromptToStartDaemon()
try: try:
dbusmanager.connect_to_dbus() dbusmanager.connect_to_dbus()
except DBusException: except dbusmanager.DBusException:
gui.error(None, "Could not connect to wicd's D-Bus interface. " + error(None, "Could not connect to wicd's D-Bus interface. " +
"Check the wicd log for error messages.") "Check the wicd log for error messages.")
return False return False
else: else:
@@ -669,12 +670,19 @@ def setup_dbus(force=True):
return True return True
def on_exit():
if DBUS_AVAIL:
try:
daemon.SetGUIOpen(False)
except dbusmanager.DBusException:
pass
def handle_no_dbus(): def handle_no_dbus():
global DBUS_AVAIL global DBUS_AVAIL
DBUS_AVAIL = False DBUS_AVAIL = False
gui.handle_no_dbus(from_tray=True) gui.handle_no_dbus(from_tray=True)
print "Wicd daemon is shutting down!" print "Wicd daemon is shutting down!"
gui.error(None, language['lost_dbus'], block=False) error(None, language['lost_dbus'], block=False)
return False return False
def main(argv): def main(argv):
@@ -709,7 +717,8 @@ def main(argv):
print 'Loading...' print 'Loading...'
setup_dbus() setup_dbus()
atexit.register(on_exit)
if not use_tray or not ICON_AVAIL: if not use_tray or not ICON_AVAIL:
the_gui = gui.appGui(standalone=True) the_gui = gui.appGui(standalone=True)
mainloop = gobject.MainLoop() mainloop = gobject.MainLoop()

View File

@@ -91,9 +91,11 @@ class WicdDaemon(dbus.service.Object):
self.vpn_session = None self.vpn_session = None
self.gui_open = False self.gui_open = False
self.suspended = False self.suspended = False
self._debug_mode = False
self.connection_state = misc.NOT_CONNECTED self.connection_state = misc.NOT_CONNECTED
self.connection_info = [""] self.connection_info = [""]
self.auto_connecting = False self.auto_connecting = False
self.prefer_wired = False
self.dhcp_client = 0 self.dhcp_client = 0
self.link_detect_tool = 0 self.link_detect_tool = 0
self.flush_tool = 0 self.flush_tool = 0
@@ -122,6 +124,13 @@ class WicdDaemon(dbus.service.Object):
self.SetForcedDisconnect(True) self.SetForcedDisconnect(True)
print "--no-autoconnect detected, not autoconnecting..." print "--no-autoconnect detected, not autoconnecting..."
def get_debug_mode(self):
return self._debug_mode
def set_debug_mode(self, mode):
self._debug_mode = mode
self.config.debug = mode
debug_mode = property(get_debug_mode, set_debug_mode)
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def Hello(self): def Hello(self):
""" Returns the version number. """ Returns the version number.
@@ -319,6 +328,10 @@ class WicdDaemon(dbus.service.Object):
fails it tries a wireless connection. fails it tries a wireless connection.
""" """
# We don't want to rescan/connect if the gui is open.
if self.gui_open:
return
if fresh: if fresh:
self.wireless_bus.Scan() self.wireless_bus.Scan()
if self.wired_bus.CheckPluggedIn(): if self.wired_bus.CheckPluggedIn():
@@ -400,7 +413,8 @@ class WicdDaemon(dbus.service.Object):
def ShouldAutoReconnect(self): def ShouldAutoReconnect(self):
""" Returns True if it's the right time to try autoreconnecting. """ """ Returns True if it's the right time to try autoreconnecting. """
if self.GetAutoReconnect() and not self.CheckIfConnecting() and \ if self.GetAutoReconnect() and not self.CheckIfConnecting() and \
not self.GetForcedDisconnect() and not self.auto_connecting: not self.GetForcedDisconnect() and not self.auto_connecting and \
not self.gui_open:
return True return True
else: else:
return False return False
@@ -421,6 +435,7 @@ class WicdDaemon(dbus.service.Object):
started. started.
""" """
if self.debug_mode and value: print "Forced disconnect on"
self.forced_disconnect = bool(value) self.forced_disconnect = bool(value)
self.wireless_bus.SetForcedDisconnect(bool(value)) self.wireless_bus.SetForcedDisconnect(bool(value))
self.wired_bus.SetForcedDisconnect(bool(value)) self.wired_bus.SetForcedDisconnect(bool(value))
@@ -492,7 +507,23 @@ class WicdDaemon(dbus.service.Object):
def GetWiredAutoConnectMethod(self): def GetWiredAutoConnectMethod(self):
""" Returns the wired autoconnect method. """ """ Returns the wired autoconnect method. """
return int(self.wired_connect_mode) return int(self.wired_connect_mode)
@dbus.service.method('org.wicd.dameon')
def GetPreferWiredNetwork(self):
""" Returns True if wired network preference is set.
If this is True, wicd will switch from a wireless connection
to a wired one if an ethernet connection is available.
"""
return self.prefer_wired
@dbus.service.method('org.wicd.daemon')
def SetPreferWiredNetwork(self, value):
""" Sets the prefer_wired state. """
self.prefer_wired = value
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetConnectionStatus(self, state, info): def SetConnectionStatus(self, state, info):
""" Sets the connection status. """ Sets the connection status.
@@ -630,13 +661,13 @@ class WicdDaemon(dbus.service.Object):
""" """
if win_name == "main": if win_name == "main":
default_width = 605 default_width = -1
default_height = 400 default_height = -1
width_str = "window_width" width_str = "window_width"
height_str = "window_height" height_str = "window_height"
else: else:
default_width = 125 default_width = -1
default_height = 500 default_height = -1
width_str = "pref_width" width_str = "pref_width"
height_str = "pref_height" height_str = "pref_height"
@@ -823,6 +854,8 @@ class WicdDaemon(dbus.service.Object):
self.SetLinkDetectionTool(app_conf.get("Settings", "link_detect_tool", self.SetLinkDetectionTool(app_conf.get("Settings", "link_detect_tool",
default=0)) default=0))
self.SetFlushTool(app_conf.get("Settings", "flush_tool", default=0)) self.SetFlushTool(app_conf.get("Settings", "flush_tool", default=0))
self.SetPreferWiredNetwork(app_conf.get("Settings", "prefer_wired",
default=False))
app_conf.write() app_conf.write()
if os.path.isfile(wireless_conf): if os.path.isfile(wireless_conf):
@@ -867,10 +900,18 @@ class WirelessDaemon(dbus.service.Object):
self.hidden_essid = None self.hidden_essid = None
self.daemon = daemon self.daemon = daemon
self.wifi = wifi self.wifi = wifi
self.debug_mode = debug self._debug_mode = debug
self.forced_disconnect = False self.forced_disconnect = False
self.config = ConfigManager(os.path.join(wpath.etc, self.config = ConfigManager(os.path.join(wpath.etc,
"wireless-settings.conf")) "wireless-settings.conf"),
debug=debug)
def get_debug_mode(self):
return self._debug_mode
def set_debug_mode(self, mode):
self._debug_mode = mode
self.config.debug = mode
debug_mode = property(get_debug_mode, set_debug_mode)
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def SetHiddenNetworkESSID(self, essid): def SetHiddenNetworkESSID(self, essid):
@@ -1216,11 +1257,19 @@ class WiredDaemon(dbus.service.Object):
object_path="/org/wicd/daemon/wired") object_path="/org/wicd/daemon/wired")
self.daemon = daemon self.daemon = daemon
self.wired = wired self.wired = wired
self.debug_mode = debug self._debug_mode = debug
self.forced_disconnect = False self.forced_disconnect = False
self.WiredNetwork = {} self.WiredNetwork = {}
self.config = ConfigManager(os.path.join(wpath.etc, self.config = ConfigManager(os.path.join(wpath.etc,
"wired-settings.conf")) "wired-settings.conf"),
debug=debug)
def get_debug_mode(self):
return self._debug_mode
def set_debug_mode(self, mode):
self._debug_mode = mode
self.config.debug = mode
debug_mode = property(get_debug_mode, set_debug_mode)
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def GetWiredIP(self, ifconfig=""): def GetWiredIP(self, ifconfig=""):

View File

@@ -33,6 +33,7 @@ class WirelessInterface() -- Control a wireless network interface.
import os import os
import re import re
import random
from string import maketrans, translate, punctuation from string import maketrans, translate, punctuation
import wpath import wpath
@@ -138,8 +139,8 @@ def NeedsExternalCalls():
def IsValidWpaSuppDriver(driver): def IsValidWpaSuppDriver(driver):
""" Returns True if given string is a valid wpa_supplicant driver. """ """ Returns True if given string is a valid wpa_supplicant driver. """
output = misc.Run(["wpa_supplicant", "-D%s" % driver, "-iwlan9", output = misc.Run(["wpa_supplicant", "-D%s" % driver, "-iolan19",
"-c/etc/zzzzzzzz.confzzz"]) "-c/etc/abcd%sdefzz.zconfz" % random.randint(1, 1000)])
if re.match("Unsupported driver", output): if re.match("Unsupported driver", output):
return False return False
else: else:
@@ -195,7 +196,7 @@ class BaseInterface(object):
paths = ['/sbin/', '/usr/sbin/', '/bin/', '/usr/bin/', paths = ['/sbin/', '/usr/sbin/', '/bin/', '/usr/bin/',
'/usr/local/sbin/', '/usr/local/bin/'] '/usr/local/sbin/', '/usr/local/bin/']
for path in paths: for path in paths:
if os.access("%s%s" % (path, client), os.F_OK): if os.path.exists("%s%s" % (path, client)):
return "%s%s" % (path, client) return "%s%s" % (path, client)
if self.verbose: if self.verbose:
print "WARNING: No path found for %s" % (client) print "WARNING: No path found for %s" % (client)
@@ -416,7 +417,7 @@ class BaseInterface(object):
pipe -- stdout pipe to the dhcpcd process. pipe -- stdout pipe to the dhcpcd process.
Returns: Returns:
'success' if succesful', an error code string otherwise. 'success' if succesful, an error code string otherwise.
""" """
dhcpcd_complete = False dhcpcd_complete = False
@@ -475,7 +476,8 @@ class BaseInterface(object):
def ReleaseDHCP(self): def ReleaseDHCP(self):
""" Release the DHCP lease for this interface. """ """ Release the DHCP lease for this interface. """
if not self.iface: return False if not self.iface: return False
cmd = self.DHCP_RELEASE + " " + self.iface + " 2>/dev/null" cmd = self.DHCP_RELEASE + " " + self.iface
if self.verbose: print cmd
misc.Run(cmd) misc.Run(cmd)
def FlushRoutes(self): def FlushRoutes(self):