author | Radek Brich <radek.brich@devl.cz> |
Sat, 02 Feb 2013 12:54:27 +0100 | |
changeset 76 | fa5301e58eca |
parent 64 | 03f591f5fe5c |
child 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) |
0 | 14 |
|
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
15 |
helpwin = Window() |
63
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
16 |
helpwin.title = 'About' |
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
17 |
helpwin.hide() |
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
18 |
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
|
19 |
helpwin.move(10, 5) |
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
20 |
#helpwin.closebutton = False |
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
21 |
#helpwin.resizable = False |
1
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
22 |
|
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
23 |
filemenu = Menu([ |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
24 |
('New', None), |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
25 |
None, |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
26 |
('Open', None), |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
27 |
('Save', None), |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
28 |
None, |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
29 |
('Quit', self.terminate), |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
30 |
]) |
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
31 |
editmenu = Menu([('Copy', None), ('Paste', None)]) |
2
684cdc352562
Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
1
diff
changeset
|
32 |
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
|
33 |
|
63
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
34 |
menubar_items = [ |
0 | 35 |
('File', filemenu), |
36 |
('Edit', editmenu), |
|
1
69318aba22bf
Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
37 |
('Help', helpmenu), |
63
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
38 |
] |
0 | 39 |
|
63
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
40 |
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
|
41 |
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
|
42 |
|
2a0e04091898
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
self.top.add(menubtn, halign='center', valign='center') |
0 | 46 |
|
64
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
47 |
helpwin.bring_up() |
03f591f5fe5c
Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
63
diff
changeset
|
48 |
|
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
|
49 |
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
|
50 |
if ev.keyname == 'escape': |
0 | 51 |
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
|
52 |
return True |
0 | 53 |
|
54 |
||
55 |
if __name__ == '__main__': |
|
56 |
app = MyApplication() |
|
57 |
app.start() |
|
58 |