demo_treeview.py
author Radek Brich <radek.brich@devl.cz>
Wed, 26 Mar 2014 21:26:39 +0100
changeset 92 b97c4e25ed6d
parent 64 03f591f5fe5c
permissions -rwxr-xr-x
Configure logging for demos.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import locale
locale.setlocale(locale.LC_ALL, '')

from tuikit import Application, TreeView, TreeModel, ScrollView


class MyApplication(Application):
    def __init__(self):
        Application.__init__(self)
        self.top.add_handler('keypress', self.on_top_keypress)

        model = TreeModel()
        model.add('/',  ['a', 'b'])
        model.add('/a', ['c', 'd'])
        model.add((0,1), ['e', 'f'])
        model.add(['a', 'd', 'e'], 'g')
        model.add('/a/d/f', 'h')

        for i in range(100):
            model.add('/b', ['x'+str(i)])

        view = TreeView(model)
        #view.collapse('/a/d')

        scroll = ScrollView()
        scroll.add(view)
        self.top.add(scroll, halign='fill', valign='fill')

    def on_top_keypress(self, ev):
        if ev.keyname == 'escape':
            self.terminate()
            return True


if __name__ == '__main__':
    app = MyApplication()
    app.start()