Mercurial > libervia-desktop-kivy
comparison src/libs/garden/garden.contextmenu/examples/simple_context_menu.py @ 83:741a7d6d8c28
garden: added contextmenu
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 24 Dec 2016 14:16:58 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
82:4c6d56c069d9 | 83:741a7d6d8c28 |
---|---|
1 import kivy | |
2 from kivy.app import App | |
3 from kivy.lang import Builder | |
4 | |
5 kivy.require('1.9.0') | |
6 | |
7 import kivy.garden.contextmenu | |
8 | |
9 | |
10 kv = """ | |
11 FloatLayout: | |
12 id: layout | |
13 Label: | |
14 pos: 10, self.parent.height - self.height - 10 | |
15 text: "Left click anywhere outside the context menu to close it" | |
16 size_hint: None, None | |
17 size: self.texture_size | |
18 | |
19 Button: | |
20 size_hint: None, None | |
21 pos_hint: {"center_x": 0.5, "center_y": 0.8 } | |
22 size: 300, 40 | |
23 text: "Click me to show the context menu" | |
24 on_release: context_menu.show(*app.root_window.mouse_pos) | |
25 | |
26 ContextMenu: | |
27 id: context_menu | |
28 visible: False | |
29 cancel_handler_widget: layout | |
30 | |
31 ContextMenuTextItem: | |
32 text: "SubMenu #2" | |
33 ContextMenuTextItem: | |
34 text: "SubMenu #3" | |
35 ContextMenu: | |
36 ContextMenuTextItem: | |
37 text: "SubMenu #5" | |
38 ContextMenuTextItem: | |
39 text: "SubMenu #6" | |
40 ContextMenu: | |
41 ContextMenuTextItem: | |
42 text: "SubMenu #9" | |
43 ContextMenuTextItem: | |
44 text: "SubMenu #10" | |
45 ContextMenuTextItem: | |
46 text: "SubMenu #11" | |
47 ContextMenuTextItem: | |
48 text: "Hello, World!" | |
49 on_release: app.say_hello(self.text) | |
50 ContextMenuTextItem: | |
51 text: "SubMenu #12" | |
52 ContextMenuTextItem: | |
53 text: "SubMenu #7" | |
54 ContextMenuTextItem: | |
55 text: "SubMenu #4" | |
56 """ | |
57 | |
58 class MyApp(App): | |
59 | |
60 def build(self): | |
61 self.title = 'Simple context menu example' | |
62 return Builder.load_string(kv) | |
63 | |
64 def say_hello(self, text): | |
65 print(text) | |
66 self.root.ids['context_menu'].hide() | |
67 | |
68 | |
69 if __name__ == '__main__': | |
70 MyApp().run() |