建模程序 多个定时程序
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.
 
 

141 lines
4.8 KiB

import win32gui, win32con, time, os, sys
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
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].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 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)
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()