Sorting a TreeView

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

Sorting a TreeView

Nemesis-6
Hi all,
 I'm using a TreeView to show threaded news articles. I use 4 columns
"Subject", "From", "Date", "Score". The threaded model is built ordering
articles by date, so at the end I get a model ordered by the date of the
first article of each thread. I use the set_sort_column_id on these
columns in order to reorder the model by the other columns.
This method works but I'd like to automatically change the order after
showing the model (I don't want the user to click on the column header).

For example I'd like to show the threads ordered with descending dates.
I tried using the method

set_sort_order(gtk.SORT_DESCENDING)

but it only changes the appearance of the arrow.

Wich is the correct solution?

--
 
 |\ |       |HomePage   : http://nem01.altervista.org
 | \|emesis |XPN (my nr): http://xpn.altervista.org
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Sorting a TreeView

Jody Steele
On Sun, 05 Jun 2005 04:39:30 -0400, Nemesis <[hidden email]> wrote:

> Hi all,
>  I'm using a TreeView to show threaded news articles. I use 4 columns
> "Subject", "From", "Date", "Score". The threaded model is built ordering
> articles by date, so at the end I get a model ordered by the date of the
> first article of each thread. I use the set_sort_column_id on these
> columns in order to reorder the model by the other columns.
> This method works but I'd like to automatically change the order after
> showing the model (I don't want the user to click on the column header).
>
> For example I'd like to show the threads ordered with descending dates.
> I tried using the method
>
> set_sort_order(gtk.SORT_DESCENDING)
>
> but it only changes the appearance of the arrow.
>
> Wich is the correct solution?
>

Hello.

 From the docs  
(http://www.pygtk.org/pygtk2reference/class-gtktreeviewcolumn.html#method-gtktreeviewcolumn--set-sort-order):

TreeViewColumn.set_sort_order

Note

This method does not actually sort the model. Use the set_sort_column_id()  
method if you want automatic sorting support. This method is primarily for  
custom sorting behavior, and should be used in conjunction with the  
set_sort_column_id() method to do that. For custom models, the mechanism  
will vary.


Assuming your ListStore is called list, I think a simple  
list.set_sort_column_id(<id of your date column>,gtk.SORT_DESCENDING)  
after adding all the data to the model is all you need to do.


Also from the docs:

TreeSortable.set_sort_column_id() (ListStore implements TreeSortable)

The set_sort_column_id() method sets the current sort comparison function  
to that associated with the sort column ID specified by sort_column_id  
with the sort order type specified by order. The value of order must be  
either: gtk.SORT_ASCENDING or gtk.SORT_DESCENDING. The treesortable will  
resort itself to reflect this change, after emitting a  
"sort_column_changed" signal.


Let me know if that does the trick.

Jody Steele


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Sorting a TreeView

Nemesis-6
On Sun, 05 Jun 2005 05:42:57 -0400
"Jody Steele" <[hidden email]> wrote:

> Assuming your ListStore is called list, I think a simple  
> list.set_sort_column_id(<id of your date column>,gtk.SORT_DESCENDING)
> after adding all the data to the model is all you need to do.

Thanks, it seems to work. Now I'm testing this solution.

--
 
 |\ |       |HomePage   : http://nem01.altervista.org
 | \|emesis |XPN (my nr): http://xpn.altervista.org
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/