#!/usr/bin/python
from gi.repository import Gtk

# http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html


class MyWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Gtk.TreeView example reorder")
        self.set_default_size(200, 200)

        self.connect("delete-event", Gtk.main_quit)

        self.store = Gtk.ListStore(str, str)
        for i in range(5):
            self.store.append([str(i), 'Item %s' % i])

        self.treeview = Gtk.TreeView(self.store)
        renderer = Gtk.CellRendererText()

        column = Gtk.TreeViewColumn('Number', renderer, text=0)
        self.treeview.append_column(column)

        column = Gtk.TreeViewColumn('Text', renderer, text=1)
        self.treeview.append_column(column)

        self.add(self.treeview)

        r = reversed(range(len(self.store)))
        print list(r)
        self.store.reorder(r)

        # TESTING: this is the case without using self.store.reorder()
        # rows = []
        # for row in reversed(self.store):
        #     rows.append([row[0], row[1]])
        # self.store.clear()
        # for row in rows:
        #     self.store.append(row)

        self.show_all()


if __name__ == '__main__':
    win = MyWindow()
    Gtk.main()
