| author | Radek Brich <radek.brich@devl.cz> | 
| Tue, 08 Jan 2013 23:36:01 +0100 | |
| changeset 58 | 50308ed5e4f9 | 
| parent 45 | 43b2279b06e1 | 
| child 62 | 2f61931520c9 | 
| permissions | -rwxr-xr-x | 
| 19 | 1 | #!/usr/bin/env python3 | 
| 2 | # -*- coding: utf-8 -*- | |
| 3 | ||
| 28 
feee783d4fc5
DriverPygame: output to character buffer, draw whole screen at once.
 Radek Brich <radek.brich@devl.cz> parents: 
19diff
changeset | 4 | import cProfile, pstats | 
| 19 | 5 | import locale | 
| 6 | import os | |
| 7 | ||
| 8 | from tuikit.application import Application | |
| 9 | from tuikit.window import Window | |
| 10 | from tuikit.button import Button | |
| 11 | ||
| 12 | ||
| 13 | class MyApplication(Application): | |
| 14 | def __init__(self): | |
| 15 | 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: 
29diff
changeset | 16 |         self.top.add_handler('keypress', self.on_top_keypress)
 | 
| 19 | 17 | |
| 18 | #edit = EditField(50, 'DlouhyTest12') | |
| 19 | #self.top.add(edit) | |
| 20 | ||
| 21 | win = Window() | |
| 22 | self.top.add(win) | |
| 23 | ||
| 24 |         button = Button('click!')
 | |
| 25 | win.add(button) | |
| 26 | button.x = 10 | |
| 27 | button.y = 7 | |
| 28 | ||
| 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: 
29diff
changeset | 29 |         button.add_handler('click', self.on_button_click)
 | 
| 19 | 30 | self.button = button | 
| 31 | ||
| 32 | subwin = Window(8,8) | |
| 33 | win.add(subwin) | |
| 34 | ||
| 35 | ||
| 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: 
29diff
changeset | 36 | def on_button_click(self, ev): | 
| 19 | 37 | 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: 
29diff
changeset | 38 | return True | 
| 19 | 39 | |
| 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: 
29diff
changeset | 41 | 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: 
29diff
changeset | 42 | if ev.keyname == 'escape': | 
| 19 | 43 | 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: 
29diff
changeset | 44 | return True | 
| 19 | 45 | |
| 46 | ||
| 47 | if __name__ == '__main__': | |
| 48 | locale.setlocale(locale.LC_ALL, '') | |
| 49 | os.environ['ESCDELAY'] = '25' # do not wait 1 second after pressing Escape key | |
| 50 | app = MyApplication() | |
| 28 
feee783d4fc5
DriverPygame: output to character buffer, draw whole screen at once.
 Radek Brich <radek.brich@devl.cz> parents: 
19diff
changeset | 51 | #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: 
29diff
changeset | 52 | |
| 29 
c0cdef06fd16
Import only one driver from application.
 Radek Brich <radek.brich@devl.cz> parents: 
28diff
changeset | 53 |     cProfile.run('app.start()', 'demo_window.appstats')
 | 
| 
c0cdef06fd16
Import only one driver from application.
 Radek Brich <radek.brich@devl.cz> parents: 
28diff
changeset | 54 |     p = pstats.Stats('demo_window.appstats')
 | 
| 28 
feee783d4fc5
DriverPygame: output to character buffer, draw whole screen at once.
 Radek Brich <radek.brich@devl.cz> parents: 
19diff
changeset | 55 |     p.sort_stats('time', 'cumulative').print_stats(20)
 | 
| 19 | 56 |