demo_tableview.py
author Radek Brich <radek.brich@devl.cz>
Wed, 03 Sep 2014 21:56:20 +0200
changeset 113 6796adfdc7eb
parent 100 3b2df86d8f94
permissions -rwxr-xr-x
Merge. Due to my schizophrenia, I've accidentally forked my own code. The other set of changes were found in another computer.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import locale
locale.setlocale(locale.LC_ALL, '')

from tuikit import Application
from tuikit.tableview import TableView, TableModel
from tuikit.scrollview import ScrollView


class MyApplication(Application):
    def __init__(self):
        Application.__init__(self)
        self.top.add_handler('keypress', self.on_top_keypress)

        model = TableModel()
        model.set_num_headers(1, 1)
        for col in range(10):
            model.insert_column(col)
            model.set_column_header(col, 0, 'col'+str(col+1))
        for row in range(100):
            model.insert_row(row)
            model.set_row_header(row, 0, 'row'+str(row+1))
            for col in range(10):
                model.set_item(row, col, 'r{}:c{}'.format(row+1, col+1))

        view = TableView(model)

        scroll = ScrollView()
        scroll.add(view)

        self.top.add(scroll, halign='fill', valign='fill')

    def on_top_keypress(self, ev):
        if ev.keyname == 'escape':
            self.terminate()
            return True


if __name__ == '__main__':
    app = MyApplication()
    app.start()