-
Notifications
You must be signed in to change notification settings - Fork 0
/
pad.py
executable file
·88 lines (77 loc) · 2.06 KB
/
pad.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
#!/usr/bin/python3
import tkinter,tkinter.ttk,subprocess
class Group:
def __init__(self,keys):
self.keys=keys
root=tkinter.Tk()
frame=tkinter.ttk.Frame(root,padding="3 3 12 12")
rows=[[Group('qwer')],
[Group('asdf')],
[Group('zxcv')],
[Group('7'),Group('8'),Group('9')],
[Group('4'),Group('5'),Group('6')],
[Group('1'),Group('2'),Group('3')]]
origin=[78,186]
active=set()
window=False
def run(command):
return subprocess.run(command,shell=True,capture_output=True,encoding='utf8')
def find(key):
i=0
for groups in rows:
for g in groups:
for k in g.keys:
if k==key:
return origin[1]+32*i
i+=1
raise Exception('No key?')
def group(key):
for groups in rows:
for g in groups:
if key in g.keys:
return g
raise Exception('No group?')
def focus():
global window
if not window:
window=run('xdotool search --name "LMMS pad"').stdout.strip()
run(f'xdotool windowfocus {window}')
def activate(key):
for k in group(key).keys:
if k==key and k not in active:
active.add(k)
elif k in active:
active.remove(k)
else:
continue
x=origin[0]
y=find(k)
run(f'xdotool mousemove {x} {y} click 1')
focus()
def mute():
for a in list(active):
activate(a)
def reset():
global active
active=set()
def setup():
root.title("LMMS pad")
root.columnconfigure(0,weight=1)
root.rowconfigure(0,weight=1)
frame.grid(column=0,row=0)
for i,groups in enumerate(rows):
column=0
for group in groups:
for k in group.keys:
do=lambda k=k:activate(k)
tkinter.ttk.Button(frame,text=k,command=do).grid(column=column,row=i)
root.bind(k,lambda x,k=k:activate(k))
if k.isnumeric():
root.bind(f'<KP_{k}>',lambda x,k=k:activate(k))
column+=1
tkinter.ttk.Button(frame,text='Mute',command=mute).grid(column=0,row=6)
tkinter.ttk.Button(frame,text='Reset',command=reset).grid(column=1,row=6)
root.bind('m',lambda x:mute())
root.bind('<Escape>',lambda x:root.destroy())
root.mainloop()
setup()