widget focus management was something I struggled with too. I did explore
focus maps but they didn't work as expected for me. If anyone had tips to
share on those I'd like to hear them.
What I ultimately ended up doing is writing my own "meta-container" classes
that handled focus management for me. I inherited from an Urwid container
class and overrode the keypress method and handled tab/shift-tab myself.
For example I would have a "FormBody" whose child was a "FormController".
The "Form Controller" had two children, a FormBody and a NavBar. The
FormBody inherited from Urwid.ListBox, and NavBar inherited from
urwid.Columns (each column had a button). The FormBody widget new how to
iterate over the contents of the list box, and if it "tabbed off the end"
it would return the tab to the FormController. The FormController knew when
a tab returned to it unhandled that the FormBody was what had the focus, so
it would call the keypress method on the NavBar. One interesting edge-case
I ran into is that when the FormBody had no selectable widgets inside, the
ListBox itself was given the focus, so in that special case I had to set
the selectable attribute on the FormBody to false.
In summary: You can set the focus position of a container widget by
set_focus. You can see if a widget is selectable by querying the
selectable() method (or attribute, or something along those lines). You
can extend and augment Urwid classes by inheriting form them and overriding
the keypress method (the tutorial documentation covers this). You might
need "orchestration" classes that help pass the keypress events around. If
you figure out focus maps or find an easier/nicer way to achieve all of
this, I'd love to know about it. :)
I was part of the group that wrote the installer UI for Clear Linux. You
can download our installer image from
https://download.clearlinux.org/image/. /usr/bin/ister_gui.py is the
application we wrote (still a number of tweaks/enhancements to make) but
you can look it over and get the idea. I'm not saying it's pretty or
perfect but if you run the installer a few times and then look at the
source for the GUI you might get some ideas.
-Rob
Post by c***@posteo.jpHi Robert,
thank you very much.
Post by Robert Urbantry adding "frame.focus_position = 'header'" after
"placeholder.original_widget = edit"
This helps for the example code. And I think I understand why. ;)
But it doesn't help me to understand the uwrid-focus-thing in a more
generalized way.
Why do I have to use a string ("header") here? Where in the docu can I
read about it? The referecen docu about 'focus_postion' doesn't help me
here.
What part of the documentation didn't I read here because I didn't knew?
How would I solve this, when frame is another type of container widget?
e.g. Columsn() or whatever.
--
You received this message because you are subscribed to the Google Groups
"Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/a/excess.org/d/optout.
--
You received this message because you are subscribed to the Google Groups "Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to urwid+***@excess.org.
To post to this group, send email to ***@excess.org.
For more options, visit https://groups.google.com/a/excess.org/d/optout.