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
|
||||
I : Raise the "Scan for hidden networks" dialog
|
||||
H : Raise help dialog
|
||||
S : Configure scripts (calls an external program, requires superuser
|
||||
privileges
|
||||
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"):
|
||||
ESC or Q: Quit dialog without saving information (if present)
|
||||
|
||||
@@ -24,6 +24,15 @@ wicd-curses.
|
||||
|
||||
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. :-)
|
||||
# Although I could have made this myself pretty easily, just want to give credit where
|
||||
# its due.
|
||||
@@ -301,7 +310,7 @@ class ComboBox(urwid.WidgetWrap):
|
||||
self.user_args = user_args
|
||||
|
||||
# Widget references to simplify some things
|
||||
self.body = None
|
||||
self.parent = None
|
||||
self.ui = None
|
||||
self.row = None
|
||||
def set_list(self,list):
|
||||
@@ -310,25 +319,27 @@ class ComboBox(urwid.WidgetWrap):
|
||||
def set_focus(self,index):
|
||||
self.focus = index
|
||||
self.cbox.set_w(SelText(self.list[index]+' vvv'))
|
||||
if self.overlay:
|
||||
self.overlay._listbox.set_focus(index)
|
||||
|
||||
def rebuild_combobox(self):
|
||||
self.build_combobox(self.body,self.ui,self.row)
|
||||
def build_combobox(self,body,ui,row):
|
||||
self.build_combobox(self.parent,self.ui,self.row)
|
||||
def build_combobox(self,parent,ui,row):
|
||||
str,trash = self.label.get_text()
|
||||
|
||||
|
||||
self.cbox = DynWrap(SelText([self.list[self.focus]+' vvv']),attrs=self.attrs,focus_attr=self.focus_attr)
|
||||
if str != '':
|
||||
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))
|
||||
else:
|
||||
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))
|
||||
|
||||
self.set_w(w)
|
||||
self.body = body
|
||||
self.parent = parent
|
||||
self.ui = ui
|
||||
self.row = row
|
||||
|
||||
@@ -341,7 +352,7 @@ class ComboBox(urwid.WidgetWrap):
|
||||
# Die if the user didn't prepare the combobox overlay
|
||||
if self.overlay == None:
|
||||
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:
|
||||
self.set_focus(self.list.index(retval))
|
||||
#self.cbox.set_w(SelText(retval+' vvv'))
|
||||
@@ -444,9 +455,9 @@ class Dialog2(urwid.WidgetWrap):
|
||||
# Simple dialog with text in it and "OK"
|
||||
class TextDialog(Dialog2):
|
||||
def __init__(self, text, height, width, header=None,align='left'):
|
||||
l = []
|
||||
for line in text:
|
||||
l.append( urwid.Text( line,align=align))
|
||||
l = [urwid.Text(text)]
|
||||
#for line in text:
|
||||
# l.append( urwid.Text( line,align=align))
|
||||
body = urwid.ListBox(l)
|
||||
body = urwid.AttrWrap(body, 'body')
|
||||
|
||||
@@ -461,8 +472,8 @@ class TextDialog(Dialog2):
|
||||
self.frame.set_focus('footer')
|
||||
|
||||
class InputDialog(Dialog2):
|
||||
def __init__(self, text, height, width,ok_name='OK'):
|
||||
self.edit = urwid.Edit(wrap='clip')
|
||||
def __init__(self, text, height, width,ok_name='OK',edit_text=''):
|
||||
self.edit = urwid.Edit(wrap='clip',edit_text=edit_text)
|
||||
body = urwid.ListBox([self.edit])
|
||||
body = urwid.AttrWrap(body, 'editbx','editfc')
|
||||
|
||||
|
||||
@@ -22,17 +22,10 @@
|
||||
# MA 02110-1301, USA.
|
||||
|
||||
import urwid
|
||||
from curses_misc import TextDialog,DynWrap,MaskingEdit,ComboBox
|
||||
from curses_misc import TextDialog,DynWrap,MaskingEdit,ComboBox,error
|
||||
import wicd.misc as misc
|
||||
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()
|
||||
|
||||
@@ -54,10 +54,10 @@ import sys
|
||||
from time import sleep
|
||||
|
||||
# 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
|
||||
import netentry_curses
|
||||
from netentry_curses import WirelessSettingsDialog, WiredSettingsDialog,error
|
||||
from netentry_curses import WirelessSettingsDialog, WiredSettingsDialog
|
||||
|
||||
# Stuff about getting the script configurer running
|
||||
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
|
||||
# online ASCII big text generators.
|
||||
theText = [
|
||||
[('green'," /// \\\\\\")," _ ___ __"],
|
||||
[('green'," /// \\\\\\")," | | /| / (_)______/ /"],
|
||||
[('green'," /// \\\\\\")," | |/ |/ / / __/ _ / "],
|
||||
[('green',"/|| // \\\\ ||\\")," |__/|__/_/\__/\_,_/ "],
|
||||
[('green',"||| ||"),"(|^|)",('green',"|| |||"),
|
||||
" ($VERSION) ".replace("$VERSION",daemon.Hello())],
|
||||
('green'," /// \\\\\\")," _ ___ __\n",
|
||||
('green'," /// \\\\\\")," | | /| / (_)______/ /\n",
|
||||
('green'," /// \\\\\\")," | |/ |/ / / __/ _ / \n",
|
||||
('green',"/|| // \\\\ ||\\")," |__/|__/_/\__/\_,_/ \n",
|
||||
('green',"||| ||"),"(|^|)",('green',"|| |||"),
|
||||
" ($VERSION) \n".replace("$VERSION",daemon.Hello()),
|
||||
|
||||
[('green',"\\|| \\\\")," |+| ",('green',"// ||/ ")],
|
||||
[('green'," \\\\\\")," |+| ",('green',"///")," http://wicd.net"],
|
||||
[('green'," \\\\\\")," |+| ",('green',"///")," Brought to you by:"],
|
||||
[('green'," \\\\\\")," |+| ",('green',"///")," Adam Blackburn (wicd)"],
|
||||
" ___|+|___ Dan O'Reilly (wicd)",
|
||||
" |---------| Andrew Psaltis (this ui)",
|
||||
('green',"\\|| \\\\")," |+| ",('green',"// ||/ \n"),
|
||||
('green'," \\\\\\")," |+| ",('green',"///")," http://wicd.net\n",
|
||||
('green'," \\\\\\")," |+| ",('green',"///")," Brought to you by:\n",
|
||||
('green'," \\\\\\")," |+| ",('green',"///")," Adam Blackburn (wicd)\n",
|
||||
" ___|+|___ Dan O'Reilly (wicd)\n",
|
||||
" |---------| Andrew Psaltis (this ui)\n",
|
||||
"-----------------------------------------------------"]
|
||||
about = TextDialog(theText,16,55,header=('header','About Wicd'))
|
||||
about.run(ui,body)
|
||||
|
||||
def help_dialog(body):
|
||||
theText = [
|
||||
"For more detailed help, consult the wicd-curses(8) man page.",
|
||||
"", "All controls are case sensitive",
|
||||
[('bold','H')," Display this help dialog"],
|
||||
[('bold','enter')," Connect to selected network"],
|
||||
[('bold','D')," Disconnect from all networks"],
|
||||
[('bold','ESC')," Stop a network connection in progress"],
|
||||
[('bold','F5')," or ", ('bold','R')," Refresh network list"],
|
||||
[('bold','P')," Prefrences dialog"],
|
||||
[('bold','I')," Scan for hidden networks"],
|
||||
[('bold','S')," Select scripts"]
|
||||
"For more detailed help, consult the wicd-curses(8) man page.\n",
|
||||
"\n", "All controls are case sensitive\n",
|
||||
('bold','H')," Display this help dialog\n",
|
||||
('bold','enter')," Connect to selected network\n",
|
||||
('bold','D')," Disconnect from all networks\n",
|
||||
('bold','ESC')," Stop a network connection in progress\n",
|
||||
('bold','F5')," or ", ('bold','R')," Refresh network list\n",
|
||||
('bold','P')," Prefrences dialog\n",
|
||||
('bold','I')," Scan for hidden networks\n",
|
||||
('bold','S')," Select scripts\n"
|
||||
]
|
||||
help = TextDialog(theText,15,62,header=('header',"Wicd-Curses Help"))
|
||||
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()
|
||||
ui.stop()
|
||||
argv = netname + ' ' +nettype
|
||||
@@ -265,7 +284,7 @@ def run_configscript(netname,nettype):
|
||||
precmd = ''
|
||||
precmdargv = ''
|
||||
postcmd = ''
|
||||
elif 'admin' in glist or 'wheel' in glist:
|
||||
elif 'admin' in glist or 'wheel' in glist or 'sudo' in glist:
|
||||
precmd = 'sudo'
|
||||
precmdargv = ''
|
||||
postcmd = ''
|
||||
@@ -278,7 +297,7 @@ def run_configscript(netname,nettype):
|
||||
system(precmd+precmdargv+cmd+postcmd)
|
||||
raw_input("Press enter!")
|
||||
main()
|
||||
|
||||
"""
|
||||
|
||||
########################################
|
||||
##### URWID SUPPORT CLASSES
|
||||
@@ -369,24 +388,46 @@ class WiredComboBox(ComboBox):
|
||||
if self.theList != []:
|
||||
wired.ReadWiredNetworkProfile(self.get_selected_profile())
|
||||
|
||||
#def rebuild_combobox(self):
|
||||
# pass
|
||||
def keypress(self,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.body)
|
||||
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)
|
||||
self.overlay._listbox.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':
|
||||
@@ -401,7 +442,8 @@ class WiredComboBox(ComboBox):
|
||||
|
||||
def get_selected_profile(self):
|
||||
"""Get the selected wired profile"""
|
||||
return self.theList[self.get_focus()[1]]
|
||||
loc = self.get_focus()[1]
|
||||
return self.theList[loc]
|
||||
|
||||
########################################
|
||||
##### APPLICATION INTERFACE CLASS
|
||||
@@ -684,7 +726,7 @@ class appGUI():
|
||||
if "f8" in keys or 'Q' in keys:
|
||||
loop.quit()
|
||||
return False
|
||||
if "f5" in keys:
|
||||
if "f5" in keys or 'R' in keys:
|
||||
self.lock_screen()
|
||||
wireless.Scan()
|
||||
if "D" in keys:
|
||||
@@ -741,7 +783,7 @@ class appGUI():
|
||||
else:
|
||||
nettype = 'wireless'
|
||||
netname = str(self.wiredLB.get_focus()[1])
|
||||
run_configscript(netname,nettype)
|
||||
run_configscript(self.frame,netname,nettype)
|
||||
|
||||
for k in keys:
|
||||
if urwid.is_mouse_event(k):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.\" First revision was r203
|
||||
.TH WICD-CURSES "8" "January 2009" "wicd-curses-r247"
|
||||
.TH WICD-CURSES "8" "January 2009" "wicd-curses-r250"
|
||||
.SH NAME
|
||||
.B wicd-curses
|
||||
\- 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
|
||||
.TP
|
||||
.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
|
||||
.\"The following are not implemented yet:
|
||||
.TP
|
||||
.BR S
|
||||
Bring up the script selector for the selected network (requires superuser privileges)
|
||||
.SH "FILES"
|
||||
.\"Bring up the script selector for the selected network (requires superuser privileges)
|
||||
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.
|
||||
.TP
|
||||
.I ~/.wicd/WHEREAREMYFILES
|
||||
|
||||
Reference in New Issue
Block a user