demo_window.py
author Radek Brich <radek.brich@devl.cz>
Sat, 05 Jan 2013 18:56:45 +0100
changeset 51 dce7325109c1
parent 45 43b2279b06e1
child 62 2f61931520c9
permissions -rwxr-xr-x
Clean up: expand unwanted tabs.

#!/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.button import Button


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

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

        win = Window()
        self.top.add(win)

        button = Button('click!')
        win.add(button)
        button.x = 10
        button.y = 7

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

        subwin = Window(8,8)
        win.add(subwin)


    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)