I too had this problem and the docs are unclear. But here's what I found
'rows-reordered' signal is emitted when you have
tvcolumn.set_sort_column_id(0)
However you still bind the signal to the treemodel.
treestore = gtk.TreeStore(str, object)
treestore.connect("rows-reordered", self.rows_r)
That will cause the visible column header to become clickable. When you click on the column header, it will reorder the items in the tree in ascending order and then in descending order if you click it again, and back and forth.
Here's a simple code you can test and see what i mean.
import pygtk
pygtk.require('2.0')
import gtk
class BasicTreeViewExample:
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Treeview")
window.set_size_request(200, 200)
window.connect("destroy", lambda w: gtk.main_quit())
treestore = gtk.TreeStore(str)
treestore.connect("rows-reordered", self.rows_reordered)
for i in range(4):
piter = treestore.append(None, ['Item %i' % i])
treeview = gtk.TreeView(treestore)
tvcolumn = gtk.TreeViewColumn('Click Me!')
treeview.append_column(tvcolumn)
cell = gtk.CellRendererText()
tvcolumn.pack_start(cell, True)
tvcolumn.add_attribute(cell, 'text', 0)
# This allows the column header ("Click me!") to be clickable and sort/order items
tvcolumn.set_sort_column_id(0)
window.add(treeview)
window.show_all()
def rows_reordered(self, a, b, c, d):
print a
print b
print c
print d
def main():
gtk.main()
if __name__ == "__main__":
tvexample = BasicTreeViewExample()
main()