populating a TreeStore in reverse order

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

populating a TreeStore in reverse order

Fabio Marzocca
I need to populate a TreeStore from a flow of data coming from a pipe.
Each line of data will also have an associated "depth" value so that I
can understand the depth in the tree.

Populating the TreeStore would not be a problem, but the data is
arriving in the pipe in reverse-order. Can I populate a TreeStore
starting from the bottom? I had a look at documentation, but it seems
not to be possible..
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: populating a TreeStore in reverse order

squentin
On Wed, 2005-06-22 at 11:49 +0200, The Saltydog wrote:
> I need to populate a TreeStore from a flow of data coming from a pipe.
> Each line of data will also have an associated "depth" value so that I
> can understand the depth in the tree.
>
> Populating the TreeStore would not be a problem, but the data is
> arriving in the pipe in reverse-order. Can I populate a TreeStore
> starting from the bottom? I had a look at documentation, but it seems
> not to be possible..

You can, using 'prepend' instead of 'append', but you can't change the
depth of a row, and the parents must already exist.
One way would be to create empty parents so you can put the row at the
desired depth, and then fill the parents with the real data when you get
there.

A _much_ more complex way, would be to keep the data in a perl array,
and use a custom store. But you have to tell the store when you
change/add/remove a row in the perl array. Scrolling would be slower,
but the initial filling would be faster (with fixed height rows).
I did it with a list, I'm not sure how much more difficult/slower it
would be with a tree.


_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: populating a TreeStore in reverse order

Fabio Marzocca
On 6/22/05, Quentin <[hidden email]> wrote:

> A _much_ more complex way, would be to keep the data in a perl array,
> and use a custom store. But you have to tell the store when you
> change/add/remove a row in the perl array. Scrolling would be slower,
> but the initial filling would be faster (with fixed height rows).
> I did it with a list, I'm not sure how much more difficult/slower it
> would be with a tree.


I already did this way into an hash, then sorting the hash and
populating the treestore directly. The only matter is that I have
first to wait for hash completion (it is very long, more than 10000
rows) and only then show the treeview..

It would be nice to populate the treeview in real-time, while getting
the data, so the user should start viewing something while waiting...
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: populating a TreeStore in reverse order

squentin
On Wed, 2005-06-22 at 14:16 +0200, The Saltydog wrote:
> I already did this way into an hash, then sorting the hash and
> populating the treestore directly. The only matter is that I have
> first to wait for hash completion (it is very long, more than 10000
> rows) and only then show the treeview..
>
> It would be nice to populate the treeview in real-time, while getting
> the data, so the user should start viewing something while waiting...

It's not what I meant, I meant keep all the data in a perl array/hash,
and use a custom store that get the data from the perl array/hash.
That way you don't have to fill the store, the data are already there.
It's much more complex but it can fit your needs, I use it with a list
of 15000 rows, and creating/displaying the treeview is really fast on a
duron800 :).

But my first solution could work: you load data until you have a full
branch (starting from depth 0), then prepend the root of the branch to
the store and fill this branch, load next branch ...
It depends on what kind of data you have.

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: populating a TreeStore in reverse order

Fabio Marzocca
On 6/22/05, Quentin <[hidden email]> wrote:
> It's not what I meant, I meant keep all the data in a perl array/hash,
> and use a custom store that get the data from the perl array/hash.
> That way you don't have to fill the store, the data are already there.
> It's much more complex but it can fit your needs, I use it with a list
> of 15000 rows, and creating/displaying the treeview is really fast on a
> duron800 :).

That should be an idea. Do you have a link to some docs for it?

>
> But my first solution could work: you load data until you have a full
> branch (starting from depth 0), then prepend the root of the branch to
> the store and fill this branch, load next branch ...
> It depends on what kind of data you have.

You can think at it as a hard disk directory tree. So, lot of branches
at different depths.
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: populating a TreeStore in reverse order

squentin
On Wed, 2005-06-22 at 15:09 +0200, The Saltydog wrote:

> On 6/22/05, Quentin <[hidden email]> wrote:
> > It's not what I meant, I meant keep all the data in a perl array/hash,
> > and use a custom store that get the data from the perl array/hash.
> > That way you don't have to fill the store, the data are already there.
> > It's much more complex but it can fit your needs, I use it with a list
> > of 15000 rows, and creating/displaying the treeview is really fast on a
> > duron800 :).
>
> That should be an idea. Do you have a link to some docs for it?
>
For the custom store/model there is the customlist.pl in the examples
directory of Gtk2-perl.
for using a perl array to store the data, there is only my program :
qsplayer (still looking for another name ;)), that you can find there :
http://squentin.free.fr
you can test it with 15000 rows by downloading the 'tags' file and
running ./qsplayer -demo -C tags
the custom list is in the qsplayer_list file, in the package SongStore
(warning: there is few comments)
> >
> > But my first solution could work: you load data until you have a full
> > branch (starting from depth 0), then prepend the root of the branch to
> > the store and fill this branch, load next branch ...
> > It depends on what kind of data you have.
>
> You can think at it as a hard disk directory tree. So, lot of branches
> at different depths.
But if you want to display a partially read tree, you have to know the
root of the branch, you can't display leaves that are not attached,
directly or not, to a row at depth=0.

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: populating a TreeStore in reverse order

Fabio Marzocca
On 6/22/05, Quentin <[hidden email]> wrote:
> for using a perl array to store the data, there is only my program :
> qsplayer (still looking for another name ;)), that you can find there :
> http://squentin.free.fr

Thank you. I'll have a look.

> But if you want to display a partially read tree, you have to know the
> root of the branch, you can't display leaves that are not attached,
> directly or not, to a row at depth=0.

Yes, I know. That's why I cannot use this method. If I have to wait
for the last element (depth=0) I cannot display while loading. The
user should wait the end of the scanning process.
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: populating a TreeStore in reverse order

Peter Haworth
On Wed, 22 Jun 2005 15:54:55 +0200, The Saltydog wrote:
> On 6/22/05, Quentin <[hidden email]> wrote:
> > But if you want to display a partially read tree, you have to know
> > the root of the branch, you can't display leaves that are not
> > attached, directly or not, to a row at depth=0.
>
> Yes, I know. That's why I cannot use this method. If I have to wait
> for the last element (depth=0) I cannot display while loading. The
> user should wait the end of the scanning process.

Do you know the path, or at least the depth of each node you're
adding? If so, you could create placeholder nodes for not-yet-existing
paths, and fill in their details as you work them out.

Or you could start by adding nodes to the root, and reparent them as
it becomes possible. That could be fun to watch, but possibly not
very useful.

--
        Peter Haworth [hidden email]
'Even among the breathtakingly awful code in Pod/Html.pm, that "feature"
 stands out as one of the more willfully pointless AND incorrect ones.'
                -- Sean M Burke
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: populating a TreeStore in reverse order

Fabio Marzocca
On 6/22/05, Peter Haworth <[hidden email]> wrote:
> Do you know the path, or at least the depth of each node you're
> adding? If so, you could create placeholder nodes for not-yet-existing
> paths, and fill in their details as you work them out.

Yes, I know the depth of each node, so I could create placeholders...

> Or you could start by adding nodes to the root, and reparent them as
> it becomes possible. That could be fun to watch, but possibly not
> very useful.

reparent? I know only of widget's reparenting...
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: populating a TreeStore in reverse order

ofey aikon
In reply to this post by Fabio Marzocca
On 6/22/05, The Saltydog <[hidden email]> wrote:
> On 6/22/05, Quentin <[hidden email]> wrote:
> > It's not what I meant, I meant keep all the data in a perl array/hash,
> > and use a custom store that get the data from the perl array/hash.
>
> That should be an idea. Do you have a link to some docs for it?
>

If you are building a custom treestore, may be this info will be of
use to you. http://live.gnome.org/GTK2_2dPerl_2fRecipes#head-1fb2ffb1d5cbf10c9d555cf2b11dbf4ed24d1b6c

Also, I had attempted to build a customtree.pl similar to the
customlist.pl in the /examples folder. The working script can be found
http://mail.gnome.org/archives/gtk-perl-list/2005-January/msg00149.html
... May or may not be of use to you :)

Regards,

Ofey.
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: populating a TreeStore in reverse order

Fabio Marzocca
On 6/23/05, ofey aikon <[hidden email]> wrote:
> ... May or may not be of use to you :)

Very useful. Thank you!
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: populating a TreeStore in reverse order

Peter Haworth
In reply to this post by Fabio Marzocca
On Wed, 22 Jun 2005 22:05:01 +0200, The Saltydog wrote:
> On 6/22/05, Peter Haworth <[hidden email]> wrote:
> > Or you could start by adding nodes to the root, and reparent them
> > as it becomes possible. That could be fun to watch, but possibly
> > not very useful.
>
> reparent? I know only of widget's reparenting...

OK, so the tree store API isn't quite a rich as I thought. You can
swap(), move_before() or move_after(), but both iters have to be "in
the same level", which presumably means "have the same parent". Fooey!

Now that I think about it some more, I did have some trouble working
out how to allow the user to move nodes to arbitrary positions with a
tree. This could explain why this application hasn't had any work done
on it for a while. I managed it in the original Gtk1 version, but I
don't remember how much pain it was :-)

--
        Peter Haworth [hidden email]
"It is always the best policy to tell the truth,
 unless, of course, you are an exceptionally good liar."
                -- Jerome K. Jerome
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list