You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
3.0 KiB
81 lines
3.0 KiB
import win32gui, win32con, time, os, sys |
|
import pyautogui as ag |
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
|
import config, libs |
|
|
|
def find_and_maximize_window(window_title): |
|
windows = [] |
|
win32gui.EnumWindows(lambda hwnd, windows: windows.append(hwnd), windows) |
|
|
|
for hwnd in windows: |
|
if win32gui.IsWindowVisible(hwnd): |
|
if window_title in win32gui.GetWindowText(hwnd): |
|
print(f'found {window_title} hwnd:{hwnd}') |
|
# win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE) |
|
win32gui.SetForegroundWindow(hwnd) |
|
pid = win32gui.GetWindowText(hwnd).split('wait')[0].split(' ')[0].split('-')[0].split('*')[0] |
|
left, top, right, bottom = win32gui.GetWindowRect(hwnd) |
|
return pid, left, top, right, bottom |
|
return '0', 0, 0, 0, 0 |
|
|
|
def get_defineDistances(pid, left, top, right, bottom): |
|
psid = libs.getPSid(pid) |
|
distances = config.ps_floor_sticker.get(psid, config.ps_floor_sticker['default']) |
|
for index, d in enumerate(distances.split(';')): |
|
p1, p2, distance = d.split(' ') |
|
if index == 0: |
|
ag.moveTo(left + 80, top + 290) |
|
else: |
|
ag.moveTo(left + 80, top + 290 + 15) # Create distance line height 15 |
|
ag.click() |
|
|
|
ag.moveTo(left + 302, (bottom - 100)) # A point |
|
ag.click();repeat_backspace(20) |
|
ag.typewrite(p1) |
|
|
|
ag.moveTo(left + 302, (bottom - 80)) # B point |
|
ag.click();repeat_backspace(20) |
|
ag.typewrite(p2) |
|
|
|
ag.moveTo(left + 302, (bottom - 35)) # Definded distance |
|
ag.click();repeat_backspace(8) |
|
ag.typewrite(distance) |
|
ag.press('enter') |
|
|
|
|
|
def repeat_backspace(times): |
|
for i in range(times): |
|
ag.press('backspace') |
|
for i in range(times): |
|
ag.press('delete') |
|
|
|
def defind_distance(pid, left, top, right, bottom): |
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 开始定义定位点距离...') |
|
print(f'left: {left}, top: {top}, right: {right}, bottom: {bottom}') |
|
# ag.PAUSE = 1 |
|
|
|
ag.moveTo(left + 20, top + 200) # open Control points |
|
ag.click() |
|
|
|
get_defineDistances(pid, left, top, right, bottom) |
|
|
|
ag.hotkey('ctrl', 's') # save project |
|
ag.hotkey('alt', 'f4') # close project |
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 定义定位点距离完成') |
|
time.sleep(3) |
|
|
|
def main(): |
|
while True: |
|
time.sleep(1) |
|
title = "wait" |
|
pid, left, top, right, bottom = find_and_maximize_window(title) |
|
if pid == '0': |
|
pass |
|
else: |
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 找到{pid}的定位点距离定义窗口,开始定位点距离定义...') |
|
start_time = time.time() |
|
defind_distance(pid, left, top, right, bottom) |
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 定位点距离定义完成,共费时{libs.diff_time(start_time)}') |
|
|
|
if __name__ == "__main__": |
|
main() |