123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- import os
- from BaseLog import CBaseLog
- from TConfig import TConfig
- from ExtraData import CExtraData
- from OptionExcel import COptionExcel
- g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth',
- 'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh', 'Twelfth']
- class COptionConfig(TConfig, CBaseLog):
- def __init__(self, exData, optionExcel):
- CBaseLog.__init__(self)
- self.__exData = exData
- self.__optionExcel = optionExcel
- if self.__optionExcel is None:
- self.error(u"路径参数错误:None")
-
- self.status = False
-
- self.__uiTreeDir = self.__exData.menuTreeDir
-
- if not os.path.isdir(self.__uiTreeDir):
- self.error(u"%s 不是menuTree目录" % self.__uiTreeDir)
-
- if not os.path.exists(self.__uiTreeDir):
- self.error(u"menuTree(%s)目录不存在" % self.__uiTreeDir)
-
- self.__configPath = os.path.join(self.__uiTreeDir, "menutree.ini")
- if os.path.exists(self.__configPath):
- self.status = True
- else:
- self.error(u"menutree配置文件不存在:%s" % self.__configPath)
-
- TConfig.__init__(self, self.__configPath)
-
- def getSuperPassword(self):
- return self.get_value("Password", "super")
-
- def getOrdinaryPassword(self):
- return self.get_value("Password", "ordinary")
-
- def getParentWaitTime(self, parent):
- optionName = parent + "WaitTime"
- try:
- waitTime = float(self.get_value("waitTime", optionName))
- except Exception:
- waitTime = 1.0
- self.error(u"获取%s界面的等待界面时间失败,使用默认值1.0s" % str(parent))
- return waitTime
-
- '''
- 函数:获取指定option的阀值字典
- 参数:
- optionName 节点名称;
- 返回:字典。
- '''
- def getThresholdDict(self, optionName):
- section = "Threshold"
- thresholdDict = {}
- value = self.get_value(section, optionName)
- self.info("value:%s,%s" % (value, type(value)))
- if not value:
- return thresholdDict
- value_str = str(value)
- self.info("value_str:%s,%s" % (value_str, type(value_str)))
- value_dict = eval(value_str)
- self.info("value_dict:%s,%s" % (value_dict, type(value_dict)))
- return value_dict
- '''
- 函数:获取Option的图片配置,方式1
- 参数:
- 返回:Boolean, 字典
- 示例:True, {"icon_path": "", "dcfg": {}, "dir_path": ""}
-
- 说明:
- 查找顺序:
- [当前父节点][当前层级][当前节点] ->[当前父节点][当前层级] ->[根节点][当前层级][当前节点]
- [curParent][curLevel][curOption] ->[curParent][curLevel] ->[firstParent][curLevel][curOption]
- '''
- def __getICONConfig1(self, optionName, is_value_sheet=False):
-
- def_cfg = {"icon_path": "", "dcfg": {}, "dir_path": ""}
- paths = self.__optionExcel.getOptionPaths(optionName)
-
- if paths.__len__() == 0:
- self.error(u"当前【%s】的路径节点空,使用默认的配置值%s" % (optionName, def_cfg))
- return False, def_cfg
-
- first_parent = paths[g_level[0]]['parent']
-
- cur_level = g_level[paths.__len__() - 1]
-
- cur_parent = paths[cur_level]['parent']
- if is_value_sheet is True:
- cur_level = "value"
-
- icon_path = os.path.join(self.__uiTreeDir, "icon\\", cur_parent + "." + cur_level + "_" + optionName + ".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)
-
- if not os.path.exists(icon_path):
-
- self.warn(u"Option(%s)首配图片不存在:%s" % (optionName, icon_path))
- icon_path = os.path.join(self.__uiTreeDir, "icon\\" + cur_parent + "." + cur_level + ".png")
- icon_dir_path = os.path.join(self.__uiTreeDir, "icon\\" + cur_parent + "." + cur_level + ".dir.png")
- if opc_cfg.__len__() == 0:
- opc_cfg = self.get_value_dict(cur_level, cur_parent)
- self.warn(u"Option(%s)首配图片不存在,尝试使用次配图(%s):%s,配置%s" % (optionName, cur_parent, icon_path, opc_cfg))
-
- if not os.path.exists(icon_path):
- self.warn(u"Option(%s)次配图片不存在:%s" % (optionName, icon_path))
-
- 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")
- if opc_cfg.__len__() == 0:
- opc_cfg = self.get_value_dict(cur_level, first_parent)
- self.warn(u"Option(%s)次配图片不存在,尝试使用顶层配图(%s):%s,配置%s" % (optionName, first_parent, icon_path, opc_cfg))
-
- if not os.path.exists(icon_path):
- self.error(u"%s对应的顶层菜单配图不存在%s,使用默认配置%s" % (optionName, icon_path, def_cfg))
- return False, def_cfg
-
-
-
- if opc_cfg.__len__() == 0:
- opc_cfg = {"offset": 20, "minPeri": 0, "maxPeri": 0, "minArea": 0, "maxArea": 0, "morphology": []}
- return True, {"icon_path": icon_path, "dcfg": opc_cfg, "dir_path": icon_dir_path}
- '''
- 函数:获取Option的图片配置,方式2
- 参数:
- 返回:Boolean, 字典
- 示例:True, {"icon_path": "", "dcfg": {}, "dir_path": ""}
- 说明:
- 查找顺序:
- [根节点][当前层级][当前节点] ->[根节点][当前层级] ->[根节点][根层级]
- [firstParent][curLevel][curOption] ->[firstParent][curLevel] ->[firstParent][firstLevel]
- '''
- def __getICONConfig2(self, optionName, is_value_sheet=False):
-
- def_cfg = {"icon_path": "", "dcfg": {}, "dir_path": ""}
- paths = self.__optionExcel.getOptionPaths(optionName)
-
- if paths.__len__() == 0:
- self.error(u"当前【%s】的路径节点空,使用默认的配置值%s" % (optionName, def_cfg))
- return False, def_cfg
-
- first_parent = paths[g_level[0]]['parent']
-
- cur_level = g_level[paths.__len__() - 1]
-
- cur_parent = paths[cur_level]['parent']
- if is_value_sheet is True:
- cur_level = "value"
-
- 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)
-
- if not os.path.exists(icon_path):
-
- self.warn(u"Option(%s)首配图片不存在:%s" % (optionName, icon_path))
- icon_path = os.path.join(self.__uiTreeDir, "icon\\" + first_parent + "." + cur_level + ".png")
- icon_dir_path = os.path.join(self.__uiTreeDir, "icon\\" + first_parent + "." + cur_level + ".dir.png")
- self.warn(u"Option(%s)首配图片不存在,尝试使用次配图(%s):%s,配置%s" % (optionName, cur_parent, icon_path, opc_cfg))
-
- if not os.path.exists(icon_path):
- self.warn(u"Option(%s)次配图片不存在:%s" % (optionName, icon_path))
-
- icon_path = os.path.join(self.__uiTreeDir, "icon\\" + first_parent + "." + "First.png")
- icon_dir_path = os.path.join(self.__uiTreeDir, "icon\\" + first_parent + "." + "First.dir.png")
- self.warn(
- u"Option(%s)次配图片不存在,尝试使用顶层配图(%s):%s,配置%s" % (optionName, first_parent, icon_path, opc_cfg))
-
- if not os.path.exists(icon_path):
- self.error(u"%s对应的顶层菜单配图不存在%s,使用默认配置%s" % (optionName, icon_path, def_cfg))
- return False, def_cfg
-
-
-
- if opc_cfg.__len__() == 0:
- opc_cfg = {"offset": 20, "minPeri": 0, "maxPeri": 0, "minArea": 0, "maxArea": 0, "morphology": []}
- return True, {"icon_path": icon_path, "dcfg": opc_cfg, "dir_path": icon_dir_path}
- '''
- 函数:获取Option的图片配置
- 参数:
- optionName 要获取的option。
- 返回:Boolean, {}
- '''
- def getOptionICONConfig(self, optionName):
- outResutl, outData = self.__getICONConfig1(optionName, False)
- if outResutl is False:
- return self.__getICONConfig2(optionName, False)
- return outResutl, outData
- '''
- 函数:获取Value的图片配置
- 参数:
- valueName 要获取的value名称。
- 返回:Boolean, {}
- '''
- def getValueICONConfig(self, valueName):
- outResutl, outData = self.__getICONConfig1(valueName, True)
- if outResutl is False:
- return self.__getICONConfig2(valueName, True)
- return outResutl, outData
- '''
- 函数:获取Option的OCR配置
- 参数:
- optionName 要获取的option名称
- 返回:字典
- '''
- def getOptionOCRConfig(self, optionName):
- ocr_dict = []
-
- def_orc = [{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253}, {"lan": "ChinesePRC+English", "type": 10001}]
- paths = self.__optionExcel.getOptionPaths(optionName)
-
- if paths.__len__() == 0:
- self.error(u"当前【%s】的路径节点空,将使用默认的ocr配置%s" % (optionName, def_orc))
- else:
-
- if self.status is False:
- self.warn(u"配置文件(%s)不存在,%s使用默认的ocr配置%s" % (self.__configPath, optionName, def_orc))
- else:
-
- cur_level = g_level[paths.__len__() - 1]
-
- first_parent = paths[g_level[0]]['parent']
-
- cur_parent = paths[cur_level]['parent']
-
-
- if self.has_option(cur_level, optionName + '.ocr'):
- ocr_dict = self.get_dict(self.get_value(cur_level, optionName + '.ocr'))
- self.warn(u"%s使用自身的ocr配置%s" % (optionName, ocr_dict))
- else:
-
- if self.has_option(cur_level, cur_parent + '.ocr'):
- ocr_dict = self.get_dict(self.get_value(cur_level, cur_parent + '.ocr'))
- self.warn(u"%s使用父节点%s的ocr配置%s" % (optionName, cur_parent, ocr_dict))
- else:
-
- if self.has_option("First", first_parent + '.ocr'):
- ocr_dict = self.get_dict(self.get_value("First", first_parent + '.ocr'))
- self.warn(u"%s使用顶层节点%s的ocr配置%s" % (optionName, first_parent, ocr_dict))
-
-
-
-
- if ocr_dict.__len__() == 0:
- ocr_dict = def_orc
- self.warn(u"无有效的ocr配置,将使用默认的ocr配置%s" % def_orc)
- self.info(u"%s使用的ocr配置=%s" % (optionName, ocr_dict))
- return ocr_dict
- '''
- 函数:获取ICON源屏幕的分辨率配置值
- 参数:
- 返回:
-
- 说明:
- 该值用途:由于有些icon是在某些分辨率下截图的,但是同机芯项目可能使用同一套UI,只是分辨率不一样而已。
- 所以,根据当初的icon分辨率,可以计算出在别的分辨率下的icon区域大小;
- '''
- def getICONResolutionConfig(self):
- return self.get_value_dict('Screen', 'shape') if self.has_option('Screen', 'shape') else [1920, 1080]
- if __name__ == "__main__":
- exData = CExtraData()
- optionExcel = COptionExcel(exData)
- optionConfig = COptionConfig(exData, optionExcel)
-
-
-
-
-
- print "getOptionICONConfig", optionConfig.getOptionICONConfig('picture_preset')
-
-
-
|