12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576 |
- from ssat_sdk.utils.LoggingUtil import printLog
- from ssat_sdk.utils.string_util import getDigitFromString
- from ssat_sdk.device_manage.capturecard_manager import CCardManager
- from ssat_sdk.MenuTree3.TExcelParser import CExcelParser
- from ssat_sdk.MenuTree3.UIT_runner import UITRunner
- from ssat_sdk import getMenuTree3SelectedProjectCfgPath, OCRConvert, getSATTmpDIR, ImageCMP, \
- getMenuTree3SelectedPExcelPath, getMenuTree3SelectedTvExcelPath
- from ssat_sdk.MenuTree3.TFocus import TFocus
- from ssat_sdk.MenuTree3.TConfig import TConfig
- from ssat_sdk.MenuTree3.TSourceImpl import TSourceImpl
- from ssat_sdk.tv_operator import *
- import json
- import time
- import cv2 as cv
- from ssat_sdk.utils.string_util import strcmp
- from ssat_sdk.picture.DoubleImage import DoubleImage
- from ssat_sdk.source_input import SourceGenInput
- g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh',
- 'Twelfth']
- class CTMenu():
-
- def __init__(self, ocrDict=[{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253},
- {"lan": "ChinesePRC+English", "type": 10001}]):
- self.uitRunner = UITRunner()
- self.uitPathManage = self.uitRunner.uitPathManage
-
- self.ccard = CCardManager()
-
- self.ocr = OCRConvert()
-
- self.imgCMP = ImageCMP()
-
-
- self.redRat3 = TvOperator()
-
- self.tconfig = self.uitRunner.uitData.tConfig
- self.icon_shape = [1920, 1080]
- if self.tconfig.has_option('Screen', 'shape'):
- self.icon_shape = self.tconfig.get_value_dict('Screen', 'shape')
-
- self.Screen = [1920, 1080]
- pic = self.getCurrentUIPath()
- if os.path.exists(pic) is True:
- img = cv.imread(pic)
- if img is not None:
- self.Screen = [img.shape[1], img.shape[0]]
-
- self.tFocus = TFocus(getMenuTree3SelectedProjectCfgPath(), self.uitRunner, self.Screen, self.icon_shape)
- self.ocrDict = ocrDict
-
- self.got_dict = {}
-
- self.sourceInput = SourceGenInput()
- self.tSource = TSourceImpl(self.ocr, self.ccard, self.redRat3, self.tFocus, self.tconfig, self.uitRunner)
- def currentTime(self):
- return time.strftime('_%Y-%m-%d_%H_%M_%S', time.localtime(time.time()))
- def get_ocr_list(self, level, option):
-
- ini_path = os.path.join(getMenuTree3SelectedProjectCfgPath(), "menutree.ini")
- if os.path.exists(ini_path) is True:
- tconfig = self.uitRunner.uitData.tConfig
-
-
-
- result, path = self.uitRunner.uitData.UITree.get_option(option)
- print u"get_ocr_list, path:",path
- if result:
-
- for i in range(g_level.index(level), -1, -1):
- cur_parent = path['parent']
- first_parent = path['first_parent']
- i_level = g_level[i]
- if tconfig.has_option(i_level, option + u'.ocr'):
- self.ocrDict = tconfig.get_dict(tconfig.get_value(i_level, option + u'.ocr'))
- printLog("TMenu.get_ocr_list:", "Get ocr list by: %s.ocr"%option)
- break
- elif tconfig.has_option(i_level, cur_parent + u'.ocr'):
- self.ocrDict = tconfig.get_dict(tconfig.get_value(i_level, cur_parent + u'.ocr'))
- printLog("TMenu.get_ocr_list:", "Get ocr list by: %s.ocr"%cur_parent)
- break
- elif tconfig.has_option(i_level, first_parent + u'.ocr'):
- self.ocrDict = tconfig.get_dict(tconfig.get_value(i_level, first_parent + u'.ocr'))
- printLog("TMenu.get_ocr_list:", "Get ocr list by: %s.ocr"%first_parent)
- break
- else:
-
- self.ocrDict = [{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253},
- {"lan": "ChinesePRC+English", "type": 10001}]
- printLog("TMenu.get_ocr_list:", "Get ocr list fail!!!Using default list!!!")
- printLog("TMenu.get_ocr_list:", "Present ocr list:%s"%self.ocrDict)
-
- def getCurrentUIPath(self):
- current_uiPic = os.path.join(getSATTmpDIR(), "menutree_runpath.png")
- self.ccard.takePicture(current_uiPic)
- return current_uiPic
- def getFocusTextBox(self, level, root, focus_box):
-
- if self.tconfig.has_option(level, root + u".text.dir") is True:
- dict_text = self.tconfig.get_dict(self.tconfig.get_value(level, root + u".text.dir"))
-
- left, top, right, bottom = 0, 0, 0, 0
- if dict_text["dir"] == u"up":
- left = focus_box[0] + dict_text["x-offset"]
- bottom = focus_box[1] + dict_text["y-offset"]
- top = bottom - dict_text["height"]
- right = left + dict_text["width"]
- elif dict_text["dir"] == u"down":
- left = focus_box[0] + dict_text["x-offset"]
- top = focus_box[3] + dict_text["y-offset"]
- right = left + dict_text["width"]
- bottom = top + dict_text["height"]
- elif dict_text["dir"] == u"left":
- top = focus_box[1] + dict_text["y-offset"]
- right = focus_box[0] + dict_text["x-offset"]
- left = right - dict_text["width"]
- bottom = top + dict_text["height"]
- elif dict_text["dir"] == u"right":
- left = focus_box[2] + dict_text["x-offset"]
- top = focus_box[1] + dict_text["y-offset"]
- right = left + dict_text["width"]
- bottom = top + dict_text["height"]
-
- return [left, top, right, bottom]
-
-
- return focus_box
- def getFocusTextBox3(self, cur_option, focus_box, is_value_sheet=False):
- resutl, opcfg = self.tFocus.getOptionConfig(cur_option, is_value_sheet)
- dcfg = opcfg['dcfg']
- icon_path = opcfg['icon_path']
- icon_dir_path = opcfg['dir_path']
- if resutl is False or os.path.exists(icon_dir_path) is False:
- print u'getFocusTextBox:current use dir_path=%s is null' % (
- icon_dir_path)
- return focus_box
- if icon_dir_path in self.got_dict:
- x, y = focus_box[0] - self.got_dict[icon_dir_path]['ref_box'][0], focus_box[1] - \
- self.got_dict[icon_dir_path]['ref_box'][1]
- return [x, y, x + self.got_dict[icon_dir_path]['width'], y + self.got_dict[icon_dir_path]['height']]
- else:
- if os.path.exists(icon_dir_path) is True:
-
- img = cv.imread(icon_dir_path)
-
- result, box = self.tFocus.findRectByIcon2(icon_dir_path, cur_option, is_value_sheet)
- if result is True:
- self.got_dict[icon_dir_path] = {"ref_box": box, "width": img.shape[1], "height": img.shape[0]}
- x, y = focus_box[0] - box[0], focus_box[1] - box[1]
- return [x, y, x + img.shape[1], y + img.shape[0]]
-
-
-
- return focus_box
- def getFocusTextBox4(self, icon_dir_path, cur_option, focus_box, is_value_sheet=False):
- if os.path.exists(icon_dir_path) is False:
- print u'getFocusTextBox:current use dir_path=%s is null' % (
- icon_dir_path)
- return focus_box
- if icon_dir_path in self.got_dict:
- x, y = focus_box[0] - self.got_dict[icon_dir_path]['ref_box'][0], focus_box[1] - \
- self.got_dict[icon_dir_path]['ref_box'][1]
- return [x, y, x + self.got_dict[icon_dir_path]['width'], y + self.got_dict[icon_dir_path]['height']]
- else:
- if os.path.exists(icon_dir_path) is True:
-
- img = cv.imread(icon_dir_path)
-
- result, box = self.tFocus.findRectByIcon2(icon_dir_path, cur_option, is_value_sheet)
- if result is True:
- self.got_dict[icon_dir_path] = {"ref_box": box, "width": img.shape[1], "height": img.shape[0]}
- x, y = focus_box[0] - box[0], focus_box[1] - box[1]
- return [x, y, x + img.shape[1], y + img.shape[0]]
-
-
-
- return focus_box
-
- def getFocusText(self, level, first_parent, paths, src_pic, focus_box, is_for_value=False):
-
- text_pic = os.path.join(getSATTmpDIR(), "meuttree_area_text.png")
- contourRect = self.getFocusTextBox3(paths['option'], focus_box, is_for_value)
- self.imgCMP.saveCropPic(src_pic, text_pic, (contourRect[0], contourRect[1], contourRect[2], contourRect[3]))
-
- cur_parent, cur_option = paths['parent'], paths['option']
- ocr_list = self.uitRunner.uitData.UITree.get_ocr_list(level, cur_parent, cur_option,
- True if cur_parent == cur_option else False)
- print u"%s,%s,%s =>ocr_list=%s" % (level, cur_parent, cur_option, str(ocr_list))
-
- found = False
- ocr_str = ''
-
- self.get_ocr_list(level, cur_option)
- for item in self.ocrDict:
-
- thresholdDict = self.tconfig.getThresholdDict(first_parent)
- ocr_str = self.ocr.getStrWithImgProcess(text_pic, thresholdDict, item["lan"], item["type"], reconTimes=1)
- printLog(u"OCR识别的类型字典:%s" % str(item))
- printLog(u"OCR识别出的ocr_str为:%s" % str(ocr_str))
-
- ocr_str = unicode(ocr_str).lower()
- if is_for_value:
- parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(cur_parent, value_sheet=True)
- else:
- parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(cur_option)
- print u"getCurrentFocusTextEx.parent_ocr_dict:", parent_ocr_dict
- list_parent_ocr_value = list(parent_ocr_dict.keys())
- print u"getCurrentFocusTextEx.list_parent_ocr_value:", list_parent_ocr_value
- current_parent_ocr_value = ""
- for parent_ocr_value in list_parent_ocr_value:
- parent_ocr_value = str(parent_ocr_value).lower()
- if parent_ocr_value in ocr_str or parent_ocr_value == ocr_str:
- current_parent_ocr_value = parent_ocr_value
- break
- try:
- curentOption = parent_ocr_dict[current_parent_ocr_value]
- except Exception, e:
- curentOption = ""
- printLog(u"OCR识别出的current_parent_ocr_value为:%s" % str(current_parent_ocr_value))
- printLog(u"OCR识别出的curentOCROption为:%s" % str(curentOption))
-
-
- if str(curentOption).lower() != "" and str(curentOption).lower() != str(cur_option).lower():
-
- printLog(u"非焦点框=%s" % str(ocr_str))
- return 0, ocr_str
-
- for std_str in paths["option_for_ocr"]:
- std_str = str(std_str).lower()
-
-
- if std_str in ocr_str or std_str == ocr_str:
- found = True
- break
-
- if found is True:
- break
-
- return found, ocr_str
-
- def getFocusBox_temp(self, level, first_parent, option=''):
-
- bx_pic = ''
-
- cur_img = self.getCurrentUIPath()
-
- bx_found, bx_focus = self.tFocus.findRectByIcon(cur_img, level, first_parent, option)
- printLog("getCurrentFocusBox(%d,%s):" % (int(bx_found), str(bx_focus)))
- if bx_found is True:
-
- bx_pic = os.path.join(getSATTmpDIR(), "menutree_focus_area" + str(time.time()) + ".png")
- self.imgCMP.saveCropPic(cur_img, bx_pic, (bx_focus[0], bx_focus[1], bx_focus[2], bx_focus[3]))
-
- return bx_found, bx_focus, bx_pic
-
- def getMarqueeText(self, level, first_parent, option=''):
-
- bx_found, bx_focus, bx_pic = self.getFocusBox_temp(level, first_parent, option)
- if bx_found is False:
- printLog("getMarqueeText=>焦点框识别失败")
- return False, ''
-
- orc_type = {"lan": "ChinesePRC+English", "type": 253}
-
- thresholdDict = self.tconfig.getThresholdDict(first_parent)
-
- ocr_result = self.ocr.getStrWithImgProcess(bx_pic, thresholdDict, orc_type["lan"], orc_type["type"],
- reconTimes=1)
- if ocr_result == "ERR<Exp>" or ocr_result.__len__() == 0:
- printLog("getMarqueeText=>ocr识别失败=%s" % (ocr_result))
- return False, ocr_result
-
- return True, ocr_result
- def getOCRStrListByOptionList(self, optionList):
- OCRStrList = []
- for option in optionList:
- hasOption, optionDict = self.uitRunner.uitData.UITree.get_option(option)
- if hasOption:
- optionStrList = optionDict["option_ocr"]
- OCRStrList.extend(optionStrList)
- return OCRStrList
- def getOCRStrDictByOptionList(self, optionList):
- OCRStrDict = {}
- for option in optionList:
- hasOption, optionDict = self.uitRunner.uitData.UITree.get_option(option)
- if hasOption:
- optionStrList = optionDict["option_ocr"]
- OCRStrDict[option] = optionStrList
- return OCRStrDict
- def getFocusBoxMarqueeText(self, marquee_dict, level, first_parent, paths):
-
-
- bx_found, bx_focus, bx_pic1 = self.getFocusBox_temp(level, first_parent, paths['option'])
- if bx_found is False:
- printLog("getFocusBoxMarqueeText:焦点框识别失败1")
- return -1, ''
-
- time.sleep(marquee_dict['sleep_time'])
-
- self.redRat3.sendKey(marquee_dict['alive_key'], 1, 0.1)
-
- bx_found, bx_focus, bx_pic2 = self.getFocusBox_temp(level, first_parent, paths['option'])
- if bx_found is False:
- printLog("getFocusBoxMarqueeText:焦点框识别失败2")
- return -1, ''
-
- thresholdDict = self.tconfig.getThresholdDict(first_parent)
-
- ocr_result_text1 = self.ocr.getStrWithImgProcess(bx_pic1, thresholdDict, "CHN_ENG", 10000,
- reconTimes=1)
-
- self.redRat3.sendKey(marquee_dict['alive_key'], 1, 0.1)
-
- ocr_result_text2 = self.ocr.getStrWithImgProcess(bx_pic2, thresholdDict, "CHN_ENG", 10000,
- reconTimes=1)
-
- self.redRat3.sendKey(marquee_dict['alive_key'], 1, 0.1)
-
- if ocr_result_text1 != "" and ocr_result_text1 == ocr_result_text2:
- return self.getCurrentFocusTextEx(level, first_parent, paths['parent'], paths['option'],
- paths['option_for_ocr'])
- else:
- destOption = paths['option']
- menuList = marquee_dict["menu"]
-
- if menuList.__len__() == 1 and (destOption in menuList):
- return 1, destOption
- list_img = []
- result = False
- ocr_result_text = ''
- ocr_text_list = []
-
- for i in range(0, 5):
- bx_found, bx_focus, bx_pic = self.getFocusBox_temp(level, first_parent, paths['option'])
- if bx_found is True:
- list_img.append(bx_pic)
-
- time.sleep(marquee_dict['sleep_time'])
-
- self.redRat3.sendKey(marquee_dict['alive_key'], 1, 0.1)
-
-
-
- orc_type = {"lan": "ChinesePRC+English", "type": 10000}
- for bx_pic in list_img:
-
-
- ocr_result_text = self.ocr.getStrWithImgProcess(bx_pic, thresholdDict, orc_type["lan"],
- orc_type["type"],
- reconTimes=1)
-
- self.redRat3.sendKey(marquee_dict['alive_key'], 1, 0.1)
- if ocr_result_text == "ERR<Exp>" and ocr_result_text.__len__() == 0:
- return 0, ocr_result_text
- ocr_text_list.append(ocr_result_text)
-
-
- ocr_text_list = self.removeDuplicateString(ocr_text_list)
-
- ocrStrDict = self.getOCRStrDictByOptionList(menuList)
- print u"获取到的跑马灯Option对应的ocr字典ocrStrDict:", ocrStrDict
- print u"识别到的跑马灯ocr文字列表ocr_text_list:",ocr_text_list
- for marquee_option in ocrStrDict:
- option_ocr_list = ocrStrDict[marquee_option]
- for option_ocr in option_ocr_list:
-
- count = 0
- for ocr_text in ocr_text_list:
- if ocr_text.lower() in option_ocr:
- count += 1
- if count >= 3 and destOption == marquee_option:
- return 1, destOption
- elif count >= 3:
- printLog(u"当前聚焦的跑马灯Option实际为:%s"%marquee_option)
- return 0, marquee_option
- else:
- printLog(u"未能识别到当前聚焦的跑马灯Option!!!")
- return 0, "unknown marquee text"
- def strSplit(self, str):
- ret = []
- str_int = ''
- str_ch = ''
- ch_last = ' '
- for ch in str:
- if ord(ch) > 47 and ord(ch) < 58:
- str_int += ch
- if str_ch.__len__():
- ret.append(str_ch)
- str_ch = ''
- else:
- if ord(ch_last) > 47 and ord(ch_last) < 58 and ch == '.':
- str_int += ch
- if str_ch.__len__():
- ret.append(str_ch)
- str_ch = ''
- else:
- str_ch += ch
- if str_int.__len__():
- ret.append(str_int)
- str_int = ''
- ch_last = ch
- if str_ch.__len__():
- ret.append(str_ch)
- if str_int.__len__():
- ret.append(str_int)
- return ret
- def getCurrentFocusOcr_Int(self, icon_level, first_parent, option="", isForValue=False):
- print u"getCurrentFocusOcr_Int Start>>>", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
-
- cur_img = self.getCurrentUIPath()
- print u"isForValue:", isForValue
- if isForValue:
- bxfound, cur_box = self.tFocus.findRectByIcon2(cur_img, option, True)
- else:
- bxfound, cur_box = self.tFocus.findRectByIcon2(cur_img, option)
-
- printLog("getCurrentFocusBox(%d,%s):" % (int(bxfound), str(cur_box)))
- if not bxfound or cur_box == []:
- return False, "", 0
- cur_box = self.getFocusTextBox3(option, cur_box, True)
- printLog("getCurrentFocusBox(%d,%s):" % (int(bxfound), str(cur_box)))
-
- txt_pic = os.path.join(getSATTmpDIR(), "meuttree_area_text.png")
- self.imgCMP.saveCropPic(cur_img, txt_pic, (cur_box[0], cur_box[1], cur_box[2], cur_box[3]))
-
- ocr_result = ''
-
- hasOption, path = self.uitRunner.uitData.UITree.get_option(option)
- if hasOption:
- self.get_ocr_list(path['level'], option)
- for orc_item in self.ocrDict:
- thresholdDict = self.tconfig.getThresholdDict(first_parent)
-
- ocr_result = self.ocr.getStrWithImgProcess(txt_pic, thresholdDict, orc_item["lan"], orc_item["type"],
- reconTimes=1)
-
- printLog("getCurrentFocusOcr_Int=ocr识别结果=%s" % (ocr_result))
- if ocr_result == "ERR<Exp>" or ocr_result.__len__() == 0:
- continue
-
- ocr_result = ocr_result.strip('>')
-
-
- list_ocr = self.strSplit(ocr_result)
-
- if list_ocr.__len__() < 1:
- errorPngName = "menutree_error_" + self.currentTime() + "ocr.png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
-
- printLog(u"当前识别的ocr 不包含int类型值,截图为:%s" % (str(ocr_result)))
- continue
- try:
-
- text_int_str = list_ocr[list_ocr.__len__() - 1]
-
- printLog('text_int_str:%s' % str(text_int_str))
- text_num = float(text_int_str)
-
- return True, ocr_result, text_num
- except Exception:
- continue
-
- print u"getCurrentFocusOcr_Int End<<<", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
- return False, "", 0
-
- def getCurrentFocusTextEx(self, level, first_parent, cur_parent, option, list_str, isSource=False,
- isForValue=False):
- print level, first_parent, cur_parent, option
- current_uiPic = self.getCurrentUIPath()
- if isForValue:
-
-
- isFind, contourRect = self.tFocus.findRectByIcon2(current_uiPic, cur_parent, isForValue)
- else:
- isFind, contourRect = self.tFocus.findRectByIcon2(current_uiPic, option)
- printLog(u"获取当前聚焦效果isFind:%s 聚焦区域contourRect:%s" % (str(isFind), str(contourRect)))
- if not isFind or contourRect == []:
- return -1, ""
- else:
- found, ocr_str = False, ''
-
-
-
-
- tmpPic = os.path.join(getSATTmpDIR(), "meuttree_area_text.png")
- if isForValue:
- contourRect = self.getFocusTextBox3(cur_parent, contourRect, True)
- else:
- contourRect = self.getFocusTextBox3(option, contourRect)
- self.imgCMP.saveCropPic(current_uiPic, tmpPic,
- (contourRect[0], contourRect[1], contourRect[2], contourRect[3]))
- if isSource:
- self.redRat3.sendKey("ok")
-
-
- ocr_list = self.uitRunner.uitData.UITree.get_ocr_list(level, cur_parent, option, True if cur_parent == option else False)
- print u"%s,%s,%s =>ocr_list=%s" % (level, cur_parent, option, str(ocr_list))
-
- self.get_ocr_list(level, option)
-
- for item in self.ocrDict:
-
- thresholdDict = self.tconfig.getThresholdDict(first_parent)
- ocr_str = self.ocr.getStrWithImgProcess(tmpPic, thresholdDict, item["lan"], item["type"], reconTimes=1)
-
-
- printLog(u"OCR识别的类型字典:%s" % str(item))
- printLog(u"OCR识别出的ocr_str为:%s" % str(ocr_str))
-
- ocr_str = unicode(ocr_str).lower()
- if isSource is False:
- if isForValue:
- parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(cur_parent, value_sheet=True)
- else:
- parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(option)
- print u"getCurrentFocusTextEx.parent_ocr_dict:", parent_ocr_dict
- list_parent_ocr_value = list(parent_ocr_dict.keys())
- print u"getCurrentFocusTextEx.list_parent_ocr_value:", list_parent_ocr_value
-
- for parent_ocr_value in list_parent_ocr_value:
- parent_ocr_value = str(parent_ocr_value).lower()
- if parent_ocr_value in ocr_str or strcmp(parent_ocr_value, ocr_str):
-
- for std_str in list_str:
- std_str = str(std_str).lower()
- if strcmp(std_str, parent_ocr_value):
- printLog(u"传入的目标Value_ocr_list为:%s" % list_str)
- printLog(u"与目标option的ocr_value:%s相同"%std_str)
- return 1, option
- else:
-
- try:
- currentOption = parent_ocr_dict[parent_ocr_value]
- except Exception,e:
- currentOption = ""
- printLog(u"识别出的currentOption为:%s" % currentOption)
- if currentOption != "":
- return 0, currentOption
- else:
- if isSource is True:
-
- for ocr_std_str_list in ocr_list:
-
- for ocr_std_str in ocr_std_str_list:
-
- ocr_std_str = str(ocr_std_str).lower()
-
-
- if ocr_std_str in ocr_str or ocr_std_str == ocr_str:
- printLog(u"非焦点信源=%s" % str(ocr_str))
- return 0, ocr_str
- else:
-
- printLog(u"未能识别出当前Option!!!请检查Mnenutree相关参数配置!!!")
- return 0, ocr_str
-
- def move2TargetGridNode(self, level, first_parent, paths, returnKeyEventCount, Max_Try=15):
- result = False
- cur_option = paths['option']
- last_box, cur_box = [], []
-
- is_positive = True
- key_idx = False
- key_dir = ['right', 'left']
-
- is_first, is_last = False, False
-
- is_up, is_down = False, False
-
- waitTime = self.getOptionWaitTime(paths['option'])
- time.sleep(waitTime)
- while True:
- cur_pic = self.getCurrentUIPath()
- found_box, cur_box = self.tFocus.findRectByIcon2(cur_pic, cur_option)
- if found_box is True:
- if last_box == cur_box:
- if is_positive is True:
- if is_last is True:
- is_positive = False
- key_idx = not key_idx
- last_box = []
-
- self.redRat3.sendKey(key_dir[int(key_idx)])
- continue
- if is_down is False:
- is_down = True
-
- self.redRat3.sendKey('down')
- key_idx = not key_idx
- else:
- is_last = True
- key_idx = not key_idx
- else:
- if is_first is True:
- break
- if is_up is False:
- is_up = True
-
- self.redRat3.sendKey('up')
- key_idx = not key_idx
- else:
- is_first = True
- key_idx = not key_idx
-
- else:
- found_target, cur_text = self.getFocusText(level, first_parent, paths, cur_pic, cur_box)
- if found_target is True:
- result = True
- break
-
- last_box = cur_box
-
- self.redRat3.sendKey(key_dir[int(key_idx)])
-
- is_first, is_last = False, False
-
- is_up, is_down = False, False
-
- else:
- printLog(u"网格焦点框识别失败")
- break
-
-
- return result
- def move2TargetGridNode_matchTemp(self, level, first_parent, paths, returnKeyEventCount, Max_Try = 15):
-
- tgt_option = paths['option']
- temp_dir = os.path.join(getMenuTree3SelectedProjectCfgPath(), "match_temp", paths['parent'])
-
- img_focus_temp = os.path.join(temp_dir, tgt_option + '_focus.jpg')
-
- img_unfocus_temp = os.path.join(temp_dir, tgt_option + '_unfocus.jpg')
-
- waitTime = self.getOptionWaitTime(paths['option'])
- time.sleep(waitTime)
-
-
- page_try_time = 15
- focus_try_time = 100
-
- tgt_focus_result = False
- while tgt_focus_result is False:
-
- img_tv = self.getCurrentUIPath()
-
- match_result = self.tFocus.feature_detect.matchSingleImage(img_tv, None, img_focus_temp)
- if match_result is not None:
- tgt_focus_result = True
- break
-
-
- match_result = self.tFocus.feature_detect.matchSingleImage(img_tv, None, img_unfocus_temp)
- if match_result is None:
-
- if page_try_time == 0:
- break
-
- self.redRat3.sendKey('right')
- page_try_time = page_try_time - 1
- continue
-
- print u'匹配度=', match_result['tmpVal']
-
- bfound_box, focus_box = self.tFocus.findRectByIcon2(img_tv, tgt_option, is_value_sheet=False)
- if bfound_box is False:
- printLog("move2TargetGridNode_matchTemp:未找到聚集框")
- break
-
- box1, box2 = focus_box, match_result['coordinate']
-
- dir = self.tFocus.feature_detect.getOrientationEx(box1, box2)
- if dir == -1:
- break
-
-
-
- if dir == 0:
- self.redRat3.sendKey('right')
- elif dir == 1:
- self.redRat3.sendKey('down')
- elif dir == 2:
- self.redRat3.sendKey('left')
- elif dir == 3:
- self.redRat3.sendKey('right')
- elif dir == 4:
- self.redRat3.sendKey('left')
- elif dir == 5:
- self.redRat3.sendKey('right')
- elif dir == 6:
- self.redRat3.sendKey('up')
- elif dir == 7:
- self.redRat3.sendKey('left')
-
-
- focus_try_time = focus_try_time -1
- if focus_try_time == 0:
- break
-
- return tgt_focus_result
-
- def move2TargetNode(self, level, first_parent, paths, returnKeyEventCount, findDirection="down", Max_Try=15):
-
-
- count = 0
- parent = paths['parent']
- option_list = self.uitRunner.uitData.UITree.getSubOptionList(parent)
- if option_list.__len__() != 0:
- Max_Try = option_list.__len__()
- print u"move2TargetNode.%s option_list:"%parent, option_list
-
- Reversecount = 0
- Reverse_Max_Try = Max_Try
- print u"move2TargetNode:Max_Try:%s, Reverse_Max_Try:%s"%(Max_Try, Reverse_Max_Try)
- if findDirection == "grid":
- temp_dir = os.path.join(getMenuTree3SelectedProjectCfgPath(), "match_temp", paths['parent'])
- if os.path.exists(temp_dir):
- return self.move2TargetGridNode_matchTemp(level, first_parent, paths, returnKeyEventCount, Max_Try)
- else:
- return self.move2TargetGridNode(level, first_parent, paths, returnKeyEventCount, Max_Try)
-
- old_text = "init_old_text"
-
- findReverseDirection = "up"
- if findDirection == "up":
- findReverseDirection = "down"
- if findDirection == "down":
- findReverseDirection = "up"
- if findDirection == "left":
- findReverseDirection = "right"
- if findDirection == "right":
- findReverseDirection = "left"
- print u"findDirection:", findDirection, type(findDirection)
- print u"findReverseDirection:", findReverseDirection, type(findReverseDirection)
-
-
- isMarquee = False
- marquee_dict = {}
-
- if paths["others"].__len__():
- data_other = json.loads(paths["others"])
- if "marquee" in data_other:
- marquee_dict = data_other['marquee']
- isMarquee = True
-
- waitTime = self.getOptionWaitTime(paths['option'])
- printLog(u"move2TargetNode:获取到进入option_%s,等待时间为%s"%(paths['option'],waitTime))
- time.sleep(waitTime)
- while (True):
- print "count:", count
- if count >= Max_Try and Reversecount >= Reverse_Max_Try:
- break
- if isMarquee is True:
- isFind, text = self.getFocusBoxMarqueeText(marquee_dict, level, first_parent, paths)
- else:
- isFind, text = self.getCurrentFocusTextEx(level, first_parent, paths["parent"], paths["option"],
- paths["option_for_ocr"])
- if isFind == -1:
- errorPngName = "menutree_error_" + str(paths["option"]) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"聚焦到目标option:%s失败!当前界面无法找到焦点区域!!!出错界面截图%s" % (str(paths["option"]), str(error_uiPic)))
- self.redRat3.sendKey("return", returnKeyEventCount, 0.5)
- return False
-
-
- else:
- if isFind == 1:
- printLog(u"聚焦到目标option:%s成功!" % str(paths["option"]))
- return True
-
- print u"move2TargetNode.text",text
- print u"move2TargetNode.old_text",old_text
- if self.ocr.cmpOcrStr(text, old_text):
-
- count = Max_Try
- old_text = "init_old_text"
- else:
- old_text = text
- if count < Max_Try:
- count = count + 1
- self.redRat3.sendKey(findDirection)
- else:
- Reversecount = Reversecount + 1
- self.redRat3.sendKey(findReverseDirection)
- errorPngName = "menutree_error_" + str(paths["option"]) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"聚焦到目标option:%s失败!正向遍历%s次,和反向遍历%s次都没有聚焦到option:%s中,截图路径:%s" % (str(paths["option"]),
- str(Max_Try), str(Reverse_Max_Try),
- str(paths["option"]),
- str(error_uiPic)))
- return False
-
- def setLeafNodeValue(self, level, first_parent, option, value_excel, value_for_ocr, value, move_key, enter_key,
- Max_Try=15):
-
-
- count = 0
- Max_Try = Max_Try
-
- Reversecount = 0
- Reverse_Max_Try = Max_Try * 2
-
- old_text = "init_old_text"
-
- findDirection = move_key[1]
-
- findReverseDirection = move_key[0]
-
- waitTime = self.getLeafWaitTime(option)
- printLog(u"setLeafNodeValue:获取到进入叶节点%s,等待时间为%s"%(option, waitTime))
- time.sleep(waitTime)
- duration = 0.2
- isMarquee = False
- marquee_dict = {}
- leaf_data = self.uitRunner.uitData.UITree.get_value(option)
- if leaf_data["others"].__len__():
- data_other = json.loads(leaf_data["others"])
-
- if "marquee" in data_other:
- marquee_dict = data_other['marquee']
- isMarquee = True
-
- if "duration" in data_other:
- duration = float(data_other['duration'])
- printLog(u"读取到的设值间隔为%s"%duration)
- value_for_ocr_low = str(value_for_ocr[0]).lower()
-
- if "range(" in value_for_ocr_low:
- isRangeType = True
- str_num = value_for_ocr_low.replace("range", "")
- list_num = eval(str_num)
- min_num = list_num[0]
- max_num = list_num[1]
- try:
- value_num = int(value)
- except Exception:
- printLog(u"传入的值value:%s和option:%s对应的类型不匹配 !" % (str(value), str(option)))
- return False
- else:
- isRangeType = False
- if isRangeType:
-
- pass
- while (True):
-
- if count > 3:
- break
- isFind, text, text_num = self.getCurrentFocusOcr_Int(level, first_parent, option=option,
- isForValue=True)
- if not isFind:
- errorPngName = "menutree_error_" + str(option) + str(value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"设置叶子节点值时,当前界面无法找到焦点区域!!!getCurrentFocusOcr_Int出错界面截图%s" % str(error_uiPic))
- return False
- else:
- if text_num < min_num or text_num > max_num:
- errorPngName = "menutree_error_" + str(option) + '_' + str(
- value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"设置叶子节点值时,当前option:%s 识别出来的值text:%s 不在value_for_ocr:%s范围内,截图为:%s" % (
- str(option), str(text), str(value_for_ocr), str(error_uiPic)))
- return False
-
- if text_num == value_num:
- printLog(u"聚焦到目标option:%s,设置value:%s选项成功!" % (str(option), str(value_excel)))
-
- if enter_key != 'default':
- self.redRat3.sendKey(enter_key)
- return True
- else:
- if findDirection == 'input':
-
- for key in list(str(value_num)):
- self.redRat3.sendKey(key, 1, duration)
- if max_num > 100:
- return True
- else:
- count = count + 1
-
- if value_num > text_num:
- self.redRat3.sendKey(findDirection, value_num - text_num, duration)
-
- if value_num < text_num:
- self.redRat3.sendKey(findReverseDirection, text_num - value_num, duration)
- errorPngName = "menutree_error_" + str(option) + '_' + str(value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"设置叶子节点值时,当前option:%s 设置3次仍未设置到目标值value:%s,截图为:%s " % (str(option), str(value), str(error_uiPic)))
- return False
- else:
-
- while (True):
- print "count:", count
- if count >= Max_Try and Reversecount >= Reverse_Max_Try:
- break
- if isMarquee is True:
-
- result, paths = self.uitRunner.uitData.UITree.get_option(option)
- leaf_data['parent'] = paths['parent']
- leaf_data['option_for_ocr'] = leaf_data['value_for_ocr']
- isFind, text = self.getFocusBoxMarqueeText(marquee_dict, level, first_parent, leaf_data)
- else:
- isFind, text = self.getCurrentFocusTextEx(level, first_parent, option, value_excel, value_for_ocr,
- isForValue=True)
- if isFind == -1:
- errorPngName = "menutree_error_" + str(option) + '_' + str(
- value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"设置叶子节点值时,当前界面无法找到焦点区域!!!getCurrentFocusTextEx 出错界面截图%s" % str(error_uiPic))
- return False
-
-
- else:
- if isFind == 1:
- printLog(u"聚焦到目标option:%s,设置value:%s选项成功!" % (str(option), str(value_excel)))
-
- if enter_key != 'default':
- self.redRat3.sendKey(enter_key)
- return True
-
-
- if self.ocr.cmpOcrStr(text, old_text):
-
- count = Max_Try
- old_text = "init_old_text"
- else:
- old_text = text
- if count < Max_Try:
- count = count + 1
- self.redRat3.sendKey(findDirection)
- else:
- Reversecount = Reversecount + 1
- self.redRat3.sendKey(findReverseDirection)
- errorPngName = "menutree_error_" + str(option) + '_' + str(value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"设置叶子节点值时,正向遍历%s次,和反向遍历%s次都没有聚焦到option:%s的value:%s选项中,截图为%s" % (
- str(Max_Try), str(Reverse_Max_Try), str(option), str(value_excel), str(error_uiPic)))
- return False
- return True
-
- def dealOthers(self, level, path):
- others = json.loads(path['others'])
- if "password" in others:
- password = self.tconfig.get_value("Password", others["password"])
-
- time.sleep(2)
-
- for key in list(password):
- self.redRat3.sendKey(key, 1, 0.2)
- time.sleep(1)
-
- if others["enter_key"] != "default":
- self.redRat3.sendKey(others["enter_key"])
-
- current_uiPic = self.getCurrentUIPath()
-
- isFind, contourRect = self.tFocus.findRectByIcon(current_uiPic, level, path['parent'])
- return not isFind
- return False
-
- def isFirstOptionShow(self, level, first_parent, first_option):
- for i in range(3):
- current_uiPic = self.getCurrentUIPath()
- isFind, contourRect = self.tFocus.findRectByIcon2(current_uiPic, first_option)
- if isFind:
- return True
- return False
-
- def setOptionValue(self, option, value, Max_Try=15, reTryTime=0, leafNodeValueWaitTime=0.0, returnKeyEventTimes=-1):
-
- self.sourceInput.setPattern(11)
- printLog(u"开始执行setOptionValue。option:%s value:%s" % (str(option), str(value)))
-
- result = False
-
- value_params, path_params = self.uitPathManage.get_menu_paths(option, value)
- printLog(u"获取到达option:%s的路径字典path_params:%s" % (str(option), str(path_params)))
- printLog(u"获取设置value:%s的值字典value_params:%s" % (str(value), str(value_params)))
- checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
- if str(checkRunOptionPathResult) == "NoExit":
- printLog(u"表格中不存在到达Option: %s 的路径,在表格中排查到达该Option路径" % str(option))
- return False
- if str(checkRunOptionPathResult) == "Fail":
- printLog(u"表格中到达Option: %s 的路径出现数据断层找不到First层级,在表格中排查到达该Option路径" % str(option))
- return False
-
- returnKeyEventCount = 0
- print u"returnKeyEventCount:", returnKeyEventCount
-
- revpp = reversed(path_params)
-
- entry = False
- first_parent = u''
- first_option = u''
-
-
- for level in revpp:
-
- printLog(u"执行路径level:%s 对应路径字典:%s" % (str(level), str(path_params[level])))
-
- if entry == False:
-
- entry = True
- first_parent = path_params[level]["parent"]
- first_option = path_params[level]["option"]
- checkFirstOptionTimes = 0
- while True:
- if checkFirstOptionTimes > 2:
- errorPngName = "menutree_error_" + str(option) + '_' + str(value) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"执行setOptionValue ERROR!option:%s value:%s ;尝试3次快捷按键仍然没有唤出聚焦焦点界面!!! 出错截图:%s" % (
- str(option), str(value), str(error_uiPic)))
- return False
- printLog(u"第%s次尝试呼出一级界面" % str(checkFirstOptionTimes))
-
- try:
- others = json.loads(path_params[level]["others"])
- except Exception,e:
- others = {}
- printLog("section others:%s"%others)
- if "first_key" in others.keys():
- first_key = others["first_key"]
- else:
- first_key = path_params[level]["parent"]
- printLog(u"进入根节点,first_key:%s"%first_key)
-
- self.redRat3.sendKey(first_key)
- waitTime = self.getParentWaitTime(path_params[level]["parent"])
- printLog(u"打开%s界面的等待时间waittime为:%s" % (str(path_params[level]["parent"]), str(waitTime)))
- time.sleep(waitTime)
-
- self.get_ocr_list(level, option)
- if self.isFirstOptionShow(level, first_parent, first_option):
- printLog(u"呼出一级菜单界面")
- break
- else:
- time.sleep(5)
- self.redRat3.sendKey("return", 1)
- checkFirstOptionTimes = checkFirstOptionTimes + 1
-
- returnKeyEventCount = returnKeyEventCount + 1
- print u"level:", level, "first_parent:", first_parent
-
- if path_params[level]["others"].__len__():
-
- if self.dealOthers(level, path_params[level]) is True:
-
- printLog(u"执行setOptionValue ERROR!option:%s value:%s ;解锁失败!!!" % (str(option), str(value)))
- return False
- cur_option_enter_key = path_params[level]["option_enter_key"]
-
- if cur_option_enter_key.__len__() == 0:
- enter_key = path_params[level]["enter_key"]
- else:
- enter_key = cur_option_enter_key
- move_key = path_params[level]["move_key"]
- if str(move_key) == str([u'up', u'down']) or str(move_key) == str([u'down', u'up']):
- findDirection = str(move_key[1])
- elif str(move_key) == str([u'left', u'right']) or str(move_key) == str([u'right', u'left']):
- findDirection = str(move_key[1])
- else:
- findDirection = 'grid'
- result = self.move2TargetNode(
- level,
- first_parent,
- path_params[level],
- returnKeyEventCount,
- findDirection=findDirection, Max_Try=Max_Try)
- if result is True:
-
- if enter_key != u'default':
- self.redRat3.sendKey(enter_key)
-
- returnKeyEventCount = returnKeyEventCount + 1
- else:
- break
-
-
- if result is True:
-
- if self.ocr.cmpOcrStr(option, 'source'):
- return True
- time.sleep(leafNodeValueWaitTime)
- print u"执行设置叶节点:", value_params
- result = self.setLeafNodeValue(
- level,
- first_parent,
- value_params["option"],
- value_params["value"],
- value_params["value_for_ocr"],
- value,
- value_params["move_key"],
- value_params["enter_key"],
- Max_Try=Max_Try)
-
- if returnKeyEventTimes == -1:
- print u"执行退出,执行退出按键次数returnKeyEventCount:", returnKeyEventCount
-
- self.redRat3.sendKey("return", returnKeyEventCount, 0.2)
- time.sleep(1)
-
- reCount = 0
- while True:
- if reCount >= returnKeyEventCount:
- printLog(u"执行了returnKeyEventCount:%s次,仍无法退出到初始界面" % str(returnKeyEventCount))
- break
-
-
- if self.isFirstOptionShow("First", first_parent, first_option):
- print u"还没有退到初始界面"
- reCount = reCount + 1
-
- self.redRat3.sendKey("return")
- else:
- printLog(u"回退到初始界面成功!")
- break
- else:
- print u"执行退出,执行退出按键次数returnKeyEventTimes:", returnKeyEventTimes
-
- self.redRat3.sendKey("return", returnKeyEventTimes, 0.2)
- if result:
- printLog(u"设置option:%s 选中value:%s的值成功!" % (str(option), str(value)))
- else:
- printLog(u"重新设置option:%s 选中value:%s的值失败!" % (str(option), str(value)))
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return result
-
- def checkOptionValue(self, option, value, Max_Try=15, leafNodeValueWaitTime=0.0):
-
- self.sourceInput.setPattern(11)
- printLog(u"开始执行checkOptionValue。option:%s value:%s" % (str(option), str(value)))
-
- result = False
-
- value_params, path_params = self.uitPathManage.get_menu_paths(option, value)
- printLog(u"获取到达option:%s的路径字典path_params:%s" % (str(option), str(path_params)))
- printLog(u"获取检测value:%s的值字典value_params:%s" % (str(value), str(value_params)))
- checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
- if str(checkRunOptionPathResult) == "NoExit":
- printLog(u"表格中不存在到达Option: %s 的路径,在表格中排查到达该Option路径" % str(option))
- return False
- if str(checkRunOptionPathResult) == "Fail":
- printLog(u"表格中到达Option: %s 的路径出现数据断层找不到First层级,在表格中排查到达该Option路径" % str(option))
- return False
-
- returnKeyEventCount = 0
- print "returnKeyEventCount:", returnKeyEventCount
-
- revpp = reversed(path_params)
-
- entry = False
- root = u''
- first_parent = u''
- first_option = u''
-
-
- for level in revpp:
-
- printLog(u"执行路径level:%s 对应路径字典:%s" % (str(level), str(path_params[level])))
-
- if entry == False:
-
- entry = True
- first_parent = path_params[level]["parent"]
- first_option = path_params[level]["option"]
- checkFirstOptionTimes = 0
- while True:
- if checkFirstOptionTimes > 2:
- errorPngName = "menutree_error_" + str(option) + '_' + str(value) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"执行checkOptionValue ERROR!option:%s value:%s ;尝试3次快捷按键仍然没有唤出聚焦焦点界面!!! 出错截图:%s" % (
- str(option), str(value), str(error_uiPic)))
- return False
- printLog(u"第%s次尝试呼出一级界面" % str(checkFirstOptionTimes))
-
-
-
- try:
- others = json.loads(path_params[level]["others"])
- except Exception,e:
- others = {}
- printLog("section others:%s"%others)
- if "first_key" in others.keys():
- first_key = others["first_key"]
- else:
- first_key = path_params[level]["parent"]
- printLog(u"进入根节点,first_key:%s"%first_key)
-
- self.redRat3.sendKey(first_key)
- waitTime = self.getParentWaitTime(path_params[level]["parent"])
- printLog(u"打开%s界面的等待时间waittime为:%s" % (str(path_params[level]["parent"]), str(waitTime)))
- time.sleep(waitTime)
-
- self.get_ocr_list(level, option)
- if self.isFirstOptionShow(level, first_parent, first_option):
- printLog(u"呼出一级菜单界面")
- break
- else:
- time.sleep(5)
- self.redRat3.sendKey("return", 1)
- checkFirstOptionTimes = checkFirstOptionTimes + 1
-
- returnKeyEventCount = returnKeyEventCount + 1
-
- if path_params[level]["others"].__len__():
-
- if self.dealOthers(level, path_params[level]) is True:
-
- printLog(u"执行checkOptionValue ERROR!option:%s value:%s ;解锁失败!!!" % (str(option), str(value)))
- return False
-
- cur_option_enter_key = path_params[level]["option_enter_key"]
-
- if cur_option_enter_key.__len__() == 0:
- enter_key = path_params[level]["enter_key"]
- else:
- enter_key = cur_option_enter_key
- move_key = path_params[level]["move_key"]
- if str(move_key) == str([u'up', u'down']) or str(move_key) == str([u'down', u'up']):
- findDirection = str(move_key[1])
- elif str(move_key) == str([u'left', u'right']) or str(move_key) == str([u'right', u'left']):
- findDirection = str(move_key[1])
- else:
- findDirection = 'grid'
- result = self.move2TargetNode(
- level,
- first_parent,
- path_params[level],
- returnKeyEventCount,
- findDirection=findDirection, Max_Try=Max_Try)
- if result is True:
-
-
-
- if enter_key != u'default':
- self.redRat3.sendKey(enter_key)
-
- returnKeyEventCount = returnKeyEventCount + 1
- else:
- break
-
-
- if result is True:
-
- if self.ocr.cmpOcrStr(option, 'source') or self.ocr.cmpOcrStr(option, 'ok'):
- return True
- time.sleep(leafNodeValueWaitTime)
- result = self.checkLeafNodeValue(level, root, value_params["option"],
- value_params["value"],
- value_params["value_for_ocr"],
- value)
- print u"执行退出,执行退出按键次数returnKeyEventCount:", returnKeyEventCount
-
- self.redRat3.sendKey("return", returnKeyEventCount, 0.2)
- time.sleep(1)
-
- reCount = 0
- while True:
- if reCount >= returnKeyEventCount:
- printLog(u"执行了returnKeyEventCount:%s次,仍无法退出到初始界面" % str(returnKeyEventCount))
- break
- if self.isFirstOptionShow("First", first_parent, first_option):
- reCount = reCount + 1
-
- self.redRat3.sendKey("return")
- else:
- printLog(u"回退到初始界面成功!")
- break
- if result:
- printLog(u"检测option:%s 选中value:%s的值成功!" % (str(option), str(value)))
- else:
- printLog(u"检测option:%s 选中value:%s的值失败!" % (str(option), str(value)))
-
- return result
- def checkLeafNodeValue(self, level, parent, option, value_excel, value_for_ocr, value):
-
- waitTime = self.getOptionWaitTime(option)
- printLog(u"checkLeafNodeValue:获取到进入叶节点%s,等待时间为%s"%(option, waitTime))
- time.sleep(waitTime)
- value_for_ocr_low = str(value_for_ocr[0]).lower()
-
- if "range(" in value_for_ocr_low:
- isRangeType = True
- str_num = value_for_ocr_low.replace("range", "")
- list_num = eval(str_num)
- min_num = list_num[0]
- max_num = list_num[1]
- try:
- value_num = int(value)
- except Exception:
- printLog(u"传入的值value:%S和option:%s对应的类型不匹配 !" % (str(value), str(option)))
- return False
- else:
- isRangeType = False
- if isRangeType:
-
- isFind, text, text_num = self.getCurrentFocusOcr_Int(level, parent, option=option, isForValue=True)
- if not isFind:
- errorPngName = "menutree_error_" + str(option) + str(value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"检测叶子节点值时,当前界面无法找到焦点区域!!!出错界面截图%s" % str(error_uiPic))
- return False
- else:
- pass
- try:
- list_text_num = getDigitFromString(text)
- if list_text_num.__len__() < 1:
- errorPngName = "menutree_error_" + str(option) + '_' + str(
- value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"检测叶子节点值时,当前option:%s 识别出来的值text:%s 不包含int类型值,截图为:%s" % (
- str(option), str(text), str(error_uiPic)))
- return False
- text_int_str = list_text_num[list_text_num.__len__() - 1]
-
- text_num = int(text_int_str)
- printLog(u"检测到的值text_num:%s" % str(text_num))
- except Exception:
- errorPngName = "menutree_error_" + str(option) + '_' + str(
- value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"检测叶子节点值时,当前option:%s 识别出来的值text:%s 不能转换成value_for_ocr:%s范围内的int类型,截图为:%s" % (
- str(option), str(text_int_str), str(value_for_ocr), str(error_uiPic)))
- return False
- if text_num < min_num or text_num > max_num:
- errorPngName = "menutree_error_" + str(option) + '_' + str(
- value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"检测叶子节点值时,当前option:%s 识别出来的值text:%s 不在value_for_ocr:%s范围内,截图为:%s" % (
- str(option), str(text), str(value_for_ocr), str(error_uiPic)))
- return False
-
- if text_num == value_num:
- printLog(u"检测叶子节点值时,聚焦到目标option:%s,检测value:%s选项成功!" % (str(option), str(value_excel)))
- return True
- else:
- return False
- else:
-
- isFind, text = self.getCurrentFocusTextEx(level, parent, option, value_excel, value_for_ocr,
- isForValue=True)
- if not isFind:
- errorPngName = "menutree_error_" + str(option) + '_' + str(value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"检测叶子节点值时,当前界面无法找到焦点区域!!!出错界面截图:%s" % str(error_uiPic))
- return False
-
-
- else:
- for value_for_ocr_text in value_for_ocr:
- value_for_ocr_text_low = str(value_for_ocr_text).lower()
- if value_for_ocr_text_low in text:
- printLog(u"检测叶子节点值时,聚焦到目标option:%s,检测value:%s选项成功!" % (str(option), str(value_excel)))
- return True
- errorPngName = "menutree_error_" + str(option) + '_' + str(value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"检测叶子节点值时,聚焦到目标option:%s,检测value:%s选项失败!出错界面截图:%s" % (
- str(option), str(value_excel), str(error_uiPic)))
- return False
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- '''
- 不允许切换信源,在MenuTree.ini文件中配置:source={"offset":20,"minPeri":0,"maxPeri":0,"minArea":0,"maxArea":0,"enable":0}。
- enable没有,默认值enable=1;enable=0,表示不允许切换信源,仅判断是否为目标信源。
- '''
- def setSourceValue(self, option, value, sourceWaitTime=1.0, Max_Try=10):
-
- self.sourceInput.setPattern(11)
- return self.tSource.setSourceValue(option, value, sourceWaitTime, Max_Try)
- def inputUnlock(self, std_str, password=''):
-
- self.redRat3.sendKey("ok")
-
- if password.__len__() == 0:
- password = self.tconfig.get_value("Password", "super")
-
- for key in list(password):
- self.redRat3.sendKey(key, 1, 0.2)
- time.sleep(1)
-
- self.redRat3.sendKey('ok')
-
- current_uiPic = self.getCurrentUIPath()
- self.get_ocr_list("", "")
-
- found = False
- for item in self.ocrDict:
-
- ocr_str = self.ocr.getStrWithImgProcess(current_uiPic, {}, item["lan"], item["type"], reconTimes=1)
- ocr_str = unicode(ocr_str).lower()
-
- printLog("lan=%s,type=%d,ocr=%s" % (item["lan"], item["type"], ocr_str))
- if ocr_str in std_str or std_str == ocr_str:
- found = True
- break
- return not found
- def openOption(self, option, Max_Try=15):
-
- self.sourceInput.setPattern(11)
-
- print "openOption start >>>"
- path_params = self.uitPathManage.get_option_paths(option)
-
- printLog('openOption=path_params:%s' % str(path_params))
- checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
- if str(checkRunOptionPathResult) == "NoExit":
- printLog(u"表格中不存在到达Option: %s 的路径,在表格中排查到达该Option路径" % str(option))
- return False
- if str(checkRunOptionPathResult) == "Fail":
- printLog(u"表格中到达Option: %s 的路径出现数据断层找不到First层级,在表格中排查到达该Option路径" % str(option))
- return False
-
- returnKeyEventCount = 0
- print "returnKeyEventCount:", returnKeyEventCount
- printLog("openOption=returnKeyEventCount:%s" % str(returnKeyEventCount))
-
- revpp = reversed(path_params)
-
- entry = False
- first_parent = u''
- first_option = u''
-
-
- printLog("openOption=revpp:%s" % str(revpp))
- for level in revpp:
-
- printLog("openOption=level:", path_params[level])
-
- if entry == False:
-
- entry = True
- first_parent = path_params[level]["parent"]
- first_option = path_params[level]["option"]
- checkFirstOptionTimes = 0
- while True:
- if checkFirstOptionTimes > 2:
- printLog(u"openOption=尝试3次快捷按键没有唤出聚焦焦点界面!!!")
- return False
- printLog(u"第%s次尝试呼出一级界面" % str(checkFirstOptionTimes))
-
-
-
- try:
- others = json.loads(path_params[level]["others"])
- except Exception,e:
- others = {}
- printLog("section others:%s"%others)
- if "first_key" in others.keys():
- first_key = others["first_key"]
- else:
- first_key = path_params[level]["parent"]
- printLog(u"进入根节点,first_key:%s"%first_key)
-
- self.redRat3.sendKey(first_key)
- waitTime = self.getParentWaitTime(path_params[level]["parent"])
- printLog(u"打开%s界面的等待时间waittime为:%s" % (str(path_params[level]["parent"]), str(waitTime)))
- time.sleep(waitTime)
-
- self.get_ocr_list(level, option)
- if self.isFirstOptionShow(level, first_parent, first_option):
- printLog(u"呼出一级菜单界面")
- break
- else:
- time.sleep(5)
- self.redRat3.sendKey("return", 2)
- checkFirstOptionTimes = checkFirstOptionTimes + 1
-
- returnKeyEventCount = returnKeyEventCount + 1
-
- if path_params[level]["others"].__len__():
-
- if self.dealOthers(level, path_params[level]) is True:
-
- printLog(u"openOption=解锁失败!!!")
- return False
-
- cur_option_enter_key = path_params[level]["option_enter_key"]
-
- if cur_option_enter_key.__len__() == 0:
- enter_key = path_params[level]["enter_key"]
- else:
- enter_key = cur_option_enter_key
- move_key = path_params[level]["move_key"]
- if str(move_key) == str([u'up', u'down']) or str(move_key) == str([u'down', u'up']):
- findDirection = str(move_key[1])
- elif str(move_key) == str([u'left', u'right']) or str(move_key) == str([u'right', u'left']):
- findDirection = str(move_key[1])
- else:
- findDirection = 'grid'
- result = self.move2TargetNode(
- level,
- first_parent,
- path_params[level],
- returnKeyEventCount,
- findDirection=findDirection, Max_Try=Max_Try)
- if result is True:
-
- self.redRat3.sendKey(enter_key)
-
- if enter_key != u'default':
- returnKeyEventCount = returnKeyEventCount + 1
- else:
- print "openOption end<<<<"
- return False
-
- print "openOption end <<<<"
- return True
-
- def checkChannelList(self, channelList, Max_Try=15):
- failChannelList = []
- checkResult = True
- if channelList == []:
- printLog(u"传入的待检测的频道列表为空!")
- return False, failChannelList
- for channel in channelList:
- isSearched = self.checkOptionValue("ok", channel, Max_Try=Max_Try)
- if not isSearched:
- printLog(u"频道:%s查找失败!" % str(channel))
- failChannelList.append(channel)
- checkResult = False
-
-
- self.redRat3.sendKey("exit")
- else:
- printLog(u"频道:%s查找成功!" % str(channel))
- self.redRat3.sendKey("exit")
- printLog(u"频道列表检测结果checkResult:%s,检测失败频道列表failChannelLis:%s" % (str(checkResult), str(failChannelList)))
- return checkResult, failChannelList
-
- def focusOptionValue(self, option, value, Max_Try=15, leafNodeValueWaitTime=0.0):
-
- self.sourceInput.setPattern(11)
- printLog(u"focusOptionValue。option:%s value:%s" % (str(option), str(value)))
-
- result = False
-
- value_params, path_params = self.uitPathManage.get_menu_paths(option, value)
- printLog(u"获取到达option:%s的路径字典path_params:%s" % (str(option), str(path_params)))
- printLog(u"获取聚焦value:%s的值字典value_params:%s" % (str(value), str(value_params)))
- checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
- if str(checkRunOptionPathResult) == "NoExit":
- printLog(u"表格中不存在到达Option: %s 的路径,在表格中排查到达该Option路径" % str(option))
- return False
- if str(checkRunOptionPathResult) == "Fail":
- printLog(u"表格中到达Option: %s 的路径出现数据断层找不到First层级,在表格中排查到达该Option路径" % str(option))
- return False
-
- returnKeyEventCount = 0
- print "returnKeyEventCount:", returnKeyEventCount
-
- revpp = reversed(path_params)
-
- entry = False
- root = u''
- first_parent = u''
- first_option = u''
-
-
- for level in revpp:
-
- printLog(u"执行路径level:%s 对应路径字典:%s" % (str(level), str(path_params[level])))
-
- if entry == False:
-
- entry = True
- first_parent = path_params[level]["parent"]
- first_option = path_params[level]["option"]
- checkFirstOptionTimes = 0
- while True:
- if checkFirstOptionTimes > 2:
- errorPngName = "menutree_error_" + str(option) + '_' + str(value) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"执行focusOptionValue ERROR!option:%s value:%s ;尝试3次快捷按键仍然没有唤出聚焦焦点界面!!! 出错截图:%s" % (
- str(option), str(value), str(error_uiPic)))
- return False
- printLog(u"第%s次尝试呼出一级界面" % str(checkFirstOptionTimes))
-
-
-
- try:
- others = json.loads(path_params[level]["others"])
- except Exception,e:
- others = {}
- printLog("section others:%s"%others)
- if "first_key" in others.keys():
- first_key = others["first_key"]
- else:
- first_key = path_params[level]["parent"]
- printLog(u"进入根节点,first_key:%s"%first_key)
-
- self.redRat3.sendKey(first_key)
- waitTime = self.getParentWaitTime(path_params[level]["parent"])
- printLog(u"打开%s界面的等待时间waittime为:%s" % (str(path_params[level]["parent"]), str(waitTime)))
- time.sleep(waitTime)
-
- self.get_ocr_list(level, option)
- if self.isFirstOptionShow(level, first_parent, first_option):
- printLog(u"呼出一级菜单界面")
- break
- else:
- time.sleep(5)
- self.redRat3.sendKey("return", 2)
- checkFirstOptionTimes = checkFirstOptionTimes + 1
-
- returnKeyEventCount = returnKeyEventCount + 1
- print "level:", level, "root:", root
-
- if path_params[level]["others"].__len__():
-
- if self.dealOthers(level, path_params[level]) is True:
-
- printLog(u"执行setOptionValue ERROR!option:%s value:%s ;解锁失败!!!" % (str(option), str(value)))
- return False
-
- cur_option_enter_key = path_params[level]["option_enter_key"]
-
- if cur_option_enter_key.__len__() == 0:
- enter_key = path_params[level]["enter_key"]
- else:
- enter_key = cur_option_enter_key
- move_key = path_params[level]["move_key"]
- if str(move_key) == str([u'up', u'down']) or str(move_key) == str([u'down', u'up']):
- findDirection = str(move_key[1])
- elif str(move_key) == str([u'left', u'right']) or str(move_key) == str([u'right', u'left']):
- findDirection = str(move_key[1])
- else:
- findDirection = 'grid'
- result = self.move2TargetNode(
- level,
- first_parent,
- path_params[level],
- returnKeyEventCount,
- findDirection=findDirection, Max_Try=Max_Try)
- if result is True:
-
-
-
- if path_params.__len__() != 1:
- self.redRat3.sendKey(enter_key)
-
- if enter_key != u'default':
- returnKeyEventCount = returnKeyEventCount + 1
- else:
- break
-
-
- if path_params.__len__() != 1:
-
- if result is True:
-
- if self.ocr.cmpOcrStr(option, 'source'):
- return True
- time.sleep(leafNodeValueWaitTime)
- print u"执行设置叶节点:", value_params
- result = self.focusLeafNodeValue(
- level,
- root,
- value_params["option"],
- value_params["value"],
- value_params["value_for_ocr"],
- value,
- value_params["move_key"],
- value_params["enter_key"],
- Max_Try=Max_Try)
-
- if result:
-
- printLog(u"设置option:%s 选中value:%s的值成功!" % (str(option), str(value)))
- else:
- printLog(u"设置option:%s 选中value:%s的值失败!" % (str(option), str(value)))
- print u"执行退出,执行退出按键次数returnKeyEventCount:", returnKeyEventCount
-
- self.redRat3.sendKey("return", returnKeyEventCount, 0.2)
- time.sleep(1)
-
- reCount = 0
- while True:
- if reCount >= returnKeyEventCount:
- printLog(u"执行了returnKeyEventCount:%s次,仍无法退出到初始界面" % str(returnKeyEventCount))
- break
- if self.isFirstOptionShow("First", first_parent, first_option):
- reCount = reCount + 1
-
- self.redRat3.sendKey("return")
- else:
- printLog(u"回退到初始界面成功!")
- break
-
- return result
-
- def focusLeafNodeValue(self, level, parent, option, value_excel, value_for_ocr, value, move_key, enter_key,
- Max_Try=15):
-
-
- count = 0
- Max_Try = Max_Try
-
- Reversecount = 0
- Reverse_Max_Try = Max_Try * 2
-
- old_text = "init_old_text"
-
- findDirection = move_key[1]
-
- findReverseDirection = move_key[0]
-
- waitTime = self.getLeafWaitTime(option)
- printLog(u"focusLeafNodeValue:获取到进入叶节点%s,等待时间为%s"%(option, waitTime))
- time.sleep(waitTime)
- value_for_ocr_low = str(value_for_ocr[0]).lower()
-
- if "range(" in value_for_ocr_low:
- isRangeType = True
- str_num = value_for_ocr_low.replace("range", "")
- list_num = eval(str_num)
- min_num = list_num[0]
- max_num = list_num[1]
- try:
- value_num = int(value)
- except Exception:
- printLog(u"传入的值value:%s和option:%s对应的类型不匹配 !" % (str(value), str(option)))
- return False
- else:
- isRangeType = False
- if isRangeType:
-
- return True
- else:
-
- while (True):
- print "count:", count
- if count >= Max_Try and Reversecount >= Reverse_Max_Try:
- break
- isFind, text = self.getCurrentFocusTextEx(level, parent, option, value_excel, value_for_ocr,
- isForValue=True)
- if isFind == -1:
- errorPngName = "menutree_error_" + str(option) + '_' + str(
- value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"聚焦叶子节点值时,当前界面无法找到焦点区域!!!出错界面截图%s" % str(error_uiPic))
- return False
-
-
- else:
- if isFind == 1:
- printLog(u"聚焦到目标option:%s,设置value:%s选项成功!" % (str(option), str(value_excel)))
-
-
-
- return True
-
-
- if self.ocr.cmpOcrStr(text, old_text):
-
- count = Max_Try
- old_text = "init_old_text"
- else:
- old_text = text
- if count < Max_Try:
- count = count + 1
- self.redRat3.sendKey(findDirection)
- else:
- Reversecount = Reversecount + 1
- self.redRat3.sendKey(findReverseDirection)
- errorPngName = "menutree_error_" + str(option) + '_' + str(value_excel) + self.currentTime() + ".png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
- printLog(u"聚焦叶子节点值时,正向遍历%s次,和反向遍历%s次都没有聚焦到option:%s的value:%s选项中,截图为%s" % (
- str(Max_Try), str(Reverse_Max_Try), str(option), str(value_excel), str(error_uiPic)))
- return False
- return True
- def getOptionValue(self, option, is_value_sheet=True):
-
- self.sourceInput.setPattern(11)
-
- result, option_data = self.uitRunner.uitData.UITree.get_option(option)
- if result is False:
- print(u"getOptionValue.获取option菜单内容失败")
- return False, ''
- first_parent = option_data['first_parent']
- thresholdDict = self.tconfig.getThresholdDict(first_parent)
-
- if self.openOption(option) is False:
- self.redRat3.sendKey('return', option_data['layers'] + 1, 0.2)
- print(u"getOptionValue.进入指定option失败")
- return False, ''
-
- waitTime = self.getOptionWaitTime(option)
- printLog(u"getOptionValue:获取到进入叶节点%s,等待时间为%s"%(option, waitTime))
- time.sleep(waitTime)
- time.sleep(0.5)
-
- current_uiPic = self.getCurrentUIPath()
-
- result, opcfg = self.tFocus.getOptionConfig(option, is_value_sheet)
- if result is False:
- self.redRat3.sendKey('return', option_data['layers'] + 1, 0.2)
- print(u"getOptionValue.获取焦点参数失败")
- return False, ''
- dcfg = opcfg['dcfg']
- icon_path = opcfg['icon_path']
- icon_dir_path = opcfg['dir_path']
-
- result, cur_box = self.tFocus.findFocusByIcon(current_uiPic, icon_path, dcfg)
- if result is False:
- self.redRat3.sendKey('return', option_data['layers'] + 1, 0.2)
- print(u"getOptionValue.获取焦点框轮廓失败")
- return False, ''
-
- cur_box = self.getFocusTextBox4(icon_dir_path, option, cur_box, is_value_sheet)
-
- ocr_result_text = ''
- txt_pic = os.path.join(getSATTmpDIR(), "meuttree_area_text.png")
- self.imgCMP.saveCropPic(current_uiPic, txt_pic, (cur_box[0], cur_box[1], cur_box[2], cur_box[3]))
- if is_value_sheet is True:
- value_paramters = self.uitRunner.uitData.UITree.get_value(option, '')
- isRangeType = False
-
- if value_paramters['value_for_ocr'].__len__() and "range(" in value_paramters['value_for_ocr'][0].lower():
- isRangeType = True
- if isRangeType is True:
-
- hasOption,path = self.uitRunner.uitData.UITree.get_option(option)
- if hasOption:
- self.get_ocr_list(path['level'], option)
- for orc_item in self.ocrDict:
-
- ocr_result = self.ocr.getStrWithImgProcess(txt_pic, thresholdDict, orc_item["lan"],
- orc_item["type"],
- reconTimes=1)
-
- printLog("getCurrentFocusOcr_Int=ocr识别结果=%s" % (ocr_result))
- if ocr_result == "ERR<Exp>" or ocr_result.__len__() == 0:
- continue
-
- ocr_result = ocr_result.strip('>')
-
- list_ocr = getDigitFromString(ocr_result)
-
-
- if list_ocr.__len__() < 1:
- errorPngName = "menutree_error_" + self.currentTime() + "ocr.png"
- error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
- self.ccard.takePicture(error_uiPic)
-
- printLog(u"当前识别的ocr 不包含int类型值,截图为:%s" % (str(ocr_result)))
- continue
- try:
-
- text_int_str = list_ocr[list_ocr.__len__() - 1]
-
- printLog('text_int_str:%s' % str(text_int_str))
- ocr_result_text = float(text_int_str)
- break
- except Exception:
- continue
- else:
-
-
- ocr_result_text = self.ocr.getStrWithImgProcess(txt_pic, thresholdDict, "ENG", 10000,
- reconTimes=1)
- else:
-
-
- ocr_result_text = self.ocr.getStrWithImgProcess(txt_pic, thresholdDict, "ENG", 10000,
- reconTimes=1)
-
- self.redRat3.sendKey('return', option_data['layers'] + 1, 0.2)
-
- return True, ocr_result_text
- def getParentWaitTime(self, parent):
- optionName = parent + "WaitTime"
- try:
- waitTime = float(self.tconfig.get_value("waitTime", optionName))
- except Exception:
- waitTime = 1.0
-
- return waitTime
- def getOptionWaitTime(self, option):
- result, option_data = self.uitRunner.uitData.UITree.get_option(option)
- print u"getOptionWaitTime.option_data:",option_data
- if result:
- try:
- others = json.loads(option_data['others'])
- waitTime = float(others['waitTime'])
- except Exception,e:
- print u"获取%s界面的等待时间失败,使用默认值1.0s" % str(option)
- waitTime = 1.0
- else:
- waitTime = 1.0
- return waitTime
- def getLeafWaitTime(self, option):
- leaf_data = self.uitRunner.uitData.UITree.get_value(option)
- print u"getLeafWaitTime.option_data:",leaf_data
- try:
- others = json.loads(leaf_data['others'])
- waitTime = float(others['waitTime'])
- except Exception,e:
- print u"获取%s界面的等待时间失败,使用默认值1.0s" % str(option)
- waitTime = 1.0
- return waitTime
-
-
-
- def getBlackChannel(self, channel_count, black_th=20, black_rate=0.8):
- result = False
-
- for i in range(0, channel_count):
- pass
-
- pic_path = self.getCurrentUIPath()
- img = cv.imread(pic_path)
- pic_path2 = os.path.join(getSATTmpDIR(), "menutree_focus_area_half.png")
- self.imgCMP.saveCropPic(pic_path, pic_path2, (0, 0, img.shape[1] / 2, img.shape[0]))
-
- result = self.imgCMP.isBlack(pic_path2, black_th, 10, 1 - black_rate)
- if result is True:
- break
-
- self.redRat3.sendKey('C+')
- time.sleep(4)
-
- return result
-
-
- def focusOption(self, option, Max_Try=15):
-
- self.sourceInput.setPattern(11)
-
- print u"focusOption start >>>"
- path_params = self.uitPathManage.get_option_paths(option)
-
- printLog('focusOption=path_params:%s' % str(path_params))
- checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
- if str(checkRunOptionPathResult) == "NoExit":
- printLog(u"表格中不存在到达Option: %s 的路径,在表格中排查到达该Option路径" % str(option))
- return False
- if str(checkRunOptionPathResult) == "Fail":
- printLog(u"表格中到达Option: %s 的路径出现数据断层找不到First层级,在表格中排查到达该Option路径" % str(option))
- return False
- runPathCount = 0
- pathCount = path_params.__len__()
- printLog("focusOption=pathCount:%s" % str(pathCount))
-
- returnKeyEventCount = 0
- print "returnKeyEventCount:", returnKeyEventCount
- printLog("focusOption=returnKeyEventCount:%s" % str(returnKeyEventCount))
-
- revpp = reversed(path_params)
-
- entry = False
- first_parent = u''
- first_option = u''
-
-
- printLog("focusOption=revpp:%s" % str(revpp))
- for level in revpp:
-
- printLog("focusOption=level:", path_params[level])
-
- if entry == False:
-
- entry = True
- first_parent = path_params[level]["parent"]
- first_option = path_params[level]["option"]
- checkFirstOptionTimes = 0
- while True:
- if checkFirstOptionTimes > 2:
- printLog(u"focusOption=尝试3次快捷按键没有唤出聚焦焦点界面!!!")
- return False
- printLog(u"第%s次尝试呼出一级界面" % str(checkFirstOptionTimes))
-
-
-
- try:
- others = json.loads(path_params[level]["others"])
- except Exception,e:
- others = {}
- printLog("section others:%s"%others)
- if "first_key" in others.keys():
- first_key = others["first_key"]
- else:
- first_key = path_params[level]["parent"]
- printLog(u"进入根节点,first_key:%s"%first_key)
-
- self.redRat3.sendKey(first_key)
- waitTime = self.getParentWaitTime(path_params[level]["parent"])
- printLog(u"打开%s界面的等待时间waittime为:%s" % (str(path_params[level]["parent"]), str(waitTime)))
- time.sleep(waitTime)
-
- self.get_ocr_list(level, option)
- if self.isFirstOptionShow(level, first_parent, first_option):
- printLog(u"呼出一级菜单界面")
- break
- else:
- time.sleep(5)
- self.redRat3.sendKey("return", 2)
- checkFirstOptionTimes = checkFirstOptionTimes + 1
-
- returnKeyEventCount = returnKeyEventCount + 1
-
- if path_params[level]["others"].__len__():
-
- if self.dealOthers(level, path_params[level]) is True:
-
- printLog(u"focusOption=解锁失败!!!")
- return False
-
- cur_option_enter_key = path_params[level]["option_enter_key"]
-
- if cur_option_enter_key.__len__() == 0:
- enter_key = path_params[level]["enter_key"]
- else:
- enter_key = cur_option_enter_key
- move_key = path_params[level]["move_key"]
- if str(move_key) == str([u'up', u'down']) or str(move_key) == str([u'down', u'up']):
- findDirection = str(move_key[1])
- elif str(move_key) == str([u'left', u'right']) or str(move_key) == str([u'right', u'left']):
- findDirection = str(move_key[1])
- else:
- findDirection = 'grid'
- result = self.move2TargetNode(
- level,
- first_parent,
- path_params[level],
- returnKeyEventCount,
- findDirection=findDirection, Max_Try=Max_Try)
- if result is True:
- runPathCount = runPathCount + 1
- printLog("focusOption=runPathCount:%s" % str(runPathCount))
- if runPathCount == pathCount:
- print u"执行到最后一级"
- pass
- else:
-
- self.redRat3.sendKey(enter_key)
-
- if enter_key != u'default':
- returnKeyEventCount = returnKeyEventCount + 1
- else:
- print "focusOption end<<<<"
- return False
-
- print "focusOption end <<<<"
- return True
-
- def moveToOption(self, option, Max_Try=15):
-
-
-
- print "moveToOption start >>>"
- path_params = self.uitPathManage.get_option_paths(option)
-
- printLog('moveToOption=path_params:%s' % str(path_params))
- checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
- if str(checkRunOptionPathResult) == "NoExit":
- printLog(u"表格中不存在到达Option: %s 的路径,在表格中排查到达该Option路径" % str(option))
- return False
- if str(checkRunOptionPathResult) == "Fail":
- printLog(u"表格中到达Option: %s 的路径出现数据断层找不到First层级,在表格中排查到达该Option路径" % str(option))
- return False
- runPathCount = 0
- pathCount = path_params.__len__()
- printLog("moveToOption=pathCount:%s" % str(pathCount))
- returnKeyEventCount = path_params.__len__()
-
- printLog("moveToOption=returnKeyEventCount:%s" % str(returnKeyEventCount))
-
- revpp = reversed(path_params)
-
- entry = False
- first_parent = u''
-
-
-
- printLog("moveToOption=revpp:%s" % str(revpp))
- for level in revpp:
-
- runPathCount = runPathCount + 1
- print "level:", level, type(level)
- print "runPathCount:", runPathCount, type(runPathCount)
- print "pathCount:", pathCount, type(pathCount)
- printLog("openOption=level:", path_params[level])
-
- if entry == False:
-
- entry = True
- first_parent = path_params[level]["parent"]
-
- if runPathCount == pathCount:
-
- cur_option_enter_key = path_params[level]["option_enter_key"]
-
- if cur_option_enter_key.__len__() == 0:
- enter_key = path_params[level]["enter_key"]
- else:
- enter_key = cur_option_enter_key
- move_key = path_params[level]["move_key"]
- if str(move_key) == str([u'up', u'down']) or str(move_key) == str([u'down', u'up']):
- findDirection = str(move_key[1])
- elif str(move_key) == str([u'left', u'right']) or str(move_key) == str([u'right', u'left']):
- findDirection = str(move_key[1])
- else:
- findDirection = 'grid'
- result = self.move2TargetNode(
- level,
- first_parent,
- path_params[level],
- returnKeyEventCount,
- findDirection=findDirection, Max_Try=Max_Try)
- if result is True:
-
- printLog("moveToOption=runPathCount:%s" % str(runPathCount))
- if runPathCount == pathCount:
- print "执行到最后一级"
- pass
- else:
-
- self.redRat3.sendKey(enter_key)
- else:
- print "moveToOption end<<<<"
- return False
-
- print "moveToOption end <<<<"
- return True
-
- def findDuplicateString(self, str1, str2, direction="right"):
- index = 0
- if direction == "right":
- while True:
- index -= 1
- if abs(index) > str1.__len__() or abs(index) > str2.__len__():
- break
- if not str1[index] == str2[index]:
- break
- if index == -1:
- return ""
- return str1[index+1:]
- elif direction == "left":
- while True:
- if abs(index) >= str1.__len__() or abs(index) >= str2.__len__():
- break
- if not str1[index] == str2[index]:
- break
- index += 1
- return str1[:index]
-
- def removeDuplicateString(self, strList):
- finishedList = strList
- directionList = ["left", "right"]
- for direction in directionList:
- same_str = self.findDuplicateString(strList[0], strList[1], direction)
- if same_str == "":
- continue
- else:
- for i in range(2, strList.__len__()):
- same_str = self.findDuplicateString(same_str,strList[i], direction)
- if same_str == "":
- break
- if same_str != "":
- finishedList = []
- for str in strList:
- if direction == "left":
- str = str[same_str.__len__():]
- else:
- str = str[:-same_str.__len__()]
- finishedList.append(str)
- return finishedList
- if __name__ == "__main__":
- tmenu = CTMenu()
- print "执行开始!"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|