def get_values(self): """ values from windows """ #windows = findwindows.find_windows(parent = self.window)#, class_name = 'Edit') win_ctrl = {} for hwnd in self.child_windows: parent = handleprops.parent(hwnd) parent_text = handleprops.text(parent) ### picked tab if parent_text in ['Serial Bridge', 'Proxy']: if parent_text not in win_ctrl: win_ctrl[parent_text] = {} classname = handleprops.classname(hwnd) if classname in ['Edit']: text = handleprops.text(hwnd) rect = handleprops.rectangle(hwnd) #log.debug("%s,%s,%s - %s" % (parent, classname, text, parent_text)) #log.debug("(%s,%s)" % (rect.top, rect.left)) #val = (rect.top, rect.left) win_ctrl[parent_text][(rect.top, rect.left)] = text if len(win_ctrl) == 0: raise (NoDataException('no data found')) for key in win_ctrl: log.info(key) data = win_ctrl[key] log.info(data) ### sort by (top, left) #(y,x) vals = sorted(data.items(), key=lambda item: item[0]) #log.debug(vals) for i, item in enumerate(vals, 1): line = "%s:%s" % (i, item[1]) #log.debug(line) self.g.msg_queue.put(line)
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 get_window_info(): all_window_handles = findwindows.enum_windows() for window_handle in all_window_handles: if handleprops.isvisible(window_handle): pos_x = handleprops.rectangle(window_handle).left pos_y = handleprops.rectangle(window_handle).top size_x = handleprops.rectangle(window_handle).width() size_y = handleprops.rectangle(window_handle).height() title_name = handleprops.text(window_handle) class_name = handleprops.classname(window_handle) pid = handleprops.processid(window_handle) date_time = datetime.datetime.now() # Note: Minimized windows have negative pos_x and pos_y values (and smaller sizes). window_info = [ pos_x, pos_y, size_x, size_y, title_name, class_name, pid, date_time ] window_db_id = database.create_window_record(window_info) logger.info( 'OpenWindow record created in database (db_id %i).' % window_db_id)
def test_classname(self): """Make sure the classname method returns correct result""" self.assertEquals("Notepad", classname(self.dlghandle)) self.assertEquals("Edit", classname(self.edit_handle))
def get_values(self): """ values from windows """ #windows = findwindows.find_windows(parent = self.window)#, class_name = 'Edit') win_ctrl = {} values = [] for hwnd in self.child_windows: parent = handleprops.parent(hwnd) parent_text = handleprops.text(parent) ### picked tab if parent_text in [ 'Serial Bridge', 'Proxy']: if parent_text not in win_ctrl: win_ctrl[parent_text] = {} classname = handleprops.classname(hwnd) if classname in ['Edit']: text = handleprops.text(hwnd) rect = handleprops.rectangle(hwnd) #log.debug("%s,%s,%s - %s" % (parent, classname, text, parent_text)) #log.debug("(%s,%s)" % (rect.top, rect.left)) #val = (rect.top, rect.left) win_ctrl[parent_text][(rect.top, rect.left)] = text if len(win_ctrl) == 0: raise(NoDataException('no data found')) for key in win_ctrl: log.info(key) data = win_ctrl[key] log.info(data) ### sort by (top, left) #(y,x) vals = sorted(data.items(),key=lambda item: item[0]) #log.debug(vals) fields = {} for i, item in enumerate(vals, 1): #line = "%s:%s" % (i, item[1]) #log.debug(line) fields[i] = item[1] log.debug(self.conf[self.channel]) """ sensu-monitoring-platform event: - action - occurrences [redis] - client -- name -- address -- timestamp - check -- name -- issued -- subscirbers [] -- handler -- history [] -- interval -- output -- command -- status """ ### msg values.append(fields) #log.debug('=='*20) return values
def test_classname(self): "Make sure the classname method returns correct result" self.assertEquals("Notepad", classname(self.dlghandle)) self.assertEquals("Edit", classname(self.edit_handle))
def test_classname(self): """Make sure the classname method returns correct result""" self.assertEqual("Notepad", classname(self.dlghandle)) self.assertEqual("Edit", classname(self.edit_handle)) self.assertEqual("", classname(sys.maxsize)) self.assertEqual(None, classname(None))
moveTo, moveRel, click, hotkey from pywinauto import \ handleprops, win32functions, keyboard __author__ = '墨焓 <*****@*****.**>' __program__ = 'dota2 lib' __version__ = 'demo' _logger = logging.getLogger(__program__) button_of_accept = 'button_of_accept.png' box_of_game_ready = 'box_of_game_ready.png' fg_window = win32functions.GetForegroundWindow fgw_title = lambda: handleprops.text(fg_window()) fgw_class = lambda: handleprops.classname(fg_window()) def dota2_accept_game_and_switch_back(): hotkey('enter') hotkey('alt', 'tab') class Dota2Controller: TIME_SLOT = 0.1 POLL_INTERVAL_MAX = 10 WINDOW_INFO = {'title': 'Dota 2', 'class': 'SDL_app', 'program': 'dota2.exe'} # WINDOW_INFO = {'class': 'HoneyviewClassX'} poll_interval = TIME_SLOT last_fg = float()
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)