author | Radek Brich <radek.brich@devl.cz> |
Mon, 17 Mar 2014 20:40:04 +0100 | |
changeset 86 | 0978fb755d31 |
parent 74 | 23767a33a781 |
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:
19
diff
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 |
|
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
10 |
from tuikit.scrollwindow import ScrollWindow |
19 | 11 |
from tuikit.button import Button |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
12 |
from tuikit.layout import AnchorLayout |
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
|
13 |
from tuikit.common import Borders |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
14 |
from tuikit.editbox import EditBox |
19 | 15 |
|
16 |
||
17 |
class MyApplication(Application): |
|
18 |
def __init__(self): |
|
19 |
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
|
20 |
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
|
21 |
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
|
22 |
self.top.add_handler('keypress', self.on_top_keypress) |
19 | 23 |
|
24 |
#edit = EditField(50, 'DlouhyTest12') |
|
25 |
#self.top.add(edit) |
|
26 |
||
27 |
win = Window() |
|
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
28 |
win.title = 'demo window' |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
29 |
win.resize(40, 25) |
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
|
30 |
self.top.add(win, halign='left', valign='top') |
19 | 31 |
|
32 |
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
|
33 |
# win.add(button, x=10, y=6) |
19 | 34 |
|
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
|
35 |
button.add_handler('click', self.on_button_click) |
19 | 36 |
self.button = button |
37 |
||
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
|
38 |
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
|
39 |
subwin.name = 'subwin' |
19 | 40 |
win.add(subwin) |
41 |
||
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
42 |
swin = ScrollWindow() |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
43 |
swin.title = 'scroll window' |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
44 |
swin.resize(40, 25) |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
45 |
self.top.add(swin) |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
46 |
|
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
47 |
swin.move(x=40) |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
48 |
|
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
49 |
text = open('tuikit/widget.py').read() |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
50 |
editbox = EditBox(text) |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
51 |
swin.add(editbox) |
19 | 52 |
|
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
|
53 |
def on_button_click(self, ev): |
19 | 54 |
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
|
55 |
return True |
19 | 56 |
|
57 |
||
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
|
58 |
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
|
59 |
if ev.keyname == 'escape': |
19 | 60 |
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
|
61 |
return True |
19 | 62 |
|
63 |
||
64 |
if __name__ == '__main__': |
|
65 |
locale.setlocale(locale.LC_ALL, '') |
|
66 |
os.environ['ESCDELAY'] = '25' # do not wait 1 second after pressing Escape key |
|
67 |
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
|
68 |
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
|
69 |
|
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
|
70 |
#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
|
71 |
#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
|
72 |
#p.sort_stats('time', 'cumulative').print_stats(20) |
19 | 73 |