#!/usr/bin/python

import pyatspi
from gi.repository import GObject, Gtk

class HelloWorldApp(Gtk.Application):
    def __init__(self):
        Gtk.Application.__init__(self)
        self.connect("activate", self.onActivate)

    def register(self):
        pyatspi.Registry.registerEventListener(
            self.onStateChange, "object:state-changed")
        pyatspi.Registry.registerKeystrokeListener(
            self.onKey,
            mask=range(255),
            kind=(pyatspi.KEY_PRESSED_EVENT, pyatspi.KEY_RELEASED_EVENT))
        pyatspi.Registry.start()

    def onActivate(self, data=None):
        window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
        window.set_title("Freezes are hard, let's do math!")
        window.set_default_size(325, 325)

        scrolledWindow = Gtk.ScrolledWindow()
        window.add(scrolledWindow)

        tree = Gtk.TreeView()
        scrolledWindow.add(tree)

        for x in range(0, 11):
            cell = Gtk.CellRendererText()
            column = Gtk.TreeViewColumn("%i" % x, cell, text=x)
            tree.append_column(column)

        types = 11 * [GObject.TYPE_STRING]
        model = Gtk.ListStore(*types)
        for row in range(1, 11):
            rowIter = model.append(None)
            model.set_value(rowIter, 0, str(row))
            for col in range(1, 11):
                model.set_value(rowIter, col, str(row*col))

        tree.set_model(model)
        window.show_all()
        self.add_window(window)
        self.register()

    def onKey(self, event):
        print(event)

    def onStateChange(self, event):
        print(event)
    
if __name__ == "__main__":
    app = HelloWorldApp()
    app.run(None)
