|
@@ -13,7 +13,7 @@ g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth',
|
|
|
|
|
|
# 注意:所有不对外暴露的变量和函数需要私有化,以明确哪些接口和参数是对外的。
|
|
|
# 这样便于后期维护时,根据对外的变量和函数来做处理。
|
|
|
-class CConfigManager(TConfig, CBaseLog):
|
|
|
+class COptionConfig(TConfig, CBaseLog):
|
|
|
def __init__(self, menuTreeDir, pathManager):
|
|
|
self.__pathManager = pathManager
|
|
|
if self.__pathManager is None:
|
|
@@ -49,16 +49,16 @@ class CConfigManager(TConfig, CBaseLog):
|
|
|
optionName = parent + "WaitTime"
|
|
|
try:
|
|
|
waitTime = float(self.get_value("waitTime", optionName))
|
|
|
- except Exception, e:
|
|
|
+ except Exception:
|
|
|
waitTime = 1.0
|
|
|
self.error("获取%s界面的等待界面时间失败,使用默认值1.0s" % str(parent))
|
|
|
return waitTime
|
|
|
|
|
|
# 获取阀值字典;
|
|
|
- def getThresholdDict(self, option):
|
|
|
+ def getThresholdDict(self, optionName):
|
|
|
section = "Threshold"
|
|
|
thresholdDict = {}
|
|
|
- value = self.get_value(section, option)
|
|
|
+ value = self.get_value(section, optionName)
|
|
|
self.info("value:%s,%s" % (value, type(value)))
|
|
|
if not value:
|
|
|
return thresholdDict
|
|
@@ -90,8 +90,7 @@ class CConfigManager(TConfig, CBaseLog):
|
|
|
# option聚焦的首配图片路径;
|
|
|
icon_path = os.path.join(self.__uiTreeDir, "icon\\", cur_parent + "." + cur_level + "_" + optionName + ".png")
|
|
|
# option聚焦的dir首配图片路径;
|
|
|
- icon_dir_path = os.path.join(self.__uiTreeDir,
|
|
|
- "icon\\" + cur_parent + "." + cur_level + "_" + optionName + ".dir.png")
|
|
|
+ icon_dir_path = os.path.join(self.__uiTreeDir, "icon\\" + cur_parent + "." + cur_level + "_" + optionName + ".dir.png")
|
|
|
# 图片聚焦时的定位参数;
|
|
|
opc_cfg = self.get_value_dict(cur_level, cur_parent + '.' + optionName)
|
|
|
|
|
@@ -107,12 +106,8 @@ class CConfigManager(TConfig, CBaseLog):
|
|
|
if not os.path.exists(icon_path):
|
|
|
self.warn("Option(%s)次配图片不存在:%s" % (optionName, icon_path))
|
|
|
# 使用顶层配图(first parent)
|
|
|
- icon_path = os.path.join(self.__uiTreeDir,
|
|
|
- "icon\\" + first_parent + "." + cur_level + "_" + optionName +
|
|
|
- ".png")
|
|
|
- icon_dir_path = os.path.join(self.__uiTreeDir,
|
|
|
- "icon\\" + first_parent + "." + cur_level + "_" + optionName +
|
|
|
- ".dir.png")
|
|
|
+ icon_path = os.path.join(self.__uiTreeDir, "icon\\" + first_parent + "." + cur_level + "_" + optionName + ".png")
|
|
|
+ icon_dir_path = os.path.join(self.__uiTreeDir, "icon\\" + first_parent + "." + cur_level + "_" + optionName + ".dir.png")
|
|
|
opc_cfg = self.get_value_dict(cur_level, first_parent)
|
|
|
self.warn("Option(%s)次配图片不存在,尝试使用顶层配图(%s):%s,配置%s" % (optionName, first_parent, icon_path, opc_cfg))
|
|
|
# 如果顶层配图不存在,退出;
|
|
@@ -139,18 +134,16 @@ class CConfigManager(TConfig, CBaseLog):
|
|
|
# 获取Option的OCR配置;
|
|
|
def getOptionOCRConfig(self, optionName):
|
|
|
ocr_dict = []
|
|
|
+ # 默认的ocr配置;
|
|
|
+ def_orc = [{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253}, {"lan": "ChinesePRC+English", "type": 10001}]
|
|
|
paths = self.__pathManager.get_option_paths(optionName)
|
|
|
# 判断路径节点是否空;
|
|
|
if paths.__len__() == 0:
|
|
|
- self.error("当前【%s】的路径节点空" % optionName)
|
|
|
- ocr_dict = [{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253},
|
|
|
- {"lan": "ChinesePRC+English", "type": 10001}]
|
|
|
+ self.error("当前【%s】的路径节点空,将使用默认的ocr配置%s" % (optionName, def_orc))
|
|
|
else:
|
|
|
# 如果状态False,退出;
|
|
|
if self.status is False:
|
|
|
- self.warn("配置文件(%s)不存在,%s使用默认的ocr配置" % (self.__configPath, optionName))
|
|
|
- ocr_dict = [{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253},
|
|
|
- {"lan": "ChinesePRC+English", "type": 10001}]
|
|
|
+ self.warn("配置文件(%s)不存在,%s使用默认的ocr配置%s" % (self.__configPath, optionName, def_orc))
|
|
|
else:
|
|
|
# 读取指定的ocr配置信息;
|
|
|
for i in range(g_level.index(paths.__len__() - 1), -1, -1):
|
|
@@ -159,23 +152,29 @@ class CConfigManager(TConfig, CBaseLog):
|
|
|
cur_level = g_level[i]
|
|
|
# 是否有当前option的ocr配置;
|
|
|
if self.has_option(cur_level, optionName + '.ocr'):
|
|
|
- self.warn("%s使用自身的ocr配置" % optionName)
|
|
|
ocr_dict = self.get_dict(self.get_value(cur_level, optionName + '.ocr'))
|
|
|
+ self.warn("%s使用自身的ocr配置%s" % (optionName, ocr_dict))
|
|
|
break
|
|
|
# 如果option本身没有配置,获取其父节点的配置;
|
|
|
if self.has_option(cur_level, cur_parent + '.ocr'):
|
|
|
- self.warn("%s使用父节点%s的ocr配置" % (optionName, cur_parent))
|
|
|
ocr_dict = self.get_dict(self.get_value(cur_level, cur_parent + '.ocr'))
|
|
|
+ self.warn("%s使用父节点%s的ocr配置%s" % (optionName, cur_parent, ocr_dict))
|
|
|
break
|
|
|
# 如果option父级没有配置,则获取顶层配置(first parent);
|
|
|
if self.has_option(cur_level, first_parent + '.ocr'):
|
|
|
- self.warn("%s使用顶层节点%s的ocr配置" % (optionName, first_parent))
|
|
|
ocr_dict = self.get_dict(self.get_value(cur_level, first_parent + '.ocr'))
|
|
|
+ self.warn("%s使用顶层节点%s的ocr配置%s" % (optionName, first_parent, ocr_dict))
|
|
|
break
|
|
|
# end-for
|
|
|
# end-if
|
|
|
# end-if
|
|
|
- self.info("%s使用的ocr配置=%" % (optionName, ocr_dict))
|
|
|
+ if ocr_dict.__len__() == 0:
|
|
|
+ ocr_dict = def_orc
|
|
|
+ self.warn("无有效的ocr配置,将使用默认的ocr配置%s" % def_orc)
|
|
|
+
|
|
|
+ self.info("%s使用的ocr配置=%s" % (optionName, ocr_dict))
|
|
|
+
|
|
|
+ return ocr_dict
|
|
|
|
|
|
# 获取ICON源屏幕的分辨率配置值;
|
|
|
# 该值用途:由于有些icon是在某些分辨率下截图的,但是同机芯项目可能使用同一套UI,只是分辨率不一样而已。
|
|
@@ -187,5 +186,5 @@ class CConfigManager(TConfig, CBaseLog):
|
|
|
if __name__ == "__main__":
|
|
|
tData = CTData()
|
|
|
upath = UITPathManage(tData)
|
|
|
- opc = CConfigManager(r'D:\SAT\resource\MenuTree\RT2851\2851', upath)
|
|
|
+ opc = COptionConfig(r'D:\SAT\resource\MenuTree\RT2851\2851', upath)
|
|
|
print opc.getOptionICONConfig("picture")
|