#!/usr/bin/env python3

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GObject

class TreeViewFilterWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Treeview Filter Demo")
        self.set_border_width(10)

        #Setting up the self.grid in which the elements are to be positionned
        self.grid = Gtk.Grid()
        self.grid.set_column_homogeneous(True)
        self.grid.set_row_homogeneous(True)
        self.add(self.grid)

        #Creating the ListStore model
        self.liststorefail = Gtk.ListStore(int, str)
        
        ### THIS FAILS WITH PYTHON 3, WHILE PY2 long WORK FINE
        # self.liststorefail.append([10**10, 'append: 10^10'])
        
        ### THIS DOES NOT FAIL, BUT GET TRUNCATED TO int32
        self.liststorefail.insert_with_valuesv(-1, [0, 1], [10**10, 'insert_wv: 10^10'])

        # A ListStore with uint64 do not fail, but insert_with_valuesv truncates the ints
        # Again py2's longs are perfectly fine
        self.liststore = Gtk.ListStore(GObject.TYPE_UINT64, str)
        self.liststore.append([10, 'append: 10'])
        self.liststore.append([10**10, 'append: 10^10'])
        self.liststore.append([10**12, 'append: 10^12'])
        self.liststore.insert_with_valuesv(-1, [0, 1], [10, 'insert_wv: 10'])
        self.liststore.insert_with_valuesv(-1, [0, 1], [10**10, 'insert_wv: 10^10'])
        self.liststore.insert_with_valuesv(-1, [0, 1], [10**12, 'insert_wv: 10^12'])


        #creating the treeview, making it use the filter as a model, and adding the columns
        self.treeview = Gtk.TreeView(self.liststorefail)
        for i, column_title in enumerate(["big integer", "status"]):
            renderer = Gtk.CellRendererText()
            column = Gtk.TreeViewColumn(column_title, renderer, text=i)
            self.treeview.append_column(column)


        #setting up the layout, putting the treeview in a scrollwindow, and the buttons in a row
        self.scrollable_treelist = Gtk.ScrolledWindow()
        self.scrollable_treelist.set_vexpand(True)
        self.grid.attach(self.scrollable_treelist, 0, 0, 8, 10)
        self.scrollable_treelist.add(self.treeview)

        self.show_all()


win = TreeViewFilterWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
