demo_tableview.py
author Radek Brich <radek.brich@devl.cz>
Mon, 17 Dec 2012 23:27:37 +0100
changeset 39 5e5deb1d3945
parent 22 6ca8b2d221c3
child 41 37b7dfc3eae6
permissions -rwxr-xr-x
Fixes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import locale
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
locale.setlocale(locale.LC_ALL, '')
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
from tuikit import Application
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
from tuikit.layout import VerticalLayout
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
from tuikit.tableview import TableView, TableModel
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
class MyApplication(Application):
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
    def __init__(self):
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
        Application.__init__(self)
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
        self.top.connect('keypress', self.globalkeypress)
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
        data = []
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
        for y in range(100):
22
6ca8b2d221c3 Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
    19
            row = [str(y+1)]
21
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
            for x in range(10):
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
                row.append('r{}:c{}'.format(y, x))
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
            data.append(row)
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
        model = TableModel(data)
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
        
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
        view = TableView(model)
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
        view.addcolumn(header=True, expand=False, sizereq=5)
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
        for x in range(10):
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
            view.addcolumn(title='head'+str(x))
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
        
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
        self.top.add(view, expand=True, fill=True)
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
        vert = VerticalLayout()
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
        self.top.layout(vert)
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
    def globalkeypress(self, keyname, char):
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
        if keyname == 'escape':
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
            self.terminate()
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
if __name__ == '__main__':
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
    app = MyApplication()
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
    app.start()
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43