From abf05c782fbf933b56e2b56adc56d33142cef4a6 Mon Sep 17 00:00:00 2001 From: Andrew Psaltis Date: Fri, 23 Jan 2009 21:13:36 -0500 Subject: [PATCH 1/2] Ad-hoc network support is added ("O"). This commit is should be the last one containing new interface elements. :-D This also may not work directly from the install. I need to change some stuff first. curses/curses_misc.py: Fixed bug in Dialog2 where mouse clicks would cause the program to crash Added DynEdit and DynIntEdit, Simple DynWrapped widgets, nothing special about them curses/wicd-curses.py: Added support for Ad-Hoc network controls (I don't know exactly how this works) curses/README,TODO,in/man=wicd-curses.8.in: Ad-Hoc network support has been added --- curses/README | 1 + curses/TODO | 1 - curses/curses_misc.py | 29 +++++++++++++---- curses/wicd-curses.py | 71 ++++++++++++++++++++++++++++++++++++++++- in/man=wicd-curses.8.in | 5 ++- 5 files changed, 97 insertions(+), 10 deletions(-) diff --git a/curses/README b/curses/README index afe8d66..a10ba07 100644 --- a/curses/README +++ b/curses/README @@ -29,6 +29,7 @@ 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) +O : Raise ad-hoc network dialog IN DIALOGS (Meta usually is "Alt"): ESC or Q: Quit dialog without saving information (if present) diff --git a/curses/TODO b/curses/TODO index 129fe2f..9861ba4 100644 --- a/curses/TODO +++ b/curses/TODO @@ -3,5 +3,4 @@ Things to do (in no particular order): * Implement a keyhandler function for the overall frame * Make keystrokes customizable * Make color schemes customizable -* Implement a "make an ad-hoc network" dialog * Perform a mass code cleanup diff --git a/curses/curses_misc.py b/curses/curses_misc.py index 0dfc374..fbe607d 100644 --- a/curses/curses_misc.py +++ b/curses/curses_misc.py @@ -88,6 +88,20 @@ class DynWrap(urwid.AttrWrap): def selectable(self): return self._sensitive +# Just an Edit Dynwrapped to the most common specifications +class DynEdit(DynWrap): + def __init__(self,caption='',edit_text='',sensitive=True,attrs=('editbx','editnfc'),focus_attr='editfc'): + caption = ('editcp',caption + ': ') + edit = urwid.Edit(caption,edit_text) + self.__super.__init__(edit,sensitive,attrs,focus_attr) + +# Just an IntEdit Dynwrapped to the most common specifications +class DynIntEdit(DynWrap): + def __init__(self,caption='',edit_text='',sensitive=True,attrs=('editbx','editnfc'),focus_attr='editfc'): + caption = ('editcp',caption + ':') + edit = urwid.IntEdit(caption,edit_text) + self.__super.__init__(edit,sensitive,attrs,focus_attr) + class MaskingEditException(Exception): pass @@ -436,13 +450,14 @@ class Dialog2(urwid.WidgetWrap): overlay.mouse_event( size, event, button, col, row, focus=True) - if k == 'window resize': - size = ui.get_cols_rows() - k = self.view.keypress( size, k ) - if k == 'esc': - raise DialogExit(-1) - if k: - self.unhandled_key( size, k) + else: + if k == 'window resize': + size = ui.get_cols_rows() + k = self.view.keypress( size, k ) + if k == 'esc': + raise DialogExit(-1) + if k: + self.unhandled_key( size, k) except DialogExit, e: return self.on_exit( e.args[0] ) diff --git a/curses/wicd-curses.py b/curses/wicd-curses.py index 9f7e201..d69e4e2 100644 --- a/curses/wicd-curses.py +++ b/curses/wicd-curses.py @@ -54,7 +54,7 @@ import sys from time import sleep # Curses UIs for other stuff -from curses_misc import SelText,ComboBox,TextDialog,InputDialog,error +from curses_misc import SelText,DynEdit,DynIntEdit,ComboBox,Dialog2,TextDialog,InputDialog,error from prefs_curses import PrefsDialog import netentry_curses from netentry_curses import WirelessSettingsDialog, WiredSettingsDialog @@ -445,6 +445,66 @@ class WiredComboBox(ComboBox): loc = self.get_focus()[1] return self.theList[loc] +# Dialog2 that initiates an Ad-Hoc network connection +class AdHocDialog(Dialog2): + def __init__(self): + essid_t = language['essid'] + ip_t = language['ip'] + channel_t = language['channel'] + key_t = " " + language['key'] + use_ics_t = language['use_ics'] + use_encrypt_t = language['use_wep_encryption'] + + self.essid_edit = DynEdit(essid_t) + self.ip_edit = DynEdit(ip_t) + self.channel_edit = DynIntEdit(channel_t) + self.key_edit = DynEdit(key_t,sensitive=False) + + self.use_ics_chkb = urwid.CheckBox(use_ics_t) + self.use_encrypt_chkb = urwid.CheckBox(use_encrypt_t, + on_state_change=self.encrypt_callback) + + blank = urwid.Text('') + + # Set defaults + self.essid_edit.set_edit_text("My_Adhoc_Network") + self.ip_edit.set_edit_text("169.254.12.10") + self.channel_edit.set_edit_text("3") + + l = [self.essid_edit,self.ip_edit,self.channel_edit,blank, + self.use_ics_chkb,self.use_encrypt_chkb,self.key_edit] + #for line in text: + # l.append( urwid.Text( line,align=align)) + body = urwid.ListBox(l) + #body = urwid.AttrWrap(body, 'body') + + header = ('header',"Create an Ad-Hoc network") + Dialog2.__init__(self, header, 15, 50, body) + self.add_buttons([('OK',1),('Cancel',-1)]) + self.frame.set_focus('body') + + def encrypt_callback(self,chkbox,new_state,user_info=None): + self.key_edit.set_sensitive(new_state) + + def unhandled_key(self, size, k): + if k in ('up','page up'): + self.frame.set_focus('body') + if k in ('down','page down'): + self.frame.set_focus('footer') + if k == 'enter': + # pass enter to the "ok" button + self.frame.set_focus('footer') + self.buttons.set_focus(0) + self.view.keypress( size, k ) + def on_exit(self,exitcode): + data = ( self.essid_edit.get_edit_text(), + self.ip_edit.get_edit_text(), + self.channel_edit.get_edit_text(), + self.use_ics_chkb.get_state(), + self.use_encrypt_chkb.get_state(), + self.key_edit.get_edit_text()) + + return exitcode, data ######################################## ##### APPLICATION INTERFACE CLASS ######################################## @@ -784,6 +844,15 @@ class appGUI(): nettype = 'wireless' netname = str(self.wiredLB.get_focus()[1]) run_configscript(self.frame,netname,nettype) + if "O" in keys: + exitcode,data = AdHocDialog().run(ui,self.frame) + #essid,ip,channel,use_ics,use_encrypt,key_edit + if exitcode == 1: + wireless.CreateAdHocNetwork(data[0], + data[2], + data[1], "WEP", + data[5], + data[4], False) for k in keys: if urwid.is_mouse_event(k): diff --git a/in/man=wicd-curses.8.in b/in/man=wicd-curses.8.in index 944452f..3d69222 100644 --- a/in/man=wicd-curses.8.in +++ b/in/man=wicd-curses.8.in @@ -1,5 +1,5 @@ .\" First revision was r203 -.TH WICD-CURSES "8" "January 2009" "wicd-curses-r250" +.TH WICD-CURSES "8" "January 2009" "wicd-curses-r251" .SH NAME .B wicd-curses \- curses-based wicd(8) controller @@ -57,6 +57,9 @@ Rename the selected wired network profile (from the wired network combo box at t .BR S .\"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. ;-) +.TP +.BR O +Raise the Ad-Hoc network creation dialog ".SH "FILES" These are not used yet. From 1b17fde01582153522f6b6d3cfd16dbc80159247 Mon Sep 17 00:00:00 2001 From: Andrew Psaltis Date: Fri, 23 Jan 2009 22:13:27 -0500 Subject: [PATCH 2/2] setup.py: Added support for keeping track of the revisions of the curses client (%CURSES_REVNO%) curses/wicd-curses.py: Added the ad-hoc controls to the Help dialog Set wireless scans to be synchronous (True), to adapt to an API change in mainline Added support for OptionParser, added and implemented the option that was described in the man page (and -h (help) and --version) in/wicd=wpath.py.in: Added a curses_revision flag in/man=wicd-curses.8.in: Option parsing has been implemented. Added the %CURSES_REVNO% flag to the man page. Fixed an accidental " added to one of the headers --- curses/wicd-curses.py | 53 ++++++++++++++++++++--------------------- in/man=wicd-curses.8.in | 5 ++-- in/wicd=wpath.py.in | 1 + setup.py | 2 ++ 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/curses/wicd-curses.py b/curses/wicd-curses.py index d69e4e2..9cd9815 100644 --- a/curses/wicd-curses.py +++ b/curses/wicd-curses.py @@ -34,8 +34,7 @@ at least get a network connection. Or those who don't like using X. ;-) """ # UI stuff -#import urwid.raw_display -import urwid.curses_display +# This library is the only reason why I wrote this program. import urwid # DBus communication stuff @@ -57,11 +56,16 @@ from time import sleep from curses_misc import SelText,DynEdit,DynIntEdit,ComboBox,Dialog2,TextDialog,InputDialog,error from prefs_curses import PrefsDialog import netentry_curses + from netentry_curses import WirelessSettingsDialog, WiredSettingsDialog +from optparse import OptionParser + # Stuff about getting the script configurer running -from grp import getgrgid -from os import getgroups,system +#from grp import getgrgid +#from os import getgroups,system + +CURSES_REVNO=wpath.curses_revision language = misc.get_language_list_gui() @@ -245,7 +249,8 @@ def help_dialog(body): ('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" +('bold','S')," Select scripts\n", +('bold','O')," Set up Ad-hoc network\n" ] help = TextDialog(theText,15,62,header=('header',"Wicd-Curses Help")) help.run(ui,body) @@ -335,15 +340,6 @@ class NetLabel(urwid.WidgetWrap): return True def keypress(self,size,key): return self._w.keypress(size,key) - #if key == 'C': - # conf = NetEntryBase(dbusmanager.get_dbus_ifaces()) - # conf.run(ui,ui.get_cols_rows(),) - #elif key == 'S': - # Configure scripts - # pass - #elif key == 'enter': - # self.connect() - #return key def connect(self): # This should work. wireless.ConnectWireless(self.id) @@ -430,15 +426,6 @@ class WiredComboBox(ComboBox): self.set_focus(self.theList.index(name)) self.rebuild_combobox() return key - #if key == 'C': - # Configure the network - # pass - #elif key == 'S': - # Configure scripts - # pass - #elif key == 'enter': - # self.connect() - #return key def get_selected_profile(self): """Get the selected wired profile""" @@ -593,7 +580,7 @@ class appGUI(): # That dialog will sit there for a while if I don't get rid of it self.update_ui() wireless.SetHiddenNetworkESSID(misc.noneToString(hidden)) - wireless.Scan() + wireless.Scan(True) wireless.SetHiddenNetworkESSID("") def update_focusloc(self): @@ -788,7 +775,7 @@ class appGUI(): return False if "f5" in keys or 'R' in keys: self.lock_screen() - wireless.Scan() + wireless.Scan(True) if "D" in keys: # Disconnect from all networks. daemon.Disconnect() @@ -846,7 +833,7 @@ class appGUI(): run_configscript(self.frame,netname,nettype) if "O" in keys: exitcode,data = AdHocDialog().run(ui,self.frame) - #essid,ip,channel,use_ics,use_encrypt,key_edit + #data = (essid,ip,channel,use_ics,use_encrypt,key_edit) if exitcode == 1: wireless.CreateAdHocNetwork(data[0], data[2], @@ -888,7 +875,15 @@ def main(): # We are _not_ python. misc.RenameProcess('wicd-curses') - ui = urwid.curses_display.Screen() + # Import the screen based on whatever the user picked. + # The raw_display will have some features that may be useful to users + # later + if options.rawscreen: + import urwid.raw_display + ui = urwid.raw_display.Screen() + else: + import urwid.curses_display + ui = urwid.curses_display.Screen() # Default Color scheme. # Other potential color schemes can be found at: # http://excess.org/urwid/wiki/RecommendedPalette @@ -970,6 +965,10 @@ setup_dbus() ##### MAIN ENTRY POINT ######################################## if __name__ == '__main__': + parser = OptionParser(version="wicd-curses-%s (using wicd %s)" % (CURSES_REVNO,daemon.Hello())) + parser.add_option("-r", "--raw-screen",action="store_true",dest='rawscreen', + help="use urwid's raw screen controller") + (options,args) = parser.parse_args() main() # Make sure that the terminal does not try to overwrite the last line of # the program, so that everything looks pretty. diff --git a/in/man=wicd-curses.8.in b/in/man=wicd-curses.8.in index 3d69222..f2b9df6 100644 --- a/in/man=wicd-curses.8.in +++ b/in/man=wicd-curses.8.in @@ -1,5 +1,5 @@ .\" First revision was r203 -.TH WICD-CURSES "8" "January 2009" "wicd-curses-r251" +.TH WICD-CURSES "8" "January 2009" "wicd-curses-%CURSES_REVNO%" .SH NAME .B wicd-curses \- curses-based wicd(8) controller @@ -10,7 +10,6 @@ It is designed to imitate the GTK-based wicd-client(1) as much as possible, and This man page only documents the current status of wicd-curses. This may/may not be the most up-to-date document. .SH "ARGUMENTS" -These are not implemented yet. .TP .BR "\-r" , " \-\-raw\-screen" Use Urwid's raw console display, instead of the (faster) curses-based one. This may be useful if you are experiencing unicode problems. @@ -61,7 +60,7 @@ Bring up instructions on how to edit the scripts. I have implemented a way to d .BR O Raise the Ad-Hoc network creation dialog -".SH "FILES" +.SH "FILES" These are not used yet. .TP .I ~/.wicd/WHEREAREMYFILES diff --git a/in/wicd=wpath.py.in b/in/wicd=wpath.py.in index 33282e7..fa4a753 100755 --- a/in/wicd=wpath.py.in +++ b/in/wicd=wpath.py.in @@ -19,6 +19,7 @@ current = os.path.dirname(os.path.realpath(__file__)) + '/' version = '%VERSION%' revision = '%REVNO%' +curses_revision = '%CURSES_REVNO%' # DIRECTORIES diff --git a/setup.py b/setup.py index b8bd9b9..f049b14 100755 --- a/setup.py +++ b/setup.py @@ -27,6 +27,7 @@ import subprocess # VERSIONNUMBER VERSION_NUM = '1.6.0' REVISION_NUM = 'unknown' +CURSES_REVNO = 'r254' try: if not os.path.exists('vcsinfo.py'): @@ -266,6 +267,7 @@ class configure(Command): # other things to replace that aren't arguments line = line.replace('%VERSION%', str(VERSION_NUM)) line = line.replace('%REVNO%', str(REVISION_NUM)) + line = line.replace('%CURSES_REVNO%', str(CURSES_REVNO)) item_out.write(line)