def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application from pywinauto.application import Application app = Application() app.start_(os.path.join(controlspy_folder, "Tab.exe")) self.texts = [ "Pluto", "Neptune", "Uranus", "Saturn", "Jupiter", "Mars", "Earth", "Venus", "Mercury", "Sun" ] self.rects = [ RECT(2, 2, 63, 21), RECT(63, 2, 141, 21), RECT(141, 2, 212, 21), RECT(212, 2, 280, 21), RECT(280, 2, 348, 21), RECT(2, 21, 68, 40), RECT(68, 21, 135, 40), RECT(135, 21, 207, 40), RECT(207, 21, 287, 40), RECT(287, 21, 348, 40), ] self.app = app self.dlg = app.MicrosoftControlSpy self.ctrl = app.MicrosoftControlSpy.TabControl.WrapperObject()
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" self.screen_w = win32api.GetSystemMetrics(0) # start the application from pywinauto.application import Application app = Application() app.start_(os.path.join(mfc_samples_folder, "CmnCtrl1.exe")) self.texts = [ u"CTreeCtrl", u"CAnimateCtrl", u"CToolBarCtrl", u"CDateTimeCtrl", u"CMonthCalCtrl"] self.rects = [ RECT(2, 2, 58, 20), RECT(58, 2, 130, 20), RECT(130, 2, 201, 20), RECT(201, 2, 281, 20), RECT(281, 2, 360, 20) ] self.app = app self.dlg = app.CommonControlsSample self.ctrl = app.CommonControlsSample.TabControl.WrapperObject()
def MenuItemAsControl(menuItem): "Make a menu item look like a control for tests" itemAsCtrl = ControlProps() itemAsCtrl["Texts"] = [ menuItem['Text'], ] itemAsCtrl["ControlID"] = menuItem['ID'] itemAsCtrl["Type"] = menuItem['Type'] itemAsCtrl["State"] = menuItem['State'] itemAsCtrl["Class"] = "MenuItem" itemAsCtrl["FriendlyClassName"] = "MenuItem" # as most of these don't matter - just set them up with default stuff itemAsCtrl["Rectangle"] = RECT(0, 0, 999, 999) itemAsCtrl["Fonts"] = [ LOGFONTW(), ] itemAsCtrl["ClientRects"] = [ RECT(0, 0, 999, 999), ] itemAsCtrl["ContextHelpID"] = 0 itemAsCtrl["UserData"] = 0 itemAsCtrl["Style"] = 0 itemAsCtrl["ExStyle"] = 0 itemAsCtrl["IsVisible"] = 1 return itemAsCtrl
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application from pywinauto.application import Application app = Application() app.start_(controlspy_folder + "Tab.exe") self.texts = [ "Pluto", "Neptune", "Uranus", "Saturn", "Jupiter", "Mars", "Earth", "Venus", "Mercury", "Sun" ] self.rects = [ RECT(2, 2, 80, 21), RECT(80, 2, 174, 21), RECT(174, 2, 261, 21), RECT(2, 21, 91, 40), RECT(91, 21, 180, 40), RECT(180, 21, 261, 40), RECT(2, 40, 64, 59), RECT(64, 40, 131, 59), RECT(131, 40, 206, 59), RECT(206, 40, 261, 59), ] self.app = app self.dlg = app.MicrosoftControlSpy self.ctrl = app.MicrosoftControlSpy.TabControl.WrapperObject()
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" self.app1 = Application.start("notepad.exe") self.app2 = Application.start("notepad.exe") self.app1.UntitledNotepad.MoveWindow(RECT(0, 0, 200, 200)) self.app2.UntitledNotepad.MoveWindow(RECT(0, 200, 200, 400))
def test_RECT_hash(self): """Test RECT is hashable""" r0 = RECT(0) r1 = RECT(1) d = {"r0": r0, "r1": r1} self.assertEqual(r0, d["r0"]) self.assertEqual(r1, d["r1"]) self.assertNotEqual(r0, r1)
def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.fast() EmptyClipboard() self.app1 = Application().start("notepad.exe") self.app2 = Application().start("notepad.exe") self.app1.UntitledNotepad.MoveWindow(RECT(0, 0, 200, 200)) self.app2.UntitledNotepad.MoveWindow(RECT(0, 200, 200, 400))
def MissalignmentTest(windows): "Run the test on the windows passed in" refAlignments = {} #find the controls alligned along each axis for win in windows: if not win.ref: continue for side in ("top", "left", "right", "bottom"): sideValue = getattr(win.ref.Rectangle(), side) # make sure that the side dictionary has been created sideAlignments = refAlignments.setdefault(side, {}) # make sure that the array of controls for this # alignment line has been created and add the current window sideAlignments.setdefault(sideValue, []).append(win) bugs = [] for side in refAlignments: for alignment in refAlignments[side]: controls = refAlignments[side][alignment] sides = [getattr(ctrl.Rectangle(), side) for ctrl in controls] sides = set(sides) if len(sides) > 1: overAllRect = RECT() overAllRect.left = min( [ctrl.Rectangle().left for ctrl in controls]) overAllRect.top = min( [ctrl.Rectangle().top for ctrl in controls]) overAllRect.right = max( [ctrl.Rectangle().right for ctrl in controls]) overAllRect.bottom = max( [ctrl.Rectangle().bottom for ctrl in controls]) bugs.append(( controls, { "AlignmentType": side.upper(), "AlignmentRect": overAllRect }, testname, 0) ) return bugs
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application from pywinauto.application import Application app = Application() app.start_(os.path.join(mfc_samples_folder, "RowList.exe"), timeout=20) self.texts = [ u'Color', u'Red', u'Green', u'Blue', u'Hue', u'Sat', u'Lum', u'Type' ] self.item_rects = [ RECT(0, 0, 150, 19), RECT(150, 0, 200, 19), RECT(200, 0, 250, 19), RECT(250, 0, 300, 19), RECT(300, 0, 400, 19), RECT(400, 0, 450, 19), RECT(450, 0, 500, 19), RECT(500, 0, 650, 19) ] self.app = app self.dlg = app.RowListSampleApplication #top_window_() self.ctrl = app.RowListSampleApplication.Header.WrapperObject()
def get_rect(self): """ Get rectangle of app or desktop resolution Returns: RECT(left, top, right, bottom) """ if self.handle: left, top, right, bottom = win32gui.GetWindowRect(self.handle) return RECT(left, top, right, bottom) else: desktop = win32gui.GetDesktopWindow() left, top, right, bottom = win32gui.GetWindowRect(desktop) return RECT(left, top, right, bottom)
def CaptureToImage(self): # img = navwin.CaptureAsImage(rect=RECT(200, 36, 250, 53)) left = 225 top = 944 width = 1227 height = 122 item_count = 13 item_width = float(width) / item_count result = list() for num in range(item_count): rect = RECT( self.rectMaster.left + self.setting.frame[3] + self.left_margin + int((left + (item_width * num)) * self.per), self.rectMaster.top + self.setting.frame[0] + self.top_margin + int(top * self.per), self.rectMaster.left + self.setting.frame[3] + self.left_margin + int( (left + (item_width * num)) * self.per) + int(item_width * self.per), self.rectMaster.top + self.setting.frame[0] + self.top_margin + int(top * self.per) + int(height * self.per)) img = self.navwin.CaptureAsImage(rect=rect) # img.save(str(num) + ".png") result.append(img) return result
def readRects(): rects = [] try: f = open("C:\Automation\TandE Rect Locations.txt", "r") for _ in range(4): rect = f.readline().split() rects.append( RECT(int(rect[0]), int(rect[1]), int(rect[2]), int(rect[3]))) f.close() except: rects = ([ RECT(15, 358, 178, 371), RECT(2090, 146, 2219, 168), RECT(2089, 233, 2191, 255), RECT(755, 356, 842, 374) ]) return rects
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application from pywinauto.application import Application app = Application() app.start_(os.path.join(controlspy_folder, "Header.exe")) self.texts = [u'Distance', u'Diameter', u'Mass'] self.item_rects = [ RECT(0, 0, 90, 21), RECT(90, 0, 180, 21), RECT(180, 0, 260, 21)] self.app = app self.dlg = app.MicrosoftControlSpy self.ctrl = app.MicrosoftControlSpy.Header.WrapperObject()
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application from pywinauto.application import Application app = Application() app.start_(os.path.join(controlspy_folder, "Status bar.exe")) self.texts = ["Long text", "", "Status Bar"] self.part_rects = [ RECT(0, 2, 65, 22), RECT(67, 2, 90, 22), RECT(92, 2, 261, 22)] self.app = app self.dlg = app.MicrosoftControlSpy self.ctrl = app.MicrosoftControlSpy.StatusBar.WrapperObject()
def _GetMinimumRect(text, font, usableRect, drawFlags): """Return the minimum rectangle that the text will fit into Uses font, usableRect and drawFlags information to find how how to do it accurately """ # try to create the font # create a Display DC (compatible to the screen) txtDC = win32functions.CreateDC(u"DISPLAY", None, None, None) hFontGUI = win32functions.CreateFontIndirect(ctypes.byref(font)) # # Maybe we could not get the font or we got the system font # if not hFontGUI: # # # So just get the default system font # hFontGUI = win32functions.GetStockObject(win32defines.DEFAULT_GUI_FONT) # # # if we still don't have a font! # # ----- ie, we're on an antiquated OS, like NT 3.51 # if not hFontGUI: # # # ----- On Asian platforms, ANSI font won't show. # if win32functions.GetSystemMetrics(win32defines.SM_DBCSENABLED): # # ----- was...(SYSTEM_FONT) # hFontGUI = win32functions.GetStockObject( # win32defines.SYSTEM_FONT) # else: # # ----- was...(SYSTEM_FONT) # hFontGUI = win32functions.GetStockObject( # win32defines.ANSI_VAR_FONT) # put our font into the Device Context win32functions.SelectObject(txtDC, hFontGUI) modifiedRect = RECT(usableRect) # Now write the text to our DC with our font to get the # rectangle that the text needs to fit in win32functions.DrawText( txtDC, # The DC unicode(text), # The Title of the control -1, # -1 because sTitle is NULL terminated ctypes.byref(modifiedRect), # The Rectangle to be calculated to #truncCtrlData.drawTextFormat | win32defines.DT_CALCRECT | drawFlags) #elif modifiedRect.right == usableRect.right and \ # modifiedRect.bottom == usableRect.bottom: # print "Oh so you thought you were perfect!!!" # Delete the font we created win32functions.DeleteObject(hFontGUI) # delete the Display context that we created win32functions.DeleteDC(txtDC) return modifiedRect
def get_rect(self): """ Get rectangle Returns: win32structures.RECT """ if self.app and self._top_window: return self._top_window.rectangle() else: return RECT(right=GetSystemMetrics(0), bottom=GetSystemMetrics(1))
def __init__(self, path, obj_tree_path, msr_tree_path): self.path = path self.obj_tree_path = obj_tree_path self.msr_tree_path = msr_tree_path self.screen_rect = RECT(0, 0, win32api.GetSystemMetrics(0), win32api.GetSystemMetrics(1)) self.delay_win_active = .5 self.app = None self.ids = None self.params_index = None self.do_common_MainWindow = True self.do_common_MainWindow_MainMenu = True
def testRowCount(self): self.assertEquals(1, self.ctrl.RowCount()) dlgClientRect = self.ctrl.Parent().Rectangle( ) # use the parent as a reference prev_rect = self.ctrl.Rectangle() - dlgClientRect # squeeze the tab control to force two rows new_rect = RECT(prev_rect) new_rect.right = int(new_rect.width() / 2) self.ctrl.MoveWindow( new_rect.left, new_rect.top, new_rect.width(), new_rect.height(), ) time.sleep(0.1) # verify two tab rows self.assertEquals(2, self.ctrl.RowCount()) # restore back the original size of the control self.ctrl.MoveWindow(prev_rect) self.assertEquals(1, self.ctrl.RowCount())
def fromDict(d: dict) -> 'Token': """ Creates a token from a dictionary. :param d: The dictionary that represents the Component. :type d: dict :return: The Token object that was constructed from the dictionary :rtype: Token """ if d is None: return None t = Token.__new__(Token) if d['pic']: d["pic"] = Image.fromarray(np.uint8(np.asarray(d["picture"]))) if d['rectangle']: r = RECT() r.left = d['rectangle'][0] r.top = d['rectangle'][1] r.right = d['rectangle'][0] + d['rectangle'][2] r.bottom = d['rectangle'][1] + d['rectangle'][3] d['rectangle'] = r t.__dict__ = d return t
def testRowCount(self): self.assertEquals(1, self.ctrl.RowCount()) dlgClientRect = self.ctrl.Parent().Rectangle() # use the parent as a reference prev_rect = self.ctrl.Rectangle() - dlgClientRect # squeeze the tab control to force two rows new_rect = RECT(prev_rect) new_rect.right = int(new_rect.width() / 2) self.ctrl.MoveWindow( new_rect.left, new_rect.top, new_rect.width(), new_rect.height(), ) time.sleep(0.1) # verify two tab rows self.assertEquals(2, self.ctrl.RowCount()) # restore back the original size of the control self.ctrl.MoveWindow(prev_rect) self.assertEquals(1, self.ctrl.RowCount())
def test_RECT_eq(self): r0 = RECT(1, 2, 3, 4) self.assertEqual(r0, RECT(1, 2, 3, 4)) self.assertEqual(r0, [1, 2, 3, 4]) self.assertNotEqual(r0, RECT(1, 2, 3, 5)) self.assertNotEqual(r0, [1, 2, 3, 5]) self.assertNotEqual(r0, [1, 2, 3]) self.assertNotEqual(r0, [1, 2, 3, 4, 5]) r0.bottom = 5 self.assertEqual(r0, RECT(1, 2, 3, 5)) self.assertEqual(r0, (1, 2, 3, 5))
def testItemRectangles(self): "Test getting item rectangles" yellow_rect = self.ctrl.GetItemRect('Yellow') gold_rect = RECT(13, 0, 61, 53) self.assertEquals(yellow_rect.left, gold_rect.left) self.assertEquals(yellow_rect.top, gold_rect.top) self.assertEquals(yellow_rect.right, gold_rect.right) if yellow_rect.bottom < 53 or yellow_rect.bottom > 55: self.assertEquals(yellow_rect.bottom, gold_rect.bottom) self.ctrl.GetItem('Green').Click(where='text') self.assertEquals(self.ctrl.GetItem('Green').IsSelected(), True) self.ctrl.GetItem('Magenta').Click(where='icon') self.assertEquals(self.ctrl.GetItem('Magenta').IsSelected(), True) self.assertEquals(self.ctrl.GetItem('Green').IsSelected(), False) self.ctrl.GetItem('Green').Click(where='all') self.assertEquals(self.ctrl.GetItem('Green').IsSelected(), True) self.assertEquals(self.ctrl.GetItem('Magenta').IsSelected(), False)
def take_screenshot(self, coords=None): self.window.set_focus() rect = self.window_rect if coords is None else RECT(*coords) img = self.window.capture_as_image(rect) return img
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)
def test_RECT_repr(self): """Test RECT repr""" r0 = RECT(0) self.assertEqual(r0.__repr__(), "<RECT L0, T0, R0, B0>")
def test_RECT_hash(self): """Test RECT is not hashable""" self.assertRaises(TypeError, hash, RECT())
def MissalignmentTest(windows): "Run the test on the windows passed in" refAlignments = {} #find the controls alligned along each axis for win in windows: if not win.ref: continue for side in ("top", "left", "right", "bottom"): sideValue = getattr(win.ref.Rectangle(), side) # make sure that the side dictionary has been created sideAlignments = refAlignments.setdefault(side, {}) # make sure that the array of controls for this # alignment line has been created and add the current window sideAlignments.setdefault(sideValue, []).append(win) bugs = [] for side in refAlignments: for alignment in refAlignments[side]: # get the controls that were alligned controls = refAlignments[side][alignment] # get the sides of the current controls sides = [getattr(ctrl.Rectangle(), side) for ctrl in controls] # if one or more of the controls have a differnt value for this # side if len(set(sides)) > 1: if side in ("top bottom"): # find how far away from each other the controls are... lefts = [c.ref.Rectangle().left for c in controls] rights = [c.ref.Rectangle().right for c in controls] nearest = [] for i, c1 in enumerate(controls): for c2 in controls[i + 1:]: dist = min( abs(c1.Rectangle().right - c2.Rectangle().left), abs(c1.Rectangle().left - c2.Rectangle().right)) if dist < 40 and getattr(c1.Rectangle(), side) != getattr( c2.Rectangle(), side): buggy_controls.append((c1, c2)) else: if side in ("left right"): # find how far away from each other the controls are... lefts = [c.ref.Rectangle().left for c in controls] rights = [c.ref.Rectangle().right for c in controls] for left in left: for right in rights: if min(abs(right - left), abs(left - right)) > 40: continue sides = set(sides) if len(sides) > 1: overAllRect = RECT() overAllRect.left = min( [ctrl.Rectangle().left for ctrl in controls]) overAllRect.top = min( [ctrl.Rectangle().top for ctrl in controls]) overAllRect.right = max( [ctrl.Rectangle().right for ctrl in controls]) overAllRect.bottom = max( [ctrl.Rectangle().bottom for ctrl in controls]) bugs.append((controls, { "AlignmentType": side.upper(), "AlignmentRect": overAllRect }, testname, 0)) return bugs
def MissalignmentTest(windows): "Run the test on the windows passed in" refAlignments = {} #find the controls alligned along each axis for win in windows: if not win.ref: continue for side in ("top", "left", "right", "bottom"): sideValue = getattr(win.ref.Rectangle(), side) # make sure that the side dictionary has been created sideAlignments = refAlignments.setdefault(side, {}) # make sure that the array of controls for this # alignment line has been created and add the current window sideAlignments.setdefault(sideValue, []).append(win) bugs = [] for side in refAlignments: for alignment in refAlignments[side]: # get the controls that were alligned controls = refAlignments[side][alignment] # get the sides of the current controls sides = [getattr(ctrl.Rectangle(), side) for ctrl in controls] # if one or more of the controls have a differnt value for this # side if len(set(sides)) > 1: if side in ("top bottom"): # find how far away from each other the controls are... lefts = [c.ref.Rectangle().left for c in controls] rights = [c.ref.Rectangle().right for c in controls] nearest = [] for i, c1 in enumerate(controls): for c2 in controls[i+1:]: dist = min ( abs(c1.Rectangle().right - c2.Rectangle().left), abs(c1.Rectangle().left - c2.Rectangle().right)) if dist < 40 and getattr(c1.Rectangle(), side) != getattr(c2.Rectangle(), side): buggy_controls.append((c1, c2)) else: if side in ("left right"): # find how far away from each other the controls are... lefts = [c.ref.Rectangle().left for c in controls] rights = [c.ref.Rectangle().right for c in controls] for left in left: for right in rights: if min (abs(right - left), abs(left - right)) > 40: continue sides = set(sides) if len(sides) > 1: overAllRect = RECT() overAllRect.left = min( [ctrl.Rectangle().left for ctrl in controls]) overAllRect.top = min( [ctrl.Rectangle().top for ctrl in controls]) overAllRect.right = max( [ctrl.Rectangle().right for ctrl in controls]) overAllRect.bottom = max( [ctrl.Rectangle().bottom for ctrl in controls]) bugs.append(( controls, { "AlignmentType": side.upper(), "AlignmentRect": overAllRect }, testname, 0) ) return bugs
def testGetButtonRect(self): self.assertEquals(self.ctrl.GetButtonRect(0), RECT(6, 0, 29, 22))