def capture_translations(app="app",lang="unknown"): wins1=l.getwindowlist() time.sleep(2) # sometimes the window is not ready yet wins=l.getwindowlist() img_name = l.imagecapture() re_pattern = r"(.*)auto([0-9]+)auto(.*)" for w in wins: obj = l.getobjectlist(w) w_clean = re.sub(re_pattern,"\\1\\3",w) for o in obj: info = l.getobjectinfo(w,o) o_clean = re.sub(re_pattern,"\\1\\3",o) if 'label' in info: label = l.getobjectproperty(w,o,'label') size = None # check if we find the "automate language" m = re.search(re_pattern, label) if m: id_num = m.group(2) size = l.getobjectsize(w,o) if size[0] > 0: translation[id_num] = (w_clean, o_clean) w_o_mapping[(w_clean, o_clean)] = id_num print("Translation #{} is here: ('{}','{}')".format(id_num, w_clean, o_clean)) print("Located in picture: {}".format(size)) else: size = None # or check if we already know the translation from the "automate language"-run elif (w, o) in w_o_mapping.keys(): id_num = w_o_mapping[(w, o)] size = l.getobjectsize(w,o) if size[0] > 0: print("Found translation #{}".format(id_num)) else: size = None # in both cases we want a screenshot if size: img = cv2.imread(img_name) new_img = cv2.rectangle(img, (size[0], size[1]), (size[0] + size[2], size[1] + size[3]), (0,0,255), 3) cv2.imwrite('/tmp/translation_{}_{}_{}_{}.png'.format(app, lang, id_num, o), new_img)
def capture_translations(app="app",lang="unknown"): wins1=l.getwindowlist() time.sleep(2) # sometimes the window is not ready yet wins=l.getwindowlist() img_name = l.imagecapture() re_pattern = r"(.*)auto([0-9]+)auto(.*)" for w in wins: obj = l.getobjectlist(w) w_clean = re.sub(re_pattern,"\\1\\3",w) for o in obj: info = l.getobjectinfo(w,o) o_clean = re.sub(re_pattern,"\\1\\3",o) if 'label' in info: label = l.getobjectproperty(w,o,'label') size = None # check if we find the "automate language" m = re.search(re_pattern, label) if m: id_num = m.group(2) size = l.getobjectsize(w,o) if size[0] > 0: translation[id_num] = (w_clean, o_clean) w_o_mapping[(w_clean, o_clean)] = id_num print("Translation #{} is here: ('{}','{}')".format(id_num, w_clean, o_clean)) print("Located in picture: {}".format(size)) else: size = None # or check if we already know the translation from the "automate language"-run elif (w, o) in w_o_mapping.keys(): id_num = w_o_mapping[(w, o)] size = l.getobjectsize(w,o) if size[0] > 0: print("Found translation #{}".format(id_num)) else: size = None # in both cases we want a screenshot if size: img = cv2.imread(img_name) new_img = cv2.rectangle(img, (size[0], size[1]), (size[0] + size[2], size[1] + size[3]), (0,0,255), 3) cv2.imwrite('{}/translation_{}_{}_{}_{}.png'.format(OUTPUT_DIR, app, lang, id_num, o), new_img)
def step_impl(context, thing, win): (win, thing) = _resolveNames(context, win, thing) (x, y, w, h) = l.getobjectsize(win, thing) click_x = x + (w / 2) click_y = y + (h / 2) print(f"Clicking {click_x}/{click_y} in {x}/{y}+{w}/{h}") if click_x < 0 or click_y < 0: print(f"I'd rather not click {click_x}/{click_y}") print(f"failed to click {thing} in {l.getobjectlist(win)}") return # assert click_x > 0, f"I'd rather not click {click_x}/{click_y}" # assert click_y > 0, f"I'd rather not click {click_x}/{click_y}" context._root["_click_animated"](context, click_x, click_y)
def get_object_size(self, window_name, object_name=None): """ Get the object size, of the given window. If object does not exist, then LdtpExecutionError will be thrown. :param window_name: :param object_name: :return: [x,y,width,height] as a list and as int type will be returned on success, LdtpExecutionError exception on failure """ try: self._info('get object size of (%s, %s)' % (window_name, object_name)) return ldtp.getobjectsize(window_name, object_name) except LdtpExecutionError: raise LdtpExecutionError('get object size failed.')
def step_impl(context, popupwin, entry, win): click_those = l.getobjectlist(win) for thing in click_those: (x, y, w, h) = l.getobjectsize(win, thing) # expecting the object to consist of square shaped icons # so let's click in the middle of those click_x = x + (h / 2) click_y = y + (h / 2) while click_x < (x + w): context._root["_click_animated"](context, click_x, click_y, button="b3c", delay=0) if l.waittillguiexist(popupwin, entry, 1): return l.generatekeyevent("<esc>") #close possible menus time.sleep(0.5) click_x += h #not found assert (False)
def step_impl(context, thing): time.sleep(1) win = None for w in l.getwindowlist(): objs = l.getobjectlist(w) if thing in objs: win = w break if not win: print(f"Failed to find {thing}") return print("Parent:") print(l.getobjectproperty(win, thing, 'parent')) (x, y, w, h) = l.getobjectsize(win, thing) click_x = x + (w / 2) click_y = y + (h / 2) print(f"Clicking {click_x}/{click_y} in {x}/{y}+{w}/{h}") if click_x < 0 or click_y < 0: print(f"I'd rather not click {click_x}/{click_y}") print(f"failed to click {thing} in {l.getobjectlist(win)}") return # assert click_x > 0, f"I'd rather not click {click_x}/{click_y}" # assert click_y > 0, f"I'd rather not click {click_x}/{click_y}" context._root["_click_animated"](context, click_x, click_y)
import ImageChops from commandes_bases import * connecter() ajouterFiche() ldtp.click('*Gestion de dossiers*', 'btnAjouter') ldtp.waittillguiexist('*une nouvelle fiche*') ldtp.mouseleftclick('*une nouvelle fiche*', 'txt0') ldtp.enterstring('*une nouvelle fiche*', 'txt0', "bonjour comment ca va") ldtp.mouseleftclick('*une nouvelle fiche*', 'cboDown') ldtp.mouseleftclick('*une nouvelle fiche*', 'lstInstallationavecbackup') ldtp.mouseleftclick('*une nouvelle fiche*', 'sldr0') ldtp.enterstring('*une nouvelle fiche*', 'sldr0', "<del>2") ldtp.click('*une nouvelle fiche*', 'btnSaveEnter') coordinate = ldtp.getobjectsize('*Gestion de dossiers*', 'pane0') if (len(sys.argv) > 1) and (sys.argv[1] == 'origin'): ldtp.imagecapture('*Gestion de dossiers*', 'images/creer_fiche_test_priorite2_origin.png', coordinate[0], coordinate[1], coordinate[2], coordinate[3]) else: ldtp.imagecapture('*Gestion de dossiers*', 'images/creer_fiche_test_priorite2.png', coordinate[0], coordinate[1], coordinate[2], coordinate[3]) im1 = Image.open("images/creer_fiche_test_priorite2.png") im2 = Image.open("images/creer_fiche_test_priorite2_origin.png") diff = ImageChops.difference(im2, im1) if diff.getbbox(): print("Erreur possible dans 'Creation Fiche test: priorite2'") fermer()
def step_impl(context, win): lang = context._root.get('my_lang', None) w_o_mapping = context._root.get('w_o_mapping', {}) feature = context._stack[1]["feature"].filename line = context._root["my_line"] po_map = context._root.get('po_map', {}) locator_map = context._root.get('locator_map', {}) (win, _) = _resolveNames(context, win) # _resolveNames() already saved the indexes - we can quit now if lang is None: return img_name = l.imagecapture() re_pattern = r"(.*)auto([0-9]+)auto(.*)" time.sleep(1) obj = l.getobjectlist(win) w_clean = re.sub(re_pattern, "\\1\\3", win) # avoiding multiple appearances with the same filename multi_appear = {} for o in obj: print(f"Get info for {o}") info = l.getobjectinfo(win, o) o_clean = re.sub(re_pattern, "\\1\\3", o) # "or o_clean" means that the pattern can be applied if 'label' in info or o_clean: if 'label' in info: print("Get real label") label = l.getobjectproperty(win, o, 'label') else: print("Use object as label") label = o print(f" label: {label}") size = None if label is None: print("label is none") continue try: size = l.getobjectsize(win, o) if size[0] < 0: size = None except Exception as e: print(e) size = None # check if we find the "automate language" m = re.search(re_pattern, label) if m: print(f"Found automate here: {label}") id_num = m.group(2) if size: # store "translation ID" (i.e. po-line number) for later w_o_mapping[(w_clean, o_clean, line)] = id_num print("Translation #{} is here: ('{}','{}')".format( id_num, w_clean, o_clean)) print("Located in picture: {}".format(size)) # or check if we already know the translation from the "automate language"-run elif (win, o, line) in w_o_mapping.keys(): print(f"Found mapping: {label}") id_num = w_o_mapping[(win, o, line)] if size: print("Found translation #{}".format(id_num)) # SMELL: move to feature function and execute only once if not os.path.exists(OUTPUT_DIR): os.makedirs(OUTPUT_DIR) img = cv2.imread(img_name) x = size[0] y = size[1] w = size[2] h = size[3] new_img = cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 3) timestamp = int(time.time()) filename = f"{feature}_{lang}_po{id_num}_featureline_{line}_{timestamp}" # for multiple ocurrances of one translation in the same window and same step multi_appear[filename] = multi_appear.get(filename, 0) + 1 filename = f"{filename}_{multi_appear[filename]}.png" cv2.imwrite(os.path.join(OUTPUT_DIR, filename), new_img) if timestamp not in locator_map: locator_map[timestamp] = [] locator_map[timestamp].append({ "x": x, "y": y, "w": w, "h": h, "timestamp": timestamp, "name": f"PO{id_num}", "filename": filename }) else: print("Neither Automate nor mapping") context._root["w_o_mapping"] = w_o_mapping context._root["locator_map"] = locator_map
fenetre = "*Traitement d'une fiche de maintenance*" ldtp.waittillguiexist(fenetre) ldtp.click(fenetre, u"btnPi\xe8ces") fenetre = "*une nouvelle*" ldtp.waittillguiexist(fenetre) ldtp.mouseleftclick(fenetre, 'txt1') ldtp.enterstring(fenetre, 'txt1', "disque dur") #ldtp.mouseleftclick(fenetre, 'txt0') #ldtp.enterstring(fenetre, 'txt0', "") ldtp.mouseleftclick(fenetre, 'sldr0') ldtp.enterstring(fenetre, 'txt0', "<del><del><del><del><del>999,99") ldtp.click(fenetre, 'btnSaveEnter') fenetre = "*Traitement d'une fiche de maintenance*" coordinate = ldtp.getobjectsize(fenetre, 'tbl1') ldtp.generatemouseevent(coordinate[0]+120, coordinate[1]+35, 'b1d') ldtp.keypress('<ctrl>') ldtp.keypress('a') ldtp.keyrelease('<ctrl>') ldtp.keypress('<bksp>') ldtp.keyrelease('<bksp>') ajouterPressePapier("Lorem ipsum dolor sit amet, consectetur adipiscing elit. In rhoncus felis sed condimentum pretium. Etiam vulputate sapien eu massa consectetur imperdiet. Nunc non pulvinar magna. Donec fermentum sagittis condimentum. Vivamus et quam nec ante turpis ") ldtp.keypress('<ctrl>') ldtp.keypress('v') ldtp.keyrelease('<ctrl>') ldtp.click(fenetre, 'btnSaveEnter') ldtp.click('*Gestion de dossiers*', 'btnTraiter')
def step_impl(context, thing, win): l.waittillguiexist(win) (x, y, w, h) = l.getobjectsize(win, thing) click_x = x + (w / 2) click_y = y + (h / 2) context._root["_click_animated"](context, click_x, click_y)