mirror of
https://github.com/gryf/wicd.git
synced 2025-12-19 20:38:00 +01:00
curses/curses_misc.py:
Added support for setting the text in the input dialog
Changed "body" to "parent" in ComboBox.
set_focus() unconditionally sets the focus now
Moved error() to this file. It fits better here, anyway.
Reverted TextDialog to its previous state
curses/netentry_curses.py:
Moved error() to curses_misc.py
curses/wicd-curses.py:
"Deimplemented" the script configurator, at the suggestion of various folks
#wicd, and replaced it with a simple instructions dialog. My original code
is still there, just commented out.
Added support for renaming wired network profiles (F2 when over the combo box)
Fixed various issues caused when deleting wired network profiles.
Refactored the help/about dialogs to support the old TextDialog
curses/README, in/man=wicd-curses.8.in:
Script configurator has been "changed"
This commit is contained in:
@@ -26,9 +26,9 @@ C : Display network configuration for selected network
|
|||||||
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 : Configure scripts (calls an external program, requires superuser
|
S : Provide instructions for configuring scripts
|
||||||
privileges
|
|
||||||
delete : Delete selected wired network profile (from the wired ComboBox)
|
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)
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -301,7 +310,7 @@ class ComboBox(urwid.WidgetWrap):
|
|||||||
self.user_args = user_args
|
self.user_args = user_args
|
||||||
|
|
||||||
# Widget references to simplify some things
|
# Widget references to simplify some things
|
||||||
self.body = None
|
self.parent = None
|
||||||
self.ui = None
|
self.ui = None
|
||||||
self.row = None
|
self.row = None
|
||||||
def set_list(self,list):
|
def set_list(self,list):
|
||||||
@@ -310,25 +319,27 @@ class ComboBox(urwid.WidgetWrap):
|
|||||||
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'))
|
self.cbox.set_w(SelText(self.list[index]+' vvv'))
|
||||||
|
if self.overlay:
|
||||||
|
self.overlay._listbox.set_focus(index)
|
||||||
|
|
||||||
def rebuild_combobox(self):
|
def rebuild_combobox(self):
|
||||||
self.build_combobox(self.body,self.ui,self.row)
|
self.build_combobox(self.parent,self.ui,self.row)
|
||||||
def build_combobox(self,body,ui,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
|
self.row = row
|
||||||
|
|
||||||
@@ -341,7 +352,7 @@ 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.set_focus(self.list.index(retval))
|
self.set_focus(self.list.index(retval))
|
||||||
#self.cbox.set_w(SelText(retval+' vvv'))
|
#self.cbox.set_w(SelText(retval+' vvv'))
|
||||||
@@ -444,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')
|
||||||
|
|
||||||
@@ -461,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')
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -54,10 +54,10 @@ 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, WiredSettingsDialog,error
|
from netentry_curses import WirelessSettingsDialog, WiredSettingsDialog
|
||||||
|
|
||||||
# Stuff about getting the script configurer running
|
# Stuff about getting the script configurer running
|
||||||
from grp import getgrgid
|
from grp import getgrgid
|
||||||
@@ -217,40 +217,59 @@ 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(netname,nettype):
|
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()
|
loop.quit()
|
||||||
ui.stop()
|
ui.stop()
|
||||||
argv = netname + ' ' +nettype
|
argv = netname + ' ' +nettype
|
||||||
@@ -265,7 +284,7 @@ def run_configscript(netname,nettype):
|
|||||||
precmd = ''
|
precmd = ''
|
||||||
precmdargv = ''
|
precmdargv = ''
|
||||||
postcmd = ''
|
postcmd = ''
|
||||||
elif 'admin' in glist or 'wheel' in glist:
|
elif 'admin' in glist or 'wheel' in glist or 'sudo' in glist:
|
||||||
precmd = 'sudo'
|
precmd = 'sudo'
|
||||||
precmdargv = ''
|
precmdargv = ''
|
||||||
postcmd = ''
|
postcmd = ''
|
||||||
@@ -278,7 +297,7 @@ def run_configscript(netname,nettype):
|
|||||||
system(precmd+precmdargv+cmd+postcmd)
|
system(precmd+precmdargv+cmd+postcmd)
|
||||||
raw_input("Press enter!")
|
raw_input("Press enter!")
|
||||||
main()
|
main()
|
||||||
|
"""
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
##### URWID SUPPORT CLASSES
|
##### URWID SUPPORT CLASSES
|
||||||
@@ -369,24 +388,46 @@ class WiredComboBox(ComboBox):
|
|||||||
if self.theList != []:
|
if self.theList != []:
|
||||||
wired.ReadWiredNetworkProfile(self.get_selected_profile())
|
wired.ReadWiredNetworkProfile(self.get_selected_profile())
|
||||||
|
|
||||||
|
#def rebuild_combobox(self):
|
||||||
|
# pass
|
||||||
def keypress(self,size,key):
|
def keypress(self,size,key):
|
||||||
prev_focus = self.get_focus()[1]
|
prev_focus = self.get_focus()[1]
|
||||||
key = self.__super.keypress(size,key)
|
key = self.__super.keypress(size,key)
|
||||||
if self.get_focus()[1] == len(self.list)-1:
|
if self.get_focus()[1] == len(self.list)-1:
|
||||||
dialog = InputDialog(('header',"Add new wired profile"),7,30)
|
dialog = InputDialog(('header',"Add new wired profile"),7,30)
|
||||||
|
|
||||||
exitcode,name = dialog.run(ui,self.body)
|
exitcode,name = dialog.run(ui,self.parent)
|
||||||
if exitcode == 0:
|
if exitcode == 0:
|
||||||
wired.CreateWiredNetworkProfile(name,False)
|
wired.CreateWiredNetworkProfile(name,False)
|
||||||
self.set_list(wired.GetWiredProfileList())
|
self.set_list(wired.GetWiredProfileList())
|
||||||
self.rebuild_combobox()
|
self.rebuild_combobox()
|
||||||
self.set_focus(prev_focus)
|
self.set_focus(prev_focus)
|
||||||
self.overlay._listbox.set_focus(prev_focus)
|
|
||||||
else:
|
else:
|
||||||
wired.ReadWiredNetworkProfile(self.get_selected_profile())
|
wired.ReadWiredNetworkProfile(self.get_selected_profile())
|
||||||
if key == 'delete':
|
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())
|
wired.DeleteWiredNetworkProfile(self.get_selected_profile())
|
||||||
self.set_list(wired.GetWiredProfileList())
|
self.set_list(wired.GetWiredProfileList())
|
||||||
|
self.set_focus(self.theList.index(name))
|
||||||
self.rebuild_combobox()
|
self.rebuild_combobox()
|
||||||
return key
|
return key
|
||||||
#if key == 'C':
|
#if key == 'C':
|
||||||
@@ -401,7 +442,8 @@ class WiredComboBox(ComboBox):
|
|||||||
|
|
||||||
def get_selected_profile(self):
|
def get_selected_profile(self):
|
||||||
"""Get the selected wired profile"""
|
"""Get the selected wired profile"""
|
||||||
return self.theList[self.get_focus()[1]]
|
loc = self.get_focus()[1]
|
||||||
|
return self.theList[loc]
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
##### APPLICATION INTERFACE CLASS
|
##### APPLICATION INTERFACE CLASS
|
||||||
@@ -684,7 +726,7 @@ 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()
|
self.lock_screen()
|
||||||
wireless.Scan()
|
wireless.Scan()
|
||||||
if "D" in keys:
|
if "D" in keys:
|
||||||
@@ -741,7 +783,7 @@ class appGUI():
|
|||||||
else:
|
else:
|
||||||
nettype = 'wireless'
|
nettype = 'wireless'
|
||||||
netname = str(self.wiredLB.get_focus()[1])
|
netname = str(self.wiredLB.get_focus()[1])
|
||||||
run_configscript(netname,nettype)
|
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):
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
.\" First revision was r203
|
.\" First revision was r203
|
||||||
.TH WICD-CURSES "8" "January 2009" "wicd-curses-r247"
|
.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
|
||||||
@@ -47,13 +47,18 @@ Bring up a rather simplistic help dialog. Of course, it mentions this man page
|
|||||||
Bring up network configuration controller for the selected network
|
Bring up network configuration controller for the selected network
|
||||||
.TP
|
.TP
|
||||||
.BR delete
|
.BR delete
|
||||||
Delete the selected wired network profile (from the wired combo box at the top)
|
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
|
.\".PP
|
||||||
.\"The following are not implemented yet:
|
.\"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
|
||||||
|
|||||||
Reference in New Issue
Block a user