[pygtk] Advanced Treeview Filtering Trouble

JUAN ERNESTO FLORES BELTRAN juanernestof at hotmail.com
Fri Apr 28 23:37:48 WST 2006


John wrote:

>If I understand your question I don't think you need to use the 
>set_modify_func() method. The set_visible_func() method should be 
>sufficient but you have to pass in an object that has mutable contents 
>corresponding to the columns that you want to use for filtering. For 
>example you could create a Python object that has one attribute that 
>contains a list of car models and another attribute that has a maximum 
>price. Pass this object as the data arg to the set_visible_func() method 
>and change the attributes as needed. Your visible_cb() function could then 
>do something like:
>
>def visible_cb(self, treestore, iter, x):
>  return treestore[iter][0] in x.models and treestore[iter][4] <= 
>x.maxprice
>
>John

It did work!!
thanks a lot jhon!!...

However a new trouble has shown up!!, now i do need to get the row data from 
the treeview which respond to the set_visible_func() method.  It is easy to 
get the data from an ordinary treeview, it can be done by "catching" the 
"cursor_changed" signal and handling it with a function as follows:

---------------------------------------------------------------------------------------------------------------------------------
  #the treeview is connected to the signal and this event is connected to a 
signal handler
  self.connection= self.treeview.connect("cursor_changed", self.getreedata)

  #then the signal handler (a callback) is in charge of getting the data of 
the row
def self.getreedata(self, iter):
   treeselection = self.treeview.get_selection()
   select= treeselection.get_selected()
   row_value= self.treestore.get_value(select[1], 0)
---------------------------------------------------------------------------------------------------------------------------------

where "select" is a list with two values [model, iter], then select[1] is an 
iter pointing to the position of the cursor in the treeview and 
consecuently, "row_value" is the value of the row where the cursor is 
positioned in the column "0" of the treeview.

This works perfectly in odinary treeviews, however when filtering (i mean 
when using the set_visible_func() method)  i do receive the following error 
message:

---------------------------------------------------------------------------
File "carstreeview.py", line 11, in getreedata
    row_value= self.treestore.get_value(select[1], 0)
TypeError = unknown type (null)
---------------------------------------------------------------------------

why this does not work when filtering the treeview???, do i need to set any 
property to the treeview?? the code above works properly for no filtered or 
commom treeviews, but not when filtering...is the case that 
set_visible_func()  avoids retrieving row values??? if so,  can the data be 
retrieved from the treemodel??, how??, i have seen there is not 
"cursor_changed" signals for treemodels

any suggestion??.
thanks for your help in advance
juan.-




More information about the pygtk mailing list