[pygtk] TreeStore & Filter

Daniel Hernández Bahr dbahr at estudiantes.uci.cu
Wed Feb 18 08:24:58 WST 2009


Hullo everyone .. 

I am working on an application using a TreeView to show a TreeStore model through a Filter, including selection capabilities. The thing is, while showing all the model, when the user selects a parent row, all the childs are selected, this much works just fine, but when i have filtered the model and i try to select any parent row i get the following warning: 

/home/darion/Projects/workspace/summon/src/summon/gui/main.py:585: GtkWarning: gtk_tree_model_filter_get_path: assertion `GTK_TREE_MODEL_FILTER (model)->priv->stamp == iter->stamp' failed 
selection.unselect_iter(iter) 

/home/darion/Projects/workspace/summon/src/summon/gui/main.py:586: GtkWarning: gtk_tree_selection_real_modify_range: assertion `start_node != NULL' failed 
selection.select_range(start_path, end_path) 

and only the parent row gets selected and none of its children. 

I include the related methods: 

# **************************** 
# Selection Section 
def select_package(self, arg1, path, column): 
filter = self.packages_view.get_model() 
real_path = filter.convert_path_to_child_path(path) 
self.select_deselect(real_path, filter) 

def select_deselect(self, path, filter): 
def do(): 
children = model.iter_n_children(iter) 
start_path = model.get_path(model.iter_children(iter)) 
end_path = model.get_path(model.iter_nth_child(iter, children-1)) 
selection = self.packages_view.get_selection() 
selection.unselect_all() 
selection.unselect_iter(iter) 
selection.select_range(start_path, end_path) 

model = filter.get_model() 
value = not model[path][0] 
model[path][0] = value 

iter = model.get_iter(path) 
piter = model.iter_parent(iter) 

if piter is None: 
if self.packages_view.row_expanded(path): 
do() 
self.on_check_button_clicked() 
else: 
self.packages_view.expand_row(path, False) 
do() 
self.on_check_button_clicked() 
self.packages_view.collapse_row(path) 
else: 
cat = model.get_value(piter, 2) 
atom = cat + "/" + model[path][2] + "-" + model[path][4] 
if value and model[path][8]: 
if self.current in ("install", "update"): 
if atom not in self.summon.install_packages: 
self.summon.install_packages.append(atom) 
elif self.current == "remove": 
if atom not in self.summon.remove_packages: 
self.summon.remove_packages.append(atom) 
else: 
if self.current in ("install", "update"): 
try: 
self.summon.install_packages.remove(atom) 
except ValueError, e: 
pass 
elif self.current == "remove": 
try: 
self.summon.remove_packages.remove(atom) 
except ValueError, e: 
pass 

sensitive = True 
if len(self.summon.install_packages) == 0 and \ 
len(self.summon.remove_packages) == 0: 
sensitive = False 
self.process_button.set_sensitive(sensitive) 

def on_check_button_clicked(self, *args): 
selection = self.packages_view.get_selection() 
filter, paths = selection.get_selected_rows() 
model = filter.get_model() 

true = 0 
false = 0 
action = True 

for path in paths: 
real_path = filter.convert_path_to_child_path(path) 
if model[real_path][0]: true += 1 
else: false += 1 
action = true < false 

for path in paths: 
real_path = filter.convert_path_to_child_path(path) 
model[real_path][0] = not action 
if model[real_path][8]: 
self.select_deselect(real_path, filter) 

def on_checkall_button_clicked(self, *args): 
selection = self.packages_view.get_selection() 
selection.select_all() 
filter, paths = selection.get_selected_rows() 
model = filter.get_model() 

for path in paths: 
real_path = filter.convert_path_to_child_path(path) 
model[real_path][0] = False 
self.select_deselect(real_path, filter) 

selection.unselect_all() 

def on_uncheck_button_clicked(self, *args): 
selection = self.packages_view.get_selection() 
selection.select_all() 
filter, paths = selection.get_selected_rows() 
model = filter.get_model() 

for path in paths: 
real_path = filter.convert_path_to_child_path(path) 
model[real_path][0] = True 
self.select_deselect(real_path, filter) 

selection.unselect_all() 

def on_files_selection_changed(self, selection): 
rows = selection.count_selected_rows() 
self.erase_button.set_sensitive(rows>0) 
self.merge_button.set_sensitive(rows>0) 

# End of Selection Section 
# ************************ 

If anyone has any idea what could be done .. i would be greatly thankful .. 

Cheers .. and best regards .. 

-- 

Daniel Hernández Bahr 
Universidad de las Ciencias Informáticas. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20090217/5fa46ddf/attachment-0001.htm 


More information about the pygtk mailing list