demo_tableview.py
author Radek Brich <radek.brich@devl.cz>
Wed, 09 Jan 2013 22:32:15 +0100
changeset 60 fccca2a60492
parent 45 43b2279b06e1
child 64 03f591f5fe5c
permissions -rwxr-xr-x
DriverSDL: Implement blink attribute.
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)
45
43b2279b06e1 Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents: 42
diff changeset
    15
        self.top.add_handler('keypress', self.on_top_keypress)
21
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)
41
37b7dfc3eae6 Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
    24
21
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))
41
37b7dfc3eae6 Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
    29
21
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
42
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
    32
        self.top.layout = VerticalLayout()
21
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
41
37b7dfc3eae6 Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
    34
    def on_top_keypress(self, ev):
37b7dfc3eae6 Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
    35
        if ev.keyname == 'escape':
21
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
            self.terminate()
45
43b2279b06e1 Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents: 42
diff changeset
    37
            return True
21
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