author | Radek Brich <radek.brich@devl.cz> |
Wed, 26 Mar 2014 21:26:39 +0100 | |
changeset 92 | b97c4e25ed6d |
parent 77 | fc1989059e19 |
permissions | -rwxr-xr-x |
0 | 1 |
#!/usr/bin/env python3 |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
import locale |
|
5 |
locale.setlocale(locale.LC_ALL, '') |
|
6 |
||
63
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
7 |
from tuikit import Application, MenuBar, MenuButton, Menu, Window |
0 | 8 |
|
9 |
||
10 |
class MyApplication(Application): |
|
11 |
def __init__(self): |
|
12 |
Application.__init__(self) |
|
63
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
13 |
self.top.add_handler('keypress', self.on_top_keypress, last=True) |
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:
64
diff
changeset
|
14 |
self.top.add_handler('quit', lambda ev: self.terminate()) |
0 | 15 |
|
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
16 |
helpwin = Window() |
63
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
17 |
helpwin.title = 'About' |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
18 |
helpwin.hide() |
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
19 |
self.top.add(helpwin) |
63
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
20 |
helpwin.move(10, 5) |
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
21 |
#helpwin.closebutton = False |
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
22 |
#helpwin.resizable = False |
1
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
23 |
|
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
24 |
filemenu = Menu([ |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
25 |
('New', None), |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
26 |
None, |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
27 |
('Open', None), |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
28 |
('Save', None), |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
29 |
None, |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
30 |
('Quit', self.terminate), |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
31 |
]) |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
32 |
editmenu = Menu([('Copy', None), ('Paste', None)]) |
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
33 |
helpmenu = Menu([('About', helpwin)]) |
1
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
34 |
|
63
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
35 |
menubar_items = [ |
0 | 36 |
('File', filemenu), |
37 |
('Edit', editmenu), |
|
1
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
38 |
('Help', helpmenu), |
63
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
39 |
] |
0 | 40 |
|
63
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
41 |
menubar = MenuBar(menubar_items) |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
42 |
self.top.add(menubar, halign='fill') |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
43 |
|
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
44 |
menu = Menu([('Copy', None), ('Paste', None)]) |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
45 |
menubtn = MenuButton('MenuButton', menu) |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
46 |
self.top.add(menubtn, halign='center', valign='center') |
0 | 47 |
|
64
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
48 |
helpwin.bring_up() |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
49 |
|
41
37b7dfc3eae6
Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents:
40
diff
changeset
|
50 |
def on_top_keypress(self, ev): |
37b7dfc3eae6
Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents:
40
diff
changeset
|
51 |
if ev.keyname == 'escape': |
0 | 52 |
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:
42
diff
changeset
|
53 |
return True |
0 | 54 |
|
55 |
||
56 |
if __name__ == '__main__': |
|
57 |
app = MyApplication() |
|
58 |
app.start() |
|
59 |