osdir.com
mailing list archive

Subject: SimpleList - sorting by column - msg#00201

List: gnome.gtk+.perl

Date: Prev Next Index Thread: Prev Next Index
Hi

Is it possible to sort items in a simplelist, in the way that is
possible with a TreeView column?

--

Regards


David Sword


Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

will we be ready for gnome 2.6.0?

there's been some talk on language-bindings lately about putting together a gnome release set of language bindings. this would require API and ABI stability, bug-free-ness, and relative completeness of bindings for the core libraries of the gnome developer platform. my question to you, the developers, testers, and users of gtk2-perl: do you think we can do this? shall we offer to pitch in on this endeavor? according to http://www.gnome.org/start/2.5/modules/ , the Developer Platform consists of these libraries... i've marked what i think is the current status of our bindings for each one. http://asofyet.org/muppet/software/gtk2-perl/module-status.html so what's the word? -- muppet <scott at asofyet dot org>

Next Message by Date: click to view message preview

Re: SimpleList - sorting by column

David Sword said: > Is it possible to sort items in a simplelist, in the way that is > possible with a TreeView column? indeed it is. in fact, you'd do it the same way you do with TreeView, because a SimpleList is just a reblessed TreeView that guarantees a 1-to-1 mapping in the order of the columns in the view with columns in the model, and which makes it a lot easier to get data in and out of the model. you will want to fetch the columns and set their sort ids accordingly: @columns = $simplelist->get_columns; for (my $i = 0 ; $i < @columns ; $i++) { $columns[$i]->set_sort_column_id ($i); } # or $simplelist->get_column (0)->set_sort_column_id (0); $simplelist->get_column (2)->set_sort_column_id (2); and that about does it. .... BUT .... if the data in the column you are making sortable is not a known type, you'll have to set a sort function. for example, in the simplelist.pl example, column 7, the "sum of array" column, is of type GPerlSV and generates the warning "Attempting to sort on invalid type GPerlSV". the solution: # add at line 86 of Gtk2/examples/simplelist.pl $slist->get_column (7)->set_sort_column_id (7); $slist->get_model->set_sort_func (7, sub { my ($sortable, $iter_left, $iter_right) = @_; my $info = $sortable->get ($iter_left, 7); my $left = 0; foreach my $i (@$info) { $left += $i } $info = $sortable->get ($iter_right, 7); my $right = 0; foreach my $i (@$info) { $right += $i } return $left <=> $right; }); and, voila, you can click the column header of the "Sum of Array" column to sort by the sum of the array. note that i use 7 everywhere because simplelist guarantees that column 7 in the view displays the contents of column 7 in the model. if, however, i wanted column 7 to display the contents of column 4 in the model, and sort column 7 in the view by the contents of column 5 in the model, i could do that, too. -- muppet <scott at asofyet dot org>

Previous Message by Thread: click to view message preview

Re: GladeXML Examples

> > Note that the scribble sample is still borked, a libglade bug that I > > haven't figured out yet :-/ > > i guess once this is resolved or we just decide to drop it we'll > do a release of GladeXML, possibly 1.0, if people think it's ready > for it Makes sense, I left in in there in case someone else happened to be interested in looking at it too. I've installed a newer libglade, and built the anon cvs-head of Gtk2-perl, but no change. I'll dig at it over lunches at work this week. > the fileman example might be a good one for the website including the > screen shot. but i'll leave that for another time. I've been meaning to write-up a few related tutorials on my site as well, which I hope to get to in the next few weeks (I'm working on a blogging back end too though). Anyway, I'll continue to contribute small bits as I use it. Great stuff! -- Bruce Alderson <mx@xxxxxxxxxxxxxxxxx> http://warpedvisions.org

Next Message by Thread: click to view message preview

Re: SimpleList - sorting by column

David Sword said: > Is it possible to sort items in a simplelist, in the way that is > possible with a TreeView column? indeed it is. in fact, you'd do it the same way you do with TreeView, because a SimpleList is just a reblessed TreeView that guarantees a 1-to-1 mapping in the order of the columns in the view with columns in the model, and which makes it a lot easier to get data in and out of the model. you will want to fetch the columns and set their sort ids accordingly: @columns = $simplelist->get_columns; for (my $i = 0 ; $i < @columns ; $i++) { $columns[$i]->set_sort_column_id ($i); } # or $simplelist->get_column (0)->set_sort_column_id (0); $simplelist->get_column (2)->set_sort_column_id (2); and that about does it. .... BUT .... if the data in the column you are making sortable is not a known type, you'll have to set a sort function. for example, in the simplelist.pl example, column 7, the "sum of array" column, is of type GPerlSV and generates the warning "Attempting to sort on invalid type GPerlSV". the solution: # add at line 86 of Gtk2/examples/simplelist.pl $slist->get_column (7)->set_sort_column_id (7); $slist->get_model->set_sort_func (7, sub { my ($sortable, $iter_left, $iter_right) = @_; my $info = $sortable->get ($iter_left, 7); my $left = 0; foreach my $i (@$info) { $left += $i } $info = $sortable->get ($iter_right, 7); my $right = 0; foreach my $i (@$info) { $right += $i } return $left <=> $right; }); and, voila, you can click the column header of the "Sum of Array" column to sort by the sum of the array. note that i use 7 everywhere because simplelist guarantees that column 7 in the view displays the contents of column 7 in the model. if, however, i wanted column 7 to display the contents of column 4 in the model, and sort column 7 in the view by the contents of column 5 in the model, i could do that, too. -- muppet <scott at asofyet dot org>
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by