def find_child_windows(self): """ find child windows """ if self.window: self.child_windows = handleprops.children(self.window) else: raise(Exception('no window found'))
def find_targets(self): """ find target window""" self.windows = findwindows.find_windows(title_re = "Settings") if len(self.windows) == 0: log.debug('no window found') else: log.debug(self.windows) hwnd = self.windows[0] self.child_windows = handleprops.children(hwnd)
def checkStuff(): app = Application(backend="win32").connect( path=r"C:\DM54_W16\DM54_W16.exe") winChildren = "" dialogs = app.windows() for x in dialogs: if handleprops.classname(x) == "WinDevObject": winChildren = handleprops.children(x) topWindow = x break for x in winChildren: if handleprops.text(x) == E1.get(): rects[0] = handleprops.rectangle(x) if handleprops.text(x).replace(",", "") == E2.get(): rects[1] = handleprops.rectangle(x) if handleprops.text(x) == E3.get(): rects[2] = handleprops.rectangle(x) if handleprops.text(x) == E4.get(): rects[3] = handleprops.rectangle(x) writeRects(rects)
def test_children(self): """Make sure the children method returns correct result""" self.assertEquals(2, len(children(self.dlghandle))) self.assertEquals([], children(self.edit_handle))
def test_children(self): "Make sure the children method returns correct result" self.assertEquals(2, len(children(self.dlghandle))) self.assertEquals([], children(self.edit_handle))
def setupDM(container): rects = readRects() app = Application(backend="win32").connect( path=r"C:\DM54_W16\DM54_W16.exe") # top_windows = [] # EnumWindows(windowEnumerationHandler, top_windows) # for i in top_windows: # if 'Dispatch-Mate' in i[1]: # SetWindowPos(i[0], None, 0, 0, 1920, 1080, SWP_SHOWWINDOW) # SetForegroundWindow(i[0]) winChildren = "" dialogs = app.windows() click(50, 365) fore = win32gui.GetForegroundWindow() DMFore = "Dispatch-Mate" in win32gui.GetWindowText(fore) while not DMFore: top = Tk() L1 = Label( top, text="Please maximize DispatchMate and the PB in the left monitor") L1.grid(row=0, column=0) def callbackDM(): top.destroy() MyButton4 = Button(top, text="OK", width=10, command=callbackDM) MyButton4.grid(row=1, column=0) popUp(top, w=350, h=50, widget=MyButton4) click(50, 350) fore = win32gui.GetForegroundWindow() DMFore = "Dispatch-Mate" in win32gui.GetWindowText(fore) # # moveTo(2000, 550) # def windowEnumerationHandler(hwnd, top_windows): # top_windows.append((hwnd, win32gui.GetWindowText(hwnd))) # # # results = [] # top_windows = [] # win32gui.EnumWindows(windowEnumerationHandler, top_windows) # for i in top_windows: # if "Dispatch-Mate" in i[1].lower(): # # win32gui.ShowWindow(i[0],5) # win32gui.SetForegroundWindow(i[0]) # break for x in dialogs: if handleprops.classname(x) == "WinDevObject": winChildren = handleprops.children(x) topWindow = x break # description = "" # weight = "" # pieces = "" # terminal = "" # containerNumber = "" # bond = "" # PB = "" # sleep(5) # topWindowWrap = app.window(handle=topWindow) # topWindowWrap.MoveWindow(0,0,1920,1080) # topWindowWrap.Maximize() for x in winChildren: # print(handleprops.text(x)) # if handleprops.classname(x)=="ListBox": # # for y in handleprops.children(x): # # print(handleprops.text(x)) # topWindowWrap = app.window(handle=topWindow) # boxWrap = topWindowWrap.child_window(handle=x).wrapper_object() # if handleprops.text(x)=="Description": # print("desc " + str(handleprops.rectangle(x))) # if "CUT - 7/13" in handleprops.text(x): # print(handleprops.rectangle(x)) # if handleprops.classname(x)=="ComboBox": if handleprops.rectangle(x) == RECT(232, 917, 443, 939): topWindowWrap = app.window(handle=topWindow) boxWrap = topWindowWrap.child_window(handle=x).wrapper_object() # print(boxWrap.texts()) # print(boxWrap.selected_index()) # print(len(boxWrap.children())) # print(boxWrap.get_properties()['texts']) # for y in boxWrap.texts(): # if y !="": # print(boxWrap.ItemData(y)) num = boxWrap.ItemData(boxWrap.texts()[1]) if num < 6: container.size = "20" else: container.size = "40" # else: # container.size = "getInput" # if boxWrap.texts()[1]==r"\x0c": # container.size = '40' # elif boxWrap.texts()[1]==r"\n": # container.size = '40' # elif boxWrap.texts()[1]==r"\x04": # container.size = '20' # elif boxWrap.texts()[1]==r"\x03": # container.size = '20' # elif boxWrap.texts()[1]==r"\x0b": # container.size = '40' # # elif boxWrap.texts()[1]==r"\r": # # container.size = '45' # elif boxWrap.texts()[1]==r"\x07": # container.size = '40' # # elif handleprops.rectangle(x)==RECT(197, 342, 256, 360): # elif handleprops.rectangle(x)==RECT(2090, 146, 2219, 168): # weight = x # # elif handleprops.rectangle(x)==RECT(512, 342, 569, 360): # elif handleprops.rectangle(x)==RECT(2089, 233, 2191, 255): # pieces = x # elif handleprops.rectangle(x)==RECT(625, 342, 722, 360): # containerNumber = x # elif handleprops.rectangle(x)==RECT(14, 295, 73, 313): # terminal = x # elif handleprops.rectangle(x)==RECT(1645, 136, 1818, 171): # bond = x # elif handleprops.rectangle(x)==RECT(182, 991, 250, 1015): # PB = x elif handleprops.rectangle(x) == rects[0]: container.description = handleprops.text(x) # elif handleprops.rectangle(x)==RECT(197, 342, 256, 360): elif handleprops.rectangle(x) == rects[1]: container.weight = handleprops.text(x) # elif handleprops.rectangle(x)==RECT(512, 342, 569, 360): elif handleprops.rectangle(x) == rects[2]: container.pieces = handleprops.text(x) elif handleprops.rectangle(x) == rects[3]: container.containerNumber = handleprops.text(x) elif handleprops.rectangle(x) == RECT(282, 295, 341, 313): container.terminal = handleprops.text(x) # elif handleprops.rectangle(x)==RECT(1645, 136, 1818, 171): # container.bond = handleprops.text(x) elif handleprops.rectangle(x) == RECT(182, 991, 250, 1015): container.PB = handleprops.text(x) elif handleprops.rectangle(x) == RECT(554, 295, 613, 313): container.customer = handleprops.text(x) elif handleprops.rectangle(x) == RECT(14, 891, 231, 985): container.extraText = handleprops.text(x) elif handleprops.rectangle(x) == RECT(14, 128, 265, 146): container.shipper = handleprops.text(x) elif handleprops.rectangle(x) == RECT(14, 176, 265, 194): container.shipperAdd1 = handleprops.text(x) elif handleprops.rectangle(x) == RECT(14, 224, 265, 242): container.shipperCity = handleprops.text(x) elif handleprops.rectangle(x) == RECT(183, 248, 227, 266): if "CDA" in handleprops.text(x): container.shipperCountry = "CA" elif "USA" in handleprops.text(x): container.shipperCountry = "US" else: container.shipperCountry = handleprops.text(x) elif handleprops.rectangle(x) == RECT(14, 248, 54, 266): container.shipperStateProv = handleprops.text(x) elif handleprops.rectangle(x) == RECT(55, 248, 182, 266): container.shipperZipPost = handleprops.text(x) elif handleprops.rectangle(x) == RECT(282, 128, 533, 146): container.consignee = handleprops.text(x) elif handleprops.rectangle(x) == RECT(282, 176, 533, 194): container.consigneeAdd1 = handleprops.text(x) elif handleprops.rectangle(x) == RECT(282, 224, 533, 242): container.consigneeCity = handleprops.text(x) elif handleprops.rectangle(x) == RECT(452, 248, 496, 266): if "CDA" in handleprops.text(x): container.consigneeCountry = "CA" elif "USA" in handleprops.text(x): container.consigneeCountry = "US" else: container.consigneeCountry = handleprops.text(x) elif handleprops.rectangle(x) == RECT(282, 248, 323, 266): container.consigneeStateProv = handleprops.text(x) elif handleprops.rectangle(x) == RECT(324, 248, 451, 266): container.consigneeZipPost = handleprops.text(x) # Pb 362000 is used for widths # if handleprops.text(x)=="MAEU 463991 2": # print("desc") # print(handleprops.rectangle(x)) # elif handleprops.text(x)=="7,660.00": # print("we") # print(handleprops.rectangle(x)) # elif handleprops.text(x)=="6": # print("pi") # print(handleprops.rectangle(x)) # elif handleprops.text(x)=="MAEU 411606 4": # print(handleprops.rectangle(x)) # print(container.containerNumber) # exit() container.containerNumber = container.containerNumber.replace(' ', '') if (container.description == "" or container.weight == "" or container.pieces == "" or container.containerNumber == "" or container.terminal == "" or # container.bond == "" or container.PB == ""): top = Tk() L0 = Label( top, text= "Some of the information is missing. Either fill it in below, or ensure \n that your Dispatch-mate is properly formatted and hit \"Try again\". \n To do so, go to PB362000 and double click on the line between \n the boxes that read \"Description\" and \"Weight\"" ) L0.grid(row=0, column=0, columnspan=2) L1 = Label(top, text="Description:") L1.grid(row=1, column=0, sticky=constants.E) E1 = Entry(top, bd=5) E1.grid(row=1, column=1) E1.insert(0, container.description) L2 = Label(top, text="Weight:") L2.grid(row=2, column=0, sticky=constants.E) E2 = Entry(top, bd=5) E2.grid(row=2, column=1) E2.insert(0, container.weight) L3 = Label(top, text="Piece Count:") L3.grid(row=3, column=0, sticky=constants.E) E3 = Entry(top, bd=5) E3.grid(row=3, column=1) E3.insert(0, container.pieces) L4 = Label(top, text="Container Number:") L4.grid(row=4, column=0, sticky=constants.E) E4 = Entry(top, bd=5) E4.grid(row=4, column=1) E4.insert(0, container.containerNumber) L5 = Label(top, text="Consignee:") L5.grid(row=5, column=0, sticky=constants.E) E5 = Entry(top, bd=5) E5.grid(row=5, column=1) E5.insert(0, container.terminal) # L6 = Label(top, text="Bond #:") # L6.grid(row=6, column=0, sticky=constants.E) # E6 = Entry(top, bd = 5) # E6.grid(row=6, column=1) # E6.insert(0, container.bond) L7 = Label(top, text="PB #:") L7.grid(row=6, column=0, sticky=constants.E) E7 = Entry(top, bd=5) E7.grid(row=6, column=1) E7.insert(0, container.PB) def callbackGoAhead(container): container.description = E1.get() container.weight = E2.get() container.pieces = E3.get() container.containerNumber = E4.get() container.terminal = E5.get() # container.bond = E6.get() container.PB = E7.get() top.destroy() def checkStuff(): app = Application(backend="win32").connect( path=r"C:\DM54_W16\DM54_W16.exe") winChildren = "" dialogs = app.windows() for x in dialogs: if handleprops.classname(x) == "WinDevObject": winChildren = handleprops.children(x) topWindow = x break for x in winChildren: if handleprops.text(x) == E1.get(): rects[0] = handleprops.rectangle(x) if handleprops.text(x).replace(",", "") == E2.get(): rects[1] = handleprops.rectangle(x) if handleprops.text(x) == E3.get(): rects[2] = handleprops.rectangle(x) if handleprops.text(x) == E4.get(): rects[3] = handleprops.rectangle(x) writeRects(rects) # top.lift() # top.attributes('-topmost',True) # top.after_idle(top.attributes,'-topmost',False) # widget = E1 # moveTo(widget.winfo_rootx()+widget.winfo_width()/2, widget.winfo_rooty()+5+widget.winfo_height()/2) def callbackDetect(): top.after_idle(checkStuff) def callbackTryAgain(container): top.destroy() setupDM(container) MyButton4 = Button(top, text="Use these values", width=17, command=lambda: callbackGoAhead(container)) MyButton4.grid(row=8, column=1) MyButton5 = Button(top, text="Try again", width=10, command=lambda: callbackTryAgain(container)) MyButton5.grid(row=8, column=0) MyButton5 = Button( top, text= "Set box locations: \n (copy description, weight, piece and cont# \n into the boxes above then hit this button)", width=10, command=callbackDetect) MyButton5.grid(row=9, column=0, columnspan=2, sticky=constants.W + constants.E) popUp(top, w=380, h=340, widget=E1)
if addCustomerWindow > 0: app.close(addCustomerWindowTitle) DebugLogger('前期准备完成', log_path) # 获取通讯录的位置 time.sleep(.5) pic = ImageGrab.grab((weChatWindow[0], weChatWindow[1], weChatWindow[0] + 300, weChatWindow[1] + 300)) pic.save('./image/weixinTongxunluBtn.png') tongxunluPosition = app.get_screenxy_from_bmp( u'./image/weixinTongxunluBtn.png', u'./image/tongxunluIcon.png') if tongxunluPosition is False: DebugLogger('未点击通讯录元素未找到', log_path) tongxunluPosition = app.get_screenxy_from_bmp( u'./image/weixinTongxunluBtn.png', u'./image/tongxunluSelectedIcon.png') handleprops.children(wechatWindowDialog) if tongxunluPosition is not False: DebugLogger('通讯录元素找到!', log_path) # 点击通讯录 app.app.window(title=wechatWindowTitle, class_name=wechatWindowClassName).click_input( coords=(tongxunluPosition[0] + 20, tongxunluPosition[1] + 10)) # 获取<新的联系人>的位置 pic = ImageGrab.grab((weChatWindow[0], weChatWindow[1], weChatWindow[0] + 400, weChatWindow[1] + 500)) pic.save('./image/newCustomerBtn.png') newCustomerPosition = app.get_screenxy_from_bmp( u'./image/newCustomerBtn.png', u'./image/newCustomerIcon.png') if newCustomerPosition is False:
def setupDM(folderPath, drivers): # app = Application(backend="win32").connect(path = r"C:\DM54_W16\DM54_W16.exe") # # # top_windows = [] # # EnumWindows(windowEnumerationHandler, top_windows) # # for i in top_windows: # # if 'Dispatch-Mate' in i[1]: # # SetWindowPos(i[0], None, 0, 0, 1920, 1080, SWP_SHOWWINDOW) # # SetForegroundWindow(i[0]) # # # winChildren = "" # # dialogs = app.windows() # # for x in dialogs: # if handleprops.classname(x) == "WinDevObject": # winChildren = handleprops.children(x) # topWindow = x # break clickTuple = False click(50, 350) fore = win32gui.GetForegroundWindow() DMFore = "Dispatch-Mate" in win32gui.GetWindowText(fore) while not DMFore: top = Tk() L1 = Label(top, text="Please maximize DispatchMate and the PB in the left monitor") L1.grid(row=0, column=0) def callbackDM(): top.destroy() MyButton4 = Button(top, text="OK", width=10, command=callbackDM) MyButton4.grid(row=1, column=0) popUp(top, w=350, h=50, widget = MyButton4) click(50, 350) fore = win32gui.GetForegroundWindow() DMFore = "Dispatch-Mate" in win32gui.GetWindowText(fore) # i=0 for driver in drivers: # if i>0: click(327, 33) sleep(3) click(399, 281) if driver.PARS[-1]=="A" or driver.PARS[-1]=="B" or driver.PARS[-1]=="C": typewrite(driver.PARS[-7:-1]) else: typewrite(driver.PARS[-6:]) press("enter") sleep(3) click(1857, 100) sleep(0.5) click(569, 900) month = str(pickupDate.month) if len(month)<2: month = "0" + month typewrite(month) day = str(pickupDate.day) if len(day)<2: day = "0" + day typewrite(day) typewrite(str(pickupDate.year)) click(569, 926) month = str(pickupDate.month) if len(month)<2: month = "0" + month typewrite(month) day = str(pickupDate.day) if len(day)<2: day = "0" + day typewrite(day) typewrite(str(pickupDate.year)) click(695, 100) click(1542, 730) typewrite(str(driver.driver)) press('enter') if str(driver.driver)[:3]!="801": click(1558,679) typewrite(driver.name) press('enter') sleep(0.5) thru = False click(189, 854) hotkey('ctrl', 'a') hotkey('ctrl', 'c') clipTk=Tk() if "THRUWAY" in clipTk.clipboard_get(): thru = True typewrite("TRUCK") press('tab') typewrite("0.55") press('tab') press('delete') press('tab') miles = "490" if str(driver.city)=="PACKER": miles = "507" if str(driver.city)=="NYCT": miles = "500" typewrite(miles) click(189, 890) hotkey('ctrl', 'a') hotkey('ctrl', 'c') if "THRUWAY" in clipTk.clipboard_get(): thru = True click(189, 872) hotkey('ctrl', 'a') hotkey('ctrl', 'c') if "THRUWAY" in clipTk.clipboard_get(): thru = True if thru: typewrite("COMPANY DR THRUWAY") press('tab') typewrite("1.00") press('tab') press('delete') press('tab') if str(driver.city)=="PACKER": typewrite("81.4") else: typewrite("31.9") else: press('delete') press('tab') press('delete') press('tab') press('delete') press('tab') press('delete') click(189, 890) hotkey('ctrl', 'a') hotkey('ctrl', 'c') if "THRUWAY" in clipTk.clipboard_get(): thru = True clipTk.destroy() if thru: press('delete') press('tab') press('delete') press('tab') press('delete') press('tab') press('delete') if GetKeyState(145) < 0: exit() sleep(2) click(1857, 120) click(1857, 120) sleep(3) click(1845, 200, button="right") sleep(1) click(1826, 312) sleep(0.3) # click(1600, 316) # # sleep(7) click(1600, 361) sleep(0.3) click(1772, 160) # sleep(5) # sleep(5) done=False while not done: try: if os.path.isfile(r"C:\Program Files\Microsoft Office 15\root\office15\outlook.exe"): app = Application(backend="win32").connect(path = r"C:\Program Files\Microsoft Office 15\root\office15\outlook.exe") elif os.path.isfile(r"C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE"): app = Application(backend="win32").connect(path = r"C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE") elif os.path.isfile(r"C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"): app = Application(backend="win32").connect(path = r"C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE") # elif os.path.isfile(r"C:\Program Files\WindowsApps\Microsoft.Office.Desktop.Outlook_16040.10827.20138.0_x86__8wekyb3d8bbwe\Office16\outlook.exe"): # app = Application(backend="win32").connect(path = r"C:\Program Files\WindowsApps\Microsoft.Office.Desktop.Outlook_16040.10827.20138.0_x86__8wekyb3d8bbwe\Office16\outlook.exe") else: directoryPath = "C:\Program Files\WindowsApps\\" if os.path.isdir("C:\Program Files\WindowsApps\\"): contents = os.listdir("C:\Program Files\WindowsApps\\") outLookFolders=[] for folder in contents: if os.path.isdir("C:\Program Files\WindowsApps\\"+folder): if "outlook" in folder.lower(): outLookFolders.append(folder) outlookPath = "" for folder in outLookFolders: contents = os.listdir("C:\Program Files\WindowsApps\\"+folder) for officeFolder in contents: if os.path.isdir(directoryPath+folder+"\\"+officeFolder): if "office" in officeFolder.lower(): contentsInner = os.listdir(directoryPath+folder+"\\"+officeFolder) for outlookProgram in contentsInner: if outlookProgram.lower()=="outlook.exe": outlookPath=directoryPath+folder+"\\"+officeFolder+"\\"+outlookProgram if os.path.isfile(outlookPath): app = Application(backend="win32").connect(path = outlookPath) else: popUpOK("Could not find Outlook in \"C:\Program Files\Microsoft Office 15\root\office15\outlook.exe\" \n or \"C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE\" \n or \"C:\Program Files (x86)\Microsoft Office\Office14\" \n or the \"C:\Program Files\WindowsApps\\\" folder") exit() done=True except: pass # top_windows = [] # EnumWindows(windowEnumerationHandler, top_windows) # for i in top_windows: # if 'Dispatch-Mate' in i[1]: # SetWindowPos(i[0], None, 0, 0, 1920, 1080, SWP_SHOWWINDOW) # SetForegroundWindow(i[0]) winChildren = "" done = False while not done: dialogs = app.windows() topWindow = None for x in dialogs: if isinstance(handleprops.text(x), str) and not handleprops.text(x)==None: try: if "Carrier Confirmation" in handleprops.text(x): winChildren = handleprops.children(x) topWindow = x break except: pass send = "" if topWindow==None: continue topWindowWrap = app.window(handle=topWindow) for x in winChildren: # print(handleprops.text(x) + " " + handleprops.classname(x)) if handleprops.text(x)=="&Send": send = x done = True # if handleprops.text(x)=="Fro&m": # buttonWrap = topWindowWrap.child_window(handle=x).wrapper_object() # buttonWrap.click() # # # if not clickTuple: # moveTo(114, 221) # # while not GetKeyState(145)<0: # True # # clickTuple = position() # # # else: # click(clickTuple) if done==True: buttonWrap = topWindowWrap.child_window(handle=send).wrapper_object() buttonWrap.click() # winChildren = handleprops.children(topWindow) # # for x in winChildren: # # print(handleprops.text(x) + " " + handleprops.classname(x)) # if handleprops.classname(x)=="NetUIHWND": # topWindowWrap = app.window(handle=topWindow) # netWrap = topWindowWrap.child_window(handle=x).wrapper_object() # print(netWrap.Texts()) # # for y in handleprops.children(x): # print(handleprops.text(y)) # # app.top_window().window(title="From", control_type="Button").print_control_identifiers() # if not clickTuple: # # moveTo(113, 167) # # while not GetKeyState(13)<0: # True # # clickTuple = position() # # else: # sleep(5) # click((113, 167)) # # click(clickTuple) sleep(4)