-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.py
executable file
·142 lines (116 loc) · 4.09 KB
/
utilities.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import subprocess as sp
import time
from pynput.keyboard import Key
import re
#Mourir
def translate(input):
if input=="a":
return "x"
elif input=="b":
return "c"
elif input=="up":
return Key.up
elif input=="down":
return Key.down
elif input=="left":
return Key.left
elif input=="right":
return Key.right
elif input=="enter":
return Key.enter
elif input=="f1":
return Key.f1
elif input=="f2":
return Key.f2
elif input=="f3":
return Key.f3
print("Input not recognized")
return
# C'est le cadeau pour la régie. L'écran de la régie doit être parfaitement à droite, en 4k.
# Ces calculs sont faits pour un moniteur principal en quadK.
#
def resizeAndPlace(pidA, pidD):
string = "xdotool windowsize $(wmctrl -lp | awk -vpid=%s '$3==pid {print $1; exit}') 1620 1080" % (pidA) #3:2 aspect ratio
sp.Popen(string, shell=True)
string = "xdotool windowsize $(wmctrl -lp | awk -vpid=%s '$3==pid {print $1; exit}') 1620 1080" % (pidD)
sp.Popen(string, shell=True)
string = "xdotool windowmove $(wmctrl -lp | awk -vpid=%s '$3==pid {print $1; exit}') 2560 0" % (pidA)
sp.Popen(string, shell=True)
string = "xdotool windowmove $(wmctrl -lp | awk -vpid=%s '$3==pid {print $1; exit}') 4480 0" % (pidD) #(2560 + 3840/2 = 4480)
sp.Popen(string, shell=True)
def switchToWindow(pid):
print("switching to ",pid)
#Trivial, le code s'explique par lui même
string = "wmctrl -ia $(wmctrl -lp | awk -vpid=%s '$3==pid {print $1}')" % (pid)
sp.Popen(string, shell=True)
#Felt clever, might delete later
def launchMenu(pid, kbd):
switchToWindow(pid)
time.sleep(0.1)
kbd.press(Key.enter)
time.sleep(0.1)
kbd.release(Key.enter)
print("Pressed enter")
#Envoie un input sur les deux fenêtres à la fois, les délais sont assez vitaux malheureusement
def sync_input(pid1, pid2, kbd, input):
switchToWindow(pid1)
time.sleep(0.05)
kbd.press(input)
time.sleep(0.2)
kbd.release(input)
switchToWindow(pid2)
time.sleep(0.1)
kbd.press(input)
time.sleep(0.2)
kbd.release(input)
#Emule un input sur une seule fenêtre.
def press_key(pid, kbd, input):
switchToWindow(pid)
time.sleep(0.05)
kbd.press(input)
time.sleep(0.2)
kbd.release(input)
#Rigolo mais useless au final
def startRoutine(pid1, pid2, kbd):
sync_input(pid1, pid2, kbd, Key.enter)
time.sleep(0.3)
sync_input(pid1, pid2, kbd, Key.enter)
time.sleep(0.3)
sync_input(pid1, pid2, kbd, Key.enter)
time.sleep(0.3)
sync_input(pid1, pid2, kbd, "x")
time.sleep(6)
for i in range(100):
sync_input(pid1, pid2, kbd, "x")
time.sleep(0.7)
# Réglé pour le setup précédemment décris. Marche très mal
def launch_place_firefox():
string = "firefox --new-window numerikplays.ch/stats & echo $!"
terminal2 = sp.Popen(string, shell=True, stdout=sp.PIPE)
time.sleep(2)
string = 'xdotool search --name "Mozilla Firefox"'
terminal2 = sp.Popen(string, shell=True, stdout=sp.PIPE)
lines = [line.rstrip() for line in terminal2.stdout.readlines()]
widFirefox = re.sub("[^0-9]","", str(lines[-1]))
print(widFirefox)
string = 'xdotool windowsize %s 3840 1080'% (widFirefox)
sp.Popen(string, shell=True)
string = 'xdotool windowmove %s 2560 1095'% (widFirefox)
sp.Popen(string, shell=True)
return widFirefox
# incase il y a un petit soucis lors du lancement de firefox, on peut réessayer ici
def reset_place_firefox(widFirefox):
print("WID", widFirefox)
string = 'xdotool windowsize %s 3840 1080'% (widFirefox)
sp.Popen(string, shell=True)
string = 'xdotool windowmove %s 2560 1095'% (widFirefox)
sp.Popen(string, shell=True)
# Utilisé pour construire une queue fifo afin d'afficher les derniers inputs
def vladi_mir_cache(cache, elem, cache_size):
if len(cache)<cache_size:
cache.append(elem)
else:
for i in range (1,cache_size-1):
cache[i-1]=cache[i]
cache[cache_size-1]=elem
return cache