OptionConfig.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. # -*- coding:utf-8 -*-
  2. import os
  3. from UIT_PathManage import UITPathManage
  4. from ssat_sdk.MenuTree3.BaseLog import CBaseLog
  5. from ssat_sdk.MenuTree3.TConfig import TConfig
  6. # 测试加头文件;
  7. from TData import CTData
  8. g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth',
  9. 'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh', 'Twelfth']
  10. # 注意:所有不对外暴露的变量和函数需要私有化,以明确哪些接口和参数是对外的。
  11. # 这样便于后期维护时,根据对外的变量和函数来做处理。
  12. class COptionConfig(TConfig, CBaseLog):
  13. def __init__(self, menuTreeDir, pathManager):
  14. self.__pathManager = pathManager
  15. if self.__pathManager is None:
  16. self.error(u"路径参数错误:None")
  17. # 状态:False表示路径值失败;
  18. self.status = False
  19. # menuTree目录;
  20. self.__uiTreeDir = menuTreeDir
  21. # 判断是否为目录;
  22. if not os.path.isdir(self.__uiTreeDir):
  23. self.error(u"%s 不是menuTree目录" % self.__uiTreeDir)
  24. # 判断目录是否存在;
  25. if not os.path.exists(self.__uiTreeDir):
  26. self.error(u"menuTree(%s)目录不存在" % self.__uiTreeDir)
  27. # 判断配置文件是否存在;
  28. self.__configPath = os.path.join(self.__uiTreeDir, "menutree.ini")
  29. if not os.path.exists(self.__configPath):
  30. self.error(u"menutree配置文件不存在:%s" % self.__configPath)
  31. self.status = True
  32. # 初始化父类;
  33. TConfig.__init__(self, self.__configPath)
  34. # 获取超级密码;
  35. def getSuperPassword(self):
  36. return self.get_value("Password", "super")
  37. # 获取普通密码;
  38. def getOrdinaryPassword(self):
  39. return self.get_value("Password", "ordinary")
  40. # 获取父节点等待进入子节点时间;
  41. def getParentWaitTime(self, parent):
  42. optionName = parent + "WaitTime"
  43. try:
  44. waitTime = float(self.get_value("waitTime", optionName))
  45. except Exception:
  46. waitTime = 1.0
  47. self.error(u"获取%s界面的等待界面时间失败,使用默认值1.0s" % str(parent))
  48. return waitTime
  49. # 获取阀值字典;
  50. def getThresholdDict(self, optionName):
  51. section = "Threshold"
  52. thresholdDict = {}
  53. value = self.get_value(section, optionName)
  54. self.info("value:%s,%s" % (value, type(value)))
  55. if not value:
  56. return thresholdDict
  57. value_str = str(value)
  58. self.info("value_str:%s,%s" % (value_str, type(value_str)))
  59. value_dict = eval(value_str)
  60. self.info("value_dict:%s,%s" % (value_dict, type(value_dict)))
  61. return value_dict
  62. # 获取Option的图片配置;
  63. def __getICONConfig(self, optionName, is_value_sheet=False):
  64. # 默认值;
  65. def_cfg = {"icon_path": "", "dcfg": {}, "dir_path": ""}
  66. paths = self.__pathManager.get_option_paths(optionName)
  67. # 判断路径节点是否空;
  68. if paths.__len__() == 0:
  69. self.error(u"当前【%s】的路径节点空,使用默认的配置值%s" % (optionName, def_cfg))
  70. return False, def_cfg
  71. # 获取first parent;
  72. first_parent = paths[g_level[0]]['parent']
  73. # 获取当前option的level;
  74. cur_level = g_level[paths.__len__() - 1]
  75. # 当前option的父节点名称;
  76. cur_parent = paths[cur_level]['parent']
  77. if is_value_sheet is True:
  78. cur_level = "value"
  79. # option聚焦的首配图片路径;
  80. icon_path = os.path.join(self.__uiTreeDir, "icon\\", cur_parent + "." + cur_level + "_" + optionName + ".png")
  81. # option聚焦的dir首配图片路径;
  82. icon_dir_path = os.path.join(self.__uiTreeDir, "icon\\" + cur_parent + "." + cur_level + "_" + optionName + ".dir.png")
  83. # 图片聚焦时的定位参数;
  84. opc_cfg = self.get_value_dict(cur_level, cur_parent + '.' + optionName)
  85. # 首配图片判断是否存在,不存在取用次配图片路径;
  86. if not os.path.exists(icon_path):
  87. # 使用次配图片,父级配图;
  88. self.warn(u"Option(%s)首配图片不存在:%s" % (optionName, icon_path))
  89. icon_path = os.path.join(self.__uiTreeDir, "icon\\" + cur_parent + "." + cur_level + ".png")
  90. icon_dir_path = os.path.join(self.__uiTreeDir, "icon\\" + cur_parent + "." + cur_level + ".dir.png")
  91. opc_cfg = self.get_value_dict(cur_level, cur_parent)
  92. self.warn(u"Option(%s)首配图片不存在,尝试使用次配图(%s):%s,配置%s" % (optionName, cur_parent, icon_path, opc_cfg))
  93. # 如果次配都不存在,使用顶层配图;
  94. if not os.path.exists(icon_path):
  95. self.warn(u"Option(%s)次配图片不存在:%s" % (optionName, icon_path))
  96. # 使用顶层配图(first parent)
  97. icon_path = os.path.join(self.__uiTreeDir, "icon\\" + first_parent + "." + cur_level + "_" + optionName + ".png")
  98. icon_dir_path = os.path.join(self.__uiTreeDir, "icon\\" + first_parent + "." + cur_level + "_" + optionName + ".dir.png")
  99. opc_cfg = self.get_value_dict(cur_level, first_parent)
  100. self.warn(u"Option(%s)次配图片不存在,尝试使用顶层配图(%s):%s,配置%s" % (optionName, first_parent, icon_path, opc_cfg))
  101. # 如果顶层配图不存在,退出;
  102. if not os.path.exists(icon_path):
  103. self.error(u"%s对应的顶层菜单配图不存在%s,使用默认配置%s" % (optionName, icon_path, def_cfg))
  104. return False, def_cfg
  105. # endif
  106. # endif
  107. # endif
  108. if opc_cfg.__len__() == 0:
  109. opc_cfg = {"offset": 20, "minPeri": 0, "maxPeri": 0, "minArea": 0, "maxArea": 0, "morphology": []}
  110. return True, {"icon_path": icon_path, "dcfg": opc_cfg, "dir_path": icon_dir_path}
  111. # 获取Option的图片配置;
  112. def getOptionICONConfig(self, optionName):
  113. return self.__getICONConfig(optionName, False)
  114. # 获取Value的图片配置;
  115. def getValueICONConfig(self, valueName):
  116. return self.__getICONConfig(valueName, True)
  117. # 获取Option的OCR配置;
  118. def getOptionOCRConfig(self, optionName):
  119. ocr_dict = []
  120. # 默认的ocr配置;
  121. def_orc = [{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253}, {"lan": "ChinesePRC+English", "type": 10001}]
  122. paths = self.__pathManager.get_option_paths(optionName)
  123. # 判断路径节点是否空;
  124. if paths.__len__() == 0:
  125. self.error(u"当前【%s】的路径节点空,将使用默认的ocr配置%s" % (optionName, def_orc))
  126. else:
  127. # 如果状态False,退出;
  128. if self.status is False:
  129. self.warn(u"配置文件(%s)不存在,%s使用默认的ocr配置%s" % (self.__configPath, optionName, def_orc))
  130. else:
  131. # 读取指定的ocr配置信息;
  132. for i in range(g_level.index(paths.__len__() - 1), -1, -1):
  133. cur_parent = paths['parent']
  134. first_parent = paths['first_parent']
  135. cur_level = g_level[i]
  136. # 是否有当前option的ocr配置;
  137. if self.has_option(cur_level, optionName + '.ocr'):
  138. ocr_dict = self.get_dict(self.get_value(cur_level, optionName + '.ocr'))
  139. self.warn(u"%s使用自身的ocr配置%s" % (optionName, ocr_dict))
  140. break
  141. # 如果option本身没有配置,获取其父节点的配置;
  142. if self.has_option(cur_level, cur_parent + '.ocr'):
  143. ocr_dict = self.get_dict(self.get_value(cur_level, cur_parent + '.ocr'))
  144. self.warn(u"%s使用父节点%s的ocr配置%s" % (optionName, cur_parent, ocr_dict))
  145. break
  146. # 如果option父级没有配置,则获取顶层配置(first parent);
  147. if self.has_option(cur_level, first_parent + '.ocr'):
  148. ocr_dict = self.get_dict(self.get_value(cur_level, first_parent + '.ocr'))
  149. self.warn(u"%s使用顶层节点%s的ocr配置%s" % (optionName, first_parent, ocr_dict))
  150. break
  151. # end-for
  152. # end-if
  153. # end-if
  154. if ocr_dict.__len__() == 0:
  155. ocr_dict = def_orc
  156. self.warn(u"无有效的ocr配置,将使用默认的ocr配置%s" % def_orc)
  157. self.info(u"%s使用的ocr配置=%s" % (optionName, ocr_dict))
  158. return ocr_dict
  159. # 获取ICON源屏幕的分辨率配置值;
  160. # 该值用途:由于有些icon是在某些分辨率下截图的,但是同机芯项目可能使用同一套UI,只是分辨率不一样而已。
  161. # 所以,根据当初的icon分辨率,可以计算出在别的分辨率下的icon区域大小;
  162. def getICONResolutionConfig(self):
  163. return self.get_value_dict('Screen', 'shape') if self.has_option('Screen', 'shape') else [1920, 1080]
  164. if __name__ == "__main__":
  165. tData = CTData()
  166. upath = UITPathManage(tData)
  167. opc = COptionConfig(r'D:\SAT\resource\MenuTree\RT2851\2851', upath)
  168. print opc.getOptionICONConfig("picture")