demo_tableview.py
author Radek Brich <radek.brich@devl.cz>
Wed, 03 Sep 2014 19:13:37 +0200
changeset 110 cf3d49cdd6e2
parent 64 03f591f5fe5c
child 99 f3063f08ba81
permissions -rwxr-xr-x
Add cursesw driver, using curses get_wch() for unicode input. It alse has enabled keypad() to let curses interpret control keys and mouse input.

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

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

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


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

        data = []
        for y in range(100):
            row = [str(y+1)]
            for x in range(10):
                row.append('r{}:c{}'.format(y, x))
            data.append(row)
        model = TableModel(data)

        view = TableView(model)
        view.addcolumn(header=True, expand=False, sizereq=5)
        for x in range(10):
            view.addcolumn(title='head'+str(x))

        self.top.add(view, 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()