demo_treeview.py
author Radek Brich <radek.brich@devl.cz>
Wed, 12 Mar 2014 23:21:20 +0100
changeset 78 6031e99c8ad3
parent 64 03f591f5fe5c
permissions -rwxr-xr-x
Add Buffer class with basic drawing methods.
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
64
03f591f5fe5c Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
     7
from tuikit import Application, TreeView, TreeModel, ScrollView
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):
64
03f591f5fe5c Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 62
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)
64
03f591f5fe5c Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    30
        self.top.add(scroll, halign='fill', valign='fill')
11
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
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
    32
    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
    33
        if ev.keyname == 'escape':
11
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
            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
    35
            return True
11
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
if __name__ == '__main__':
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
    app = MyApplication()
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
    app.start()
762513aacc87 TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41