[sugar] Of TreeViews, TreeModels, and Custom Object Graphs

Marco Pesenti Gritti mpg
Fri Feb 23 04:47:37 EST 2007


On Fri, 2007-02-23 at 02:25 -0500, Andrew Clunis wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hey folks,
> 
> I've been having a real bear of a time in implementing a sane and
> functional TreeView in Develop to represent the source tree of an
> activity.
> 
> I opted to use a so-called GenericTreeModel to bind the GTK TreeView to
> the "activity/directory/file" object graph Develop maintains in memory
> to describe the activity.
> 
> However, I've hung up on an issue.  The TreeModel interface specifies
> that it (and, by extension, the TreeView) need to be informed when the
> data they represent changes.  Thus, I've implemented an observer pattern
> in which whenever the directory/file object graph changes it calls a
> list of callbacks of interested Develop components.  These callbacks are
> given a single argument, the directory that changed.  If a file or
> directory is removed, moved, or added the changed handler is invoked on
> the parent of that object.  This is intuitive because creating a new
> file involves writing to the directory that will contain it.
> 
> However, dragging and dropping confounds (after Develop has changed the
> object graph, of course) the TreeView and displays the message "There is
> a disparity between the internal view of the GtkTreeVew and the
> GtkTreeModel." on stdout.
> 
> I'm not sure why this can be happening.  Perhaps I made a mistake in
> assuming that row-changed will cause the TreeView to rescan the children
> of the specified row.  The PyGTK and GTK documentation alike are very
> light on information. :(

You are just calling row_changed on the toplevel node when something
change in the directory, right?

I don't think that's going to be enough. TreeModel has several other
signals that needs to be emitted when something changes. You can see
them here:

http://www.pygtk.org/docs/pygtk/class-gtktreemodel.html

An example of a similar model:

http://cvs.gnome.org/viewcvs/nautilus/src/file-manager/fm-tree-model.c?rev=1.14&view=markup

Marco



More information about the Sugar-devel mailing list