forked from AthaSSiN/Zoom-Meeting-and-Recording
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locate.py
76 lines (59 loc) · 2.07 KB
/
locate.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
import os
import logging
from subprocess import PIPE, Popen
import pyautogui
import platform
if 'windows' in platform.platform().lower():
from screeninfo import get_monitors
resolutions = []
def cmdline(command):
process = Popen(
args=command,
stdout=PIPE,
shell=True
)
return process.communicate()[0].decode('utf-8')
def getResolutions():
plat = platform.platform().lower()
if 'linux' in plat:
return getResolutionsLinux()
elif 'windows' in plat:
return getResolutionsWindows()
else:
print('Error: Unsupported operating system: {}. Please submit an issue'.format(plat))
exit(1)
def getResolutionsWindows():
return ['{}x{}'.format(m.width, m.height) for m in get_monitors()]
def getResolutionsLinux():
results = cmdline('xrandr | grep -E "[[:digit:]]+x[[:digit:]]+\+" -o | sed "s/\+//g"')
results = results.strip().split('\n')
exists = []
for res in results:
if not os.path.isdir(res):
logging.error('Resolution {} is not supported. Please submit an issue'.format(res))
exists.append(False)
else:
exists.append(True)
if sum(exists) == 0:
logging.error('Error: No supported resolutions.')
exit()
return [res for (res, exist) in zip(results, exists) if exist]
def resolveName(name):
global resolutions
if len(resolutions) == 0:
resolutions = getResolutions()
if 'windows' in platform.platform().lower():
return ['{}windows/{}.png'.format(res, name) for res in resolutions]
else:
return ['{}/{}.png'.format(res, name) for res in resolutions]
#Search through all screens
def locate(name):
paths = resolveName(name)
for path in paths:
logging.info('Locating {}'.format(path))
result = pyautogui.locateCenterOnScreen(path, confidence=0.5)
if result:
logging.info('Found {}'.format(path))
return result
logging.info('Could not locate {}'.format(path))
return None