demo_window.py
author Radek Brich <radek.brich@devl.cz>
Sat, 19 Jan 2013 13:05:21 +0100
changeset 63 2a0e04091898
parent 62 2f61931520c9
child 74 23767a33a781
permissions -rwxr-xr-x
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters. LinearLayout: spacing now applies to all children, not just those with expand. Fix Window resize request inside layouts. UnicodeGraphics: prepare for styling/theming.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
28
feee783d4fc5 DriverPygame: output to character buffer, draw whole screen at once.
Radek Brich <radek.brich@devl.cz>
parents: 19
diff changeset
     4
import cProfile, pstats
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
import locale
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
import os
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
from tuikit.application import Application
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
from tuikit.window import Window
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
from tuikit.button import Button
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    11
from tuikit import AnchorLayout
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    12
from tuikit.common import Borders
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
class MyApplication(Application):
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
    def __init__(self):
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
        Application.__init__(self)
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    18
        self.top = AnchorLayout()
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    19
        self.top.name = 'top'
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: 29
diff changeset
    20
        self.top.add_handler('keypress', self.on_top_keypress)
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
        #edit = EditField(50, 'DlouhyTest12')
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
        #self.top.add(edit)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
        win = Window()
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    26
        win.title = 'demo_window'
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    27
        win.resize(80, 25)
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    28
        self.top.add(win, halign='left', valign='top')
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
        button = Button('click!')
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    31
#        win.add(button, x=10, y=6)
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
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: 29
diff changeset
    33
        button.add_handler('click', self.on_button_click)
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
        self.button = button
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    36
        subwin = Window()
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    37
        subwin.name = 'subwin'
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
        win.add(subwin)
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
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: 29
diff changeset
    41
    def on_button_click(self, ev):
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
        self.button.label = 'YES'
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: 29
diff changeset
    43
        return True
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
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: 29
diff changeset
    46
    def on_top_keypress(self, ev):
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: 29
diff changeset
    47
        if ev.keyname == 'escape':
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
            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: 29
diff changeset
    49
            return True
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    50
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    51
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    52
if __name__ == '__main__':
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    53
    locale.setlocale(locale.LC_ALL, '')
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
    os.environ['ESCDELAY'] = '25' # do not wait 1 second after pressing Escape key
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
    app = MyApplication()
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    56
    app.start()
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: 29
diff changeset
    57
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    58
    #cProfile.run('app.start()', 'demo_window.appstats')
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    59
    #p = pstats.Stats('demo_window.appstats')
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    60
    #p.sort_stats('time', 'cumulative').print_stats(20)
19
5e78d52ebb24 Update demos and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61