[Idle-dev] Changes to TreeWidget

Nicholas Riley njriley@uiuc.edu
Fri, 7 Apr 2000 12:38:15 -0500


Hi,

I am pretty new to Python (about three weeks now).  IDLE has been a
real help in learning the language.  I especially like its
multi-window model - I have had enough of IDEs which presume to own
your entire screen in order to work properly.  One of my first things
to do in Python was implementing a tree-style viewer.  I found two
that looked good - "TreeBox.py" by Arpad Kiss, and "TreeWidget.py"
from IDLE.  TreeBox is very powerful and efficient but didn't really
permit binding of objects to nodes, or editing of nodes.  TreeWidget
was simple, not hugely efficient, but looked really easily extendable.

The only visible problems with TreeWidget I could find were:

- text disappeared while expanding nodes, and flashed when the
TreeWidget was scrolled
- the two columns' text baselines didn't line up (in the standard IDLE
interface, see the variable browser in the thread viewer for an
example)
- text was inappropriately drawn from nodes that had been collapsed,
at times

So I fixed these, and optimized a few things (like not walking the
entire tree just to get the current selection). I've tried to keep as
much of the TreeWidget behavior as possible, however there are some
behaviors related to double-clicking that I couldn't figure out how to
simulate effectively.

I don't really trust my Python/Tkinter knowledge enough to just submit
a patch, so I was wondering if I could get some feedback from this
list as to any problems with my changes; in particular, I haven't
tested on Windows.  I have tested with IDLE 0.5, 0.6, and XIDLE and
haven't seen anything.  As for feature requests, I'm behind with my
main open-source project right now, so I probably can't do anything
big.  (Side projects like this and the Sawmill theme I did last week
don't help, even if I rationalize them as helping me with my
research. :-)

The file is just a drop-in replacement, and downloadable from:

<http://www.canis.uiuc.edu/~njriley/TreeWidget.py>

If some of the changes related to double-clicking look a bit weird, it
might help to explain what I'm using it for.  Instead of changing the
icon of a particular node depending on whether it's selected or not,
I'm changing it on double-click.  The interface I've got it hooked up
to will display "detail" information about a node you double-click on
in the right side of the window, but you should be able to move the
selection without disturbing the detail view, and still be able to see
what node the detail display corresponds to - hence the icon change.

-- 
Nicholas Riley <njriley@uiuc.edu>