Jeff 5 years ago
parent
commit
6b59eb87c7
3 changed files with 116 additions and 25 deletions
  1. 8 8
      ssat_sdk/MenuTree3/ExtraData.py
  2. 107 16
      ssat_sdk/MenuTree3/OptionExcel.py
  3. 1 1
      ssat_sdk/MenuTree3/TExcelParser.py

+ 8 - 8
ssat_sdk/MenuTree3/ExtraData.py

@@ -9,7 +9,7 @@ import sys
 # 自动化sdk头;
 from ssat_sdk.sat_environment import getMenuTree3SelectedProjectCfgPath
 from ssat_sdk.sat_environment import getMenuTreeSelectedChannel
-from ssat_sdk.MenuTree3.BaseLog import CBaseLog
+from BaseLog import CBaseLog
 
 
 # 外部数据,禁止外部修改;
@@ -26,7 +26,7 @@ class CExtraData(CBaseLog):
         # enter key excel路径;
         self.__enterKeyExcelPath = ""
         # menu tree低下的xls或xlsx文件集;
-        self.__listAppExcelPath = []
+        self.__listExcelPath = []
         # 数据状态(只要menuTreeDir和defaultExcelPath有效即为True);
         self.__status = False
         # 加载数据;
@@ -92,13 +92,13 @@ class CExtraData(CBaseLog):
 
         # 6、加载UITree开头的所有xls或xlsx
         fileList = os.listdir(self.menuTreeDir)
-        self.listAppExcelPath.append(self.defaultExcelPath)
+        self.listExcelPath.append(self.defaultExcelPath)
         if self.defaultExcelPath != self.tvExcelPath:
-            self.listAppExcelPath.append(self.tvExcelPath)
+            self.listExcelPath.append(self.tvExcelPath)
         for filePath in fileList:
             if filePath.lower().startswith("uitree") and (
                     filePath.lower().endswith(".xls") or filePath.lower().endswith(".xlsx")):
-                self.listAppExcelPath.append(os.path.join(self.menuTreeDir, filePath))
+                self.listExcelPath.append(os.path.join(self.menuTreeDir, filePath))
 
     @property
     def configPath(self):
@@ -121,8 +121,8 @@ class CExtraData(CBaseLog):
         return self.__enterKeyExcelPath
 
     @property
-    def listAppExcelPath(self):
-        return self.__listAppExcelPath
+    def listExcelPath(self):
+        return self.__listExcelPath
 
     @property
     def status(self):
@@ -139,7 +139,7 @@ if __name__ == "__main__":
     print u"默认excel路径                 ", exdata.defaultExcelPath
     print u"tv表格路径                    ", exdata.tvExcelPath
     print u"enterkey表格路径              ", exdata.enterKeyExcelPath
-    print u"所有表格列表                  ", exdata.listAppExcelPath
+    print u"所有表格列表                  ", exdata.listExcelPath
     print u"加载状态                      ", exdata.status
     print u"[==============================================]"
 

+ 107 - 16
ssat_sdk/MenuTree3/OptionExcel.py

@@ -2,14 +2,17 @@
 import os
 from collections import OrderedDict
 from UIT_PathManage import UITPathManage
-from ssat_sdk.MenuTree3.BaseLog import CBaseLog
-from ssat_sdk.MenuTree3.TExcelParser import CExcelParser
+from TExcelParser import CExcelParser
 from ssat_sdk.utils.string_util import strToList
 
 from xlsConst import xlsConst as xlsc
+from BaseLog import CBaseLog
+from ExtraData import CExtraData
+
 
 def parseMoveKey(keyStr):
-    return strToList(keyStr,";")
+    return strToList(keyStr, ";")
+
 
 g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth',
            'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh', 'Twelfth']
@@ -19,17 +22,17 @@ class CPathParams(CBaseLog):
     def __init__(self):
         self.paths = OrderedDict()
 
-    def addParent(self,level, pDict):
+    def addParent(self, level, pDict):
         if level not in self.paths:
             self.paths[level] = {}
         # endif
-        pDict["value"]=[]
+        pDict["value"] = []
         pDict[xlsc.move_key] = parseMoveKey(pDict[xlsc.move_key])
         if pDict[xlsc.parent] in self.paths:
-            self.error("Parent %s conflict."%(pDict[xlsc.parent]))
+            self.error("Parent %s conflict." % (pDict[xlsc.parent]))
         self.paths[level][pDict[xlsc.parent]] = pDict
 
-    def addOption(self,level, pDict):
+    def addOption(self, level, pDict):
         if level in self.paths:
             if pDict[xlsc.parent] in self.paths[level]:
                 if pDict[xlsc.option].__len__() > 0:
@@ -39,14 +42,15 @@ class CPathParams(CBaseLog):
         else:
             self.error("Level %s not exist." % (level))
 
+
 class CValueParams(CBaseLog):
     def __init__(self):
         self.values = OrderedDict()
 
     def addParent(self, pDict):
         if pDict[xlsc.value_name] in self.values:
-            self.error("Parent %s conflict."%(pDict[xlsc.value_name]))
-        pDict["value"]=[]
+            self.error("Parent %s conflict." % (pDict[xlsc.value_name]))
+        pDict["value"] = []
         pDict[xlsc.move_key] = parseMoveKey(pDict[xlsc.move_key])
         self.values[pDict[xlsc.value_name]] = pDict
 
@@ -57,19 +61,20 @@ class CValueParams(CBaseLog):
         else:
             self.error("Parent %s not exist." % (pDict[xlsc.value_name]))
 
+
 class CDialogParams(CBaseLog):
     def __init__(self):
         self.dialogs = OrderedDict()
 
-    def addParent(self,level, pDict):
+    def addParent(self, level, pDict):
         # endif
         if pDict[xlsc.parent] in self.dialogs:
-            self.error("Parent %s conflict."%(pDict[xlsc.parent]))
+            self.error("Parent %s conflict." % (pDict[xlsc.parent]))
         pDict["value"] = []
         pDict[xlsc.move_key] = parseMoveKey(pDict[xlsc.move_key])
         self.dialogs[pDict[xlsc.parent]] = pDict
 
-    def addOption(self,level,pDict):
+    def addOption(self, level, pDict):
         if pDict[xlsc.parent] in self.dialogs:
             if pDict[xlsc.option].__len__() > 0:
                 self.dialogs[pDict[xlsc.parent]]["value"].append(pDict)
@@ -81,20 +86,106 @@ class CDialogParams(CBaseLog):
 # 这样便于后期维护时,根据对外的变量和函数来做处理。
 class COptionExcel(CBaseLog):
     def __init__(self, exData):
-        self.__excelParse = CExcelParser()
+        self.__excelParse = CExcelParser(self)
         self.__exData = exData
         self.__pathParams = CPathParams()
         self.__valueParams = CValueParams()
         self.__dialogParams = CDialogParams()
+        # 加载excel;
+        self.loadExcel()
+
+    @property
+    def pathParams(self):
+        return self.__pathParams
+
+    @property
+    def valueParams(self):
+        return self.__valueParams
+
+    @property
+    def dialogParams(self):
+        return self.__dialogParams
 
     # 加载已知表格;
     def loadExcel(self):
-        pass
+        self.info(u"加载excel表")
+        if self.__exData.listExcelPath.__len__() == 0:
+            self.error(u"没有任何excel表格可加载")
+
+        for xls in self.__exData.listExcelPath:
+            self.info(u"当前加载:%s" % xls)
+            self.__excelParse.read_excel(xls)
 
     # 加载其他表格;
     def addExcel(self, xlsPath):
-        pass
+        self.__excelParse.read_excel(xlsPath)
+
+    
+    # 获取指定option/value_name下的所有子项(option/value)的ocr键对值;
+    # 示例:[{'suboption1': 'suboption1 ocr'}, {'suboption2': 'suboption2 ocr'}]
+    def getOptionSubitemMap(self, optionName, isOption = True):
+        if type(optionName) == str:
+            optionName = unicode(optionName)
+        pairs = []
+        # 路径表或值表;
+        if isOption is True:
+            found = False
+            for lev in self.__pathParams.paths:
+                for item in self.__pathParams.paths[lev]:
+                    if item.lower() == optionName.lower():
+                        found = True
+                        for item in self.__pathParams.paths[lev][optionName]["value"]:
+                            pairs.append({item['option']: item['option_for_ocr'].split(';')})
+                        break
+                    #endif
+                #endfor
+                if found is True:
+                    break
+            #endfor
+        else:
+            if optionName in self.__valueParams.values:
+                for item in self.__valueParams.values[optionName]["value"]:
+                    pairs.append({item['value']: item['value_for_ocr'].split(';')})
+        #endif
+
+        return pairs
+
+    
+    # 获取指定option/value_name下的所有子项(option/value)的ocr值;
+    # 示例:[['suboption1 ocr', 'ocr2', 'ocr3'],['suboption2 ocr'], ['suboption3 orc']]
+    def getOptionSubItemOcrList(self, optionName, isOption = True):
+        if type(optionName) == str:
+            optionName = unicode(optionName)
+
+        list_ocr = []
+        # 路径表或值表;
+        if isOption is True:
+            found = False
+            for lev in self.__pathParams.paths:
+                for item in self.__pathParams.paths[lev]:
+                    if item.lower() == optionName.lower():
+                        found = True
+                        for item in self.__pathParams.paths[lev][optionName]["value"]:
+                            if optionName.lower() != item['option'].lower():
+                                list_ocr.append(item['option_for_ocr'].split(';'))
+                        break
+                    #endif
+                #endfor
+                if found is True:
+                    break
+            #endfor
+        else:
+            if optionName in self.__valueParams.values:
+                for item in self.__valueParams.values[optionName]["value"]:
+                    list_ocr.append(item['value_for_ocr'].split(';'))
+        # endif
+        return list_ocr
 
+    def getOption
 
 if __name__ == "__main__":
-    pass
+    exData = CExtraData()
+    opxls = COptionExcel(exData)
+    # print opxls.pathParams.paths
+    print u"getOptionMap", opxls.getOptionSubitemMap('picture')
+    print u"getOptionSubItemOcrList", opxls.getOptionSubItemOcrList('picture', False)

+ 1 - 1
ssat_sdk/MenuTree3/TExcelParser.py

@@ -11,7 +11,7 @@ from BaseLog import CBaseLog
 
 
 class CExcelParser(CBaseLog):
-    def __init__(self, xls_path=None, optionExcel=None):
+    def __init__(self, optionExcel, xls_path=None):
         self.__optionExcel = optionExcel
         if type(xls_path) == str:
             xls_path = xls_path.decode('utf-8')