demo_treeview.py
author Radek Brich <radek.brich@devl.cz>
Mon, 07 Jan 2013 23:15:17 +0100
changeset 56 282a07d20680
parent 45 43b2279b06e1
child 62 2f61931520c9
permissions -rwxr-xr-x
Drop PyGame driver, replaced by compiled SDL driver.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import locale
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
locale.setlocale(locale.LC_ALL, '')
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
42
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
     7
from tuikit import Application, TreeView, TreeModel, ScrollView, VerticalLayout
11
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
class MyApplication(Application):
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
    def __init__(self):
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
        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
    13
        self.top.add_handler('keypress', self.on_top_keypress)
11
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
        model = TreeModel()
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
        model.add('/',  ['a', 'b'])
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
        model.add('/a', ['c', 'd'])
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
        model.add((0,1), ['e', 'f'])
39
Radek Brich <radek.brich@devl.cz>
parents: 19
diff changeset
    19
        model.add(['a', 'd', 'e'], 'g')
11
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
        model.add('/a/d/f', 'h')
39
Radek Brich <radek.brich@devl.cz>
parents: 19
diff changeset
    21
40
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 39
diff changeset
    22
        for i in range(100):
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 39
diff changeset
    23
            model.add('/b', ['x'+str(i)])
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 39
diff changeset
    24
11
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
        view = TreeView(model)
40
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 39
diff changeset
    26
        #view.collapse('/a/d')
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 39
diff changeset
    27
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 39
diff changeset
    28
        scroll = ScrollView()
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 39
diff changeset
    29
        scroll.add(view)
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 39
diff changeset
    30
        self.top.add(scroll, expand=True, fill=True)
11
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
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()
11
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
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: 40
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: 40
diff changeset
    35
        if ev.keyname == 'escape':
11
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
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
11
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
if __name__ == '__main__':
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
    app = MyApplication()
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
    app.start()
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43