I want to get the number of rows in a Treeview , after Filter has been applied . I tried using len(Gtk.ListStore) and Gtk.Liststore.iter_n_children() after filtering the rows but both of these functions returned Total number of rows that were there without filtering .
Is there any way I can get number of rows returned after filtering ?
EDIT : A snippet of my program as requested by Rawing :
self.listfortreeview = Gtk.ListStore(str, str, str, str, str, str, str, str, str, str, str)
for item in win.result:
self.listfortreeview.append(list(item))
self.current_ps_filter = None
self.ps_filter = self.listfortreeview.filter_new()
self.ps_filter.set_visible_func(self.ps_filter_func)
self.ps_filter_sorted = Gtk.TreeModelSort(model=self.ps_filter)
self.votertreeview = Gtk.TreeView.new_with_model(self.ps_filter_sorted)
for i, coltitle in enumerate(["ID", "WARD", "PS NO", "SR NO", "NAME", "RELATION'S NAME", "SEX", "AGE", "ADDRESS",
"PSTATION", "IDCARD NO"]):
rendered = Gtk.CellRendererText(foreground = "blue")
column = Gtk.TreeViewColumn(coltitle, rendered, text=i)
column.set_sort_column_id(i)
self.votertreeview.append_column(column)
def filter_btn_clicked(self, button):
self.get_typed_filter = self.filter_text.get_text().strip()
if self.get_typed_filter == "":
self.current_ps_filter = "None"
else:
self.current_ps_filter = self.get_typed_filter
self.ps_filter.refilter()
self.text_Filtered_records = "\tFiltered Records : " + str(self.listfortreeview.iter_n_children())
self.label_Filtered_records.set_text(self.text_Filtered_records)
self.label_Filtered_records.show()
def ps_filter_func(self, model, iter, data):
if self.current_ps_filter is None or self.current_ps_filter == "None":
return True
elif self.combo_text == "PS No.":
return model[iter][2] == self.current_ps_filter
Here - win.result is a list of tuples
self.filter_text is an Entry in which user enters a string by which filter applies on 3rd column
self.combo_text is a Combo box by which user selects a column to perfrom on(for simplicity consider filter will be applied on 3rd column always)