demo_tableview.py
author Radek Brich <radek.brich@devl.cz>
Sun, 15 Feb 2015 17:50:24 +0100
changeset 116 165b5d65e1cb
parent 100 3b2df86d8f94
permissions -rwxr-xr-x
Drop AnchorLayout, merge its features into FixedLayout.
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.tableview import TableView, TableModel
100
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
     9
from tuikit.scrollview import ScrollView
21
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
100
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    17
        model = TableModel()
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    18
        model.set_num_headers(1, 1)
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    19
        for col in range(10):
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    20
            model.insert_column(col)
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    21
            model.set_column_header(col, 0, 'col'+str(col+1))
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    22
        for row in range(100):
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    23
            model.insert_row(row)
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    24
            model.set_row_header(row, 0, 'row'+str(row+1))
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    25
            for col in range(10):
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    26
                model.set_item(row, col, 'r{}:c{}'.format(row+1, col+1))
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
    27
21
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
        view = TableView(model)
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
100
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    30
        scroll = ScrollView()
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    31
        scroll.add(view)
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    32
3b2df86d8f94 Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    33
        self.top.add(scroll, halign='fill', valign='fill')
21
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
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
    35
    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
    36
        if ev.keyname == 'escape':
21
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
            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
    38
            return True
21
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
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
if __name__ == '__main__':
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
    app = MyApplication()
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
    app.start()
8553a6bd2d82 Add TableView plus demo.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44