[Urwid] Advice on overhaul vs tweak
ian at excess.org
Mon Feb 8 18:19:38 EST 2010
Rob Lanphier wrote on 2010-02-08 14:14:
> 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.
The TreeWalker in browse.py is really set up to allow really lazy
loading of directory contents while still appearing to be viewing the
complete nested tree of files, including parent directories. That has
made it more complicated than a common tree view where everything is
already in memory.
What the ListBox/ListWalker separation gives you is the ability to
create widgets (and load data or do other processing) lazily. You can
also use it to delete objects as they scroll off screen so memory usage
doesn't grow in an unbounded way.
If you are always loading the complete JSON structure into memory, a
ListWalker could give you the ability to walk that structure directly
and create/delete widgets as required, but it's not a huge gain over
just creating a regular list of those widgets.
The bigger problem with having one big widget is that the whole thing
has to be rendered every time there is a change or screen resize,
including all the widgets off the screen.. definitely not good.
So yes, I think you should either create a ListWalker suited to your
data, or create a flat list of widgets (with SimpleListWalker) and sync
it with your structure on changes.
More information about the Urwid