|
@@ -3,71 +3,22 @@ import time,sys,os
|
|
from UAT_tree import UATTree
|
|
from UAT_tree import UATTree
|
|
from UAT_log import error,info,debug
|
|
from UAT_log import error,info,debug
|
|
from UAT_PathManage import UATPathManage
|
|
from UAT_PathManage import UATPathManage
|
|
-from UAT_runnerCommand import UATRunnerCommand
|
|
|
|
|
|
+from UIParamUtil import UIParamUtil
|
|
|
|
+# from UAT_runnerCommand import UATRunnerCommand
|
|
from ssat_sdk.python_uiautomator import PyUIAutomator,DirectionManageAndroid,FocusManageAndroid
|
|
from ssat_sdk.python_uiautomator import PyUIAutomator,DirectionManageAndroid,FocusManageAndroid
|
|
|
|
+import math
|
|
|
|
+import traceback
|
|
|
|
|
|
ERROR = True
|
|
ERROR = True
|
|
INFO = True
|
|
INFO = True
|
|
-DEBUG = True
|
|
|
|
|
|
+DEBUG = True # 上传SVN版本此参数关闭
|
|
'''
|
|
'''
|
|
采用uiautomator技术,处理界面定位问题,用于移动焦点到目标组件上
|
|
采用uiautomator技术,处理界面定位问题,用于移动焦点到目标组件上
|
|
'''
|
|
'''
|
|
class FocusCommand():
|
|
class FocusCommand():
|
|
cls = "FocusCommand"
|
|
cls = "FocusCommand"
|
|
- UIObjParam = {
|
|
|
|
- "text": None, # MASK_TEXT,
|
|
|
|
- "textContains": None, # MASK_TEXTCONTAINS,
|
|
|
|
- "textMatches": None, # MASK_TEXTMATCHES,
|
|
|
|
- "textStartsWith": None, # MASK_TEXTSTARTSWITH,
|
|
|
|
- "className": None, # MASK_CLASSNAME
|
|
|
|
- "classNameMatches": None, # MASK_CLASSNAMEMATCHES
|
|
|
|
- "description": None, # MASK_DESCRIPTION
|
|
|
|
- "descriptionContains": None, # MASK_DESCRIPTIONCONTAINS
|
|
|
|
- "descriptionMatches": None, # MASK_DESCRIPTIONMATCHES
|
|
|
|
- "descriptionStartsWith": None, # MASK_DESCRIPTIONSTARTSWITH
|
|
|
|
- "checkable": None, # MASK_CHECKABLE
|
|
|
|
- "checked": None, # MASK_CHECKED
|
|
|
|
- "clickable": None, # MASK_CLICKABLE
|
|
|
|
- "longClickable": None, # MASK_LONGCLICKABLE,
|
|
|
|
- "scrollable": None, # MASK_SCROLLABLE,
|
|
|
|
- "enabled": None, # MASK_ENABLED,
|
|
|
|
- "focusable": None, # MASK_FOCUSABLE,
|
|
|
|
- "focused": None, # MASK_FOCUSED,
|
|
|
|
- "selected": None, # MASK_SELECTED,
|
|
|
|
- "packageName": None, # MASK_PACKAGENAME,
|
|
|
|
- "packageNameMatches": None, # MASK_PACKAGENAMEMATCHES,
|
|
|
|
- "resourceId": None, # MASK_RESOURCEID,
|
|
|
|
- "resourceIdMatches": None, # MASK_RESOURCEIDMATCHES,
|
|
|
|
- "index": None, # MASK_INDEX,
|
|
|
|
- "instance": None # MASK_INSTANCE,
|
|
|
|
- }
|
|
|
|
- UATParamMap = {
|
|
|
|
- "text":"text", # MASK_TEXT,
|
|
|
|
- "textContains":"textContains", # MASK_TEXTCONTAINS,
|
|
|
|
- "textMatch":"textMatches", # MASK_TEXTMATCHES,
|
|
|
|
- "textSWith":"textStartsWith", # MASK_TEXTSTARTSWITH,
|
|
|
|
- "class":"className", # MASK_CLASSNAME
|
|
|
|
- "classMatches":"classNameMatches", # MASK_CLASSNAMEMATCHES
|
|
|
|
- "desc":"description", # MASK_DESCRIPTION
|
|
|
|
- "descContain":"descriptionContains", # MASK_DESCRIPTIONCONTAINS
|
|
|
|
- "descMatch":"descriptionMatches", # MASK_DESCRIPTIONMATCHES
|
|
|
|
- "descSWith":"descriptionStartsWith", # MASK_DESCRIPTIONSTARTSWITH
|
|
|
|
- "checkable":"checkable", # MASK_CHECKABLE
|
|
|
|
- "checked":"checked", # MASK_CHECKED
|
|
|
|
- "clickable":"clickable", # MASK_CLICKABLE
|
|
|
|
- "lClickable":"longClickable", # MASK_LONGCLICKABLE,
|
|
|
|
- "scrollable":"scrollable", # MASK_SCROLLABLE,
|
|
|
|
- "enable":"enabled", # MASK_ENABLED,
|
|
|
|
- "focusable":"focusable", # MASK_FOCUSABLE,
|
|
|
|
- "focused":"focused", # MASK_FOCUSED,
|
|
|
|
- "selected":"selected", # MASK_SELECTED,
|
|
|
|
- "pkg":"packageName", # MASK_PACKAGENAME,
|
|
|
|
- "pkgMatch":"packageNameMatches", # MASK_PACKAGENAMEMATCHES,
|
|
|
|
- "resid":"resourceId", # MASK_RESOURCEID,
|
|
|
|
- "residMatch":"resourceIdMatches", # MASK_RESOURCEIDMATCHES,
|
|
|
|
- "index":"index", # MASK_INDEX,
|
|
|
|
- "instance":"instance" # MASK_INSTANCE,
|
|
|
|
- }
|
|
|
|
|
|
+ UIObjParam = UIParamUtil.UIObjParam
|
|
|
|
+ UATParamMap = UIParamUtil.UATParamMap
|
|
def __init__(self, runnerCommand):
|
|
def __init__(self, runnerCommand):
|
|
self.runnerCommand = runnerCommand
|
|
self.runnerCommand = runnerCommand
|
|
self.pyU = PyUIAutomator()
|
|
self.pyU = PyUIAutomator()
|
|
@@ -76,6 +27,68 @@ class FocusCommand():
|
|
self.inLayout= False
|
|
self.inLayout= False
|
|
|
|
|
|
'''
|
|
'''
|
|
|
|
+ 解析option的焦点组件参数,返回focusView或者focus-select组件参数
|
|
|
|
+ :param option: option字典
|
|
|
|
+ :return 返回 focus焦点参数字典,采用setObjParam可以转换成UIObject识别需要的参数。
|
|
|
|
+ 如果为None,则表示不需要焦点选中。
|
|
|
|
+ '''
|
|
|
|
+ def getFPFromOption(self, option):
|
|
|
|
+ focusParam = None
|
|
|
|
+ fsParam = option[UATTree.TAB_FOCUS_SELECT]
|
|
|
|
+ fvParam = option[UATTree.TAB_FOCUSE_VIEW]
|
|
|
|
+ if fsParam[UATTree.FS_Type].__len__() > 1:
|
|
|
|
+ if fsParam[UATTree.FS_Type].lower() == "focus":
|
|
|
|
+ fsParam["focus"] = True
|
|
|
|
+ focusParam = fsParam
|
|
|
|
+ elif fsParam[UATTree.FS_Type].lower() == "select":
|
|
|
|
+ fsParam["select"] = True
|
|
|
|
+ focusParam = fsParam
|
|
|
|
+ elif fsParam[UATTree.FS_Type].lower() == "no":
|
|
|
|
+ focusParam = None
|
|
|
|
+ else:
|
|
|
|
+ error(self.cls, "getFPFromOption", "Option %s focus-select参数异常。" % option[UATTree.TAB_NAME], ERROR)
|
|
|
|
+ else:
|
|
|
|
+ focusParam = fvParam
|
|
|
|
+ return focusParam
|
|
|
|
+
|
|
|
|
+ '''
|
|
|
|
+ 解析option的焦点组件参数,返回focusView或者focus-select组件参数.
|
|
|
|
+ 在getFPFromOption返回值上,采用setObjParam转换成UIObject识别需要的参数。
|
|
|
|
+ :param option: option字典
|
|
|
|
+ :return 返回 focus焦点UIObject参数字典.
|
|
|
|
+ '''
|
|
|
|
+ def getFPObjParam(self, option):
|
|
|
|
+ focusParam = self.getFPFromOption(option)
|
|
|
|
+ fpObjParam = UIParamUtil.setObjParam(focusParam)
|
|
|
|
+ return fpObjParam
|
|
|
|
+
|
|
|
|
+ '''
|
|
|
|
+ 解析存储在UATree里的moveKey字典,得到按键类型、键值数组、最大尝试次数
|
|
|
|
+ :param moveKey, parent字典中moveKey字典
|
|
|
|
+ :param optionCount: moveKey对应的parent的option个数
|
|
|
|
+ :return keyType, keyCodeList, Max_Trye
|
|
|
|
+ '''
|
|
|
|
+ def parseMoveKey(self,moveKey, optionCount):
|
|
|
|
+ if moveKey[UATTree.Max_Try] != "":
|
|
|
|
+ Max_Try = int(moveKey[UATTree.Max_Try])
|
|
|
|
+ else:
|
|
|
|
+ Max_Try = optionCount
|
|
|
|
+ findDirection = ["down","up"]
|
|
|
|
+ keyType = UATTree.Key_Event
|
|
|
|
+ if moveKey[UATTree.Key_Event].__len__() > 1:
|
|
|
|
+ findDirection = moveKey[UATTree.Key_Event]
|
|
|
|
+ keyType = UATTree.Key_Event
|
|
|
|
+ elif moveKey[UATTree.Key_IR].__len__() > 1:
|
|
|
|
+ findDirection = moveKey[UATTree.Key_IR]
|
|
|
|
+ keyType = UATTree.Key_IR
|
|
|
|
+ elif moveKey[UATTree.Key_Input].__len__() > 1:
|
|
|
|
+ inputCmd = moveKey[UATTree.Key_Input]
|
|
|
|
+ #TODO input情况的处理
|
|
|
|
+ return None,None,None
|
|
|
|
+ else:
|
|
|
|
+ return None,None,None
|
|
|
|
+ return keyType, findDirection, Max_Try
|
|
|
|
+ '''
|
|
在parent界面,将焦点移动到目标option上。
|
|
在parent界面,将焦点移动到目标option上。
|
|
焦点定位:根据layout是不是限制焦点范围,进行焦点组件寻找,焦点组件类型:focus、select、focusView、long-click
|
|
焦点定位:根据layout是不是限制焦点范围,进行焦点组件寻找,焦点组件类型:focus、select、focusView、long-click
|
|
目标定位:纯粹是根据optionView配置组建坐标定位
|
|
目标定位:纯粹是根据optionView配置组建坐标定位
|
|
@@ -83,223 +96,398 @@ class FocusCommand():
|
|
:param option:目标option字典
|
|
:param option:目标option字典
|
|
:return True/False
|
|
:return True/False
|
|
'''
|
|
'''
|
|
- def focusOptionView(self, parent, option):
|
|
|
|
|
|
+ def focusOptionView(self, parent, option,chooseType):
|
|
#是否采用layout限制焦点判断范围
|
|
#是否采用layout限制焦点判断范围
|
|
layout = parent[UATTree.TAB_LAYOUT]
|
|
layout = parent[UATTree.TAB_LAYOUT]
|
|
print "focusOptionView,layout:",layout
|
|
print "focusOptionView,layout:",layout
|
|
self.inLayout = layout[UATTree.Layout_Limit]
|
|
self.inLayout = layout[UATTree.Layout_Limit]
|
|
# 找到目标optionView参数
|
|
# 找到目标optionView参数
|
|
layoutUIObj = {}
|
|
layoutUIObj = {}
|
|
- optionUIObjParam = self.setObjParam(option[UATTree.TAB_OPTION_VIEW])
|
|
|
|
|
|
+ optionUIObjParam = UIParamUtil.setObjParam(option[UATTree.TAB_OPTION_VIEW])
|
|
if self.inLayout == 1:
|
|
if self.inLayout == 1:
|
|
- layoutUIObjParam = self.setObjParam(layout)
|
|
|
|
|
|
+ layoutUIObjParam = UIParamUtil.setObjParam(layout)
|
|
else:
|
|
else:
|
|
layoutUIObjParam = {}
|
|
layoutUIObjParam = {}
|
|
# 获取move key按键
|
|
# 获取move key按键
|
|
moveKey = parent[UATTree.TAB_MOVE_KEY]
|
|
moveKey = parent[UATTree.TAB_MOVE_KEY]
|
|
- if moveKey[UATTree.Max_Try] != "":
|
|
|
|
- Max_Try = int(moveKey[UATTree.Max_Try])
|
|
|
|
- else:
|
|
|
|
- Max_Try = parent[UATTree.TAB_OPTION].__len__()
|
|
|
|
- findDirection = ["down","up"]
|
|
|
|
- keyType = UATTree.Key_Event
|
|
|
|
- if moveKey[UATTree.Key_Event].__len__() > 1:
|
|
|
|
- findDirection = moveKey[UATTree.Key_Event]
|
|
|
|
- keyType = UATTree.Key_Event
|
|
|
|
- elif moveKey[UATTree.Key_IR].__len__() > 1:
|
|
|
|
- findDirection = moveKey[UATTree.Key_IR]
|
|
|
|
- keyType = UATTree.Key_IR
|
|
|
|
- elif moveKey[UATTree.Key_Input].__len__() > 1:
|
|
|
|
- inputCmd = moveKey[UATTree.Key_Input]
|
|
|
|
- #TODO input情况的处理
|
|
|
|
- return False
|
|
|
|
- else:
|
|
|
|
|
|
+ keyType, findDirection,Max_Try = self.parseMoveKey(moveKey, parent[UATTree.TAB_OPTION].__len__())
|
|
|
|
+ if keyType is None:
|
|
error(self.cls, "focusTargetOption", option[UATTree.TAB_NAME] + " option 读取 move_key失败", ERROR)
|
|
error(self.cls, "focusTargetOption", option[UATTree.TAB_NAME] + " option 读取 move_key失败", ERROR)
|
|
return False
|
|
return False
|
|
- #获取焦点View和optionview的area参数
|
|
|
|
|
|
+ #获取optionview的View_sambounds参数
|
|
osamBounds = option[UATTree.TAB_OPTION_VIEW][UATTree.View_sambounds]
|
|
osamBounds = option[UATTree.TAB_OPTION_VIEW][UATTree.View_sambounds]
|
|
- fsamBounds = ""
|
|
|
|
#获取焦点view参数
|
|
#获取焦点view参数
|
|
- fsParam = option[UATTree.TAB_FOCUS_SELECT]
|
|
|
|
- fvParam = option[UATTree.TAB_FOCUSE_VIEW]
|
|
|
|
- fvUIParam = self.setObjParam(fvParam)
|
|
|
|
- if fsParam[UATTree.FS_Type].__len__() > 1:
|
|
|
|
- if fsParam[UATTree.FS_Type].lower() == "focus":
|
|
|
|
- fsParam["focused"] = True
|
|
|
|
- elif fsParam[UATTree.FS_Type].lower() == "select":
|
|
|
|
- fsParam["select"] = True
|
|
|
|
- else:
|
|
|
|
- error(self.cls,"focusOptionView","Option %s focus-select参数异常。"%option[UATTree.TAB_NAME], ERROR)
|
|
|
|
- return False
|
|
|
|
- fsamBounds = fsParam[UATTree.View_sambounds]
|
|
|
|
- fsUIParam = self.setObjParam(fsParam)
|
|
|
|
- return self.toDestObj(optionUIObjParam, fsUIParam,Max_Try,findDirection,keyType,layoutUIObjParam,fsamBounds,osamBounds)
|
|
|
|
- elif fvUIParam.__len__() > 0:
|
|
|
|
- fsamBounds = fvParam[UATTree.View_sambounds]
|
|
|
|
- return self.toDestObj(optionUIObjParam, fvUIParam,Max_Try,findDirection,keyType,layoutUIObjParam,fsamBounds,osamBounds)
|
|
|
|
|
|
+ focusParam = self.getFPFromOption(option)
|
|
|
|
+ focusUIParam = UIParamUtil.setObjParam(focusParam)
|
|
|
|
+ if focusParam is None:
|
|
|
|
+ fsamBounds = []
|
|
else:
|
|
else:
|
|
- error(self.cls, "focusOptionView", "Option %s focusView参数异常。" % option[UATTree.TAB_NAME], ERROR)
|
|
|
|
- return False
|
|
|
|
|
|
+ fsamBounds = focusParam[UATTree.View_sambounds]
|
|
|
|
+ if chooseType.lower()== 'no':
|
|
|
|
+ return self.getNoFocusedObj(option, Max_Try, findDirection, keyType, layoutUIObjParam)
|
|
|
|
+ else:
|
|
|
|
+ return self.toDestObj(parent, option, Max_Try, findDirection, keyType, layoutUIObjParam,fsamBounds,osamBounds)
|
|
|
|
|
|
- def toDestObj(self, destUIParam, focusObjParam, Max_Try=10, findDirections=["down","up"], keyType=UATTree.Key_Event
|
|
|
|
- ,layoutUIParam={},fsamBounds="",osamBounds=""):
|
|
|
|
|
|
+ '''
|
|
|
|
+ 传入uiautomator需要的目标组件参数,获取无聚焦属性的option对象
|
|
|
|
+ '''
|
|
|
|
+ def getNoFocusedObj(self,option, Max_Try, findDirection, keyType, layoutUIObjParam):
|
|
|
|
+ count = 0
|
|
|
|
+ directIndex = 0
|
|
|
|
+ while(True):
|
|
|
|
+ if count >= Max_Try and directIndex >= findDirection.__len__()-1:
|
|
|
|
+ break
|
|
|
|
+ time.sleep(0.1)
|
|
|
|
+ destUIObject = self.getOptionUIObj(option, layoutUIObjParam)
|
|
|
|
+ if destUIObject and destUIObject.exists():
|
|
|
|
+ info(self.cls,"getNoFocusedObj","找到目标option %s"%option[UATTree.TAB_NAME],INFO)
|
|
|
|
+ return True
|
|
|
|
+ else:
|
|
|
|
+ if count < Max_Try:
|
|
|
|
+ count = count + 1
|
|
|
|
+ elif count >= Max_Try and directIndex<findDirection.__len__() -1:
|
|
|
|
+ count=0
|
|
|
|
+ Max_Try *= 2
|
|
|
|
+ directIndex = directIndex + 1
|
|
|
|
+ self.fm.pressKeyByType(findDirection[directIndex], keyType)
|
|
|
|
+ error(self.cls, "getNoFocusedObj", "执行%s 次查找,仍未找到目标焦点!!" % (str(Max_Try)), ERROR)
|
|
|
|
+ return False
|
|
|
|
+
|
|
|
|
+ '''
|
|
|
|
+ 传入uiautomator需要的目标组件参数和焦点框参数,用于寻找目标。
|
|
|
|
+ '''
|
|
|
|
+ def toDestObj(self, parent, option, Max_Try=10, findDirections=["down","up"], keyType=UATTree.Key_Event,
|
|
|
|
+ layoutUIParam={}, fsamBounds=[],osamBounds=[]):
|
|
# 按照传入的方向寻找Max_Try次,如果仍未聚焦到选中area,则按照传入方向的反方向 反向寻找 2*Max_Try 次
|
|
# 按照传入的方向寻找Max_Try次,如果仍未聚焦到选中area,则按照传入方向的反方向 反向寻找 2*Max_Try 次
|
|
- print "toDestObj,enter:",Max_Try,findDirections,keyType
|
|
|
|
|
|
+ print "toDestObj,enter:",Max_Try,findDirections,keyType,fsamBounds,osamBounds
|
|
count = 0
|
|
count = 0
|
|
Max_Try = Max_Try
|
|
Max_Try = Max_Try
|
|
directIndex = 0
|
|
directIndex = 0
|
|
|
|
+ focusCount = 0 # 当目标和聚焦点在一个页面同时存在时,从当前聚焦点到目标的移动次数
|
|
|
|
+ focusedBoundsPre = {u'top': 0, u'left': 0, u'right': 0, u'bottom': 0} # 上一轮聚焦点的坐标
|
|
|
|
+ destBoundsPre = {u'top': 0, u'left': 0, u'right': 0, u'bottom': 0} # 上一轮目标的坐标
|
|
while (True):
|
|
while (True):
|
|
- if count >= Max_Try and directIndex >= findDirections.__len__():
|
|
|
|
|
|
+ if count >= Max_Try and directIndex >= findDirections.__len__()-1:
|
|
break
|
|
break
|
|
# 等待聚焦效果刷新完成,稳定之后再获取相关的属性
|
|
# 等待聚焦效果刷新完成,稳定之后再获取相关的属性
|
|
- time.sleep(0.5)
|
|
|
|
- print "toDestObj,focusObjParam:",focusObjParam
|
|
|
|
- focusedUIObject = self.pyU.getUiObject2(focusObjParam)
|
|
|
|
- focusedBounds = focusedUIObject.info['bounds']
|
|
|
|
- # print "focusedBounds:",focusedBounds
|
|
|
|
- if layoutUIParam.__len__() > 0:
|
|
|
|
- layoutUIObj = self.pyU.getUiObject2(layoutUIParam)
|
|
|
|
- destUIObject = layoutUIObj.child(**destUIParam)
|
|
|
|
- else:
|
|
|
|
- destUIObject = self.pyU.getUiObject2(destUIParam)
|
|
|
|
- if destUIObject:
|
|
|
|
- print "focusOptionView,focusedBounds,destUIBounds:",focusedBounds, destUIObject.info['bounds']
|
|
|
|
|
|
+ time.sleep(0.1)
|
|
|
|
+ destUIObject = self.getOptionUIObj(option,layoutUIParam)
|
|
|
|
+ focusParam = self.getFPFromOption(option)
|
|
|
|
+ #option是否需要聚焦
|
|
|
|
+ needFocus = True
|
|
|
|
+ if focusParam.has_key(UATTree.FS_Type) and \
|
|
|
|
+ focusParam[UATTree.FS_Type] == "no":
|
|
|
|
+ needFocus = False
|
|
|
|
+ if destUIObject and destUIObject.exists(): # 有聚焦属性的option存在不代表已聚焦,无聚焦属性的option存在即当作已聚焦
|
|
try:
|
|
try:
|
|
|
|
+ retCode, focusedUIObject = self.getChooseUIObjP(parent, layoutUIParam,needFocus=needFocus)
|
|
|
|
+ debug(self.cls, "toDestObj", "Parent %s 当前聚焦框retCode:%d" % (parent[UATTree.TAB_NAME],retCode), DEBUG)
|
|
|
|
+ #如果焦点不存在,只需要判断optionView存在即可算是聚焦成功
|
|
|
|
+ if retCode == self.Focus_Need_Not:
|
|
|
|
+ return True
|
|
|
|
+ #根据已获取到destUIObject和focusedUIObject,进行是否选中目标option判断,
|
|
|
|
+ #未选中,则继续利用moveKey查找
|
|
|
|
+ focusedBounds = focusedUIObject.info['bounds']
|
|
|
|
+ info(self.cls,"toDestObj","当前聚焦框所在坐标:%s"%focusedBounds,INFO)
|
|
destBounds = destUIObject.info['bounds']
|
|
destBounds = destUIObject.info['bounds']
|
|
- # print "destBounds:", destBounds
|
|
|
|
- if self.hasFocusDest(focusedBounds, destBounds, ):
|
|
|
|
- print '成功聚焦到目标焦点:',destUIParam
|
|
|
|
|
|
+ info(self.cls, "toDestObj", "已寻找%s次" % focusCount, INFO)
|
|
|
|
+ info(self.cls,"toDestObj","目标Option %s坐标:%s"%(option[UATTree.TAB_NAME], destBounds),INFO)
|
|
|
|
+ if self.hasFocusDest(focusedBounds, destBounds, fsamBounds=fsamBounds, osamBounds=osamBounds):
|
|
|
|
+ info(self.cls,"toDestObj","成功聚焦到目标焦点:%s"%option[UATTree.TAB_NAME],INFO)
|
|
return True
|
|
return True
|
|
|
|
+ # 如果往同一个方向跑了5次,聚焦坐标和目标坐标的位置都没变化,则说明目标可能为非聚焦,跑不动了
|
|
|
|
+ if focusCount<5:
|
|
|
|
+ direction = self.dm.getTargetDirection(focusedBounds, destBounds, findDirections)
|
|
|
|
+ self.dm.goOneStep(self.pyU, direction, keyType)
|
|
|
|
+ isSameFocused = self.dm.isSameBounds(focusedBoundsPre,focusedBounds) # 前一次聚焦点与当前聚焦点坐标对比
|
|
|
|
+ isSameDest = self.dm.isSameBounds(destBoundsPre,destBounds)
|
|
|
|
+ if isSameFocused == True and isSameDest == True:
|
|
|
|
+ focusCount += 1
|
|
|
|
+ focusedBoundsPre = focusedBounds
|
|
|
|
+ destBoundsPre = destBounds
|
|
|
|
+ if focusCount == 0:
|
|
|
|
+ focusCount += 1 # 如果focusCount=0,则将当前聚焦点和目标坐标赋值给前一次
|
|
|
|
+ focusedBoundsPre = focusedBounds
|
|
|
|
+ destBoundsPre = destBounds
|
|
else:
|
|
else:
|
|
- count = count + 1
|
|
|
|
- direction = self.dm.getTargetDirection(focusedBounds, destBounds)
|
|
|
|
- self.dm.goOneStep(self.pyU, direction, keyType)
|
|
|
|
|
|
+ error(self.cls, "toDestObj", "未找到目标焦点!!!", ERROR)
|
|
|
|
+ return False
|
|
|
|
+
|
|
except Exception,e:
|
|
except Exception,e:
|
|
- print "toDestObj,e:",e
|
|
|
|
|
|
+ info(self.cls,"toDestObj","未获取到目标/焦点对象坐标:count:%d,Max_Try:%d,directIndex:%d"%(count,Max_Try,directIndex),INFO)
|
|
|
|
+ traceback.print_exc()
|
|
# 出现控件出现一半的时候,获取控件信息会报错
|
|
# 出现控件出现一半的时候,获取控件信息会报错
|
|
if count < Max_Try:
|
|
if count < Max_Try:
|
|
count = count + 1
|
|
count = count + 1
|
|
- else:
|
|
|
|
|
|
+ elif count >= Max_Try and directIndex < findDirections.__len__() -1:
|
|
|
|
+ count=0
|
|
|
|
+ Max_Try *= 2
|
|
directIndex = directIndex + 1
|
|
directIndex = directIndex + 1
|
|
self.fm.pressKeyByType(findDirections[directIndex], keyType)
|
|
self.fm.pressKeyByType(findDirections[directIndex], keyType)
|
|
# 如果界面中没有目标文字的控件出现,则按照传入的方向寻找Max_Try次;仍然未找到 则反方向寻找2*Max_Try次
|
|
# 如果界面中没有目标文字的控件出现,则按照传入的方向寻找Max_Try次;仍然未找到 则反方向寻找2*Max_Try次
|
|
else:
|
|
else:
|
|
if count < Max_Try:
|
|
if count < Max_Try:
|
|
count = count + 1
|
|
count = count + 1
|
|
- self.fm.pressKeyByType(findDirections[directIndex], keyType)
|
|
|
|
- else:
|
|
|
|
|
|
+ elif count >= Max_Try and directIndex<findDirections.__len__() -1:
|
|
|
|
+ count=0
|
|
|
|
+ Max_Try *= 2
|
|
directIndex = directIndex + 1
|
|
directIndex = directIndex + 1
|
|
- self.fm.pressKeyByType(findDirections[directIndex], keyType)
|
|
|
|
|
|
+ self.fm.pressKeyByType(findDirections[directIndex], keyType)
|
|
|
|
|
|
- print "执行%s 次查找,仍未找到目标焦点!!" % (str(Max_Try))
|
|
|
|
|
|
+ error(self.cls, "toDestObj", "执行%s 次查找,仍未找到目标焦点!!" % (str(Max_Try)), ERROR)
|
|
return False
|
|
return False
|
|
|
|
|
|
'''
|
|
'''
|
|
根据配置的样本焦点框和OptionView 区域坐标,计算是否聚焦
|
|
根据配置的样本焦点框和OptionView 区域坐标,计算是否聚焦
|
|
|
|
+ :param focusedBounds 当前电视焦点框坐标
|
|
|
|
+ :param destBounds 当前电视目标坐标
|
|
|
|
+ :param fsamBounds 取样时的焦点框坐标
|
|
|
|
+ :param osamBounds 取样时的目标坐标
|
|
|
|
+ :return True/False True:焦点在目标上;False:焦点不在目标上
|
|
'''
|
|
'''
|
|
- def hasFocusDest(self,focusedBounds, destBounds, fsamBounds="",osamBounds=""):
|
|
|
|
|
|
+ def hasFocusDest(self,focusedBounds, destBounds, fsamBounds=[],osamBounds=[]):
|
|
|
|
+ # print "hasFocusDest,focusedBounds,destBounds,fsamBounds,osamBounds:",focusedBounds, destBounds,fsamBounds,osamBounds
|
|
if fsamBounds.__len__() < 1 or osamBounds.__len__()<1:
|
|
if fsamBounds.__len__() < 1 or osamBounds.__len__()<1:
|
|
return self.dm.isHasAnotherBounds(focusedBounds, destBounds)
|
|
return self.dm.isHasAnotherBounds(focusedBounds, destBounds)
|
|
else:#在焦点框bounds特别大时,同时包含多个目标optionView时,用此方法判断是否选中。
|
|
else:#在焦点框bounds特别大时,同时包含多个目标optionView时,用此方法判断是否选中。
|
|
- fsamBounds = self.strToBounds(fsamBounds)
|
|
|
|
- osamBounds = self.strToBounds(osamBounds)
|
|
|
|
- sdx=fsamBounds[0][0] - osamBounds[0][0]
|
|
|
|
- sdy=fsamBounds[0][1] - osamBounds[0][1]
|
|
|
|
- sdrate = self.calPointAngle(fsamBounds)
|
|
|
|
-
|
|
|
|
- focusBounds = self.strToBounds(focusedBounds)
|
|
|
|
- destBounds = self.strToBounds(destBounds)
|
|
|
|
- dx = focusBounds[0][0] - destBounds[0][0]
|
|
|
|
- dy = focusBounds[0][1] - destBounds[0][1]
|
|
|
|
- drate = dy / dx
|
|
|
|
- if (drate - sdrate) < 5:
|
|
|
|
|
|
+ focusBounds = UIParamUtil.atxBounds2UATBounds(focusedBounds)
|
|
|
|
+ destBounds = UIParamUtil.atxBounds2UATBounds(destBounds)
|
|
|
|
+ print "fsamBounds,osamBounds"
|
|
|
|
+ sdrate = self.calPointAngle(fsamBounds[0], osamBounds[0])
|
|
|
|
+ sdLine = self.calPointLine(fsamBounds[0], osamBounds[0])
|
|
|
|
+ print "focusBounds,destBounds"
|
|
|
|
+ drate = self.calPointAngle(focusBounds[0],destBounds[0])
|
|
|
|
+ dLine = self.calPointLine(focusBounds[0],destBounds[0])
|
|
|
|
+ if abs(drate - sdrate) < 5 and abs(dLine - sdLine) < 30:
|
|
return True
|
|
return True
|
|
else:
|
|
else:
|
|
return False
|
|
return False
|
|
-
|
|
|
|
'''
|
|
'''
|
|
- 计算点p1相对点p2的角度
|
|
|
|
|
|
+ 计算点p2相对点p1的角度
|
|
'''
|
|
'''
|
|
def calPointAngle(self, p1, p2):
|
|
def calPointAngle(self, p1, p2):
|
|
- dx = p1[0]-p2[0]
|
|
|
|
- dy = p1[1]-p2[1]
|
|
|
|
|
|
+ angle = 0.0
|
|
|
|
+ print "calPointAngle,p1,p2:", p1,p2
|
|
|
|
+ dx = float(p2[0])-float(p1[0])
|
|
|
|
+ dy = float(p2[1])-float(p1[1])
|
|
|
|
+ print "calPointAngle,dx,dy:",dx,dy
|
|
|
|
+ if dx == 0 and dy >= 0:
|
|
|
|
+ return 90
|
|
|
|
+ elif dx == 0 and dy < 0:
|
|
|
|
+ return 180
|
|
|
|
|
|
- '''
|
|
|
|
- 将‘[801,116][1280,180]’转成数组[[801,116][1280,180]]
|
|
|
|
- '''
|
|
|
|
- def strToBounds(self,bstr):
|
|
|
|
- char = "[]"
|
|
|
|
- print "strToBounds,bstr:",bstr
|
|
|
|
- keyIndex = 1
|
|
|
|
- # key.__len__()-1 为去掉"["的处理
|
|
|
|
- i1 = bstr.find(char[0])
|
|
|
|
- i2 = bstr.find(char[1])
|
|
|
|
- if i1 == -1 or i2 == -1:
|
|
|
|
- return []
|
|
|
|
- str1 = bstr[i1: i2+1]
|
|
|
|
- str2 = bstr[i2+1 : bstr.__len__()]
|
|
|
|
- return [eval(str1),eval(str2)]
|
|
|
|
|
|
+ radian = math.atan(dy/dx) #计算出弧度值
|
|
|
|
+ angle = 180 * radian/math.pi
|
|
|
|
+ print "calPointAngle,angle,radian:",angle,radian
|
|
|
|
+ return angle
|
|
|
|
+
|
|
|
|
+ def calPointLine(self, p1,p2):
|
|
|
|
+ print "calPointLine,p1,p2:", p1,p2
|
|
|
|
+ dx = float(p2[0])-float(p1[0])
|
|
|
|
+ dy = float(p2[1])-float(p1[1])
|
|
|
|
+ line = round(math.sqrt(dx*dx + dy*dy),1)
|
|
|
|
+ print "calPointLine,line:", line
|
|
|
|
+ return line
|
|
|
|
|
|
- '''
|
|
|
|
- 根据传入的uat界面obj参数,转换成UIObject参数
|
|
|
|
- 参数均用字典存储。
|
|
|
|
- '''
|
|
|
|
- def setObjParam(self, uatObjParam):
|
|
|
|
- uiObjParam = {}
|
|
|
|
- for uatKey in uatObjParam:
|
|
|
|
- uatParam = uatObjParam[uatKey]
|
|
|
|
- if self.UATParamMap.has_key(uatKey) and uatParam is not None and str(uatParam).__len__() > 0:
|
|
|
|
- uiObjParam[self.UATParamMap[uatKey]] = uatParam
|
|
|
|
- return uiObjParam
|
|
|
|
'''
|
|
'''
|
|
检测option组件,在电视上是否被选中了
|
|
检测option组件,在电视上是否被选中了
|
|
:param option 数据字典
|
|
:param option 数据字典
|
|
|
|
+ :param layoutUIParam, parent的layout组件定位字典
|
|
|
|
+ :param focusUIObj, 焦点组件
|
|
:return -1:未进入option的页面,找不到option UIObject;0:进入了option的页面,未选中option;1 已经选中option
|
|
:return -1:未进入option的页面,找不到option UIObject;0:进入了option的页面,未选中option;1 已经选中option
|
|
-2:代表未找到焦点
|
|
-2:代表未找到焦点
|
|
'''
|
|
'''
|
|
- def checkOptionChoose(self, option):
|
|
|
|
- optionUIObj = self.pyU.getUiObject(text=option["optionView"][UATTree.View_Text],
|
|
|
|
- resourceId=option["optionView"][UATTree.View_ID],
|
|
|
|
- description=option["optionView"][UATTree.View_Desc])
|
|
|
|
- if optionUIObj is None or optionUIObj.count == 0:
|
|
|
|
|
|
+ def checkOptionChoose(self, option, layoutUIParam, focusUIObj):
|
|
|
|
+ optionUIObj = self.getOptionUIObj(option, layoutUIParam)
|
|
|
|
+ if optionUIObj is None or optionUIObj.exists() is False:
|
|
return -1
|
|
return -1
|
|
- curUIObj = self.getChooseUIObj(option)
|
|
|
|
- if curUIObj is None or curUIObj.count == 0:
|
|
|
|
|
|
+ if focusUIObj is None or focusUIObj.exists() is False:
|
|
return -2
|
|
return -2
|
|
- if self.dm.isHasAnotherBounds(curUIObj.info["bounds"], optionUIObj.info['bounds']):
|
|
|
|
|
|
+ focusParam = self.getFPFromOption(option)
|
|
|
|
+ if focusParam is None:
|
|
|
|
+ return 1
|
|
|
|
+ try:
|
|
|
|
+ focusedBounds = focusUIObj.info()["bounds"]
|
|
|
|
+ destBounds = optionUIObj.info()['bounds']
|
|
|
|
+ except Exception,e:
|
|
|
|
+ return 0
|
|
|
|
+ fsamBounds = focusParam[UATTree.View_sambounds]
|
|
|
|
+ osamBounds = option[UATTree.TAB_OPTION_VIEW][UATTree.View_sambounds]
|
|
|
|
+ if self.hasFocusDest(focusedBounds, destBounds,fsamBounds, osamBounds):
|
|
return 1
|
|
return 1
|
|
else:
|
|
else:
|
|
return 0
|
|
return 0
|
|
|
|
|
|
|
|
+ def checkOptionExist(self, option, parent):
|
|
|
|
+ # print "checkOptionExist,option:",option
|
|
|
|
+ moveKey = parent[UATTree.TAB_MOVE_KEY]
|
|
|
|
+ optionName = option['name']
|
|
|
|
+ print "checkOptionExist,moveKey:", moveKey
|
|
|
|
+ Max_Try = moveKey[UATTree.Max_Try]
|
|
|
|
+ if Max_Try == "":
|
|
|
|
+ Max_Try = 1
|
|
|
|
+ else:
|
|
|
|
+ Max_Try = int(Max_Try)
|
|
|
|
+ Reverse_Max_Try = Max_Try * 2
|
|
|
|
+ print "Max_Try:", Max_Try
|
|
|
|
+ count = 0
|
|
|
|
+ Reversecount = 0
|
|
|
|
+ lastObj = ""
|
|
|
|
+
|
|
|
|
+ while (True):
|
|
|
|
+ if count >= Max_Try and Reversecount >= Reverse_Max_Try:
|
|
|
|
+ break
|
|
|
|
+ # 如果找到目标直接返回
|
|
|
|
+ debug(self.cls,"checkOptionExist","optionView:%s"%option,DEBUG)
|
|
|
|
+ opUIParam = UIParamUtil.setObjParam(option["optionView"])
|
|
|
|
+ ###
|
|
|
|
+ try:
|
|
|
|
+ opOBJ = self.pyU.getUiObject2(opUIParam)
|
|
|
|
+ opOBJInfo = opOBJ.info
|
|
|
|
+ debug(self.cls,"checkOptionExist","opOBJInfo: %s"%opOBJInfo,DEBUG)
|
|
|
|
+ break
|
|
|
|
+ except Exception,e:
|
|
|
|
+ opOBJ = None
|
|
|
|
+ if count < Max_Try:
|
|
|
|
+ flag = 1
|
|
|
|
+ count += 1
|
|
|
|
+ print "now count:", count
|
|
|
|
+ else:
|
|
|
|
+ flag = 0
|
|
|
|
+ Reversecount += 1
|
|
|
|
+ print "now Reversecount:", Reversecount
|
|
|
|
+ self.runnerCommand.executeMoveKey(moveKey, flag)
|
|
|
|
+ if opOBJ is not None and opOBJ.exists():
|
|
|
|
+ info(self.cls, "checkOptionExist", "当前页面已找到option: %s" % optionName, INFO)
|
|
|
|
+ return True
|
|
|
|
+ info(self.cls, "checkOptionExist", "注意!!!当前页面未找到option: %s" % optionName, INFO)
|
|
|
|
+ return False
|
|
|
|
+
|
|
'''
|
|
'''
|
|
根据option配置的焦点方式,返回当前页面焦点组件
|
|
根据option配置的焦点方式,返回当前页面焦点组件
|
|
|
|
+ :param option: option字典
|
|
|
|
+ :param layoutUIObj : option对应组件的根组件
|
|
|
|
+ :return retCode,UIObject对象:reCode=0表示默认为不需要选中状态,retCode=1表示option默认为需要选中状态
|
|
|
|
+ '''
|
|
|
|
+ Focus_Need = 1
|
|
|
|
+ Focus_Need_Not = 0
|
|
|
|
+ def getChooseUIObj(self, option, layoutUIObj = None):
|
|
|
|
+ debug(self.cls, "getChooseUIObj", "option name:"+option[UATTree.TAB_NAME],DEBUG)
|
|
|
|
+ focusObjParam = self.getFPObjParam(option)
|
|
|
|
+ debug(self.cls, "getChooseUIObj", "focusObjParam:"+str(focusObjParam)+"; layoutUIObj:"+str(layoutUIObj),DEBUG)
|
|
|
|
+ if focusObjParam.__len__() <= 0:
|
|
|
|
+ return self.Focus_Need_Not,None
|
|
|
|
+ if layoutUIObj is None:
|
|
|
|
+ return self.Focus_Need,self.pyU.getUiObject2(focusObjParam)
|
|
|
|
+ else:
|
|
|
|
+ return self.Focus_Need,layoutUIObj.child(**focusObjParam)
|
|
|
|
+
|
|
|
|
+ '''
|
|
|
|
+ 根据parent字典,检索parent是否有一个option被选中,任何一个备选中,返回option的UIObject
|
|
|
|
+ :param parent: parent 字典
|
|
|
|
+ :param needFocus: 目标option需要聚焦,则优先找焦点,再处理select type为no情况
|
|
|
|
+ :return retCode,UIObject对象:reCode=0表示默认为不需要选中状态,retCode=1表示option默认为需要选中状态
|
|
'''
|
|
'''
|
|
- def getChooseUIObj(self, option):
|
|
|
|
- print "getChooseUIObj option:", option["focus-select"]
|
|
|
|
- if option["focus-select"]["type"].__len__() > 1:
|
|
|
|
- chooseType = option["focus-select"][UATTree.FS_Type]
|
|
|
|
- if chooseType.lower() == "focus":
|
|
|
|
- return self.pyU.getFocusedUIObject()
|
|
|
|
- elif chooseType.lower() == "select":
|
|
|
|
- return self.pyU.getSelectedUIObject()
|
|
|
|
- elif chooseType.lower() == "no":
|
|
|
|
- resId = option[UATTree.TAB_OPTION_VIEW][UATTree.View_ID]
|
|
|
|
- text = option[UATTree.TAB_OPTION_VIEW][UATTree.View_Text]
|
|
|
|
- className = option[UATTree.TAB_OPTION_VIEW][UATTree.View_Class]
|
|
|
|
- desc = option[UATTree.TAB_OPTION_VIEW][UATTree.View_Desc]
|
|
|
|
- return self.pyU.getUiObject(resourceId=resId, text=text, className=className, description=desc)
|
|
|
|
|
|
+ def getChooseUIObjP(self, parent, layoutUIParam, needFocus = True):
|
|
|
|
+ if layoutUIParam.__len__() > 0:
|
|
|
|
+ layoutUIObj = self.pyU.getUiObject2(layoutUIParam)
|
|
|
|
+ else:
|
|
|
|
+ layoutUIObj = None
|
|
|
|
+ # 筛选焦点定位类型,减少重复判断
|
|
|
|
+ focusOptionDict = self.reMuFocusOption(parent[UATTree.TAB_OPTION])
|
|
|
|
+ debug(self.cls,"getChooseUIObjP","focusOptionDict:"+str(focusOptionDict.keys()),DEBUG)
|
|
|
|
+ for optionName in focusOptionDict:
|
|
|
|
+ option = focusOptionDict[optionName]
|
|
|
|
+ retCode, uiObj = self.getChooseUIObj(option, layoutUIObj)
|
|
|
|
+ if retCode == self.Focus_Need_Not and needFocus is False:
|
|
|
|
+ return self.Focus_Need_Not, None
|
|
|
|
+ elif retCode == self.Focus_Need and uiObj is not None and uiObj.exists():
|
|
|
|
+ return retCode, uiObj
|
|
|
|
+ return self.Focus_Need,None
|
|
|
|
+
|
|
|
|
+ def reMuFocusOption(self, optionDict):
|
|
|
|
+ retDict = {}
|
|
|
|
+ for optionName in optionDict:
|
|
|
|
+ option = optionDict[optionName]
|
|
|
|
+ focusObjParam = self.getFPObjParam(option)
|
|
|
|
+ if retDict.__len__() == 0:
|
|
|
|
+ retDict[optionName] = option
|
|
|
|
+ continue
|
|
|
|
+ isSame = False
|
|
|
|
+ for retName in retDict:
|
|
|
|
+ retOption = optionDict[retName]
|
|
|
|
+ retFocusObjParam = self.getFPObjParam(option)
|
|
|
|
+ if UIParamUtil.cmpObjParam(focusObjParam, retFocusObjParam):
|
|
|
|
+ isSame = True
|
|
|
|
+ break
|
|
|
|
+ if isSame is False:
|
|
|
|
+ retDict[optionName] = option
|
|
|
|
+ return retDict
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ '''
|
|
|
|
+ 根据option和layoutUIParam参数,获取option UIObject对象
|
|
|
|
+ layoutUIParam参数有效,则在layout里查找子组件option,否则全界面查找子组件。
|
|
|
|
+ '''
|
|
|
|
+ def getOptionUIObj(self, option, layoutUIParam):
|
|
|
|
+ debug(self.cls, "getOptionUIObj","OptionView:"+str(option[UATTree.TAB_OPTION_VIEW]),DEBUG)
|
|
|
|
+ destUIParam = UIParamUtil.setObjParam(option[UATTree.TAB_OPTION_VIEW])
|
|
|
|
+ debug(self.cls, "getOptionUIObj", "destUIParam:" + str(destUIParam), DEBUG)
|
|
|
|
+ destUITextExist = False
|
|
|
|
+ try:
|
|
|
|
+ destUIText = destUIParam['text']
|
|
|
|
+ destUITextExist = True
|
|
|
|
+ except Exception, e:
|
|
|
|
+ info(self.cls, "getOptionUIObj", "目标对象%s的optionView无text属性"%option[UATTree.TAB_NAME], INFO)
|
|
|
|
+ if destUITextExist is True:
|
|
|
|
+ #####################
|
|
|
|
+ if type(destUIParam['text']) is type([]):
|
|
|
|
+ destUIObjectExist = False
|
|
|
|
+ tempTextList = destUIParam['text']
|
|
|
|
+ txtCount = 0
|
|
|
|
+ for txt in tempTextList:
|
|
|
|
+ destUIParam['text'] = txt
|
|
|
|
+ uix = self.pyU.dump_hierarchy()
|
|
|
|
+ if txt not in uix:
|
|
|
|
+ continue
|
|
|
|
+ if layoutUIParam.__len__() > 0:
|
|
|
|
+ layoutUIObj = self.pyU.getUiObject2(layoutUIParam)
|
|
|
|
+ try:
|
|
|
|
+ destUIObject = layoutUIObj.child(**destUIParam)
|
|
|
|
+ destUIObjectInfo = destUIObject.info
|
|
|
|
+ destUIObjectExist = True
|
|
|
|
+ info(self.cls, "getOptionUIObj", "文本%s对应的option对象已找到" % txt, INFO)
|
|
|
|
+ except Exception, e:
|
|
|
|
+ nextText = tempTextList[txtCount + 1]
|
|
|
|
+ error(self.cls, "getOptionUIObj", "文本%s对应的option对象未找到,匹配下一个文本%s" % (txt, nextText), ERROR)
|
|
|
|
+ if destUIObjectExist is True:
|
|
|
|
+ break
|
|
|
|
+ else:
|
|
|
|
+ try:
|
|
|
|
+ destUIObject = self.pyU.getUiObject2(destUIParam)
|
|
|
|
+ destUIObjectInfo = destUIObject.info
|
|
|
|
+ destUIObjectExist = True
|
|
|
|
+ info(self.cls, "getOptionUIObj", "文本%s对应的option对象已找到" % txt, INFO)
|
|
|
|
+ except Exception, e:
|
|
|
|
+ nextText = tempTextList[txtCount + 1]
|
|
|
|
+ error(self.cls, "getOptionUIObj", "文本%s对应的option对象未找到,匹配下一个文本%s" % (txt, nextText), ERROR)
|
|
|
|
+ if destUIObjectExist is True:
|
|
|
|
+ break
|
|
|
|
+ txtCount += 1
|
|
else:
|
|
else:
|
|
- error(self.cls, "getChooseUIObj", option["name"] + " option focus-select属性配置异常", ERROR)
|
|
|
|
- return None
|
|
|
|
- elif option["focuseView"][UATTree.Focus_Text].__len__() > 0 \
|
|
|
|
- or option["focuseView"][UATTree.Focus_ID].__len__() > 1 \
|
|
|
|
- or option["focuseView"][UATTree.Focus_Desc].__len__() > 0:
|
|
|
|
- return self.pyU.getUiObject(text=option["focuseView"][UATTree.Focus_Text],
|
|
|
|
- resourceId=option["focuseView"][UATTree.Focus_ID],
|
|
|
|
- description=option["focuseView"][UATTree.Focus_Desc])
|
|
|
|
|
|
+ if layoutUIParam.__len__() > 0:
|
|
|
|
+ layoutUIObj = self.pyU.getUiObject2(layoutUIParam)
|
|
|
|
+ destUIObject = layoutUIObj.child(**destUIParam)
|
|
|
|
+ else:
|
|
|
|
+ destUIObject = self.pyU.getUiObject2(destUIParam)
|
|
|
|
+ #########################
|
|
else:
|
|
else:
|
|
- error(self.cls, "getChooseUIObj", option["name"] + " option 需要配置 focus-select或者FocusView", ERROR)
|
|
|
|
- return None
|
|
|
|
|
|
+ if layoutUIParam.__len__() > 0:
|
|
|
|
+ layoutUIObj = self.pyU.getUiObject2(layoutUIParam)
|
|
|
|
+ destUIObject = layoutUIObj.child(**destUIParam)
|
|
|
|
+ else:
|
|
|
|
+ destUIObject = self.pyU.getUiObject2(destUIParam)
|
|
|
|
+ return destUIObject
|
|
|
|
|
|
'''
|
|
'''
|
|
检测parent,在电视上是否被选中了。一个option被选中,表示选中
|
|
检测parent,在电视上是否被选中了。一个option被选中,表示选中
|
|
@@ -312,97 +500,64 @@ class FocusCommand():
|
|
1:已经选中parent
|
|
1:已经选中parent
|
|
'''
|
|
'''
|
|
def checkParentChoose(self, parent):
|
|
def checkParentChoose(self, parent):
|
|
- debug(self.cls, "checkParentChoose", "parent:" + parent["name"], DEBUG)
|
|
|
|
|
|
+ debug(self.cls, "checkParentChoose", "parent:" + parent[UATTree.TAB_NAME], DEBUG)
|
|
chooseTypeDict = {}
|
|
chooseTypeDict = {}
|
|
- layoutResId = parent["layout"][UATTree.Layout_ID]
|
|
|
|
|
|
+ layoutParam = parent[UATTree.TAB_LAYOUT]
|
|
|
|
+ layoutUIParam = UIParamUtil.setObjParam(layoutParam)
|
|
|
|
+ layoutResId = layoutParam[UATTree.Layout_ID]
|
|
uiView = parent[UATTree.TAB_UI_VIEW]
|
|
uiView = parent[UATTree.TAB_UI_VIEW]
|
|
uiViewResId = uiView[UATTree.View_ID]
|
|
uiViewResId = uiView[UATTree.View_ID]
|
|
uiViewText = uiView[UATTree.View_Text]
|
|
uiViewText = uiView[UATTree.View_Text]
|
|
uiViewDesc = uiView[UATTree.View_Desc]
|
|
uiViewDesc = uiView[UATTree.View_Desc]
|
|
|
|
+ # print "checkParentChoose,layoutUIParam:",layoutUIParam
|
|
if layoutResId == "" and uiViewResId == "" and uiViewText == "" and uiViewDesc == "":
|
|
if layoutResId == "" and uiViewResId == "" and uiViewText == "" and uiViewDesc == "":
|
|
debug(self.cls, "checkParentChoose",
|
|
debug(self.cls, "checkParentChoose",
|
|
- "Warning:Parent %s的Layout resId和UIView信息获取失败!!请注意检查UATree文件!!!" % parent['name'], DEBUG)
|
|
|
|
|
|
+ "Warning:Parent %s的Layout resId和UIView信息获取失败!!请注意检查UATree文件!!!" % parent[UATTree.TAB_NAME], DEBUG)
|
|
return -1
|
|
return -1
|
|
- elif layoutResId != "":
|
|
|
|
|
|
+ elif layoutUIParam.__len__() > 0:
|
|
# 如果存在UIView信息,则先判断UIView
|
|
# 如果存在UIView信息,则先判断UIView
|
|
- if uiViewResId != "" or uiViewText != "" or uiViewDesc != "":
|
|
|
|
- isExist = self.checkUIViewExist(uiView)
|
|
|
|
- if isExist is False:
|
|
|
|
- info(self.cls, "checkParentChoose", "当前页面不存在Parent:%s的UIView组件,判断该界面非此parent" % parent['name'],
|
|
|
|
- INFO)
|
|
|
|
- return -3
|
|
|
|
- else:
|
|
|
|
- info(self.cls, "checkParentChoose", "已识别出Parent:%s的UIView组件" % parent['name'], INFO)
|
|
|
|
- description = parent["layout"][UATTree.Layout_Desc]
|
|
|
|
- if description != "":
|
|
|
|
- layoutUIObj = self.pyU.getUiObject(resourceId=parent["layout"][UATTree.Layout_ID],
|
|
|
|
- description=parent["layout"][UATTree.Layout_Desc])
|
|
|
|
|
|
+ isExist = self.checkUIViewExist(uiView)
|
|
|
|
+ if isExist is False:
|
|
|
|
+ info(self.cls, "checkParentChoose", "当前页面不存在Parent:%s的UIView组件,判断该界面非此parent" % parent[UATTree.TAB_NAME],
|
|
|
|
+ INFO)
|
|
|
|
+ return -3
|
|
else:
|
|
else:
|
|
- layoutUIObj = self.pyU.getUiObject(resourceId=parent["layout"][UATTree.Layout_ID])
|
|
|
|
- if layoutUIObj is None or layoutUIObj.count == 0:
|
|
|
|
- # debug(self.cls, "checkParentChoose", "parent isn't " + parent["name"], DEBUG)
|
|
|
|
|
|
+ debug(self.cls, "checkParentChoose", "已识别出Parent:%s的UIView组件" % parent[UATTree.TAB_NAME], DEBUG)
|
|
|
|
+ # 判断Layout是否存在
|
|
|
|
+ layoutUIObj = self.pyU.getUiObject2(layoutUIParam)
|
|
|
|
+ if layoutUIObj is None or layoutUIObj.exists() is False:
|
|
|
|
+ info(self.cls, "checkParentChoose", "parent %s layout 不存在 "%parent[UATTree.TAB_NAME], INFO)
|
|
return -1
|
|
return -1
|
|
- # print "checkParentChoose, layoutUIObj:",layoutUIObj.info
|
|
|
|
- debug(self.cls, "checkParentChoose", "layoutUIObj:" + str(layoutUIObj.info), DEBUG)
|
|
|
|
|
|
+ debug(self.cls, "checkParentChoose", "parent %s layout 存在"%parent[UATTree.TAB_NAME], DEBUG)
|
|
|
|
+
|
|
|
|
+ # 获取焦点组件,判断是否在layout中
|
|
|
|
+ retCode, focusObj = self.getChooseUIObjP(parent, layoutUIParam, needFocus=False)
|
|
|
|
+ if retCode == self.Focus_Need_Not:
|
|
|
|
+ debug(self.cls, "checkParentChoose",
|
|
|
|
+ "已找到目标parent %s,不需要选中。" % (parent['name']), DEBUG)
|
|
|
|
+ elif focusObj is not None and focusObj.exists():
|
|
|
|
+ debug(self.cls, "checkParentChoose",
|
|
|
|
+ "已找到目标parent %s,焦点在Layout中。" % (parent['name']), DEBUG)
|
|
|
|
+ else:
|
|
|
|
+ info(self.cls, "checkParentChoose",
|
|
|
|
+ "已找到目标parent %s,但是焦点不在Layout中。" % (parent['name']), INFO)
|
|
|
|
+ return -2
|
|
|
|
+ # 判断parent中存在一个option,则标识parent被选中。注意:为了快速消失界面相应
|
|
|
|
+ if layoutParam[UATTree.Layout_Limit] <> 1:
|
|
|
|
+ layoutUIParam = {}
|
|
|
|
+ optionUIObj = None
|
|
|
|
+ optionExist = False
|
|
for optionName in parent["option"]:
|
|
for optionName in parent["option"]:
|
|
option = parent["option"][optionName]
|
|
option = parent["option"][optionName]
|
|
- if option["focus-select"]["type"].__len__() > 1:
|
|
|
|
- chooseTypeDict[option["focus-select"][UATTree.FS_Type]] = option
|
|
|
|
- elif option["focuseView"][UATTree.Focus_Text].__len__() > 0 \
|
|
|
|
- or option["focuseView"][UATTree.Focus_ID].__len__() > 1 \
|
|
|
|
- or option["focuseView"][UATTree.Focus_Desc].__len__() > 0:
|
|
|
|
- chooseTypeDict[option["focuseView"][UATTree.Focus_ID]
|
|
|
|
- + option["focuseView"][UATTree.Focus_Text]
|
|
|
|
- + option["focuseView"][UATTree.Focus_Desc]] = option
|
|
|
|
- info(self.cls, "checkParentChoose", str(chooseTypeDict), INFO)
|
|
|
|
- for key in chooseTypeDict.keys():
|
|
|
|
- option = chooseTypeDict[key]
|
|
|
|
- chooseUIObj = self.getChooseUIObj(option)
|
|
|
|
- # TODO 如果选中效果,是没有type[no],例如快捷键,如何处理?
|
|
|
|
- if chooseUIObj is None or chooseUIObj.count == 0:
|
|
|
|
- return -2
|
|
|
|
- debug(self.cls, "checkParentChoose", "chooseUIObj:" + str(chooseUIObj.info), DEBUG)
|
|
|
|
-
|
|
|
|
- # 获取到chooseUIObj后,与layout对比坐标,确认焦点是否存在于layout之中
|
|
|
|
- layoutBounds = layoutUIObj.info['bounds']
|
|
|
|
- choosingBounds = chooseUIObj.info['bounds']
|
|
|
|
- if not self.dm.isHasAnotherBounds(layoutBounds, choosingBounds):
|
|
|
|
|
|
+ ret = self.checkOptionExist(option,parent)
|
|
|
|
+ if ret is True:
|
|
info(self.cls, "checkParentChoose",
|
|
info(self.cls, "checkParentChoose",
|
|
- "识别出parent %s的Layout,但焦点不在该Layout之中,判断界面未处于该parent" % (parent['name']), INFO)
|
|
|
|
- return -2
|
|
|
|
-
|
|
|
|
- # 如果该页面text属性不为空,则确认该parent下所有option的text,是否存在于当前页面中;如果text属性为空,则判断index属性
|
|
|
|
- for optionName in parent["option"]:
|
|
|
|
- option = parent["option"][optionName]
|
|
|
|
- # 如果有text属性则确认Text,是否能对比成功
|
|
|
|
- optionText = option[UATTree.TAB_OPTION_VIEW][UATTree.View_Text]
|
|
|
|
- optionId = option[UATTree.TAB_OPTION_VIEW][UATTree.View_ID]
|
|
|
|
- optionIndex = option[UATTree.TAB_OPTION_VIEW][UATTree.View_Index]
|
|
|
|
- if optionText.__len__() > 0:
|
|
|
|
- info(self.cls, "checkParentChoose",
|
|
|
|
- "checking parent %s text %s" % (parent['name'], optionText), INFO)
|
|
|
|
- textObj = self.pyU.getUiObject(text=optionText)
|
|
|
|
- elif optionId.__len__() > 0:
|
|
|
|
- info(self.cls, "checkParentChoose",
|
|
|
|
- "checking parent %s optionId %s" % (parent['name'], optionId),
|
|
|
|
- INFO)
|
|
|
|
- textObj = self.pyU.getUiObject(resourceId=optionId)
|
|
|
|
- elif optionIndex != "":
|
|
|
|
- # index属性无法用于判断option,如果在以index属性作为判断依据的页面,则直接返回在这个页面
|
|
|
|
- info(self.cls, "checkParentChoose",
|
|
|
|
- "已找到目标parent %s,该页面为Index item页面,无法判断具体option" % parent['name'], INFO)
|
|
|
|
- return 1
|
|
|
|
- else:
|
|
|
|
- error(self.cls, "checkParentChoose", "当前参数不足以判断option %s是否存在" % (option['name']), ERROR)
|
|
|
|
- continue
|
|
|
|
- if textObj.exists:
|
|
|
|
- info(self.cls, "checkParentChoose",
|
|
|
|
- "已找到目标parent %s,并识别出该parent下的option %s" % (parent['name'], option['name']), INFO)
|
|
|
|
- return 1
|
|
|
|
- else:
|
|
|
|
- info(self.cls, "checkParentChoose",
|
|
|
|
- "return 0", INFO)
|
|
|
|
- return 0
|
|
|
|
|
|
+ "已找到目标parent %s,识别出该parent下的option %s。" % (parent['name'], option['name']),
|
|
|
|
+ INFO)
|
|
|
|
+ return 1
|
|
|
|
+ info(self.cls, "checkParentChoose",
|
|
|
|
+ "已找到目标parent %s,但是parent下的option未被发现。" % (parent['name']), INFO)
|
|
|
|
+ return 0
|
|
else:
|
|
else:
|
|
isExist = self.checkUIViewExist(uiView)
|
|
isExist = self.checkUIViewExist(uiView)
|
|
if not isExist:
|
|
if not isExist:
|
|
@@ -418,6 +573,7 @@ class FocusCommand():
|
|
当存在resId参数时,使用resId获取对象并获取文本,再与text做比较;
|
|
当存在resId参数时,使用resId获取对象并获取文本,再与text做比较;
|
|
当不存在resId参数时,使用text直接获取对象,判断对象是否存在。
|
|
当不存在resId参数时,使用text直接获取对象,判断对象是否存在。
|
|
与checkParentChoose判断不一致,做特殊处理。
|
|
与checkParentChoose判断不一致,做特殊处理。
|
|
|
|
+ :return 整型:0代表不存在,1代表存在
|
|
'''
|
|
'''
|
|
def checkDialogExist(self, dialog):
|
|
def checkDialogExist(self, dialog):
|
|
debug(self.cls, "checkDialogExist", "dialog:" + dialog["name"], DEBUG)
|
|
debug(self.cls, "checkDialogExist", "dialog:" + dialog["name"], DEBUG)
|
|
@@ -444,13 +600,12 @@ class FocusCommand():
|
|
return 0
|
|
return 0
|
|
|
|
|
|
def checkUIViewExist(self, uiView):
|
|
def checkUIViewExist(self, uiView):
|
|
- resid = uiView[UATTree.View_ID]
|
|
|
|
- text = uiView[UATTree.View_Text]
|
|
|
|
- description = uiView[UATTree.View_Desc]
|
|
|
|
- uiViewObj = self.pyU.getUiObject(resourceId=resid,
|
|
|
|
- text=text,
|
|
|
|
- description=description)
|
|
|
|
- if not uiViewObj.exists:
|
|
|
|
|
|
+ #uiview未配置默认为检测通过
|
|
|
|
+ if uiView.__len__() == 0:
|
|
|
|
+ return True
|
|
|
|
+ uiviewObjParam = UIParamUtil.setObjParam(uiView)
|
|
|
|
+ uiViewObj = self.pyU.getUiObject2(uiviewObjParam)
|
|
|
|
+ if uiViewObj is None or uiViewObj.exists is False:
|
|
return False
|
|
return False
|
|
else:
|
|
else:
|
|
return True
|
|
return True
|
|
@@ -463,7 +618,10 @@ if __name__ == "__main__":
|
|
runnerCmd = UATRunnerCommand(uatPathManage, pyU, dm, fm)
|
|
runnerCmd = UATRunnerCommand(uatPathManage, pyU, dm, fm)
|
|
focusCmd = FocusCommand(runnerCmd)
|
|
focusCmd = FocusCommand(runnerCmd)
|
|
|
|
|
|
- focusCmd.strToBounds('[801,116][1280,180]')
|
|
|
|
|
|
+ # ret = focusCmd.calPointAngle([0,0],[244,151])
|
|
|
|
+ ret = focusCmd.calPointAngle([244,151],[107,641])
|
|
|
|
+
|
|
|
|
+ # focusCmd.strToBounds('[801,116][1280,180]')
|
|
|
|
|
|
# option = focusCmd.runnerCommand.uatPathManage.uatData.getOption("av_devices_settings")
|
|
# option = focusCmd.runnerCommand.uatPathManage.uatData.getOption("av_devices_settings")
|
|
# parent = focusCmd.runnerCommand.uatPathManage.uatData.getParentByOption(option)
|
|
# parent = focusCmd.runnerCommand.uatPathManage.uatData.getParentByOption(option)
|