|  | @@ -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)
 |