TMenu.py 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464
  1. # -*- coding:utf-8 -*-
  2. from ssat_sdk.utils.LoggingUtil import printLog
  3. from ssat_sdk.utils.string_util import getDigitFromString
  4. from ssat_sdk.device_manage.capturecard_manager import CCardManager
  5. from ssat_sdk.MenuTree3.TExcelParser import CExcelParser
  6. from ssat_sdk.MenuTree3.UIT_runner import UITRunner
  7. from ssat_sdk import getMenuTree3SelectedProjectCfgPath, OCRConvert, getSATTmpDIR, ImageCMP, \
  8. getMenuTree3SelectedPExcelPath, getMenuTree3SelectedTvExcelPath
  9. from ssat_sdk.MenuTree3.TFocus import TFocus
  10. from ssat_sdk.MenuTree3.TConfig import TConfig
  11. from ssat_sdk.MenuTree3.TSourceImpl import TSourceImpl
  12. from ssat_sdk.tv_operator import *
  13. import json
  14. import time
  15. import cv2 as cv
  16. from ssat_sdk.utils.string_util import strcmp
  17. from ssat_sdk.picture.DoubleImage import DoubleImage
  18. from ssat_sdk.source_input import SourceGenInput
  19. g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh',
  20. 'Twelfth']
  21. class CTMenu():
  22. # def __init__(self, ocrDict={"lan": "CHN_ENG", "type": 10000}):
  23. def __init__(self, ocrDict=[{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253},
  24. {"lan": "ChinesePRC+English", "type": 10001}]):
  25. self.uitRunner = UITRunner()
  26. self.uitPathManage = self.uitRunner.uitPathManage
  27. # 创建视频采集对象
  28. self.ccard = CCardManager()
  29. # 创建OCR对象
  30. self.ocr = OCRConvert()
  31. # 图片切割对象
  32. self.imgCMP = ImageCMP()
  33. # 读取excel并解析出内容;
  34. # 红老鼠遥控对象;
  35. self.redRat3 = TvOperator()
  36. # 配置文件;
  37. self.tconfig = self.uitRunner.uitData.tConfig
  38. self.icon_shape = [1920, 1080]
  39. if self.tconfig.has_option('Screen', 'shape'):
  40. self.icon_shape = self.tconfig.get_value_dict('Screen', 'shape')
  41. # 截图,获取分辨率;
  42. self.Screen = [1920, 1080]
  43. pic = self.getCurrentUIPath()
  44. if os.path.exists(pic) is True:
  45. img = cv.imread(pic)
  46. if img is not None:
  47. self.Screen = [img.shape[1], img.shape[0]]
  48. # 创建获取聚焦区域对象
  49. self.tFocus = TFocus(getMenuTree3SelectedProjectCfgPath(), self.uitRunner, self.Screen, self.icon_shape)
  50. self.ocrDict = ocrDict
  51. # 某数据是否读取过;
  52. self.got_dict = {}
  53. # 22293
  54. self.sourceInput = SourceGenInput()
  55. self.tSource = TSourceImpl(self.ocr, self.ccard, self.redRat3, self.tFocus, self.tconfig, self.uitRunner)
  56. def currentTime(self):
  57. return time.strftime('_%Y-%m-%d_%H_%M_%S', time.localtime(time.time()))
  58. '''
  59. 对应OptionConfig中的getThresholdDict和__getICONConfig
  60. '''
  61. def get_ocr_list(self, level, option):
  62. # OCR识别参数字典 默认值为:百度中英文免费类型
  63. ini_path = os.path.join(getMenuTree3SelectedProjectCfgPath(), "menutree.ini")
  64. if os.path.exists(ini_path) is True:
  65. tconfig = self.uitRunner.uitData.tConfig
  66. # if tconfig.has_option(level, parent + u'.ocr'):
  67. # self.ocrDict = tconfig.get_dict(tconfig.get_value(level, parent + u'.ocr'))
  68. # return
  69. result, path = self.uitRunner.uitData.UITree.get_option(option)
  70. print u"get_ocr_list, path:",path
  71. if result:
  72. # 从当前层逐层往上遍历,寻找ocr参数列表
  73. for i in range(g_level.index(level), -1, -1):
  74. cur_parent = path['parent']
  75. first_parent = path['first_parent']
  76. i_level = g_level[i]
  77. if tconfig.has_option(i_level, option + u'.ocr'):
  78. self.ocrDict = tconfig.get_dict(tconfig.get_value(i_level, option + u'.ocr'))
  79. printLog("TMenu.get_ocr_list:", "Get ocr list by: %s.ocr"%option)
  80. break
  81. elif tconfig.has_option(i_level, cur_parent + u'.ocr'):
  82. self.ocrDict = tconfig.get_dict(tconfig.get_value(i_level, cur_parent + u'.ocr'))
  83. printLog("TMenu.get_ocr_list:", "Get ocr list by: %s.ocr"%cur_parent)
  84. break
  85. elif tconfig.has_option(i_level, first_parent + u'.ocr'):
  86. self.ocrDict = tconfig.get_dict(tconfig.get_value(i_level, first_parent + u'.ocr'))
  87. printLog("TMenu.get_ocr_list:", "Get ocr list by: %s.ocr"%first_parent)
  88. break
  89. else:
  90. # 如果没有,使用默认;
  91. self.ocrDict = [{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253},
  92. {"lan": "ChinesePRC+English", "type": 10001}]
  93. printLog("TMenu.get_ocr_list:", "Get ocr list fail!!!Using default list!!!")
  94. printLog("TMenu.get_ocr_list:", "Present ocr list:%s"%self.ocrDict)
  95. # 截图并返回当前截图路径
  96. def getCurrentUIPath(self):
  97. current_uiPic = os.path.join(getSATTmpDIR(), "menutree_runpath.png")
  98. self.ccard.takePicture(current_uiPic)
  99. return current_uiPic
  100. def getFocusTextBox3(self, cur_option, focus_box, is_value_sheet=False):
  101. resutl, opcfg = self.tFocus.getOptionConfig(cur_option, is_value_sheet)
  102. dcfg = opcfg['dcfg']
  103. icon_path = opcfg['icon_path']
  104. icon_dir_path = opcfg['dir_path']
  105. if resutl is False or os.path.exists(icon_dir_path) is False:
  106. print u'getFocusTextBox:current use dir_path=%s is null' % (
  107. icon_dir_path)
  108. return focus_box
  109. if icon_dir_path in self.got_dict:
  110. x, y = focus_box[0] - self.got_dict[icon_dir_path]['ref_box'][0], focus_box[1] - \
  111. self.got_dict[icon_dir_path]['ref_box'][1]
  112. return [x, y, x + self.got_dict[icon_dir_path]['width'], y + self.got_dict[icon_dir_path]['height']]
  113. else:
  114. if os.path.exists(icon_dir_path) is True:
  115. # 读取例图,宽高;
  116. img = cv.imread(icon_dir_path)
  117. # 在例图中查找轮廓;
  118. result, box = self.tFocus.findRectByIcon2(icon_dir_path, cur_option, is_value_sheet)
  119. if result is True:
  120. self.got_dict[icon_dir_path] = {"ref_box": box, "width": img.shape[1], "height": img.shape[0]}
  121. x, y = focus_box[0] - box[0], focus_box[1] - box[1]
  122. return [x, y, x + img.shape[1], y + img.shape[0]]
  123. # endif
  124. # endif
  125. # 如果没有字段原样返回;
  126. return focus_box
  127. def getFocusTextBox4(self, icon_dir_path, cur_option, focus_box, is_value_sheet=False):
  128. if os.path.exists(icon_dir_path) is False:
  129. print u'getFocusTextBox:current use dir_path=%s is null' % (
  130. icon_dir_path)
  131. return focus_box
  132. if icon_dir_path in self.got_dict:
  133. x, y = focus_box[0] - self.got_dict[icon_dir_path]['ref_box'][0], focus_box[1] - \
  134. self.got_dict[icon_dir_path]['ref_box'][1]
  135. return [x, y, x + self.got_dict[icon_dir_path]['width'], y + self.got_dict[icon_dir_path]['height']]
  136. else:
  137. if os.path.exists(icon_dir_path) is True:
  138. # 读取例图,宽高;
  139. img = cv.imread(icon_dir_path)
  140. # 在例图中查找轮廓;
  141. result, box = self.tFocus.findRectByIcon2(icon_dir_path, cur_option, is_value_sheet)
  142. if result is True:
  143. self.got_dict[icon_dir_path] = {"ref_box": box, "width": img.shape[1], "height": img.shape[0]}
  144. x, y = focus_box[0] - box[0], focus_box[1] - box[1]
  145. return [x, y, x + img.shape[1], y + img.shape[0]]
  146. # endif
  147. # endif
  148. # 如果没有字段原样返回;
  149. return focus_box
  150. # 获取焦点框文本;
  151. def getFocusText(self, level, first_parent, paths, src_pic, focus_box, is_for_value=False):
  152. # 是否有文字方向字段存在在ini里,如果有则转换文本框坐标;
  153. text_pic = os.path.join(getSATTmpDIR(), "meuttree_area_text.png")
  154. contourRect = self.getFocusTextBox3(paths['option'], focus_box, is_for_value)
  155. self.imgCMP.saveCropPic(src_pic, text_pic, (contourRect[0], contourRect[1], contourRect[2], contourRect[3]))
  156. # 获取ocr_list;
  157. cur_parent, cur_option = paths['parent'], paths['option']
  158. ocr_list = self.uitRunner.uitData.UITree.get_ocr_list(level, cur_parent, cur_option,
  159. True if cur_parent == cur_option else False)
  160. print u"%s,%s,%s =>ocr_list=%s" % (level, cur_parent, cur_option, str(ocr_list))
  161. # 遍历ocr类型;
  162. found = False
  163. ocr_str = ''
  164. # 获取ocr列表;
  165. self.get_ocr_list(level, cur_option)
  166. for item in self.ocrDict:
  167. # 识别ocr;
  168. thresholdDict = self.tconfig.getThresholdDict(first_parent)
  169. ocr_str = self.ocr.getStrWithImgProcess(text_pic, thresholdDict, item["lan"], item["type"], reconTimes=1)
  170. printLog(u"OCR识别的类型字典:%s" % str(item))
  171. printLog(u"OCR识别出的ocr_str为:%s" % str(ocr_str))
  172. # print(u"getCurrentFocusTextEx.ocr_str land = %s, type =%d, ocr_str=%s:"%(item["lan"], item["type"], ocr_str.encode('GB18030')))
  173. ocr_str = unicode(ocr_str).lower()
  174. if is_for_value:
  175. parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(cur_parent, value_sheet=True)
  176. else:
  177. parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(cur_option)
  178. print u"getCurrentFocusTextEx.parent_ocr_dict:", parent_ocr_dict
  179. list_parent_ocr_value = list(parent_ocr_dict.keys())
  180. print u"getCurrentFocusTextEx.list_parent_ocr_value:", list_parent_ocr_value
  181. current_parent_ocr_value = ""
  182. for parent_ocr_value in list_parent_ocr_value:
  183. parent_ocr_value = str(parent_ocr_value).lower()
  184. if parent_ocr_value in ocr_str or parent_ocr_value == ocr_str:
  185. current_parent_ocr_value = parent_ocr_value
  186. break
  187. try:
  188. curentOption = parent_ocr_dict[current_parent_ocr_value]
  189. except Exception, e:
  190. curentOption = ""
  191. printLog(u"OCR识别出的current_parent_ocr_value为:%s" % str(current_parent_ocr_value))
  192. printLog(u"OCR识别出的curentOCROption为:%s" % str(curentOption))
  193. # printLog(u"传入的目标option为:%s" % str(option))
  194. # 通过OCR来反向识别判断当前识别的option是否为传入的option
  195. if str(curentOption).lower() != "" and str(curentOption).lower() != str(cur_option).lower():
  196. # print "非焦点框=%s" % (ocr_str)
  197. printLog(u"非焦点框=%s" % str(ocr_str))
  198. return 0, ocr_str
  199. # 再遍历目标焦点ocr;
  200. for std_str in paths["option_for_ocr"]:
  201. std_str = str(std_str).lower()
  202. # print 'std_str:', std_str, type(std_str)
  203. # print 'ocr_str:', ocr_str, type(ocr_str)
  204. if std_str in ocr_str or std_str == ocr_str:
  205. found = True
  206. break
  207. # endfor
  208. if found is True:
  209. break
  210. # endfor
  211. return found, ocr_str
  212. # 获取焦点框轮廓;
  213. def getFocusBox_temp(self, level, first_parent, option=''):
  214. # 焦点框截图;
  215. bx_pic = ''
  216. # 当前截图;
  217. cur_img = self.getCurrentUIPath()
  218. # 查找焦点框轮廓;
  219. bx_found, bx_focus = self.tFocus.findRectByIcon(cur_img, level, first_parent, option)
  220. printLog("getCurrentFocusBox(%d,%s):" % (int(bx_found), str(bx_focus)))
  221. if bx_found is True:
  222. # 保存焦点框截图;
  223. bx_pic = os.path.join(getSATTmpDIR(), "menutree_focus_area" + str(time.time()) + ".png")
  224. self.imgCMP.saveCropPic(cur_img, bx_pic, (bx_focus[0], bx_focus[1], bx_focus[2], bx_focus[3]))
  225. # 返回结果;
  226. return bx_found, bx_focus, bx_pic
  227. # 获取焦点框滚动文本;
  228. def getMarqueeText(self, level, first_parent, option=''):
  229. # 获取焦点框信息;
  230. bx_found, bx_focus, bx_pic = self.getFocusBox_temp(level, first_parent, option)
  231. if bx_found is False:
  232. printLog("getMarqueeText=>焦点框识别失败")
  233. return False, ''
  234. # 按要求,跑马灯只需要百度高精度;
  235. orc_type = {"lan": "ChinesePRC+English", "type": 253}
  236. # ocr识别;
  237. thresholdDict = self.tconfig.getThresholdDict(first_parent)
  238. # ocr_result = self.ocr.getStr(bx_pic, orc_type["lan"], orc_type["type"])
  239. ocr_result = self.ocr.getStrWithImgProcess(bx_pic, thresholdDict, orc_type["lan"], orc_type["type"],
  240. reconTimes=1)
  241. if ocr_result == "ERR<Exp>" or ocr_result.__len__() == 0:
  242. printLog("getMarqueeText=>ocr识别失败=%s" % (ocr_result))
  243. return False, ocr_result
  244. # 返回结果;
  245. return True, ocr_result
  246. def getOCRStrListByOptionList(self, optionList):
  247. OCRStrList = []
  248. for option in optionList:
  249. hasOption, optionDict = self.uitRunner.uitData.UITree.get_option(option)
  250. if hasOption:
  251. optionStrList = optionDict["option_ocr"]
  252. OCRStrList.extend(optionStrList)
  253. return OCRStrList
  254. def getOCRStrDictByOptionList(self, optionList):
  255. OCRStrDict = {}
  256. for option in optionList:
  257. hasOption, optionDict = self.uitRunner.uitData.UITree.get_option(option)
  258. if hasOption:
  259. optionStrList = optionDict["option_ocr"]
  260. OCRStrDict[option] = optionStrList
  261. return OCRStrDict
  262. def getFocusBoxMarqueeText(self, marquee_dict, level, first_parent, paths):
  263. # 截图2次,判断是否是跑马菜单;
  264. # 第一次;
  265. bx_found, bx_focus, bx_pic1 = self.getFocusBox_temp(level, first_parent, paths['option'])
  266. if bx_found is False:
  267. printLog("getFocusBoxMarqueeText:焦点框识别失败1")
  268. return -1, ''
  269. # 等待1秒后截图;
  270. time.sleep(marquee_dict['sleep_time'])
  271. # 发送鲜活键;
  272. self.redRat3.sendKey(marquee_dict['alive_key'], 1, 0.1)
  273. # 第二次;
  274. bx_found, bx_focus, bx_pic2 = self.getFocusBox_temp(level, first_parent, paths['option'])
  275. if bx_found is False:
  276. printLog("getFocusBoxMarqueeText:焦点框识别失败2")
  277. return -1, ''
  278. # 二图ocr文本是否相似,如果相似认为不是滚动文本;#如果网络问题;
  279. thresholdDict = self.tconfig.getThresholdDict(first_parent)
  280. # ocr_result_text1 = self.ocr.getStr(bx_pic1, "ChinesePRC+English", 253)
  281. ocr_result_text1 = self.ocr.getStrWithImgProcess(bx_pic1, thresholdDict, "CHN_ENG", 10000,
  282. reconTimes=1)
  283. # 发送鲜活键;
  284. self.redRat3.sendKey(marquee_dict['alive_key'], 1, 0.1)
  285. # ocr_result_text2 = self.ocr.getStr(bx_pic2, "ChinesePRC+English", 253)
  286. ocr_result_text2 = self.ocr.getStrWithImgProcess(bx_pic2, thresholdDict, "CHN_ENG", 10000,
  287. reconTimes=1)
  288. # 发送鲜活键;
  289. self.redRat3.sendKey(marquee_dict['alive_key'], 1, 0.1)
  290. # 对比结果:相等非滚动文本,否则视为滚动文本;
  291. if ocr_result_text1 != "" and ocr_result_text1 == ocr_result_text2:
  292. return self.getCurrentFocusTextEx(level, first_parent, paths['parent'], paths['option'],
  293. paths['option_for_ocr'])
  294. else:
  295. destOption = paths['option']
  296. menuList = marquee_dict["menu"]
  297. # 如果只有一项跑马灯,且目标option亦在跑马灯列表中,则直接返回成功结果
  298. if menuList.__len__() == 1 and (destOption in menuList):
  299. return 1, destOption
  300. list_img = []
  301. result = False
  302. ocr_result_text = ''
  303. ocr_text_list = []
  304. # 截图5次;
  305. for i in range(0, 5):
  306. bx_found, bx_focus, bx_pic = self.getFocusBox_temp(level, first_parent, paths['option'])
  307. if bx_found is True:
  308. list_img.append(bx_pic)
  309. # 间隔多久截图;
  310. time.sleep(marquee_dict['sleep_time'])
  311. # 发送鲜活键;
  312. self.redRat3.sendKey(marquee_dict['alive_key'], 1, 0.1)
  313. # endfor
  314. # 遍历文本list_img;
  315. # 按要求,跑马灯只用百度识别;
  316. orc_type = {"lan": "ChinesePRC+English", "type": 10000}
  317. for bx_pic in list_img:
  318. # ocr识别;
  319. # ocr_result_text = self.ocr.getStr(bx_pic, orc_type["lan"], orc_type["type"])
  320. ocr_result_text = self.ocr.getStrWithImgProcess(bx_pic, thresholdDict, orc_type["lan"],
  321. orc_type["type"],
  322. reconTimes=1)
  323. # 识别一次,发送一次鲜活键;
  324. self.redRat3.sendKey(marquee_dict['alive_key'], 1, 0.1)
  325. if ocr_result_text == "ERR<Exp>" and ocr_result_text.__len__() == 0:
  326. return 0, ocr_result_text
  327. ocr_text_list.append(ocr_result_text)
  328. #end for
  329. # 处理识别到的ocr列表:有部分聚焦状态会将option及其值一起包括其中,所以要把相同的部分(option或者值)去掉
  330. ocr_text_list = self.removeDuplicateString(ocr_text_list)
  331. # 获取到跑马灯option的ocr字典
  332. ocrStrDict = self.getOCRStrDictByOptionList(menuList)
  333. print u"获取到的跑马灯Option对应的ocr字典ocrStrDict:", ocrStrDict
  334. print u"识别到的跑马灯ocr文字列表ocr_text_list:",ocr_text_list
  335. for marquee_option in ocrStrDict:
  336. option_ocr_list = ocrStrDict[marquee_option]
  337. for option_ocr in option_ocr_list:
  338. # 一共5张截图,只要有3张满足条件,就算找到了该option(规避同时存在两条相似的跑马灯选项问题,以及跑马灯头尾同时显示的问题)
  339. count = 0
  340. for ocr_text in ocr_text_list:
  341. if ocr_text.lower() in option_ocr:
  342. count += 1
  343. if count >= 3 and destOption == marquee_option:
  344. return 1, destOption
  345. elif count >= 3:
  346. printLog(u"当前聚焦的跑马灯Option实际为:%s"%marquee_option)
  347. return 0, marquee_option
  348. else:
  349. printLog(u"未能识别到当前聚焦的跑马灯Option!!!")
  350. return 0, "unknown marquee text"
  351. def strSplit(self, str):
  352. ret = []
  353. str_int = ''
  354. str_ch = ''
  355. ch_last = ' '
  356. for ch in str:
  357. if 47 < ord(ch) < 58:
  358. str_int += ch
  359. if str_ch.__len__():
  360. ret.append(str_ch)
  361. str_ch = ''
  362. else:
  363. if 47 < ord(ch_last) < 58 and ch == '.':
  364. str_int += ch
  365. if str_ch.__len__():
  366. ret.append(str_ch)
  367. str_ch = ''
  368. else:
  369. str_ch += ch
  370. if str_int.__len__():
  371. ret.append(str_int)
  372. str_int = ''
  373. ch_last = ch
  374. if str_ch.__len__():
  375. ret.append(str_ch)
  376. if str_int.__len__():
  377. ret.append(str_int)
  378. return ret
  379. def getCurrentFocusOcr_Int(self, icon_level, first_parent, option="", isForValue=False):
  380. print u"getCurrentFocusOcr_Int Start>>>", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
  381. # 聚集框识别;
  382. cur_img = self.getCurrentUIPath()
  383. print u"isForValue:", isForValue
  384. if isForValue:
  385. bxfound, cur_box = self.tFocus.findRectByIcon2(cur_img, option, True)
  386. else:
  387. bxfound, cur_box = self.tFocus.findRectByIcon2(cur_img, option)
  388. # print "getCurrentFocusBox(%d,%s):" % (int(bxfound), str(cur_box))
  389. printLog("getCurrentFocusBox(%d,%s):" % (int(bxfound), str(cur_box)))
  390. if not bxfound or cur_box == []:
  391. return False, "", 0
  392. cur_box = self.getFocusTextBox3(option, cur_box, True)
  393. printLog("getCurrentFocusBox(%d,%s):" % (int(bxfound), str(cur_box)))
  394. # 截图文本框;
  395. txt_pic = os.path.join(getSATTmpDIR(), "meuttree_area_text.png")
  396. self.imgCMP.saveCropPic(cur_img, txt_pic, (cur_box[0], cur_box[1], cur_box[2], cur_box[3]))
  397. # ocr识别;
  398. ocr_result = ''
  399. # 获取ocr列表;
  400. hasOption, path = self.uitRunner.uitData.UITree.get_option(option)
  401. if hasOption:
  402. self.get_ocr_list(path['level'], option)
  403. for orc_item in self.ocrDict:
  404. thresholdDict = self.tconfig.getThresholdDict(first_parent)
  405. # ocr_result = self.ocr.getStr(txt_pic, orc_item["lan"], orc_item["type"])
  406. ocr_result = self.ocr.getStrWithImgProcess(txt_pic, thresholdDict, orc_item["lan"], orc_item["type"],
  407. reconTimes=1)
  408. # print("getCurrentFocusOcr_Int=ocr识别结果=%s" % (ocr_result))
  409. printLog("getCurrentFocusOcr_Int=ocr识别结果=%s" % (ocr_result))
  410. if ocr_result == "ERR<Exp>" or ocr_result.__len__() == 0:
  411. continue
  412. # 字符串去掉末尾">"符号;
  413. ocr_result = ocr_result.strip('>')
  414. # 按数字分解多组文本;
  415. # list_orc = getDigitFromString(ocr_result)
  416. list_ocr = self.strSplit(ocr_result)
  417. # 只判断最后一位是否是数字;
  418. if list_ocr.__len__() < 1:
  419. errorPngName = "menutree_error_" + self.currentTime() + "ocr.png"
  420. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  421. self.ccard.takePicture(error_uiPic)
  422. # print u"当前识别的ocr 不包含int类型值,截图为:%s" % (str(ocr_result))
  423. printLog(u"当前识别的ocr 不包含int类型值,截图为:%s" % (str(ocr_result)))
  424. continue
  425. try:
  426. # 获取最右边的文本,如果是数字则退出;
  427. text_int_str = list_ocr[list_ocr.__len__() - 1]
  428. # print 'text_int_str:', text_int_str
  429. printLog('text_int_str:%s' % str(text_int_str))
  430. text_num = float(text_int_str)
  431. # 返回结果;
  432. return True, ocr_result, text_num
  433. except Exception:
  434. continue
  435. # endfor
  436. print u"getCurrentFocusOcr_Int End<<<", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
  437. return False, "", 0
  438. # 遍历获取ocr结果;
  439. def getCurrentFocusTextEx(self, level, first_parent, cur_parent, option, list_str, isSource=False,
  440. isForValue=False):
  441. print level, first_parent, cur_parent, option
  442. current_uiPic = self.getCurrentUIPath()
  443. if isForValue:
  444. # cur_parent 对应value表里的option;
  445. # option_info = self.xlsparser.get_option(cur_parent)
  446. isFind, contourRect = self.tFocus.findRectByIcon2(current_uiPic, cur_parent, isForValue)
  447. else:
  448. isFind, contourRect = self.tFocus.findRectByIcon2(current_uiPic, option)
  449. printLog(u"获取当前聚焦效果isFind:%s 聚焦区域contourRect:%s" % (str(isFind), str(contourRect)))
  450. if not isFind or contourRect == []:
  451. return -1, ""
  452. else:
  453. found, ocr_str = False, ''
  454. # tmpPic = os.path.join(getSATTmpDIR(), "meuttree_area_text11.png")
  455. # self.imgCMP.saveCropPic(current_uiPic, tmpPic,
  456. # (contourRect[0], contourRect[1], contourRect[2], contourRect[3]))
  457. # 是否有文字方向字段存在在ini里,如果有则转换文本框坐标;
  458. tmpPic = os.path.join(getSATTmpDIR(), "meuttree_area_text.png")
  459. if isForValue:
  460. contourRect = self.getFocusTextBox3(cur_parent, contourRect, True)
  461. else:
  462. contourRect = self.getFocusTextBox3(option, contourRect)
  463. self.imgCMP.saveCropPic(current_uiPic, tmpPic,
  464. (contourRect[0], contourRect[1], contourRect[2], contourRect[3]))
  465. if isSource:
  466. self.redRat3.sendKey("ok")
  467. # print "self.ocrDict:", self.ocrDict
  468. # 获取ocr_list;
  469. ocr_list = self.uitRunner.uitData.UITree.get_ocr_list(level, cur_parent, option, True if cur_parent == option else False)
  470. print u"%s,%s,%s =>ocr_list=%s" % (level, cur_parent, option, str(ocr_list))
  471. # 获取ocr列表;
  472. self.get_ocr_list(level, option)
  473. # 遍历ocr类型;
  474. for item in self.ocrDict:
  475. # 识别ocr;
  476. thresholdDict = self.tconfig.getThresholdDict(first_parent)
  477. ocr_str = self.ocr.getStrWithImgProcess(tmpPic, thresholdDict, item["lan"], item["type"], reconTimes=1)
  478. # print "\n\ngetCurrentFocusTextEx ==========================:OCR-Type=%s, OCR-Text=%s\n\n" % (
  479. # str(item), str(ocr_str))
  480. printLog(u"OCR识别的类型字典:%s" % str(item))
  481. printLog(u"OCR识别出的ocr_str为:%s" % str(ocr_str))
  482. # print(u"getCurrentFocusTextEx.ocr_str land = %s, type =%d, ocr_str=%s:"%(item["lan"], item["type"], ocr_str.encode('GB18030')))
  483. ocr_str = unicode(ocr_str).lower()
  484. if isSource is False:
  485. if isForValue:
  486. parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(cur_parent, value_sheet=True)
  487. else:
  488. parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(option)
  489. print u"getCurrentFocusTextEx.parent_ocr_dict:", parent_ocr_dict
  490. list_parent_ocr_value = list(parent_ocr_dict.keys())
  491. print u"getCurrentFocusTextEx.list_parent_ocr_value:", list_parent_ocr_value
  492. # 比较所有的ocr
  493. for parent_ocr_value in list_parent_ocr_value:
  494. parent_ocr_value = str(parent_ocr_value).lower()
  495. if parent_ocr_value in ocr_str or strcmp(parent_ocr_value, ocr_str):
  496. # 优先比较目标option,如果符合要求则直接返回找到结果
  497. for std_str in list_str:
  498. std_str = str(std_str).lower()
  499. if strcmp(std_str, parent_ocr_value):
  500. printLog(u"传入的目标Value_ocr_list为:%s" % list_str)
  501. printLog(u"与目标option的ocr_value:%s相同"%std_str)
  502. return 1, option
  503. else:
  504. # 否则则识别出该ocr_value所对应的option
  505. try:
  506. currentOption = parent_ocr_dict[parent_ocr_value]
  507. except Exception,e:
  508. currentOption = ""
  509. printLog(u"识别出的currentOption为:%s" % currentOption)
  510. if currentOption != "":
  511. return 0, currentOption
  512. else:
  513. if isSource is True:
  514. # 如果是信源 而且识别出是非目标信源则跳出该语言
  515. for ocr_std_str_list in ocr_list:
  516. # print "ocr_std_str_list:",ocr_std_str_list
  517. for ocr_std_str in ocr_std_str_list:
  518. # print "ocr_std_str:",ocr_std_str
  519. ocr_std_str = str(ocr_std_str).lower()
  520. # print 'ocr_std_str:', ocr_std_str, type(ocr_std_str)
  521. # print 'ocr_str:', ocr_str, type(ocr_str)
  522. if ocr_std_str in ocr_str or ocr_std_str == ocr_str:
  523. printLog(u"非焦点信源=%s" % str(ocr_str))
  524. return 0, ocr_str
  525. else:
  526. # 全部ocr_value都不符合要求,则视为menutree中不存在此option相关的数据
  527. printLog(u"未能识别出当前Option!!!请检查Mnenutree相关参数配置!!!")
  528. return 0, ocr_str
  529. # 移动到目标网格焦点上;
  530. def move2TargetGridNode(self, level, first_parent, paths, returnKeyEventCount, Max_Try=15):
  531. result = False
  532. cur_option = paths['option']
  533. last_box, cur_box = [], []
  534. # 遍历正序;
  535. is_positive = True
  536. key_idx = False
  537. key_dir = ['right', 'left']
  538. # 第一个,最后一个;
  539. is_first, is_last = False, False
  540. # 上一行,下一行;
  541. is_up, is_down = False, False
  542. # 获取等待时间
  543. waitTime = self.getOptionWaitTime(paths['option'])
  544. time.sleep(waitTime)
  545. while True:
  546. cur_pic = self.getCurrentUIPath()
  547. found_box, cur_box = self.tFocus.findRectByIcon2(cur_pic, cur_option)
  548. if found_box is True:
  549. if last_box == cur_box:
  550. if is_positive is True: # 正序;
  551. if is_last is True:
  552. is_positive = False
  553. key_idx = not key_idx
  554. last_box = []
  555. # 移动上一格;
  556. self.redRat3.sendKey(key_dir[int(key_idx)])
  557. continue
  558. if is_down is False:
  559. is_down = True
  560. # 移动下一行;
  561. self.redRat3.sendKey('down')
  562. key_idx = not key_idx
  563. else:
  564. is_last = True
  565. key_idx = not key_idx
  566. else: # 逆序;
  567. if is_first is True:
  568. break
  569. if is_up is False:
  570. is_up = True
  571. # 移动上一行;
  572. self.redRat3.sendKey('up')
  573. key_idx = not key_idx
  574. else:
  575. is_first = True
  576. key_idx = not key_idx
  577. # endif
  578. else:
  579. found_target, cur_text = self.getFocusText(level, first_parent, paths, cur_pic, cur_box)
  580. if found_target is True:
  581. result = True
  582. break
  583. # 保留为上一焦点框;
  584. last_box = cur_box
  585. # 移动下一焦点;
  586. self.redRat3.sendKey(key_dir[int(key_idx)])
  587. # 第一个,最后一个;
  588. is_first, is_last = False, False
  589. # 上一行,下一行;
  590. is_up, is_down = False, False
  591. # endif
  592. else:
  593. printLog(u"网格焦点框识别失败")
  594. break
  595. # endif
  596. # 返回结果;
  597. return result
  598. def move2TargetGridNode_matchTemp(self, level, first_parent, paths, returnKeyEventCount, Max_Try = 15):
  599. # 目标结点;
  600. tgt_option = paths['option']
  601. temp_dir = os.path.join(getMenuTree3SelectedProjectCfgPath(), "match_temp", paths['parent'])
  602. # 选中时的模板
  603. img_focus_temp = os.path.join(temp_dir, tgt_option + '_focus.jpg')
  604. # 未选中模板图
  605. img_unfocus_temp = os.path.join(temp_dir, tgt_option + '_unfocus.jpg')
  606. # 获取等待时间
  607. waitTime = self.getOptionWaitTime(paths['option'])
  608. time.sleep(waitTime)
  609. # 尝试次数;
  610. page_try_time = 15
  611. focus_try_time = 100
  612. # 目标聚集结果;
  613. tgt_focus_result = False
  614. while tgt_focus_result is False:
  615. # 电视截图(原图);
  616. img_tv = self.getCurrentUIPath()
  617. # 查找聚集框是否在目标上;
  618. match_result = self.tFocus.feature_detect.matchSingleImage(img_tv, None, img_focus_temp)
  619. if match_result is not None:
  620. tgt_focus_result = True
  621. break
  622. #end-if
  623. # 查找非聚集目标;
  624. match_result = self.tFocus.feature_detect.matchSingleImage(img_tv, None, img_unfocus_temp)
  625. if match_result is None:
  626. # 尝试次数使用完;
  627. if page_try_time == 0:
  628. break
  629. # 没找到,可能在别的页面,向右移动;
  630. self.redRat3.sendKey('right')
  631. page_try_time = page_try_time - 1
  632. continue
  633. # end-if
  634. print u'匹配度=', match_result['tmpVal']
  635. # 找到非聚集目标后,再查找当前聚集框坐标;
  636. bfound_box, focus_box = self.tFocus.findRectByIcon2(img_tv, tgt_option, is_value_sheet=False) # 不支持叶结点;
  637. if bfound_box is False:
  638. printLog("move2TargetGridNode_matchTemp:未找到聚集框")
  639. break
  640. #end-if
  641. box1, box2 = focus_box, match_result['coordinate']
  642. # 计算非聚集模板与聚集框的位置;
  643. dir = self.tFocus.feature_detect.getOrientationEx(box1, box2)
  644. if dir == -1:
  645. break
  646. # 中心点坐标;center point
  647. # cpt1 = [box1[2]-box1[0],box1[3]-box1[1]]
  648. # cpt2 = [box2[2]-box2[0],box2[3]-box2[1]]
  649. if dir == 0:# 左上方;
  650. self.redRat3.sendKey('right')
  651. elif dir == 1:# 正上方;
  652. self.redRat3.sendKey('down')
  653. elif dir == 2:# 右上方;
  654. self.redRat3.sendKey('left')
  655. elif dir == 3:# 正左方;
  656. self.redRat3.sendKey('right')
  657. elif dir == 4:# 正右方;
  658. self.redRat3.sendKey('left')
  659. elif dir == 5:# 左下方;
  660. self.redRat3.sendKey('right')
  661. elif dir == 6:# 正下方;
  662. self.redRat3.sendKey('up')
  663. elif dir == 7:# 右下方;
  664. self.redRat3.sendKey('left')
  665. # 移动次数用完;
  666. focus_try_time = focus_try_time -1
  667. if focus_try_time == 0:
  668. break
  669. #end-while;
  670. return tgt_focus_result
  671. # 移动到目标节点上;
  672. def move2TargetNode(self, level, first_parent, paths, returnKeyEventCount, findDirection="down", Max_Try=15):
  673. # 按照传入的方向寻找Max_Try次,如果仍未聚焦到option_for_ocr所在的区域,则按照传入方向的反方向 反向寻找 Max_Try 次
  674. # 正向寻找的次数计数和最大次数
  675. count = 0
  676. parent = paths['parent']
  677. option_list = self.uitRunner.uitData.UITree.getSubOptionList(parent)
  678. if option_list.__len__() != 0:
  679. Max_Try = option_list.__len__()
  680. print u"move2TargetNode.%s option_list:"%parent, option_list
  681. # 反向寻找的次数计数和最大次数
  682. Reversecount = 0
  683. Reverse_Max_Try = Max_Try
  684. print u"move2TargetNode:Max_Try:%s, Reverse_Max_Try:%s"%(Max_Try, Reverse_Max_Try)
  685. if findDirection == "grid":
  686. temp_dir = os.path.join(getMenuTree3SelectedProjectCfgPath(), "match_temp", paths['parent'])
  687. if os.path.exists(temp_dir):
  688. return self.move2TargetGridNode_matchTemp(level, first_parent, paths, returnKeyEventCount, Max_Try)
  689. else:
  690. return self.move2TargetGridNode(level, first_parent, paths, returnKeyEventCount, Max_Try)
  691. # 记录上一个焦点识别的文字内容 用于判断是否到达列表的边界 如果到达边界则反向寻找
  692. old_text = "init_old_text"
  693. # 反向寻找的遥控器按键值
  694. findReverseDirection = "up"
  695. if findDirection == "up":
  696. findReverseDirection = "down"
  697. if findDirection == "down":
  698. findReverseDirection = "up"
  699. if findDirection == "left":
  700. findReverseDirection = "right"
  701. if findDirection == "right":
  702. findReverseDirection = "left"
  703. print u"findDirection:", findDirection, type(findDirection)
  704. print u"findReverseDirection:", findReverseDirection, type(findReverseDirection)
  705. # # 去除大小写的识别字符
  706. # option_for_ocr_low = str(option_for_ocr).lower()
  707. isMarquee = False
  708. marquee_dict = {}
  709. # 是否有跑马灯文本;
  710. if paths["others"].__len__():
  711. data_other = json.loads(paths["others"])
  712. if "marquee" in data_other:
  713. marquee_dict = data_other['marquee']
  714. isMarquee = True
  715. # 获取等待时间
  716. waitTime = self.getOptionWaitTime(paths['option'])
  717. printLog(u"move2TargetNode:获取到进入option_%s,等待时间为%s"%(paths['option'],waitTime))
  718. time.sleep(waitTime)
  719. while (True):
  720. print "count:", count
  721. if count >= Max_Try and Reversecount >= Reverse_Max_Try:
  722. break
  723. if isMarquee is True:
  724. isFind, text = self.getFocusBoxMarqueeText(marquee_dict, level, first_parent, paths)
  725. else:
  726. isFind, text = self.getCurrentFocusTextEx(level, first_parent, paths["parent"], paths["option"],
  727. paths["option_for_ocr"])
  728. if isFind == -1:
  729. errorPngName = "menutree_error_" + str(paths["option"]) + self.currentTime() + ".png"
  730. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  731. self.ccard.takePicture(error_uiPic)
  732. printLog(u"聚焦到目标option:%s失败!当前界面无法找到焦点区域!!!出错界面截图%s" % (str(paths["option"]), str(error_uiPic)))
  733. self.redRat3.sendKey("return", returnKeyEventCount, 0.5)
  734. return False
  735. # elif (self.ocr.cmpOcrStr(text, option_for_ocr)):
  736. # 由比较目标文本和识别文本 是否相等 改为 识别文本是否包含目标文本
  737. else:
  738. if isFind == 1:
  739. printLog(u"聚焦到目标option:%s成功!" % str(paths["option"]))
  740. return True
  741. # 判断两次识别的text是否相等来判断是否到达边界
  742. print u"move2TargetNode.text",text
  743. print u"move2TargetNode.old_text",old_text
  744. if self.ocr.cmpOcrStr(text, old_text):
  745. # 如果已经到达边界则不再正方向寻找焦点
  746. count = Max_Try
  747. old_text = "init_old_text"
  748. else:
  749. old_text = text
  750. if count < Max_Try:
  751. count = count + 1
  752. self.redRat3.sendKey(findDirection)
  753. else:
  754. Reversecount = Reversecount + 1
  755. self.redRat3.sendKey(findReverseDirection)
  756. errorPngName = "menutree_error_" + str(paths["option"]) + self.currentTime() + ".png"
  757. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  758. self.ccard.takePicture(error_uiPic)
  759. printLog(u"聚焦到目标option:%s失败!正向遍历%s次,和反向遍历%s次都没有聚焦到option:%s中,截图路径:%s" % (str(paths["option"]),
  760. str(Max_Try), str(Reverse_Max_Try),
  761. str(paths["option"]),
  762. str(error_uiPic)))
  763. return False
  764. # 设置叶子节点值;
  765. def setLeafNodeValue(self, level, first_parent, option, value_excel, value_for_ocr, value, move_key, enter_key,
  766. Max_Try=15):
  767. # 按照传入的方向寻找Max_Try次,如果仍未聚焦到option_for_ocr所在的区域,则按照传入方向的反方向 反向寻找 2*Max_Try 次
  768. # 正向寻找的次数计数和最大次数
  769. count = 0
  770. Max_Try = Max_Try
  771. # 反向寻找的次数计数和最大次数
  772. Reversecount = 0
  773. Reverse_Max_Try = Max_Try * 2
  774. # 记录上一个焦点识别的文字内容 用于判断是否到达列表的边界 如果到达边界则反向寻找
  775. old_text = "init_old_text"
  776. # 正向寻找的遥控器按键值
  777. findDirection = move_key[1] # 向右或者向下
  778. # 反向寻找的遥控器按键值
  779. findReverseDirection = move_key[0] # 向左或者向上
  780. # 获取等待时间
  781. waitTime = self.getLeafWaitTime(option)
  782. printLog(u"setLeafNodeValue:获取到进入叶节点%s,等待时间为%s"%(option, waitTime))
  783. time.sleep(waitTime)
  784. duration = 0.2
  785. isMarquee = False
  786. marquee_dict = {}
  787. leaf_data = self.uitRunner.uitData.UITree.get_value(option)
  788. if leaf_data["others"].__len__():
  789. data_other = json.loads(leaf_data["others"])
  790. # 是否有跑马灯文本;
  791. if "marquee" in data_other:
  792. marquee_dict = data_other['marquee']
  793. isMarquee = True
  794. # 是否有按键时间设置
  795. if "duration" in data_other:
  796. duration = float(data_other['duration'])
  797. printLog(u"读取到的设值间隔为%s"%duration)
  798. value_for_ocr_low = str(value_for_ocr[0]).lower()
  799. # 判断设置值的类型 是rang类型还是str类型
  800. if "range(" in value_for_ocr_low:
  801. isRangeType = True
  802. str_num = value_for_ocr_low.replace("range", "")
  803. list_num = eval(str_num)
  804. min_num = list_num[0]
  805. max_num = list_num[1]
  806. try:
  807. value_num = int(value)
  808. except Exception:
  809. printLog(u"传入的值value:%s和option:%s对应的类型不匹配 !" % (str(value), str(option)))
  810. return False
  811. else:
  812. isRangeType = False
  813. if isRangeType:
  814. # 设置数值范围类型的处理
  815. pass
  816. while (True):
  817. # 执行超过3次操作仍然失败则返回False
  818. if count > 3:
  819. break
  820. isFind, text, text_num = self.getCurrentFocusOcr_Int(level, first_parent, option=option,
  821. isForValue=True)
  822. if not isFind:
  823. errorPngName = "menutree_error_" + str(option) + str(value_excel) + self.currentTime() + ".png"
  824. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  825. self.ccard.takePicture(error_uiPic)
  826. printLog(u"设置叶子节点值时,当前界面无法找到焦点区域!!!getCurrentFocusOcr_Int出错界面截图%s" % str(error_uiPic))
  827. return False
  828. else:
  829. if text_num < min_num or text_num > max_num:
  830. errorPngName = "menutree_error_" + str(option) + '_' + str(
  831. value_excel) + self.currentTime() + ".png"
  832. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  833. self.ccard.takePicture(error_uiPic)
  834. printLog(u"设置叶子节点值时,当前option:%s 识别出来的值text:%s 不在value_for_ocr:%s范围内,截图为:%s" % (
  835. str(option), str(text), str(value_for_ocr), str(error_uiPic)))
  836. return False
  837. # if abs(text_num) == abs(value_num):
  838. if text_num == value_num:
  839. printLog(u"聚焦到目标option:%s,设置value:%s选项成功!" % (str(option), str(value_excel)))
  840. # 聚焦成功发送enter_key
  841. if enter_key != 'default':
  842. self.redRat3.sendKey(enter_key)
  843. return True
  844. else:
  845. if findDirection == 'input':
  846. # 发送按键;
  847. for key in list(str(value_num)):
  848. self.redRat3.sendKey(key, 1, duration)
  849. if max_num > 100:
  850. return True
  851. else:
  852. count = count + 1
  853. # 如果目标值大于现有值,则按正方向按键(向下或者向右)增加当前界面的值
  854. if value_num > text_num:
  855. self.redRat3.sendKey(findDirection, value_num - text_num, duration)
  856. # 如果目标值小于现有值,则按反方向按键(向上或者向左)减少当前界面的值
  857. if value_num < text_num:
  858. self.redRat3.sendKey(findReverseDirection, text_num - value_num, duration)
  859. errorPngName = "menutree_error_" + str(option) + '_' + str(value_excel) + self.currentTime() + ".png"
  860. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  861. self.ccard.takePicture(error_uiPic)
  862. printLog(u"设置叶子节点值时,当前option:%s 设置3次仍未设置到目标值value:%s,截图为:%s " % (str(option), str(value), str(error_uiPic)))
  863. return False
  864. else:
  865. # 设置选项类型的处理
  866. while (True):
  867. print "count:", count
  868. if count >= Max_Try and Reversecount >= Reverse_Max_Try:
  869. break
  870. if isMarquee is True:
  871. # 跑马灯函数需要cur_parent的参数,把cur_parent参数加入到leaf_data中再传进去
  872. result, paths = self.uitRunner.uitData.UITree.get_option(option)
  873. leaf_data['parent'] = paths['parent']
  874. leaf_data['option_for_ocr'] = leaf_data['value_for_ocr']
  875. isFind, text = self.getFocusBoxMarqueeText(marquee_dict, level, first_parent, leaf_data)
  876. else:
  877. isFind, text = self.getCurrentFocusTextEx(level, first_parent, option, value_excel, value_for_ocr,
  878. isForValue=True)
  879. if isFind == -1:
  880. errorPngName = "menutree_error_" + str(option) + '_' + str(
  881. value_excel) + self.currentTime() + ".png"
  882. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  883. self.ccard.takePicture(error_uiPic)
  884. printLog(u"设置叶子节点值时,当前界面无法找到焦点区域!!!getCurrentFocusTextEx 出错界面截图%s" % str(error_uiPic))
  885. return False
  886. # elif (self.ocr.cmpOcrStr(text, value_for_ocr)):
  887. # 由比较目标文本和识别文本 是否相等 改为 识别文本是否包含目标文本
  888. else:
  889. if isFind == 1:
  890. printLog(u"聚焦到目标option:%s,设置value:%s选项成功!" % (str(option), str(value_excel)))
  891. # 聚焦成功发送enter_key
  892. if enter_key != 'default':
  893. self.redRat3.sendKey(enter_key)
  894. return True
  895. # 判断两次识别
  896. # 判断两次识别的text是否相等来判断是否到达边界
  897. if self.ocr.cmpOcrStr(text, old_text):
  898. # 如果已经到达边界则不再正方向寻找焦点
  899. count = Max_Try
  900. old_text = "init_old_text"
  901. else:
  902. old_text = text
  903. if count < Max_Try:
  904. count = count + 1
  905. self.redRat3.sendKey(findDirection)
  906. else:
  907. Reversecount = Reversecount + 1
  908. self.redRat3.sendKey(findReverseDirection)
  909. errorPngName = "menutree_error_" + str(option) + '_' + str(value_excel) + self.currentTime() + ".png"
  910. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  911. self.ccard.takePicture(error_uiPic)
  912. printLog(u"设置叶子节点值时,正向遍历%s次,和反向遍历%s次都没有聚焦到option:%s的value:%s选项中,截图为%s" % (
  913. str(Max_Try), str(Reverse_Max_Try), str(option), str(value_excel), str(error_uiPic)))
  914. return False
  915. return True
  916. # 处理others字段;
  917. def dealOthers(self, level, path):
  918. others = json.loads(path['others'])
  919. if "password" in others:
  920. password = self.tconfig.get_value("Password", others["password"])
  921. # 发送密码前,停2秒(因为像6586机芯响应很慢,密码框还没弹出就完成了密码输入的操作);
  922. time.sleep(2)
  923. # 发送按键;
  924. for key in list(password):
  925. self.redRat3.sendKey(key, 1, 0.2)
  926. time.sleep(1)
  927. # 发送ok键;
  928. if others["enter_key"] != "default":
  929. self.redRat3.sendKey(others["enter_key"])
  930. # 判断是否成功输入密码;
  931. current_uiPic = self.getCurrentUIPath()
  932. # 此处findRectByIcon参数3传递的不是first_parent,而是当前option的parent;
  933. isFind, contourRect = self.tFocus.findRectByIcon(current_uiPic, level, path['parent'])
  934. return not isFind
  935. return False
  936. # 由于测试开始之前都切到黑屏背景,去掉聚焦效果OCR验证,3次焦点验证,验证到有聚焦效果就返回
  937. def isFirstOptionShow(self, level, first_parent, first_option):
  938. for i in range(3):
  939. current_uiPic = self.getCurrentUIPath()
  940. isFind, contourRect = self.tFocus.findRectByIcon2(current_uiPic, first_option)
  941. if isFind:
  942. return True
  943. return False
  944. # 对外接口:设置操作值;
  945. def setOptionValue(self, option, value, Max_Try=15, reTryTime=0, leafNodeValueWaitTime=0.0, returnKeyEventTimes=-1):
  946. # 切黑场;
  947. self.sourceInput.setPattern(11)
  948. printLog(u"开始执行setOptionValue。option:%s value:%s" % (str(option), str(value)))
  949. # 寻路结果;
  950. result = False
  951. # 获取menu path;
  952. value_params, path_params = self.uitPathManage.get_menu_paths(option, value)
  953. printLog(u"获取到达option:%s的路径字典path_params:%s" % (str(option), str(path_params)))
  954. printLog(u"获取设置value:%s的值字典value_params:%s" % (str(value), str(value_params)))
  955. checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
  956. if str(checkRunOptionPathResult) == "NoExit":
  957. printLog(u"表格中不存在到达Option: %s 的路径,在表格中排查到达该Option路径" % str(option))
  958. return False
  959. if str(checkRunOptionPathResult) == "Fail":
  960. printLog(u"表格中到达Option: %s 的路径出现数据断层找不到First层级,在表格中排查到达该Option路径" % str(option))
  961. return False
  962. # returnKeyEventCount = path_params.__len__() + 1
  963. returnKeyEventCount = 0
  964. print u"returnKeyEventCount:", returnKeyEventCount
  965. # 逆序路径key;
  966. revpp = reversed(path_params)
  967. # 根节点是否已进入;
  968. entry = False
  969. first_parent = u''
  970. first_option = u''
  971. # 遍历路径(已排序,从first开始);
  972. # print "revpp:", revpp
  973. for level in revpp:
  974. # print "level:", level, path_params[level]
  975. printLog(u"执行路径level:%s 对应路径字典:%s" % (str(level), str(path_params[level])))
  976. # 是否进入根结点;
  977. if entry == False:
  978. # 标记已进入根;
  979. entry = True
  980. first_parent = path_params[level]["parent"]
  981. first_option = path_params[level]["option"]
  982. checkFirstOptionTimes = 0
  983. while True:
  984. if checkFirstOptionTimes > 2:
  985. errorPngName = "menutree_error_" + str(option) + '_' + str(value) + self.currentTime() + ".png"
  986. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  987. self.ccard.takePicture(error_uiPic)
  988. printLog(u"执行setOptionValue ERROR!option:%s value:%s ;尝试3次快捷按键仍然没有唤出聚焦焦点界面!!! 出错截图:%s" % (
  989. str(option), str(value), str(error_uiPic)))
  990. return False
  991. printLog(u"第%s次尝试呼出一级界面" % str(checkFirstOptionTimes))
  992. # 判断是否存在others字段,others字段中存在first_key,则优先使用first_key进入
  993. try:
  994. others = json.loads(path_params[level]["others"])
  995. except Exception,e:
  996. others = {}
  997. printLog("section others:%s"%others)
  998. if "first_key" in others.keys():
  999. first_key = others["first_key"]
  1000. else:
  1001. first_key = path_params[level]["parent"]
  1002. printLog(u"进入根节点,first_key:%s"%first_key)
  1003. # 进入根节点
  1004. self.redRat3.sendKey(first_key)
  1005. waitTime = self.getParentWaitTime(path_params[level]["parent"])
  1006. printLog(u"打开%s界面的等待时间waittime为:%s" % (str(path_params[level]["parent"]), str(waitTime)))
  1007. time.sleep(waitTime)
  1008. # 获取ocr列表;
  1009. self.get_ocr_list(level, option)
  1010. if self.isFirstOptionShow(level, first_parent, first_option):
  1011. printLog(u"呼出一级菜单界面")
  1012. break
  1013. else:
  1014. time.sleep(5)
  1015. self.redRat3.sendKey("return", 1)
  1016. checkFirstOptionTimes = checkFirstOptionTimes + 1
  1017. # 如果一级界面弹出成功,则退出时候返回按键次数加1
  1018. returnKeyEventCount = returnKeyEventCount + 1
  1019. print u"level:", level, "first_parent:", first_parent
  1020. # 如果 others 字段不为空;
  1021. if path_params[level]["others"].__len__():
  1022. # 如果不是跑马灯处理则按照输入密码处理
  1023. if self.dealOthers(level, path_params[level]) is True:
  1024. # print u"解锁失败!!!"
  1025. printLog(u"执行setOptionValue ERROR!option:%s value:%s ;解锁失败!!!" % (str(option), str(value)))
  1026. return False
  1027. cur_option_enter_key = path_params[level]["option_enter_key"]
  1028. # 移动到子节点;
  1029. if cur_option_enter_key.__len__() == 0:
  1030. enter_key = path_params[level]["enter_key"]
  1031. else:
  1032. enter_key = cur_option_enter_key
  1033. move_key = path_params[level]["move_key"]
  1034. if str(move_key) == str([u'up', u'down']) or str(move_key) == str([u'down', u'up']):
  1035. findDirection = str(move_key[1])
  1036. elif str(move_key) == str([u'left', u'right']) or str(move_key) == str([u'right', u'left']):
  1037. findDirection = str(move_key[1])
  1038. else:
  1039. findDirection = 'grid'
  1040. result = self.move2TargetNode(
  1041. level,
  1042. first_parent,
  1043. path_params[level],
  1044. returnKeyEventCount,
  1045. findDirection=findDirection, Max_Try=Max_Try)
  1046. if result is True:
  1047. # 子节点的进入方式默认为ok;
  1048. if enter_key != u'default':
  1049. self.redRat3.sendKey(enter_key)
  1050. # 如果执行一次enter_key,则退出时按返回键的次数加一
  1051. returnKeyEventCount = returnKeyEventCount + 1
  1052. else:
  1053. break
  1054. # end-for
  1055. # 寻路成功,设置叶节点值;
  1056. if result is True:
  1057. # 如果是信源选择 自动选择不需要执行 enter_key
  1058. if self.ocr.cmpOcrStr(option, 'source'):
  1059. return True
  1060. time.sleep(leafNodeValueWaitTime)
  1061. print u"执行设置叶节点:", value_params
  1062. result = self.setLeafNodeValue(
  1063. level,
  1064. first_parent,
  1065. value_params["option"],
  1066. value_params["value"],
  1067. value_params["value_for_ocr"],
  1068. value,
  1069. value_params["move_key"],
  1070. value_params["enter_key"],
  1071. Max_Try=Max_Try)
  1072. # else:
  1073. if returnKeyEventTimes == -1:
  1074. print u"执行退出,执行退出按键次数returnKeyEventCount:", returnKeyEventCount
  1075. # 无论成功失败,要返回到初始界面
  1076. self.redRat3.sendKey("return", returnKeyEventCount, 0.2)
  1077. time.sleep(1)
  1078. # 检测执行回退键是否成功,吐过仍有聚焦效果则继续执行return键
  1079. reCount = 0
  1080. while True:
  1081. if reCount >= returnKeyEventCount:
  1082. printLog(u"执行了returnKeyEventCount:%s次,仍无法退出到初始界面" % str(returnKeyEventCount))
  1083. break
  1084. # isFind, text = self.getCurrentFocusText("First", first_parent)
  1085. # if isFind:
  1086. if self.isFirstOptionShow("First", first_parent, first_option):
  1087. print u"还没有退到初始界面"
  1088. reCount = reCount + 1
  1089. # 如果仍然可以检测到聚焦效果,则继续执行return
  1090. self.redRat3.sendKey("return")
  1091. else:
  1092. printLog(u"回退到初始界面成功!")
  1093. break
  1094. else:
  1095. print u"执行退出,执行退出按键次数returnKeyEventTimes:", returnKeyEventTimes
  1096. # 无论成功失败,要返回到初始界面
  1097. self.redRat3.sendKey("return", returnKeyEventTimes, 0.2)
  1098. if result:
  1099. printLog(u"设置option:%s 选中value:%s的值成功!" % (str(option), str(value)))
  1100. else:
  1101. printLog(u"重新设置option:%s 选中value:%s的值失败!" % (str(option), str(value)))
  1102. # 不再执行重试动作
  1103. # else:
  1104. # if reTryTime < 1:
  1105. # reTryTime = reTryTime + 1
  1106. # result = self.setOptionValue(option, value, reTryTime=reTryTime)
  1107. # if result:
  1108. # printLog(u"重新设置option:%s 选中value:%s的值成功!" % (str(option), str(value)))
  1109. # return True
  1110. # else:
  1111. # printLog(u"重新设置option:%s 选中value:%s的值失败!" % (str(option), str(value)))
  1112. # return False
  1113. # else:
  1114. # printLog(u"设置option:%s 选中value:%s的值尝试2次仍失败!" % (str(option), str(value)))
  1115. # return False
  1116. # 返回结果;
  1117. return result
  1118. # 对外接口:检测操作值是否正确;
  1119. def checkOptionValue(self, option, value, Max_Try=15, leafNodeValueWaitTime=0.0):
  1120. # 切黑场;
  1121. self.sourceInput.setPattern(11)
  1122. printLog(u"开始执行checkOptionValue。option:%s value:%s" % (str(option), str(value)))
  1123. # 寻路结果;
  1124. result = False
  1125. # 获取menu path;
  1126. value_params, path_params = self.uitPathManage.get_menu_paths(option, value)
  1127. printLog(u"获取到达option:%s的路径字典path_params:%s" % (str(option), str(path_params)))
  1128. printLog(u"获取检测value:%s的值字典value_params:%s" % (str(value), str(value_params)))
  1129. checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
  1130. if str(checkRunOptionPathResult) == "NoExit":
  1131. printLog(u"表格中不存在到达Option: %s 的路径,在表格中排查到达该Option路径" % str(option))
  1132. return False
  1133. if str(checkRunOptionPathResult) == "Fail":
  1134. printLog(u"表格中到达Option: %s 的路径出现数据断层找不到First层级,在表格中排查到达该Option路径" % str(option))
  1135. return False
  1136. # returnKeyEventCount = path_params.__len__() + 1
  1137. returnKeyEventCount = 0
  1138. print "returnKeyEventCount:", returnKeyEventCount
  1139. # 逆序路径key;
  1140. revpp = reversed(path_params)
  1141. # 根节点是否已进入;
  1142. entry = False
  1143. root = u''
  1144. first_parent = u''
  1145. first_option = u''
  1146. # 遍历路径(已排序,从first开始);
  1147. # print "revpp:", revpp
  1148. for level in revpp:
  1149. # print "level:", level, path_params[level]
  1150. printLog(u"执行路径level:%s 对应路径字典:%s" % (str(level), str(path_params[level])))
  1151. # 是否进入根结点;
  1152. if entry == False:
  1153. # 标记已进入根;
  1154. entry = True
  1155. first_parent = path_params[level]["parent"]
  1156. first_option = path_params[level]["option"]
  1157. checkFirstOptionTimes = 0
  1158. while True:
  1159. if checkFirstOptionTimes > 2:
  1160. errorPngName = "menutree_error_" + str(option) + '_' + str(value) + self.currentTime() + ".png"
  1161. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  1162. self.ccard.takePicture(error_uiPic)
  1163. printLog(u"执行checkOptionValue ERROR!option:%s value:%s ;尝试3次快捷按键仍然没有唤出聚焦焦点界面!!! 出错截图:%s" % (
  1164. str(option), str(value), str(error_uiPic)))
  1165. return False
  1166. printLog(u"第%s次尝试呼出一级界面" % str(checkFirstOptionTimes))
  1167. # # 进入根节点(根节点名就是遥控键名);
  1168. # self.redRat3.sendKey(path_params[level]["parent"])
  1169. # 判断是否存在others字段,others字段中存在first_key,则优先使用first_key进入
  1170. try:
  1171. others = json.loads(path_params[level]["others"])
  1172. except Exception,e:
  1173. others = {}
  1174. printLog("section others:%s"%others)
  1175. if "first_key" in others.keys():
  1176. first_key = others["first_key"]
  1177. else:
  1178. first_key = path_params[level]["parent"]
  1179. printLog(u"进入根节点,first_key:%s"%first_key)
  1180. # 进入根节点
  1181. self.redRat3.sendKey(first_key)
  1182. waitTime = self.getParentWaitTime(path_params[level]["parent"])
  1183. printLog(u"打开%s界面的等待时间waittime为:%s" % (str(path_params[level]["parent"]), str(waitTime)))
  1184. time.sleep(waitTime)
  1185. # 获取ocr列表;
  1186. self.get_ocr_list(level, option)
  1187. if self.isFirstOptionShow(level, first_parent, first_option):
  1188. printLog(u"呼出一级菜单界面")
  1189. break
  1190. else:
  1191. time.sleep(5)
  1192. self.redRat3.sendKey("return", 1)
  1193. checkFirstOptionTimes = checkFirstOptionTimes + 1
  1194. # 如果一级界面弹出成功,则退出时候返回按键次数加1
  1195. returnKeyEventCount = returnKeyEventCount + 1
  1196. # 如果 others 字段不为空;
  1197. if path_params[level]["others"].__len__():
  1198. # 如果不是跑马灯处理则按照输入密码处理
  1199. if self.dealOthers(level, path_params[level]) is True:
  1200. # print u"解锁失败!!!"
  1201. printLog(u"执行checkOptionValue ERROR!option:%s value:%s ;解锁失败!!!" % (str(option), str(value)))
  1202. return False
  1203. # 移动到子节点;
  1204. cur_option_enter_key = path_params[level]["option_enter_key"]
  1205. # 移动到子节点;
  1206. if cur_option_enter_key.__len__() == 0:
  1207. enter_key = path_params[level]["enter_key"]
  1208. else:
  1209. enter_key = cur_option_enter_key
  1210. move_key = path_params[level]["move_key"]
  1211. if str(move_key) == str([u'up', u'down']) or str(move_key) == str([u'down', u'up']):
  1212. findDirection = str(move_key[1])
  1213. elif str(move_key) == str([u'left', u'right']) or str(move_key) == str([u'right', u'left']):
  1214. findDirection = str(move_key[1])
  1215. else:
  1216. findDirection = 'grid'
  1217. result = self.move2TargetNode(
  1218. level,
  1219. first_parent,
  1220. path_params[level],
  1221. returnKeyEventCount,
  1222. findDirection=findDirection, Max_Try=Max_Try)
  1223. if result is True:
  1224. # 子节点的进入方式默认为ok;
  1225. # self.redRat3.sendKey('ok')
  1226. # 子节点的进入方式默认为ok;
  1227. if enter_key != u'default':
  1228. self.redRat3.sendKey(enter_key)
  1229. # 如果执行一次enter_key,则退出时按返回键的次数加一
  1230. returnKeyEventCount = returnKeyEventCount + 1
  1231. else:
  1232. break
  1233. # end-for
  1234. # 寻路成功,设置叶节点值;
  1235. if result is True:
  1236. # 如果是信源选择 自动选择不需要执行 enter_key
  1237. if self.ocr.cmpOcrStr(option, 'source') or self.ocr.cmpOcrStr(option, 'ok'):
  1238. return True
  1239. time.sleep(leafNodeValueWaitTime)
  1240. result = self.checkLeafNodeValue(level, root, value_params["option"],
  1241. value_params["value"],
  1242. value_params["value_for_ocr"],
  1243. value)
  1244. print u"执行退出,执行退出按键次数returnKeyEventCount:", returnKeyEventCount
  1245. # 无论成功失败,要返回到初始界面
  1246. self.redRat3.sendKey("return", returnKeyEventCount, 0.2)
  1247. time.sleep(1)
  1248. # 检测执行回退键是否成功,吐过仍有聚焦效果则继续执行return键
  1249. reCount = 0
  1250. while True:
  1251. if reCount >= returnKeyEventCount:
  1252. printLog(u"执行了returnKeyEventCount:%s次,仍无法退出到初始界面" % str(returnKeyEventCount))
  1253. break
  1254. if self.isFirstOptionShow("First", first_parent, first_option):
  1255. reCount = reCount + 1
  1256. # 如果仍然可以检测到聚焦效果,则继续执行return
  1257. self.redRat3.sendKey("return")
  1258. else:
  1259. printLog(u"回退到初始界面成功!")
  1260. break
  1261. if result:
  1262. printLog(u"检测option:%s 选中value:%s的值成功!" % (str(option), str(value)))
  1263. else:
  1264. printLog(u"检测option:%s 选中value:%s的值失败!" % (str(option), str(value)))
  1265. # 返回结果;
  1266. return result
  1267. def checkLeafNodeValue(self, level, parent, option, value_excel, value_for_ocr, value):
  1268. # 获取等待时间
  1269. waitTime = self.getOptionWaitTime(option)
  1270. printLog(u"checkLeafNodeValue:获取到进入叶节点%s,等待时间为%s"%(option, waitTime))
  1271. time.sleep(waitTime)
  1272. value_for_ocr_low = str(value_for_ocr[0]).lower()
  1273. # 判断设置值的类型 是rang类型还是str类型
  1274. if "range(" in value_for_ocr_low:
  1275. isRangeType = True
  1276. str_num = value_for_ocr_low.replace("range", "")
  1277. list_num = eval(str_num)
  1278. min_num = list_num[0]
  1279. max_num = list_num[1]
  1280. try:
  1281. value_num = int(value)
  1282. except Exception:
  1283. printLog(u"传入的值value:%S和option:%s对应的类型不匹配 !" % (str(value), str(option)))
  1284. return False
  1285. else:
  1286. isRangeType = False
  1287. if isRangeType:
  1288. # 设置数值范围类型的处理
  1289. isFind, text, text_num = self.getCurrentFocusOcr_Int(level, parent, option=option, isForValue=True)
  1290. if not isFind:
  1291. errorPngName = "menutree_error_" + str(option) + str(value_excel) + self.currentTime() + ".png"
  1292. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  1293. self.ccard.takePicture(error_uiPic)
  1294. printLog(u"检测叶子节点值时,当前界面无法找到焦点区域!!!出错界面截图%s" % str(error_uiPic))
  1295. return False
  1296. else:
  1297. pass
  1298. try:
  1299. list_text_num = getDigitFromString(text)
  1300. if list_text_num.__len__() < 1:
  1301. errorPngName = "menutree_error_" + str(option) + '_' + str(
  1302. value_excel) + self.currentTime() + ".png"
  1303. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  1304. self.ccard.takePicture(error_uiPic)
  1305. printLog(u"检测叶子节点值时,当前option:%s 识别出来的值text:%s 不包含int类型值,截图为:%s" % (
  1306. str(option), str(text), str(error_uiPic)))
  1307. return False
  1308. text_int_str = list_text_num[list_text_num.__len__() - 1]
  1309. # print 'text_int_str:', text_int_str
  1310. text_num = int(text_int_str)
  1311. printLog(u"检测到的值text_num:%s" % str(text_num))
  1312. except Exception:
  1313. errorPngName = "menutree_error_" + str(option) + '_' + str(
  1314. value_excel) + self.currentTime() + ".png"
  1315. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  1316. self.ccard.takePicture(error_uiPic)
  1317. printLog(u"检测叶子节点值时,当前option:%s 识别出来的值text:%s 不能转换成value_for_ocr:%s范围内的int类型,截图为:%s" % (
  1318. str(option), str(text_int_str), str(value_for_ocr), str(error_uiPic)))
  1319. return False
  1320. if text_num < min_num or text_num > max_num:
  1321. errorPngName = "menutree_error_" + str(option) + '_' + str(
  1322. value_excel) + self.currentTime() + ".png"
  1323. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  1324. self.ccard.takePicture(error_uiPic)
  1325. printLog(u"检测叶子节点值时,当前option:%s 识别出来的值text:%s 不在value_for_ocr:%s范围内,截图为:%s" % (
  1326. str(option), str(text), str(value_for_ocr), str(error_uiPic)))
  1327. return False
  1328. # if abs(text_num) == abs(value_num):
  1329. if text_num == value_num:
  1330. printLog(u"检测叶子节点值时,聚焦到目标option:%s,检测value:%s选项成功!" % (str(option), str(value_excel)))
  1331. return True
  1332. else:
  1333. return False
  1334. else:
  1335. # 设置选项类型的处理
  1336. isFind, text = self.getCurrentFocusTextEx(level, parent, option, value_excel, value_for_ocr,
  1337. isForValue=True)
  1338. if not isFind:
  1339. errorPngName = "menutree_error_" + str(option) + '_' + str(value_excel) + self.currentTime() + ".png"
  1340. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  1341. self.ccard.takePicture(error_uiPic)
  1342. printLog(u"检测叶子节点值时,当前界面无法找到焦点区域!!!出错界面截图:%s" % str(error_uiPic))
  1343. return False
  1344. # elif (self.ocr.cmpOcrStr(text, value_for_ocr)):
  1345. # 由比较目标文本和识别文本 是否相等 改为 识别文本是否包含目标文本
  1346. else:
  1347. for value_for_ocr_text in value_for_ocr:
  1348. value_for_ocr_text_low = str(value_for_ocr_text).lower()
  1349. if value_for_ocr_text_low in text:
  1350. printLog(u"检测叶子节点值时,聚焦到目标option:%s,检测value:%s选项成功!" % (str(option), str(value_excel)))
  1351. return True
  1352. errorPngName = "menutree_error_" + str(option) + '_' + str(value_excel) + self.currentTime() + ".png"
  1353. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  1354. self.ccard.takePicture(error_uiPic)
  1355. printLog(u"检测叶子节点值时,聚焦到目标option:%s,检测value:%s选项失败!出错界面截图:%s" % (
  1356. str(option), str(value_excel), str(error_uiPic)))
  1357. return False
  1358. # 对外接口:信源设置接口; 先切换再识别
  1359. '''
  1360. 不允许切换信源,在MenuTree.ini文件中配置:source={"offset":20,"minPeri":0,"maxPeri":0,"minArea":0,"maxArea":0,"enable":0}。
  1361. enable没有,默认值enable=1;enable=0,表示不允许切换信源,仅判断是否为目标信源。
  1362. '''
  1363. def setSourceValue(self, option, value, sourceWaitTime=1.0, Max_Try=10):
  1364. # 切黑场;
  1365. self.sourceInput.setPattern(11)
  1366. return self.tSource.setSourceValue(option, value, sourceWaitTime, Max_Try)
  1367. def inputUnlock(self, std_str, password=''):
  1368. # 如果锁住,按ok会弹出输入密码框;
  1369. self.redRat3.sendKey("ok")
  1370. # 获取密码;
  1371. if password.__len__() == 0:
  1372. password = self.tconfig.get_value("Password", "super")
  1373. # 发送按键;
  1374. for key in list(password):
  1375. self.redRat3.sendKey(key, 1, 0.2)
  1376. time.sleep(1)
  1377. # 发送ok键;
  1378. self.redRat3.sendKey('ok')
  1379. # 判断是否成功输入密码;
  1380. current_uiPic = self.getCurrentUIPath()
  1381. self.get_ocr_list("", "")
  1382. # 遍历ocr类型;
  1383. found = False
  1384. for item in self.ocrDict:
  1385. # 识别ocr;
  1386. ocr_str = self.ocr.getStrWithImgProcess(current_uiPic, {}, item["lan"], item["type"], reconTimes=1)
  1387. ocr_str = unicode(ocr_str).lower()
  1388. # print("lan=%s,type=%d,ocr=%s" % (item["lan"], item["type"], ocr_str))
  1389. printLog("lan=%s,type=%d,ocr=%s" % (item["lan"], item["type"], ocr_str))
  1390. if ocr_str in std_str or std_str == ocr_str:
  1391. found = True
  1392. break
  1393. return not found
  1394. def openOption(self, option, Max_Try=15):
  1395. # 切黑场;
  1396. self.sourceInput.setPattern(11)
  1397. # 获取menu path;
  1398. print "openOption start >>>"
  1399. path_params = self.uitPathManage.get_option_paths(option)
  1400. # print 'openOption=path_params:', path_params
  1401. printLog('openOption=path_params:%s' % str(path_params))
  1402. checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
  1403. if str(checkRunOptionPathResult) == "NoExit":
  1404. printLog(u"表格中不存在到达Option: %s 的路径,在表格中排查到达该Option路径" % str(option))
  1405. return False
  1406. if str(checkRunOptionPathResult) == "Fail":
  1407. printLog(u"表格中到达Option: %s 的路径出现数据断层找不到First层级,在表格中排查到达该Option路径" % str(option))
  1408. return False
  1409. # returnKeyEventCount = path_params.__len__() + 1
  1410. returnKeyEventCount = 0
  1411. print "returnKeyEventCount:", returnKeyEventCount
  1412. printLog("openOption=returnKeyEventCount:%s" % str(returnKeyEventCount))
  1413. # 逆序路径key;
  1414. revpp = reversed(path_params)
  1415. # 根节点是否已进入;
  1416. entry = False
  1417. first_parent = u''
  1418. first_option = u''
  1419. # 遍历路径(已排序,从first开始);
  1420. # print "revpp:", revpp
  1421. printLog("openOption=revpp:%s" % str(revpp))
  1422. for level in revpp:
  1423. # print "openOption=level:", path_params[level]
  1424. printLog("openOption=level:", path_params[level])
  1425. # 是否进入根结点;
  1426. if entry == False:
  1427. # 标记已进入根;
  1428. entry = True
  1429. first_parent = path_params[level]["parent"]
  1430. first_option = path_params[level]["option"]
  1431. checkFirstOptionTimes = 0
  1432. while True:
  1433. if checkFirstOptionTimes > 2:
  1434. printLog(u"openOption=尝试3次快捷按键没有唤出聚焦焦点界面!!!")
  1435. return False
  1436. printLog(u"第%s次尝试呼出一级界面" % str(checkFirstOptionTimes))
  1437. # # 进入根节点(根节点名就是遥控键名);
  1438. # self.redRat3.sendKey(path_params[level]["parent"])
  1439. # 判断是否存在others字段,others字段中存在first_key,则优先使用first_key进入
  1440. try:
  1441. others = json.loads(path_params[level]["others"])
  1442. except Exception,e:
  1443. others = {}
  1444. printLog("section others:%s"%others)
  1445. if "first_key" in others.keys():
  1446. first_key = others["first_key"]
  1447. else:
  1448. first_key = path_params[level]["parent"]
  1449. printLog(u"进入根节点,first_key:%s"%first_key)
  1450. # 进入根节点
  1451. self.redRat3.sendKey(first_key)
  1452. waitTime = self.getParentWaitTime(path_params[level]["parent"])
  1453. printLog(u"打开%s界面的等待时间waittime为:%s" % (str(path_params[level]["parent"]), str(waitTime)))
  1454. time.sleep(waitTime)
  1455. # 获取ocr列表;
  1456. self.get_ocr_list(level, option)
  1457. if self.isFirstOptionShow(level, first_parent, first_option):
  1458. printLog(u"呼出一级菜单界面")
  1459. break
  1460. else:
  1461. time.sleep(5)
  1462. self.redRat3.sendKey("return", 2)
  1463. checkFirstOptionTimes = checkFirstOptionTimes + 1
  1464. # 如果一级界面弹出成功,则退出时候返回按键次数加1
  1465. returnKeyEventCount = returnKeyEventCount + 1
  1466. # 如果 others 字段不为空;
  1467. if path_params[level]["others"].__len__():
  1468. # 如果不是跑马灯处理则按照输入密码处理
  1469. if self.dealOthers(level, path_params[level]) is True:
  1470. # print u"解锁失败!!!"
  1471. printLog(u"openOption=解锁失败!!!")
  1472. return False
  1473. # 移动到子节点;
  1474. cur_option_enter_key = path_params[level]["option_enter_key"]
  1475. # 移动到子节点;
  1476. if cur_option_enter_key.__len__() == 0:
  1477. enter_key = path_params[level]["enter_key"]
  1478. else:
  1479. enter_key = cur_option_enter_key
  1480. move_key = path_params[level]["move_key"]
  1481. if str(move_key) == str([u'up', u'down']) or str(move_key) == str([u'down', u'up']):
  1482. findDirection = str(move_key[1])
  1483. elif str(move_key) == str([u'left', u'right']) or str(move_key) == str([u'right', u'left']):
  1484. findDirection = str(move_key[1])
  1485. else:
  1486. findDirection = 'grid'
  1487. result = self.move2TargetNode(
  1488. level,
  1489. first_parent,
  1490. path_params[level],
  1491. returnKeyEventCount,
  1492. findDirection=findDirection, Max_Try=Max_Try)
  1493. if result is True:
  1494. # 子节点的进入方式默认为ok;
  1495. self.redRat3.sendKey(enter_key)
  1496. # 如果执行一次enter_key,则退出时按返回键的次数加一
  1497. if enter_key != u'default':
  1498. returnKeyEventCount = returnKeyEventCount + 1
  1499. else:
  1500. print "openOption end<<<<"
  1501. return False
  1502. # end-for
  1503. print "openOption end <<<<"
  1504. return True
  1505. # 对外接口:检测频道列表;
  1506. def checkChannelList(self, channelList, Max_Try=15):
  1507. failChannelList = []
  1508. checkResult = True
  1509. if channelList == []:
  1510. printLog(u"传入的待检测的频道列表为空!")
  1511. return False, failChannelList
  1512. for channel in channelList:
  1513. isSearched = self.checkOptionValue("ok", channel, Max_Try=Max_Try)
  1514. if not isSearched:
  1515. printLog(u"频道:%s查找失败!" % str(channel))
  1516. failChannelList.append(channel)
  1517. checkResult = False
  1518. # 部分机芯项目(如6586外协松下)按return键无法退出频道,故改为exit键
  1519. # self.redRat3.sendKey("return")
  1520. self.redRat3.sendKey("exit")
  1521. else:
  1522. printLog(u"频道:%s查找成功!" % str(channel))
  1523. self.redRat3.sendKey("exit")
  1524. printLog(u"频道列表检测结果checkResult:%s,检测失败频道列表failChannelLis:%s" % (str(checkResult), str(failChannelList)))
  1525. return checkResult, failChannelList
  1526. # 对外唯一接口:设置操作值;
  1527. def focusOptionValue(self, option, value, Max_Try=15, leafNodeValueWaitTime=0.0):
  1528. # 切黑场;
  1529. self.sourceInput.setPattern(11)
  1530. printLog(u"focusOptionValue。option:%s value:%s" % (str(option), str(value)))
  1531. # 寻路结果;
  1532. result = False
  1533. # 获取menu path;
  1534. value_params, path_params = self.uitPathManage.get_menu_paths(option, value)
  1535. printLog(u"获取到达option:%s的路径字典path_params:%s" % (str(option), str(path_params)))
  1536. printLog(u"获取聚焦value:%s的值字典value_params:%s" % (str(value), str(value_params)))
  1537. checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
  1538. if str(checkRunOptionPathResult) == "NoExit":
  1539. printLog(u"表格中不存在到达Option: %s 的路径,在表格中排查到达该Option路径" % str(option))
  1540. return False
  1541. if str(checkRunOptionPathResult) == "Fail":
  1542. printLog(u"表格中到达Option: %s 的路径出现数据断层找不到First层级,在表格中排查到达该Option路径" % str(option))
  1543. return False
  1544. # returnKeyEventCount = path_params.__len__() + 1
  1545. returnKeyEventCount = 0
  1546. print "returnKeyEventCount:", returnKeyEventCount
  1547. # 逆序路径key;
  1548. revpp = reversed(path_params)
  1549. # 根节点是否已进入;
  1550. entry = False
  1551. root = u''
  1552. first_parent = u''
  1553. first_option = u''
  1554. # 遍历路径(已排序,从first开始);
  1555. # print "revpp:", revpp
  1556. for level in revpp:
  1557. # print "level:", level, path_params[level]
  1558. printLog(u"执行路径level:%s 对应路径字典:%s" % (str(level), str(path_params[level])))
  1559. # 是否进入根结点;
  1560. if entry == False:
  1561. # 标记已进入根;
  1562. entry = True
  1563. first_parent = path_params[level]["parent"]
  1564. first_option = path_params[level]["option"]
  1565. checkFirstOptionTimes = 0
  1566. while True:
  1567. if checkFirstOptionTimes > 2:
  1568. errorPngName = "menutree_error_" + str(option) + '_' + str(value) + self.currentTime() + ".png"
  1569. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  1570. self.ccard.takePicture(error_uiPic)
  1571. printLog(u"执行focusOptionValue ERROR!option:%s value:%s ;尝试3次快捷按键仍然没有唤出聚焦焦点界面!!! 出错截图:%s" % (
  1572. str(option), str(value), str(error_uiPic)))
  1573. return False
  1574. printLog(u"第%s次尝试呼出一级界面" % str(checkFirstOptionTimes))
  1575. # # 进入根节点(根节点名就是遥控键名);
  1576. # self.redRat3.sendKey(path_params[level]["parent"])
  1577. # 判断是否存在others字段,others字段中存在first_key,则优先使用first_key进入
  1578. try:
  1579. others = json.loads(path_params[level]["others"])
  1580. except Exception,e:
  1581. others = {}
  1582. printLog("section others:%s"%others)
  1583. if "first_key" in others.keys():
  1584. first_key = others["first_key"]
  1585. else:
  1586. first_key = path_params[level]["parent"]
  1587. printLog(u"进入根节点,first_key:%s"%first_key)
  1588. # 进入根节点
  1589. self.redRat3.sendKey(first_key)
  1590. waitTime = self.getParentWaitTime(path_params[level]["parent"])
  1591. printLog(u"打开%s界面的等待时间waittime为:%s" % (str(path_params[level]["parent"]), str(waitTime)))
  1592. time.sleep(waitTime)
  1593. # 获取ocr列表;
  1594. self.get_ocr_list(level, option)
  1595. if self.isFirstOptionShow(level, first_parent, first_option):
  1596. printLog(u"呼出一级菜单界面")
  1597. break
  1598. else:
  1599. time.sleep(5)
  1600. self.redRat3.sendKey("return", 2)
  1601. checkFirstOptionTimes = checkFirstOptionTimes + 1
  1602. # 如果一级界面弹出成功,则退出时候返回按键次数加1
  1603. returnKeyEventCount = returnKeyEventCount + 1
  1604. print "level:", level, "root:", root
  1605. # 如果 others 字段不为空;
  1606. if path_params[level]["others"].__len__():
  1607. # 如果不是跑马灯处理则按照输入密码处理
  1608. if self.dealOthers(level, path_params[level]) is True:
  1609. # print u"解锁失败!!!"
  1610. printLog(u"执行setOptionValue ERROR!option:%s value:%s ;解锁失败!!!" % (str(option), str(value)))
  1611. return False
  1612. # 移动到子节点;
  1613. cur_option_enter_key = path_params[level]["option_enter_key"]
  1614. # 移动到子节点;
  1615. if cur_option_enter_key.__len__() == 0:
  1616. enter_key = path_params[level]["enter_key"]
  1617. else:
  1618. enter_key = cur_option_enter_key
  1619. move_key = path_params[level]["move_key"]
  1620. if str(move_key) == str([u'up', u'down']) or str(move_key) == str([u'down', u'up']):
  1621. findDirection = str(move_key[1])
  1622. elif str(move_key) == str([u'left', u'right']) or str(move_key) == str([u'right', u'left']):
  1623. findDirection = str(move_key[1])
  1624. else:
  1625. findDirection = 'grid'
  1626. result = self.move2TargetNode(
  1627. level,
  1628. first_parent,
  1629. path_params[level],
  1630. returnKeyEventCount,
  1631. findDirection=findDirection, Max_Try=Max_Try)
  1632. if result is True:
  1633. # 子节点的进入方式默认为ok;
  1634. # self.redRat3.sendKey('ok')
  1635. # 如果只一层,不进行enter_key执行
  1636. if path_params.__len__() != 1:
  1637. self.redRat3.sendKey(enter_key)
  1638. # 如果执行一次enter_key,则退出时按返回键的次数加一
  1639. if enter_key != u'default':
  1640. returnKeyEventCount = returnKeyEventCount + 1
  1641. else:
  1642. break
  1643. # end-for
  1644. # 如果只一层不进行focusLeafNodeValue设置
  1645. if path_params.__len__() != 1:
  1646. # 寻路成功,设置叶节点值;
  1647. if result is True:
  1648. # 如果是信源选择 自动选择不需要执行 enter_key
  1649. if self.ocr.cmpOcrStr(option, 'source'):
  1650. return True
  1651. time.sleep(leafNodeValueWaitTime)
  1652. print u"执行设置叶节点:", value_params
  1653. result = self.focusLeafNodeValue(
  1654. level,
  1655. root,
  1656. value_params["option"],
  1657. value_params["value"],
  1658. value_params["value_for_ocr"],
  1659. value,
  1660. value_params["move_key"],
  1661. value_params["enter_key"],
  1662. Max_Try=Max_Try)
  1663. # 无论成功失败,要返回到初始界面
  1664. if result:
  1665. # 如果执行成功则不返回到初始界面
  1666. printLog(u"设置option:%s 选中value:%s的值成功!" % (str(option), str(value)))
  1667. else:
  1668. printLog(u"设置option:%s 选中value:%s的值失败!" % (str(option), str(value)))
  1669. print u"执行退出,执行退出按键次数returnKeyEventCount:", returnKeyEventCount
  1670. # 执行聚焦失败时候,返回到初始界面
  1671. self.redRat3.sendKey("return", returnKeyEventCount, 0.2)
  1672. time.sleep(1)
  1673. # 检测执行回退键是否成功,吐过仍有聚焦效果则继续执行return键
  1674. reCount = 0
  1675. while True:
  1676. if reCount >= returnKeyEventCount:
  1677. printLog(u"执行了returnKeyEventCount:%s次,仍无法退出到初始界面" % str(returnKeyEventCount))
  1678. break
  1679. if self.isFirstOptionShow("First", first_parent, first_option):
  1680. reCount = reCount + 1
  1681. # 如果仍然可以检测到聚焦效果,则继续执行return
  1682. self.redRat3.sendKey("return")
  1683. else:
  1684. printLog(u"回退到初始界面成功!")
  1685. break
  1686. # 返回结果;
  1687. return result
  1688. # 设置叶子节点值;
  1689. def focusLeafNodeValue(self, level, parent, option, value_excel, value_for_ocr, value, move_key, enter_key,
  1690. Max_Try=15):
  1691. # 按照传入的方向寻找Max_Try次,如果仍未聚焦到option_for_ocr所在的区域,则按照传入方向的反方向 反向寻找 2*Max_Try 次
  1692. # 正向寻找的次数计数和最大次数
  1693. count = 0
  1694. Max_Try = Max_Try
  1695. # 反向寻找的次数计数和最大次数
  1696. Reversecount = 0
  1697. Reverse_Max_Try = Max_Try * 2
  1698. # 记录上一个焦点识别的文字内容 用于判断是否到达列表的边界 如果到达边界则反向寻找
  1699. old_text = "init_old_text"
  1700. # 正向寻找的遥控器按键值
  1701. findDirection = move_key[1] # 向右或者向下
  1702. # 反向寻找的遥控器按键值
  1703. findReverseDirection = move_key[0] # 向左或者向上
  1704. # 获取等待时间
  1705. waitTime = self.getLeafWaitTime(option)
  1706. printLog(u"focusLeafNodeValue:获取到进入叶节点%s,等待时间为%s"%(option, waitTime))
  1707. time.sleep(waitTime)
  1708. value_for_ocr_low = str(value_for_ocr[0]).lower()
  1709. # 判断设置值的类型 是rang类型还是str类型
  1710. if "range(" in value_for_ocr_low:
  1711. isRangeType = True
  1712. str_num = value_for_ocr_low.replace("range", "")
  1713. list_num = eval(str_num)
  1714. min_num = list_num[0]
  1715. max_num = list_num[1]
  1716. try:
  1717. value_num = int(value)
  1718. except Exception:
  1719. printLog(u"传入的值value:%s和option:%s对应的类型不匹配 !" % (str(value), str(option)))
  1720. return False
  1721. else:
  1722. isRangeType = False
  1723. if isRangeType:
  1724. # 如果是数值类型,则直接返回聚焦成功
  1725. return True
  1726. else:
  1727. # 设置选项类型的处理
  1728. while (True):
  1729. print "count:", count
  1730. if count >= Max_Try and Reversecount >= Reverse_Max_Try:
  1731. break
  1732. isFind, text = self.getCurrentFocusTextEx(level, parent, option, value_excel, value_for_ocr,
  1733. isForValue=True)
  1734. if isFind == -1:
  1735. errorPngName = "menutree_error_" + str(option) + '_' + str(
  1736. value_excel) + self.currentTime() + ".png"
  1737. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  1738. self.ccard.takePicture(error_uiPic)
  1739. printLog(u"聚焦叶子节点值时,当前界面无法找到焦点区域!!!出错界面截图%s" % str(error_uiPic))
  1740. return False
  1741. # elif (self.ocr.cmpOcrStr(text, value_for_ocr)):
  1742. # 由比较目标文本和识别文本 是否相等 改为 识别文本是否包含目标文本
  1743. else:
  1744. if isFind == 1:
  1745. printLog(u"聚焦到目标option:%s,设置value:%s选项成功!" % (str(option), str(value_excel)))
  1746. # 聚焦到某个焦点成功,由于是聚焦接口调用,不用send enter_key进入到焦点
  1747. # if enter_key != 'default':
  1748. # self.redRat3.sendKey(enter_key)
  1749. return True
  1750. # 判断两次识别
  1751. # 判断两次识别的text是否相等来判断是否到达边界
  1752. if self.ocr.cmpOcrStr(text, old_text):
  1753. # 如果已经到达边界则不再正方向寻找焦点
  1754. count = Max_Try
  1755. old_text = "init_old_text"
  1756. else:
  1757. old_text = text
  1758. if count < Max_Try:
  1759. count = count + 1
  1760. self.redRat3.sendKey(findDirection)
  1761. else:
  1762. Reversecount = Reversecount + 1
  1763. self.redRat3.sendKey(findReverseDirection)
  1764. errorPngName = "menutree_error_" + str(option) + '_' + str(value_excel) + self.currentTime() + ".png"
  1765. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  1766. self.ccard.takePicture(error_uiPic)
  1767. printLog(u"聚焦叶子节点值时,正向遍历%s次,和反向遍历%s次都没有聚焦到option:%s的value:%s选项中,截图为%s" % (
  1768. str(Max_Try), str(Reverse_Max_Try), str(option), str(value_excel), str(error_uiPic)))
  1769. return False
  1770. return True
  1771. def getOptionValue(self, option, is_value_sheet=True):
  1772. # 切黑场;
  1773. self.sourceInput.setPattern(11)
  1774. # 获取路径参数;
  1775. result, option_data = self.uitRunner.uitData.UITree.get_option(option)
  1776. if result is False:
  1777. print(u"getOptionValue.获取option菜单内容失败")
  1778. return False, ''
  1779. first_parent = option_data['first_parent']
  1780. thresholdDict = self.tconfig.getThresholdDict(first_parent)
  1781. # 根据parent打开特定的option;
  1782. if self.openOption(option) is False:
  1783. self.redRat3.sendKey('return', option_data['layers'] + 1, 0.2)
  1784. print(u"getOptionValue.进入指定option失败")
  1785. return False, ''
  1786. # 获取等待时间
  1787. waitTime = self.getOptionWaitTime(option)
  1788. printLog(u"getOptionValue:获取到进入叶节点%s,等待时间为%s"%(option, waitTime))
  1789. time.sleep(waitTime)
  1790. time.sleep(0.5)
  1791. # 截图;
  1792. current_uiPic = self.getCurrentUIPath()
  1793. # 获取焦点框;
  1794. result, opcfg = self.tFocus.getOptionConfig(option, is_value_sheet)
  1795. if result is False:
  1796. self.redRat3.sendKey('return', option_data['layers'] + 1, 0.2)
  1797. print(u"getOptionValue.获取焦点参数失败")
  1798. return False, ''
  1799. dcfg = opcfg['dcfg']
  1800. icon_path = opcfg['icon_path']
  1801. icon_dir_path = opcfg['dir_path']
  1802. # 获取聚集框;
  1803. result, cur_box = self.tFocus.findFocusByIcon(current_uiPic, icon_path, dcfg)
  1804. if result is False:
  1805. self.redRat3.sendKey('return', option_data['layers'] + 1, 0.2)
  1806. print(u"getOptionValue.获取焦点框轮廓失败")
  1807. return False, ''
  1808. # 根据dir计算文本框;
  1809. cur_box = self.getFocusTextBox4(icon_dir_path, option, cur_box, is_value_sheet)
  1810. # 获取文本区域截图;
  1811. ocr_result_text = ''
  1812. txt_pic = os.path.join(getSATTmpDIR(), "meuttree_area_text.png")
  1813. self.imgCMP.saveCropPic(current_uiPic, txt_pic, (cur_box[0], cur_box[1], cur_box[2], cur_box[3]))
  1814. if is_value_sheet is True:
  1815. value_paramters = self.uitRunner.uitData.UITree.get_value(option, '')
  1816. isRangeType = False
  1817. # 判断设置值的类型 是rang类型还是str类型
  1818. if value_paramters['value_for_ocr'].__len__() and "range(" in value_paramters['value_for_ocr'][0].lower():
  1819. isRangeType = True
  1820. if isRangeType is True:
  1821. # 获取ocr列表;
  1822. hasOption,path = self.uitRunner.uitData.UITree.get_option(option)
  1823. if hasOption:
  1824. self.get_ocr_list(path['level'], option)
  1825. for orc_item in self.ocrDict:
  1826. # ocr_result = self.ocr.getStr(txt_pic, orc_item["lan"], orc_item["type"])
  1827. ocr_result = self.ocr.getStrWithImgProcess(txt_pic, thresholdDict, orc_item["lan"],
  1828. orc_item["type"],
  1829. reconTimes=1)
  1830. # print("getCurrentFocusOcr_Int=ocr识别结果=%s" % (ocr_result))
  1831. printLog("getCurrentFocusOcr_Int=ocr识别结果=%s" % (ocr_result))
  1832. if ocr_result == "ERR<Exp>" or ocr_result.__len__() == 0:
  1833. continue
  1834. # 字符串去掉末尾">"符号;
  1835. ocr_result = ocr_result.strip('>')
  1836. # 按数字分解多组文本;
  1837. list_ocr = getDigitFromString(ocr_result)
  1838. # list_ocr = self.strSplit(ocr_result)
  1839. # 只判断最后一位是否是数字;
  1840. if list_ocr.__len__() < 1:
  1841. errorPngName = "menutree_error_" + self.currentTime() + "ocr.png"
  1842. error_uiPic = os.path.join(getSATTmpDIR(), errorPngName)
  1843. self.ccard.takePicture(error_uiPic)
  1844. # print u"当前识别的ocr 不包含int类型值,截图为:%s" % (str(ocr_result))
  1845. printLog(u"当前识别的ocr 不包含int类型值,截图为:%s" % (str(ocr_result)))
  1846. continue
  1847. try:
  1848. # 获取最右边的文本,如果是数字则退出;
  1849. text_int_str = list_ocr[list_ocr.__len__() - 1]
  1850. # print 'text_int_str:', text_int_str
  1851. printLog('text_int_str:%s' % str(text_int_str))
  1852. ocr_result_text = float(text_int_str)
  1853. break
  1854. except Exception:
  1855. continue
  1856. else:
  1857. # 普通ocr文本识别;
  1858. # ocr_result_text = self.ocr.getStr(txt_pic, "ChinesePRC+English", 4)
  1859. ocr_result_text = self.ocr.getStrWithImgProcess(txt_pic, thresholdDict, "ENG", 10000,
  1860. reconTimes=1)
  1861. else:
  1862. # 普通ocr文本识别;
  1863. # ocr_result_text = self.ocr.getStr(txt_pic, "ChinesePRC+English", 4)
  1864. ocr_result_text = self.ocr.getStrWithImgProcess(txt_pic, thresholdDict, "ENG", 10000,
  1865. reconTimes=1)
  1866. # 退出菜单;
  1867. self.redRat3.sendKey('return', option_data['layers'] + 1, 0.2)
  1868. # 返回结果;
  1869. return True, ocr_result_text
  1870. def getParentWaitTime(self, parent):
  1871. optionName = parent + "WaitTime"
  1872. try:
  1873. waitTime = float(self.tconfig.get_value("waitTime", optionName))
  1874. except Exception:
  1875. waitTime = 1.0
  1876. # print "获取%s界面的等待界面时间失败,使用默认值1.0s" % str(parent)
  1877. return waitTime
  1878. def getOptionWaitTime(self, option):
  1879. result, option_data = self.uitRunner.uitData.UITree.get_option(option)
  1880. print u"getOptionWaitTime.option_data:",option_data
  1881. if result:
  1882. try:
  1883. others = json.loads(option_data['others'])
  1884. waitTime = float(others['waitTime'])
  1885. except Exception,e:
  1886. print u"获取%s界面的等待时间失败,使用默认值1.0s" % str(option)
  1887. waitTime = 1.0
  1888. else:
  1889. waitTime = 1.0
  1890. return waitTime
  1891. def getLeafWaitTime(self, option):
  1892. leaf_data = self.uitRunner.uitData.UITree.get_value(option)
  1893. print u"getLeafWaitTime.option_data:",leaf_data
  1894. try:
  1895. others = json.loads(leaf_data['others'])
  1896. waitTime = float(others['waitTime'])
  1897. except Exception,e:
  1898. print u"获取%s界面的等待时间失败,使用默认值1.0s" % str(option)
  1899. waitTime = 1.0
  1900. return waitTime
  1901. # channel_count:如果有频道,最大可能的频道数量;
  1902. # black_th:黑色频道背景色RGB单通道值
  1903. # black_rate:图片分割成100块,纯黑色区域占有比
  1904. def getBlackChannel(self, channel_count, black_th=20, black_rate=0.8):
  1905. result = False
  1906. # 根据频道数量遍历;
  1907. for i in range(0, channel_count):
  1908. pass
  1909. # 截图,取左半边;
  1910. pic_path = self.getCurrentUIPath()
  1911. img = cv.imread(pic_path)
  1912. pic_path2 = os.path.join(getSATTmpDIR(), "menutree_focus_area_half.png")
  1913. self.imgCMP.saveCropPic(pic_path, pic_path2, (0, 0, img.shape[1] / 2, img.shape[0]))
  1914. # 是否符合要求;
  1915. result = self.imgCMP.isBlack(pic_path2, black_th, 10, 1 - black_rate)
  1916. if result is True:
  1917. break
  1918. # 下一频道号;
  1919. self.redRat3.sendKey('C+')
  1920. time.sleep(4)
  1921. # endfor
  1922. return result
  1923. # 新增操作接口
  1924. # 聚焦到Option 区别于openOption,focusOption不会执行到option的子界面中
  1925. def focusOption(self, option, Max_Try=15):
  1926. # 切黑场;
  1927. self.sourceInput.setPattern(11)
  1928. # 获取menu path;
  1929. print u"focusOption start >>>"
  1930. path_params = self.uitPathManage.get_option_paths(option)
  1931. # print 'openOption=path_params:', path_params
  1932. printLog('focusOption=path_params:%s' % str(path_params))
  1933. checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
  1934. if str(checkRunOptionPathResult) == "NoExit":
  1935. printLog(u"表格中不存在到达Option: %s 的路径,在表格中排查到达该Option路径" % str(option))
  1936. return False
  1937. if str(checkRunOptionPathResult) == "Fail":
  1938. printLog(u"表格中到达Option: %s 的路径出现数据断层找不到First层级,在表格中排查到达该Option路径" % str(option))
  1939. return False
  1940. runPathCount = 0
  1941. pathCount = path_params.__len__()
  1942. printLog("focusOption=pathCount:%s" % str(pathCount))
  1943. # returnKeyEventCount = path_params.__len__() + 1
  1944. returnKeyEventCount = 0
  1945. print "returnKeyEventCount:", returnKeyEventCount
  1946. printLog("focusOption=returnKeyEventCount:%s" % str(returnKeyEventCount))
  1947. # 逆序路径key;
  1948. revpp = reversed(path_params)
  1949. # 根节点是否已进入;
  1950. entry = False
  1951. first_parent = u''
  1952. first_option = u''
  1953. # 遍历路径(已排序,从first开始);
  1954. # print "revpp:", revpp
  1955. printLog("focusOption=revpp:%s" % str(revpp))
  1956. for level in revpp:
  1957. # print "openOption=level:", path_params[level]
  1958. printLog("focusOption=level:", path_params[level])
  1959. # 是否进入根结点;
  1960. if entry == False:
  1961. # 标记已进入根;
  1962. entry = True
  1963. first_parent = path_params[level]["parent"]
  1964. first_option = path_params[level]["option"]
  1965. checkFirstOptionTimes = 0
  1966. while True:
  1967. if checkFirstOptionTimes > 2:
  1968. printLog(u"focusOption=尝试3次快捷按键没有唤出聚焦焦点界面!!!")
  1969. return False
  1970. printLog(u"第%s次尝试呼出一级界面" % str(checkFirstOptionTimes))
  1971. # # 进入根节点(根节点名就是遥控键名);
  1972. # self.redRat3.sendKey(path_params[level]["parent"])
  1973. # 判断是否存在others字段,others字段中存在first_key,则优先使用first_key进入
  1974. try:
  1975. others = json.loads(path_params[level]["others"])
  1976. except Exception,e:
  1977. others = {}
  1978. printLog("section others:%s"%others)
  1979. if "first_key" in others.keys():
  1980. first_key = others["first_key"]
  1981. else:
  1982. first_key = path_params[level]["parent"]
  1983. printLog(u"进入根节点,first_key:%s"%first_key)
  1984. # 进入根节点
  1985. self.redRat3.sendKey(first_key)
  1986. waitTime = self.getParentWaitTime(path_params[level]["parent"])
  1987. printLog(u"打开%s界面的等待时间waittime为:%s" % (str(path_params[level]["parent"]), str(waitTime)))
  1988. time.sleep(waitTime)
  1989. # 获取ocr列表;
  1990. self.get_ocr_list(level, option)
  1991. if self.isFirstOptionShow(level, first_parent, first_option):
  1992. printLog(u"呼出一级菜单界面")
  1993. break
  1994. else:
  1995. time.sleep(5)
  1996. self.redRat3.sendKey("return", 2)
  1997. checkFirstOptionTimes = checkFirstOptionTimes + 1
  1998. # 如果一级界面弹出成功,则退出时候返回按键次数加1
  1999. returnKeyEventCount = returnKeyEventCount + 1
  2000. # 如果 others 字段不为空;
  2001. if path_params[level]["others"].__len__():
  2002. # 如果不是跑马灯处理则按照输入密码处理
  2003. if self.dealOthers(level, path_params[level]) is True:
  2004. # print u"解锁失败!!!"
  2005. printLog(u"focusOption=解锁失败!!!")
  2006. return False
  2007. # 移动到子节点;
  2008. cur_option_enter_key = path_params[level]["option_enter_key"]
  2009. # 移动到子节点;
  2010. if cur_option_enter_key.__len__() == 0:
  2011. enter_key = path_params[level]["enter_key"]
  2012. else:
  2013. enter_key = cur_option_enter_key
  2014. move_key = path_params[level]["move_key"]
  2015. if str(move_key) == str([u'up', u'down']) or str(move_key) == str([u'down', u'up']):
  2016. findDirection = str(move_key[1])
  2017. elif str(move_key) == str([u'left', u'right']) or str(move_key) == str([u'right', u'left']):
  2018. findDirection = str(move_key[1])
  2019. else:
  2020. findDirection = 'grid'
  2021. result = self.move2TargetNode(
  2022. level,
  2023. first_parent,
  2024. path_params[level],
  2025. returnKeyEventCount,
  2026. findDirection=findDirection, Max_Try=Max_Try)
  2027. if result is True:
  2028. runPathCount = runPathCount + 1
  2029. printLog("focusOption=runPathCount:%s" % str(runPathCount))
  2030. if runPathCount == pathCount:
  2031. print u"执行到最后一级"
  2032. pass
  2033. else:
  2034. # 子节点的进入方式默认为ok;
  2035. self.redRat3.sendKey(enter_key)
  2036. # 如果执行一次enter_key,则退出时按返回键的次数加一
  2037. if enter_key != u'default':
  2038. returnKeyEventCount = returnKeyEventCount + 1
  2039. else:
  2040. print "focusOption end<<<<"
  2041. return False
  2042. # end-for
  2043. print "focusOption end <<<<"
  2044. return True
  2045. # 假定已经在option所在的页面,逐步移动到目标option,聚焦到option
  2046. def moveToOption(self, option, Max_Try=15):
  2047. # 切黑场;
  2048. # self.sourceInput.setPattern(11)
  2049. # 获取menu path;
  2050. print "moveToOption start >>>"
  2051. path_params = self.uitPathManage.get_option_paths(option)
  2052. # print 'openOption=path_params:', path_params
  2053. printLog('moveToOption=path_params:%s' % str(path_params))
  2054. checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
  2055. if str(checkRunOptionPathResult) == "NoExit":
  2056. printLog(u"表格中不存在到达Option: %s 的路径,在表格中排查到达该Option路径" % str(option))
  2057. return False
  2058. if str(checkRunOptionPathResult) == "Fail":
  2059. printLog(u"表格中到达Option: %s 的路径出现数据断层找不到First层级,在表格中排查到达该Option路径" % str(option))
  2060. return False
  2061. runPathCount = 0
  2062. pathCount = path_params.__len__()
  2063. printLog("moveToOption=pathCount:%s" % str(pathCount))
  2064. returnKeyEventCount = path_params.__len__()
  2065. # print "returnKeyEventCount:", returnKeyEventCount
  2066. printLog("moveToOption=returnKeyEventCount:%s" % str(returnKeyEventCount))
  2067. # 逆序路径key;
  2068. revpp = reversed(path_params)
  2069. # 根节点是否已进入;
  2070. entry = False
  2071. first_parent = u''
  2072. # first_option = u''
  2073. # 遍历路径(已排序,从first开始);
  2074. # print "revpp:", revpp
  2075. printLog("moveToOption=revpp:%s" % str(revpp))
  2076. for level in revpp:
  2077. # print "openOption=level:", path_params[level]
  2078. runPathCount = runPathCount + 1
  2079. print "level:", level, type(level)
  2080. print "runPathCount:", runPathCount, type(runPathCount)
  2081. print "pathCount:", pathCount, type(pathCount)
  2082. printLog("openOption=level:", path_params[level])
  2083. # 是否进入根结点;
  2084. if entry == False:
  2085. # 标记已进入根;
  2086. entry = True
  2087. first_parent = path_params[level]["parent"]
  2088. # 由于已经到达option同级界面,只执行最后一层
  2089. if runPathCount == pathCount:
  2090. # 移动到子节点;
  2091. cur_option_enter_key = path_params[level]["option_enter_key"]
  2092. # 移动到子节点;
  2093. if cur_option_enter_key.__len__() == 0:
  2094. enter_key = path_params[level]["enter_key"]
  2095. else:
  2096. enter_key = cur_option_enter_key
  2097. move_key = path_params[level]["move_key"]
  2098. if str(move_key) == str([u'up', u'down']) or str(move_key) == str([u'down', u'up']):
  2099. findDirection = str(move_key[1])
  2100. elif str(move_key) == str([u'left', u'right']) or str(move_key) == str([u'right', u'left']):
  2101. findDirection = str(move_key[1])
  2102. else:
  2103. findDirection = 'grid'
  2104. result = self.move2TargetNode(
  2105. level,
  2106. first_parent,
  2107. path_params[level],
  2108. returnKeyEventCount,
  2109. findDirection=findDirection, Max_Try=Max_Try)
  2110. if result is True:
  2111. # runPathCount = runPathCount+1
  2112. printLog("moveToOption=runPathCount:%s" % str(runPathCount))
  2113. if runPathCount == pathCount:
  2114. print "执行到最后一级"
  2115. pass
  2116. else:
  2117. # 子节点的进入方式默认为ok;
  2118. self.redRat3.sendKey(enter_key)
  2119. else:
  2120. print "moveToOption end<<<<"
  2121. return False
  2122. # end-for
  2123. print "moveToOption end <<<<"
  2124. return True
  2125. # 找到两个字符串左边或者右边相同的部分
  2126. def findDuplicateString(self, str1, str2, direction="right"):
  2127. index = 0
  2128. if direction == "right":
  2129. while True:
  2130. index -= 1
  2131. if abs(index) > str1.__len__() or abs(index) > str2.__len__():
  2132. break
  2133. if not str1[index] == str2[index]:
  2134. break
  2135. if index == -1:
  2136. return ""
  2137. return str1[index+1:]
  2138. elif direction == "left":
  2139. while True:
  2140. if abs(index) >= str1.__len__() or abs(index) >= str2.__len__():
  2141. break
  2142. if not str1[index] == str2[index]:
  2143. break
  2144. index += 1
  2145. return str1[:index]
  2146. # 去掉字符串数组中每个字符串 左边或右边相同的部分
  2147. def removeDuplicateString(self, strList):
  2148. finishedList = strList
  2149. directionList = ["left", "right"]
  2150. for direction in directionList:
  2151. same_str = self.findDuplicateString(strList[0], strList[1], direction)
  2152. if same_str == "":
  2153. continue
  2154. else:
  2155. for i in range(2, strList.__len__()):
  2156. same_str = self.findDuplicateString(same_str,strList[i], direction)
  2157. if same_str == "":
  2158. break
  2159. if same_str != "":
  2160. finishedList = []
  2161. for str in strList:
  2162. if direction == "left":
  2163. str = str[same_str.__len__():]
  2164. else:
  2165. str = str[:-same_str.__len__()]
  2166. finishedList.append(str)
  2167. return finishedList
  2168. if __name__ == "__main__":
  2169. tmenu = CTMenu()
  2170. print "执行开始!"
  2171. # ThresholdDict = tmenu.tconfig.getThresholdDict("factory")
  2172. # ThresholdDict = tmenu.tconfig.getThresholdDict("setting")
  2173. # print "ThresholdDict:", ThresholdDict, type(ThresholdDict)
  2174. # tmenu.getOptionValue("picture_preset")value
  2175. # parent_ocr_dict = tmenu.xlsparser.get_parent_ocr_dict("automatic_search_analogue")
  2176. # print "parent_ocr_dict:",parent_ocr_dict
  2177. # 获取menu path;
  2178. # value_params, path_params = tmenu.xlsparser.get_menu_paths('av', '')
  2179. # print value_params, path_params
  2180. # tmenu.redRat3.sendKey('home')
  2181. # tmenu.move2TargetGridNode_matchTemp('First', 'home', path_params['First'], 1)
  2182. # isSuccessed = tmenu.setOptionValue("picture_preset", "stadium")
  2183. # isSuccessed = tmenu.setOptionValue("backlight", 50)
  2184. # isSuccessed = tmenu.checkOptionValue("picture_preset", "stadium")
  2185. # isSuccessed = tmenu.checkOptionValue("backlight", 50)
  2186. # print u'isSuccessed:', isSuccessed
  2187. # isSuccessed_focusOption = tmenu.focusOption("picture_preset")
  2188. # print u'聚焦到目标Option:auto_volume_control 结果isSuccessed_focusOption:', isSuccessed_focusOption
  2189. # 确保当前焦点是在目标Option同级的
  2190. # if isSuccessed_focusOption:
  2191. # isSuccessed_moveToOption = tmenu.moveToOption("picture_reset")
  2192. # print u'焦点移动到目标Option结果isSuccessed_moveToOption:', isSuccessed_moveToOption
  2193. # value_params, path_params = tmenu.xlsparser.get_menu_paths("picture_preset ", "personal")
  2194. # print "value_params:",value_params
  2195. # print "path_params:",path_params
  2196. #
  2197. # path_params_1 = tmenu.xlsparser.get_option_paths("picture_preset ")
  2198. # print "path_params_1:", path_params_1
  2199. # isHasValue, ocr_result_text = tmenu.getOptionValue("backlight")
  2200. # print "isHasValue:",isHasValue,type(isHasValue)
  2201. # print "ocr_result_text:",ocr_result_text,type(ocr_result_text)
  2202. # tmenu.setOptionValue("backlight",ocr_result_text)
  2203. # paths = tmenu.xlsparser.get_option_paths('usb')
  2204. # tmenu.move2TargetGridNode('first', 'usb', paths, 5)
  2205. # isSuccessed = tmenu.setOptionValue("source", "tv")
  2206. # isSuccessed = tmenu.setOptionValue("picture_preset", "stadium")
  2207. # isSuccessed = tmenu.setOptionValue("picture_preset", "dynamic")
  2208. # isSuccessed = tmenu.setOptionValue("gamma", 0)
  2209. # isSuccessed = tmenu.setOptionValue("instant_power_on", "on")
  2210. # isSuccessed = tmenu.setOptionValue("RGB_mode", "green_only")
  2211. # isSuccessed = tmenu.focusOptionValue("option", "enjoy_music")
  2212. # print "isSuccessed:", isSuccessed
  2213. # settingWaitTime = tmenu.getParentWaitTime("setting")
  2214. # print settingWaitTime
  2215. # sourceWaitTime = tmenu.getParentWaitTime("source")
  2216. # print sourceWaitTime
  2217. # print tmenu.setOptionValue('overscan', 'off')
  2218. # print tmenu.getOptionValue('overscan')
  2219. # settings 检测焦点选择类的setOptionValue
  2220. # isSuccessed = tmenu.setOptionValue("backlight", 50)
  2221. # print "isSuccessed:", isSuccessed
  2222. # isSuccessed = tmenu.setOptionValue("500hz", 50)
  2223. # print u'isSuccessed:', isSuccessed
  2224. # settings 检测值设置类的setOptionValue
  2225. # isSuccessed = tmenu.setOptionValue("backlight", 70)
  2226. # isSuccessed = tmenu.setOptionValue("auto_volume_control", "on")
  2227. # print u'isSuccessed:', isSuccessed
  2228. # settings 检测焦点选择类的checkOptionValue
  2229. # isSuccessed = tmenu.checkOptionValue("picture_preset", "movie")
  2230. # print u'isSuccessed:', isSuccessed
  2231. # isSuccessed = tmenu.setOptionValue("picture_preset", "movie", leafNodeValueWaitTime=2.0)
  2232. # print u'isSuccessed:', isSuccessed
  2233. # settings 检测值设置类的checkOptionValue
  2234. # isSuccessed = tmenu.checkOptionValue("backlight", 70)
  2235. # print u'isSuccessed:', isSuccessed
  2236. # 信源切换检测
  2237. # isSuccessed = tmenu.setSourceValue('source', 'hdmi2', sourceWaitTime=1.5)
  2238. # print u'进入信源(hdmi2)isSuccessed:', isSuccessed
  2239. # isSuccessed = tmenu.setSourceValue('source', 'av')
  2240. # print u'进入信源(tv)isSuccessed:', isSuccessed
  2241. # 频道列表检测
  2242. # checkResult,failChannelList=tmenu.checkChannelList(["6", "22"])
  2243. # print u'checkResult,failChannelList:', checkResult,failChannelList
  2244. # 检测自动搜台
  2245. # isSuccessed = tmenu.auto_search("automatic_search",[["as_tuner_mode","air"],["as_channel_type","analog"]])
  2246. # print u'isSuccessed:', isSuccessed
  2247. # isSuccessed =tmenu.auto_search("automatic_search", [["as_tuner_mode", "air"], ["as_channel_type", "analog"]],
  2248. # ["as_search", "finished"])
  2249. # print u'isSuccessed:', isSuccessed
  2250. # 检测手动搜台
  2251. # isSuccessed =tmenu.manual_search("manual_tuning", [["mt_tuner_mode", "air"], ["mt_channel_type", "analog"], ["mt_ch", 12]])
  2252. # print u'isSuccessed:', isSuccessed
  2253. # isSuccessed = tmenu.manual_search("manual_tuning",
  2254. # [["mt_tuner_mode", "cable"], ["mt_channel_type", "digital"], ["mt_ch", 12]])
  2255. # print u'isSuccessed:', isSuccessed