Walter Anger <[EMAIL PROTECTED]> writes:

> On Fri, 07 Nov 2003 02:17:02 -0600
>
> Your addition of the collapse/expand feature is splendid. only I
> must admit I do not yet understand thoroughly whats going on there.

Tree row expansion is a bit tricky in gtk+ since to expand a row its
parent must be expanded and it must have at least one child.  The
pygtk FAQ contains an entry about this.  My code checks each source
row after it and its children (if any) are copied to see if it is
expanded and expands the newly created copy if necessary.  After the
entire copy is done if the drop created a child as opposed to a top
level row, it expands the parent to make sure that the newly copied
child is visible.

As you mention it would be easier if we could reparent a subtree of
the treemodel in a single operation, but gtk.TreeStore requires that
each row be copied individually.

An obvious thought is that a custom tree model might make it simpler
to move subtrees, but some experiments I've tried seem to indicate
that the treeview code expects to receive a 'row-inserted' signal for
each row that is added.  For instance, adding a parent and 4 children
seems to require 5 signals and this implies that rows must be added
individually.  Another possibility might be to do the updates
"off-line", by which I mean making the updates to a tree model that
isn't associated with a treeview.  Then the treeview's model can be
replaced with the newly updated model.  Maybe someone else has
something to suggest.

> Doug Quale <[EMAIL PROTECTED]> wrote:
>> Pygtk already includes the method TreeModel.is_ancestor() that does
>> the same thing as checkSanity().
>
> now, thats the only point at which I'm dissenting with you. "sanity"
> is in that case not alone a question of ancestry, but of identity
> too. (try dropping an iter onto itself with your version). One could
> think that replacing the line: if not model.is_ancestor(source,
> target): with: if not model.is_ancestor(source, target) and not
> (source == target): should do the job. but no, it doesn't work. for
> some reasons, buried deep in gtk/pygtk, the two objects are never
> identic, even if they are "the same". therefore I still see the best
> solution in comparing the paths.

Excellent catch, you're right.  The code I posted fails when dropping
a row onto itself -- this is a bad mistake.  Your code is correct.

As you note, (source == target) won't work to fix my code, so
(model.get_path(source) == model.get_path(target)) is needed instead.
Simply using your checkSanity() works well also, because as you
understood but I failed to see, it combines the ancestor and equality
checks.  Thanks for pointing this out.
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to