Advanced Treeview Filtering Help

  • Thread starter JUAN ERNESTO FLORES BELTRAN
  • Start date
J

JUAN ERNESTO FLORES BELTRAN

Hi you all,

I am developping a python application which connects to a database
(postresql) and displays the query results on a treeview. In adittion to
displaying the info i do need to implement filtering facility for all the
columns of the treestore/liststore model in order to allow the user an easy
search method to find the desired information.

The treestore is created with information related to cars, the columns are:

car_model car_year car_color car_type car_price
chevrolet 1998 white sedan 5.000 US$
ford 1996 blue sedan 3.000 US$
- - - - -
- - - - -
- - - - -

I have been able to allow filtering to only one column, an extract of my
code as follows:


------------------------------------------------------------------------------------------------------------------------
#treestore creation
self.treestore = gtk.TreeStore(str, str, str, str, str)
self.modelfilter = self.treestore.filter_new()
self.treeview=gtk.TreeView()

#append treestore columns
self.treestore.append(None, [self.model, self.year, self.color,
self.type, self.price]

#set treestore model to allow filtering by car_model column
self.modelfilter.set_visible_func(self.visible_cd, self.car_model)

#the function to filter the treestore
def visible_cb(self, treestore, iter, x)
return treestore.get_value(iter, 0) in x

#self.car_model is a list of items wich change according to user needs and
can be controlled by a #secundary treeview or a button this function is
not explained.

------------------------------------------------------------------------------------------------------------------------

The code mentioned above does work but i can only fllter by defining
criterias in the first column. To allow filtering to all the columns i do
need the following code to work:

-------------------------------------------------------------------------------------------------------------------------
treemodelfilter.set_modify_func(types, func, data=None)
def func(model, iter, column, user_data)
-------------------------------------------------------------------------------------------------------------------------

where types should be:
types = (str, str, str, str, str)

the function to allow filtering:
def visible_cb(self, treestore, column, iter, x)
return treestore.get_value(iter, column) in x

and the rest of the code never changes...however it is not woking. Any
suggestion about the code mention?? am i making mistakes?? where?? do i have
to pass the column number someway to the visible_cb function??? how??

can any of you suggest a code example to follow and find out how the
treeview must be coded in order to allow "multicolumn filtering"???

thanks in advance for your support..
Juan
 
J

Jarek Zgoda

JUAN ERNESTO FLORES BELTRAN napisa³(a):
can any of you suggest a code example to follow and find out how the
treeview must be coded in order to allow "multicolumn filtering"???

thanks in advance for your support..

Your question was answered on PyGTK mailing list. Please, don't crosspost.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top