demo_window.py
author Radek Brich <radek.brich@devl.cz>
Sat, 02 Feb 2013 12:54:27 +0100
changeset 76 fa5301e58eca
parent 74 23767a33a781
permissions -rwxr-xr-x
Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.

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

import cProfile, pstats
import locale
import os

from tuikit.application import Application
from tuikit.window import Window
from tuikit.scrollwindow import ScrollWindow
from tuikit.button import Button
from tuikit.layout import AnchorLayout
from tuikit.common import Borders
from tuikit.editbox import EditBox


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

        #edit = EditField(50, 'DlouhyTest12')
        #self.top.add(edit)

        win = Window()
        win.title = 'demo window'
        win.resize(40, 25)
        self.top.add(win, halign='left', valign='top')

        button = Button('click!')
#        win.add(button, x=10, y=6)

        button.add_handler('click', self.on_button_click)
        self.button = button

        subwin = Window()
        subwin.name = 'subwin'
        win.add(subwin)

        swin = ScrollWindow()
        swin.title = 'scroll window'
        swin.resize(40, 25)
        self.top.add(swin)

        swin.move(x=40)

        text = open('tuikit/widget.py').read()
        editbox = EditBox(text)
        swin.add(editbox)

    def on_button_click(self, ev):
        self.button.label = 'YES'
        return True


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


if __name__ == '__main__':
    locale.setlocale(locale.LC_ALL, '')
    os.environ['ESCDELAY'] = '25' # do not wait 1 second after pressing Escape key
    app = MyApplication()
    app.start()

    #cProfile.run('app.start()', 'demo_window.appstats')
    #p = pstats.Stats('demo_window.appstats')
    #p.sort_stats('time', 'cumulative').print_stats(20)