[Urwid] [Fwd: Find focused Edit]
cantabile.03 at wanadoo.fr
Tue Jul 19 22:23:49 EDT 2005
Ian Ward a écrit :
> cantabile wrote:
> >Hi all,
> >I'm trying end write a urwid based gui for server tools install.
> >I have several Edit's piled (with Pile() of course) in Columns.
> >Now, I'd like to display some help for each Edit in the frame footer.
> >I'm aware that get_focus() exists, but in that case, it gives back a
> >Column instead of the Edit.
> >How could I do to get the highlighted / focused Edit to display its
> >help, or the app. to retrieve the highlighted Edit when it changes ?
> >Thanks for your help.
> Columns and Pile objects also have get_focus() methods that you can
> use to drill down to the Edit widget. To make your code generic with
> respect to the containing Columns and Pile widgets you could use a
> "while hasattr( w, 'get_focus' ): w = w.get_focus()" loop to drill down.
> Urwid mailing list
> Urwid at lists.excess.org
Well, doesn't work. I think it may come from the way I'm using the widgets.
I wrap them in this class
""" Wrapper class for widgets
Items are stored as objects in order to get their
value by using getval() below.
def __init__(self, title, value, help):
self.widget = urwid.Edit(('editcp', title + " : "), value)
self.help = help
self.padd = urwid.Padding(urwid.AttrWrap(self.widget,
('fixed left',3), ('fixed right',
For example :
name = It(dict['name'], dict['name'], dict['name'])
context = ...
and so on
Then I write content like this :
CONTENT = [
urwid.Pile([ name.get(), blank, context.get() ]),
urwid.Pile([ method.get(), blank, flags.get() ]),
], 5 ),
## lots of other edits piled in two columns
Then in run():
while not keys:
for k in keys:
if k == 'window resize':
size = self.ui.get_cols_rows()
#other tests cut here
w = self.listbox.get_focus()
while hasattr(w, 'get_focus'):
# For testing purposes
# The idea would be to retrieve the It.gethelp
# message once the Edit is identified
What do you think ?
Another idea : is it possible that wrapping the edits in urwid.Padding
and urwid.AttrWrap stops the loop before it reaches the urwid.Edit itself ?
More information about the Urwid