-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_menu.py
100 lines (84 loc) · 2.37 KB
/
example_menu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import sys
IS_MAC = sys.platform == 'darwin'
IS_WIN = sys.platform == 'win32'
if IS_MAC:
from rumps import *
elif IS_WIN:
from ruwps import *
else:
print('Linux not supported!') # We really also need rulps! ;-)
sys.exit(1)
try:
from urllib import urlretrieve
except ImportError:
from urllib.request import urlretrieve
def sayhello(sender):
print('hello {}'.format(sender))
def e(_):
print('EEEEEEE')
def adjust_f(sender):
if adjust_f.huh:
sender.add('$')
sender.add('%')
sender['zzz'] = 'zzz'
sender['separator'] = separator
sender['ppp'] = MenuItem('ppp')
else:
del sender['$']
del sender['%']
del sender['separator']
del sender['ppp']
adjust_f.huh = not adjust_f.huh
adjust_f.huh = True
def print_f(_):
print(f)
f = MenuItem('F', callback=adjust_f)
if IS_MAC:
icon_file = 'kiss.png'
urlretrieve('http://upload.wikimedia.org/wikipedia/commons/thumb/c/'
'c4/Kiss_Logo.svg/200px-Kiss_Logo.svg.png', icon_file)
else:
icon_file = 'favicon.ico'
urlretrieve('https://en.wikipedia.org/static/favicon/wikipedia.ico',
icon_file)
app = App('lovegun', icon=icon_file)
app.menu = [
MenuItem('A', callback=print_f, key='F'),
('B', ['1', 2, '3', [4, [5, (6, range(7, 14))]]]),
'C',
[MenuItem('D', callback=sayhello), (1, 11, 111)],
MenuItem('E', callback=e, key='e'),
f,
None,
{
'x': {'hello', 'hey'},
'y': ['what is up']
},
[1, [2]],
('update method', ['walking', 'back', 'to', 'you']),
'stuff',
None
]
@clicked('update method')
def dict_update(menu):
print(menu)
print(menu.setdefault('boo', MenuItem('boo',
callback=lambda _: add_separator(menu)))) # lambda gets THIS menu not submenu
def add_separator(menu):
menu.add(separator)
@clicked('C')
def change_main_menu(_):
print(app.menu)
print('goodbye C')
del app.menu['C'] # DELETE SELF!!!1
@clicked('stuff')
def stuff(sender):
print(sender)
if len(sender):
sender.insert_after('lets', 'go?')
sender['the'].insert_before('band', 'not')
sender['the'].insert_before('band', 'a')
else:
sender.update(['hey', ['ho', MenuItem('HOOOO')], 'lets', 'teenage'], the=['who', 'is', 'band'])
sender.add('waste land')
app.run()