As I alluded to in my last mail, the widget work I'm doing stems from a larger project I'm working on. I'm building a tool for taking a generic JSON schema, and building a UI for it using urwid. The code for that project is here:
I'm looking for some advice. Things on that project are going pretty well, but I'm worried that I painted myself into a corner with my current approach. Due to the way I've nested the widgets, I don't seem to have a good way of reseting the focus. If you're feeling adventurous, you can grab the code, and try the following test:
* Run ./jsonedit
* Add a couple items to the list
* Move the cursor to one of them, then type 'ctrl d' (delete node). Notice that you can see your selection (and ignore the display quirks for now, as well as the fact that deletion doesn't actually work yet)
* Add more items (enough that scrolling is needed to see the bottom of the list)
* Select one of the bottom nodes
* Notice that focus pops up to the top.
My hunch is that my problems stem from not really having a good ListWalker in place. As it stands, my ListBox widget contains one big widget, which in turn contains lots of subwidgets. There was a comment that Ian made on IRC that I didn't fully understand at the time, but I think I'm coming into the exact problem that he warned me about. He wrote: "just a general comment about deeply-nested widgets: they will be opaque to your ListBox, so scrolling might not behave the way you want".
Actually internalizing that realization lead me to looking at browse.py, and thus my work on separating out the TreeWalker from that code. However, fitting everything into a new TreeWidget/TreeWalker regime looks like it's going to be a large overhaul to an existing part of my code.
My question: does my hunch about needing TreeWalker seem correct? Is there an easier tweak I can make, or am I probably better off biting the bullet and doing the overhaul now? I realize the answer is almost certainly going to be "it depends", but some general advice about handling focus issues would be much appreciated.
p.s. if this seems like an easier question to answer on IRC, feel free to ping me there. I'm on #urwid as "robla"