123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547 |
- 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()))
- '''
- 对应OptionConfig中的getThresholdDict和__getICONConfig
- '''
- 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 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 "执行开始!"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|