5 Jun 2011 20:21
Screens with forms with fixed-length input fields.
Christopher R. Hertel <crh <at> ubiqx.mn.org>
2011-06-05 18:21:19 GMT
2011-06-05 18:21:19 GMT
I raised a question on IRC and got some very good help. I was asked to post both problem and solution to the list, so here goes... I am working on a module to create old-school input screens. I used this code as an example: http://bitbucket.org/robla/urwid-demo/wiki/Home ...but I needed slightly different behavior so I written my own module. (Note: If you want to view the above referenced code, dig through the web page a little. There are several versions. I used the newest I could find.) The demo code at that URL uses the urwid Edit widget for all input. I needed a couple of changes to meet my goals. In particular, the Edit widget does not support fixed-length input. Here's a code snippet to show what I've done: prompt = u.Text( "Gimme Input:", align='right' ) prompt = u.AttrMap( prompt, 'normal', 'focusprompt' ) # f_widget = u.AttrMap( TextEdit( "", fwidth ), 'normal', 'focusfield' ) f_widget = u.Padding( f_widget, width=fwidth+1, right=2 ) f_widget = [ prompt, ('weight', 2, f_widget) ] f_widget = u.Columns( f_widget, dividechars=1 ) f_widget = u.AttrMap( f_widget, None, {'normal':'focusprompt'} ) self._widgets.append( f_widget ) The first line creates the prompt Text widget from the string "Gimme Input:". In my code I use a variable. Promise. ;)(Continue reading)
RSS Feed