demo_tableview.py
author Radek Brich <radek.brich@devl.cz>
Wed, 03 Sep 2014 08:57:24 +0200
changeset 108 11dac45bfba4
parent 100 3b2df86d8f94
permissions -rwxr-xr-x
Fix cursor.

#!/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()