forked from IamFlea/bartender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui_overlay_geometry.py
36 lines (32 loc) · 1.43 KB
/
ui_overlay_geometry.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
from PyQt5 import Qt
from win32gui import GetWindowRect, EnumWindows, GetWindowText
from config import *
import time
class OverlayGeometry(object):
WINDOW_FRAME_MARGIN = [8, 30, 16, 38] # LEFT, TOP, RIGHT, BOT
def get_aoe_window_geometry():
# Getting aoe window location and resolution
global geometry
geometry = None
def function(hwnd, extra):
global geometry
if AOE_WINDOW_TITLE != GetWindowText(hwnd):
return
rect = GetWindowRect(hwnd)
geometry = Qt.QRect(rect[0], rect[1], rect[2] - rect[0], rect[3] - rect[1])
EnumWindows(function, None) # Previous values are filled with this
if geometry is None:
time.sleep(1) # Waiting 1 second
EnumWindows(function, None) # Previous values are filled with this
return geometry
def __new__(cls):
geometry = OverlayGeometry.get_aoe_window_geometry()
if geometry.x() > 0 or geometry.y() > 0:
return Qt.QRect(geometry.x() + OverlayGeometry.WINDOW_FRAME_MARGIN[0],
geometry.y() + OverlayGeometry.WINDOW_FRAME_MARGIN[1],
geometry.width() - OverlayGeometry.WINDOW_FRAME_MARGIN[2],
geometry.height() - OverlayGeometry.WINDOW_FRAME_MARGIN[3])
else:
return geometry
if __name__ == '__main__':
import bartender