import win32gui, win32con, time, os, sys,redis import pyautogui as ag import platform if platform.system() == 'Windows': sys.path.append('e:\\libs\\') else: sys.path.append('/data/deploy/make3d/make2/libs/') import config, libs,libs_db redisLocal = config.redis_local 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): pid = win32gui.GetWindowText(hwnd).split('wait')[0].split(' ')[0].split('-')[0].split('*')[0].split('_')[0] #判断是否已经存在了,已经存在就不在处理了 if redisLocal.lpos('model:auto_distance',pid+"_0") != None or redisLocal.lpos('model:auto_distance',pid+"_1") != None: #pid+"_0" in result or pid+"_1" in result: return '0', 0, 0, 0, 0 win32gui.SetForegroundWindow(hwnd) win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE) print(f'found {window_title} hwnd:{hwnd}') 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 get_defineDistances(pid, left, top, right, bottom): psid = libs.getPSid(pid) distances = libs_db.get_floor_sticker_distances(psid) #config.ps_floor_sticker.get(psid, config.ps_floor_sticker['default']) time.sleep(5) y = 748 yCreateDistance = 0 if len(distances.split(';')) == 1: yCreateDistance = 2 for index, d in enumerate(distances.split(';')): p1, p2, distance = d.split(' ') if index == 0: #移动到 control points ag.moveTo(14, 191) else: #不是第一次就移动到 create distance ag.moveTo(65, 300+yCreateDistance*15) # Create distance line height 15 time.sleep(0.5) ag.click() time.sleep(1.2) if index == 0: ag.moveTo(65, 285+yCreateDistance*15) time.sleep(1) ag.click() #点击左下的A点 time.sleep(0.5) ag.moveTo(233, y) # A point time.sleep(0.5) ag.click() time.sleep(0.5) repeat_backspace(20) time.sleep(1) ag.typewrite(p1) time.sleep(1) #点击左下的B点 ag.moveTo(233, y+15) # B point time.sleep(0.5) ag.click(); time.sleep(0.5) repeat_backspace(20) time.sleep(1) ag.typewrite(p2) time.sleep(1) #点击左下的Definded distance ag.moveTo(233,y+60) # Definded distance time.sleep(0.5) ag.click(); time.sleep(0.5) repeat_backspace(15) time.sleep(1.5) ag.typewrite(distance) time.sleep(1.5) ag.press('enter') print(f'执行距离划定{index}') 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) time.sleep(2) ag.hotkey('ctrl', 's') # save project print("点击保存按钮") time.sleep(6) ag.hotkey('alt', 'f4') # close project print("点击关闭按钮") print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 定义定位点距离完成') #更新 r.lpush('model:auto_distance', pid+"_0") #加入pid+"_1"的队列 redisLocal.lpush('model:auto_distance', pid+"_1") #去掉pid+"_0"的队列 redisLocal.lrem('model:auto_distance', 0, pid+"_0") time.sleep(5) def main(): while True: time.sleep(1) title = "wait" pid, left, top, right, bottom = find_and_maximize_window(title) if pid == '0': pass else: redisLocal.lpush('model:auto_distance', pid+"_0") 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()