Prechádzať zdrojové kódy

修复getOptionOCRConfig的BUG.

scbc.sat2 5 rokov pred
rodič
commit
a1a2288ab8
1 zmenil súbory, kde vykonal 40 pridanie a 26 odobranie
  1. 40 26
      ssat_sdk/MenuTree3/OptionConfig.py

+ 40 - 26
ssat_sdk/MenuTree3/OptionConfig.py

@@ -4,6 +4,7 @@ from UIT_PathManage import UITPathManage
 from BaseLog import CBaseLog
 from TConfig import TConfig
 from ExtraData import CExtraData
+from OptionExcel import COptionExcel
 
 
 g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth',
@@ -13,15 +14,15 @@ g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth',
 # 注意:所有不对外暴露的变量和函数需要私有化,以明确哪些接口和参数是对外的。
 # 这样便于后期维护时,根据对外的变量和函数来做处理。
 class COptionConfig(TConfig, CBaseLog):
-    def __init__(self, exData, pathManager):
+    def __init__(self, exData, optionExcel):
         self.__exData = exData
-        self.__pathManager = pathManager
-        if self.__pathManager is None:
+        self.__optionExcel = optionExcel
+        if self.__optionExcel is None:
             self.error(u"路径参数错误:None")
         # 状态:False表示路径值失败;
         self.status = False
         # menuTree目录;
-        self.__uiTreeDir = self.__exData.menutreeDir
+        self.__uiTreeDir = self.__exData.menuTreeDir
         # 判断是否为目录;
         if not os.path.isdir(self.__uiTreeDir):
             self.error(u"%s 不是menuTree目录" % self.__uiTreeDir)
@@ -30,9 +31,10 @@ class COptionConfig(TConfig, CBaseLog):
             self.error(u"menuTree(%s)目录不存在" % self.__uiTreeDir)
         # 判断配置文件是否存在;
         self.__configPath = os.path.join(self.__uiTreeDir, "menutree.ini")
-        if not os.path.exists(self.__configPath):
-            self.error(u"menutree配置文件不存在:%s" % self.__configPath)
+        if os.path.exists(self.__configPath):
             self.status = True
+        else:
+            self.error(u"menutree配置文件不存在:%s" % self.__configPath)
         # 初始化父类;
         TConfig.__init__(self, self.__configPath)
 
@@ -72,7 +74,7 @@ class COptionConfig(TConfig, CBaseLog):
     def __getICONConfig(self, optionName, is_value_sheet=False):
         # 默认值;
         def_cfg = {"icon_path": "", "dcfg": {}, "dir_path": ""}
-        paths = self.__pathManager.get_option_paths(optionName)
+        paths = self.__optionExcel.getOptionPaths(optionName)
         # 判断路径节点是否空;
         if paths.__len__() == 0:
             self.error(u"当前【%s】的路径节点空,使用默认的配置值%s" % (optionName, def_cfg))
@@ -136,7 +138,7 @@ class COptionConfig(TConfig, CBaseLog):
         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)
+        paths = self.__optionExcel.getOptionPaths(optionName)
         # 判断路径节点是否空;
         if paths.__len__() == 0:
             self.error(u"当前【%s】的路径节点空,将使用默认的ocr配置%s" % (optionName, def_orc))
@@ -145,29 +147,32 @@ class COptionConfig(TConfig, CBaseLog):
             if self.status is False:
                 self.warn(u"配置文件(%s)不存在,%s使用默认的ocr配置%s" % (self.__configPath, optionName, def_orc))
             else:
-                # 读取指定的ocr配置信息;
-                for i in range(g_level.index(paths.__len__() - 1), -1, -1):
-                    cur_parent = paths['parent']
-                    first_parent = paths['first_parent']
-                    cur_level = g_level[i]
-                    # 是否有当前option的ocr配置;
-                    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))
-                        break
+                # 获取当前option的level;
+                cur_level = g_level[paths.__len__() - 1]
+                # 获取first parent;
+                first_parent = paths[g_level[0]]['parent']
+                # 当前option的父节点名称;
+                cur_parent = paths[cur_level]['parent']
+
+                # 是否有当前option的ocr配置;
+                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:
                     # 如果option本身没有配置,获取其父节点的配置;
                     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))
-                        break
-                    # 如果option父级没有配置,则获取顶层配置(first parent);
-                    if self.has_option(cur_level, first_parent + '.ocr'):
-                        ocr_dict = self.get_dict(self.get_value(cur_level, first_parent + '.ocr'))
-                        self.warn(u"%s使用顶层节点%s的ocr配置%s" % (optionName, first_parent, ocr_dict))
-                        break
-                # end-for
+                    else:
+                        # 如果option父级没有配置,则获取顶层配置(first parent);
+                        if self.has_option(cur_level, first_parent + '.ocr'):
+                            ocr_dict = self.get_dict(self.get_value(cur_level, first_parent + '.ocr'))
+                            self.warn(u"%s使用顶层节点%s的ocr配置%s" % (optionName, first_parent, ocr_dict))
+                    #endif
+                #endif
             # end-if
         # end-if
+
         if ocr_dict.__len__() == 0:
             ocr_dict = def_orc
             self.warn(u"无有效的ocr配置,将使用默认的ocr配置%s" % def_orc)
@@ -185,4 +190,13 @@ class COptionConfig(TConfig, CBaseLog):
 
 if __name__ == "__main__":
     exData = CExtraData()
-    
+    optionExcel = COptionExcel(exData)
+    optionConfig = COptionConfig(exData, optionExcel)
+    # print "getSuperPassword", optionConfig.getSuperPassword()
+    # print "getOrdinaryPassword", optionConfig.getOrdinaryPassword()
+    # print "getParentWaitTime", optionConfig.getParentWaitTime('setting')
+    # print "getThresholdDict", optionConfig.getThresholdDict('setting')
+    # print "getOptionICONConfig", optionConfig.getOptionICONConfig('picture')
+    # print "getValueICONConfig", optionConfig.getValueICONConfig('picture')
+    print "getOptionOCRConfig", optionConfig.getOptionOCRConfig('picture')
+