Hi,
I have created a two-column sortable TreeView using a ListStore with
Python lists containing the real data. When I try to sort the TreeView
by a column, weird things happen:
1) the first line of TreeView is never sorted (other lines are)
2) putting the column in sorted DESC state toggles between DESC and ASC
order
3) putting the column in sorted ASC state does nothing
Example:
C1 | C2
----+----
1 | D
1.1 | C
1.2 | B
2 | A
(click on header of C1)
C1 v| C2
----+----
1 | D <-- this line is not sorted, should appear as last
2 | A
1.2 | B
1.1 | C
(click on header of C1)
C1 ^| C2
----+----
1 | D
2 | A
1.2 | B
1.1 | C
=> nothing happens which is wrong -- the order should be reversed
(click on header of C1)
C1 v| C2
----+----
1 | D
1.1 | C
1.2 | B
2 | A
=> this is order ASC but sort indocator shows DESC order
What am I doing wrong?
Thanks,
Jirka
class Test:
def __init__(self):
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.connect('delete-event', self.app_quit)
win.set_size_request(400, 200)
view = gtk.TreeView()
model = gtk.ListStore(gobject.TYPE_PYOBJECT)
renderer1 = gtk.CellRendererText()
column1 = gtk.TreeViewColumn('C1', renderer1)
column1.set_cell_data_func(renderer1, self._get_data, 0)
column1.set_sort_column_id(0)
view.append_column(column1)
renderer2 = gtk.CellRendererText()
column2 = gtk.TreeViewColumn('C2', renderer2)
column2.set_cell_data_func(renderer2, self._get_data, 1)
column2.set_sort_column_id(1)
view.append_column(column2)
win.add(view)
view.set_model(model)
win.show_all()
model.append([['1', 'D']])
model.append([['1.1', 'C']])
model.append([['1.2', 'B']])
model.append([['2', 'A']])
model.set_sort_func(0, self._compare_data, 0)
model.set_sort_func(1, self._compare_data, 1)
def _get_data(self, treview_column, renderer, model, titer, column):
path = model.get_path(titer)
data = model[path][0]
renderer.set_property('text', data[column])
def _compare_data(self, model, iter1, iter2, column):
data1 = model[model.get_path(iter1)][0][column]
data2 = model[model.get_path(iter2)][0][column]
print data1, data2, cmp(data1, data2)
return cmp(data1, data2)
def app_quit(self, widget, event):
gtk.main_quit()
Test()
gtk.main()
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/