author | Radek Brich <radek.brich@devl.cz> |
Wed, 03 Sep 2014 08:53:44 +0200 | |
changeset 106 | abcadb7e2ef1 |
parent 77 | fc1989059e19 |
permissions | -rwxr-xr-x |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python3 |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
import locale |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
import os |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
from tuikit.application import Application |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
from tuikit.window import Window |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
9 |
from tuikit.label import Label |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
10 |
from tuikit.button import Button |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
from tuikit.layout import AnchorLayout |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
12 |
from tuikit.common import Borders |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
13 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
15 |
class MyApplication(Application): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
16 |
def __init__(self): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
17 |
Application.__init__(self) |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
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:
diff
changeset
|
19 |
self.top.name = 'top' |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
20 |
self.top.add_handler('keypress', self.on_top_keypress) |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
22 |
win = Window() |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
23 |
win.name = 'window' |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
24 |
win.title = 'AnchorLayout demo' |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
25 |
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:
diff
changeset
|
26 |
self.top.add(win, halign='left', valign='top') |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
27 |
self.win = win |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
28 |
|
76
fa5301e58eca
Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
29 |
button_valign = Button('valign: ' + self.win.hint_value('valign')) |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
30 |
button_valign.name = 'button_valign' |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
31 |
button_valign.add_handler('click', self.on_button_align_click) |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
32 |
win.add(button_valign, halign='center', margin=Borders(t=2)) |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
33 |
|
76
fa5301e58eca
Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
34 |
button_halign = Button('halign: ' + self.win.hint_value('halign')) |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
35 |
button_halign.name = 'button_halign' |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
36 |
button_halign.add_handler('click', self.on_button_align_click) |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
37 |
win.add(button_halign, halign='center', margin=Borders(t=4)) |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
38 |
|
76
fa5301e58eca
Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
39 |
label_margin = Label(str(self.win.hint_value('margin'))) |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
40 |
label_margin.name = 'label_margin' |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
41 |
label_margin.add_handler('draw', self.on_label_margin_draw) |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
42 |
win.add(label_margin, halign='center', margin=Borders(t=6)) |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
43 |
|
71
cfd3445107b4
Report mousemove relative position change. Window: when in AnchorLayout, aligned right/bottom - fix resizing by mouse to behave as expected.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
44 |
label_size = Label(str(self.win.sizereq)) |
cfd3445107b4
Report mousemove relative position change. Window: when in AnchorLayout, aligned right/bottom - fix resizing by mouse to behave as expected.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
45 |
label_size.name = 'label_size' |
cfd3445107b4
Report mousemove relative position change. Window: when in AnchorLayout, aligned right/bottom - fix resizing by mouse to behave as expected.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
46 |
label_size.add_handler('draw', self.on_label_size_draw) |
cfd3445107b4
Report mousemove relative position change. Window: when in AnchorLayout, aligned right/bottom - fix resizing by mouse to behave as expected.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
47 |
win.add(label_size, halign='center', margin=Borders(t=8)) |
cfd3445107b4
Report mousemove relative position change. Window: when in AnchorLayout, aligned right/bottom - fix resizing by mouse to behave as expected.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
48 |
|
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
49 |
def on_button_align_click(self, ev): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
50 |
align_type = ev.originator.label.split(':', 1)[0] |
76
fa5301e58eca
Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
51 |
align = self.win.get_hint(align_type) |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
52 |
align.select_next() |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
53 |
ev.originator.label = '%s: %s' % (align_type, align.selected) |
77
fc1989059e19
Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents:
76
diff
changeset
|
54 |
self.top.need_resize() |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
55 |
return True |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
56 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
57 |
def on_label_margin_draw(self, ev): |
76
fa5301e58eca
Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
58 |
ev.originator.label = str(self.win.hint_value('margin')) |
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
59 |
|
71
cfd3445107b4
Report mousemove relative position change. Window: when in AnchorLayout, aligned right/bottom - fix resizing by mouse to behave as expected.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
60 |
def on_label_size_draw(self, ev): |
cfd3445107b4
Report mousemove relative position change. Window: when in AnchorLayout, aligned right/bottom - fix resizing by mouse to behave as expected.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
61 |
ev.originator.label = str(self.win.sizereq) |
cfd3445107b4
Report mousemove relative position change. Window: when in AnchorLayout, aligned right/bottom - fix resizing by mouse to behave as expected.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
62 |
|
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
63 |
def on_top_keypress(self, ev): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
64 |
if ev.keyname == 'escape': |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
65 |
self.terminate() |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
66 |
return True |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
67 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
68 |
|
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
69 |
if __name__ == '__main__': |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
70 |
locale.setlocale(locale.LC_ALL, '') |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
71 |
os.environ['ESCDELAY'] = '25' # do not wait 1 second after pressing Escape key |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
72 |
app = MyApplication() |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
73 |
app.start() |