Przeglądaj źródła

MenuTree3经过康师傅修改后的版本;

scbc.sat2 5 lat temu
rodzic
commit
9c6d2b0d23

+ 32 - 14
ssat_sdk/MenuTree3/TData.py

@@ -1,35 +1,49 @@
 # -*- coding:utf-8 -*-
+import os,sys,time
 from ssat_sdk.MenuTree3.TExcelParser import CExcelParser
-
 from ssat_sdk import getMenuTree3SelectedProjectCfgPath, getMenuTree3SelectedPExcelPath
+from UIT_tree import UITTree
+from UIT_FileManage import UITFileManage
+from UIT_log import error, debug, info
+from TConfig import TConfig
 
-
+DEBUG = True
+INFO =True
+ERROR = True
 class CTData():
+    cls = "CTData"
     def __init__(self):
-        # excel路径,根据界面选择的项目来确定;
-        # self.xlspath = getMenuTree3SelectedProjectCfgPath() + '\\MenuTree.xls'
-        self.xlspath = getMenuTree3SelectedPExcelPath()
-        # excel解析器对象;
-        self.xlsparser = CExcelParser(self.xlspath)
-        # 读取excel并解析出内容;
-        self.xlsparser.read_excel()
-        # 新增表格查询接口
+        ini_path = os.path.join(getMenuTree3SelectedProjectCfgPath(), "menutree.ini")
+        self.tConfig = TConfig(ini_path)
+        self.UITree = UITTree(self.tConfig)
+        self.excelParser = CExcelParser(UITree=self.UITree)
+        self.fileManage = UITFileManage()
+        treeFileList = self.fileManage.getUITreeList()
+        for excelFile in treeFileList:
+            info(self.cls,"__init__","excelFile="+excelFile,INFO)
+            self.addUITExcel(excelFile)
+
+    '''
+    加载指定的UATree excel表格
+    '''
+    def addUITExcel(self, excelPath):
+        self.excelParser.read_excel(excelPath)
 
     # 获取表格Value层级中,value_name下包含的value列表
     def getSubValueList(self, value_name):
-        return self.xlsparser.getSubValueList(value_name)
+        return self.UITree.getSubValueList(value_name)
 
     # 获取表格First~Sixth层级中,parent下包含的option列表
     def getSubOptionList(self, parent):
-        return self.xlsparser.getSubOptionList(parent)
+        return self.UITree.getSubOptionList(parent)
 
     # 获取表格Value层级中,value_name下的指定value的ocr列表
     def getValueTextList(self, value_name, value):
-        return self.xlsparser.getValueTextList(value_name, value)
+        return self.UITree.getValueTextList(value_name, value)
 
     # 获取表格First~Sixth层级中,parent下的指定option的ocr列表
     def getOptionTextList(self, parent, option):
-        return self.xlsparser.getOptionTextList(parent, option)
+        return self.UITree.getOptionTextList(parent, option)
 
 
 if __name__ == "__main__":
@@ -56,3 +70,7 @@ if __name__ == "__main__":
     optionTextList = tData.getOptionTextList(parent, option)
     print u"获取表格First~Sixth层级中,parent:picture  下的option:picture_reset的ocr列表:", optionTextList
     # 执行结果:[u'picture reset']
+
+    print "pathParams:",tData.UITree.pathParams.paths
+    print "valueParams:",tData.UITree.valueParams.values
+    print "dialogParams:",tData.UITree.dialogParams.dialogs

+ 47 - 614
ssat_sdk/MenuTree3/TExcelParser.py

@@ -5,58 +5,21 @@ import xlwt
 import json
 # 字典不排序;
 from collections import OrderedDict
-
 from xlwt import XFStyle, Pattern
+from UIT_treeConstant import TreeConst
+from UIT_log import info,debug,error
 
-g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh',
-           'Twelfth']
-
-
-class CPathParams():
-    def __init__(self):
-        self.paths = OrderedDict()
-
-    def add_name(self, level, parent, move_key, enter_key, others):
-        if level not in self.paths:
-            self.paths[level] = {}
-        # endif
-        move_key = move_key.replace(' ', '')
-        self.paths[level][parent] = {"move_key": move_key.split(';'), "enter_key": enter_key, "others": others,
-                                     "value": []}
-
-    def add_item(self, level, parent, option, ocr, move_key, enter_key, others):
-        if level in self.paths:
-            if parent not in self.paths[level]:
-                self.paths[level][parent] = {}
-        else:
-            self.paths[level] = {}
-            self.paths[level][parent] = {}
-        self.paths[level][parent]["value"].append(
-            {"option": option, "option_for_ocr": ocr, "option_move_key": move_key, "option_enter_key": enter_key,
-             "option_others": others})
-
-
-class CValueParams():
-    def __init__(self):
-        self.values = OrderedDict()
-
-    def add_name(self, name, move_key, enter_key, others):
-        if name not in self.values:
-            move_key = move_key.replace(' ', '')
-            self.values[name] = {"move_key": move_key.split(';'), "enter_key": enter_key, "others": others, "value": []}
-
-    def add_item(self, name, option, ocr):
-        if name in self.values:
-            self.values[name]["value"].append({"value": option, "value_for_ocr": ocr})
-
+INFO =True
+DEBUG =True
+ERROR = True
 
 class CExcelParser():
-    def __init__(self, xls_path):
+    cls = "CExcelParser"
+    def __init__(self, xls_path=None,UITree=None):
+        self.UITree = UITree
         if type(xls_path) == str:
             xls_path = xls_path.decode('utf-8')
         self.xls_path = xls_path
-        self.pathParams = CPathParams()
-        self.valueParams = CValueParams()
 
     def read_excel(self, path=None):
         if path is not None:
@@ -90,521 +53,54 @@ class CExcelParser():
     # endfun
 
     def parse_excel(self, sheet, bpath=True):
-        last_name = None
+        pKeys = sheet.row_values(0)
+        info(self.cls,"parse_excel","params sheet %s keys: %s"%(sheet.name,str(pKeys)),INFO)
+        parentName = None
         if u"Value" == sheet.name:
             for i in range(1, sheet.nrows):
                 # 获取每行内容;
-                rows = tuple(sheet.row_values(i))
-                if rows[1].__len__() > 0 and rows[2].__len__() > 0 and last_name.__len__() > 0:
-                    # print sheet.name,"last_name:",last_name
-                    self.valueParams.add_item(last_name, rows[1], rows[2])
-                elif rows[0].__len__() > 0:
-                    last_name = rows[0]
-                    # print sheet.name, "last_name:", last_name
-                    self.valueParams.add_name(last_name, rows[3], rows[4], rows[5])
-        else:  # 路径;
-            for i in range(1, sheet.nrows):
-                # 获取每行内容;
-                rows = tuple(sheet.row_values(i))
-                if rows[1].__len__() > 0 and rows[2].__len__() > 0 and last_name.__len__() > 0:
-                    move_key = rows[3].split(';')
-                    self.pathParams.add_item(sheet.name, last_name, rows[1], rows[2], move_key, rows[4], rows[5])
-                elif rows[0].__len__() > 0:
-                    last_name = rows[0]
-                    self.pathParams.add_name(sheet.name, last_name, rows[3], rows[4], rows[5])
-
-    # endfun
-
-    def get_menu_paths(self, option, value):
-        if type(option) == str:
-            option = unicode(option)
-        if type(value) == str:
-            value = unicode(value)
-        # pp必须不排序;
-        vp, pp = {}, OrderedDict()
-        if option in self.valueParams.values:
-            vp = {"option": option, "value": value, "enter_key": self.valueParams.values[option]["enter_key"],
-                  "move_key": self.valueParams.values[option]["move_key"]}
-            # 找到value对应的ocr;
-            for item in self.valueParams.values[option]["value"]:
-                if "range(" in item["value"]:
-                    vp["value_for_ocr"] = item["value_for_ocr"].split(';')
-                    break
-                elif item["value"].lower() == value.lower():
-                    vp["value_for_ocr"] = item["value_for_ocr"].split(';')
-                    break
-
-        # 首先,字典不排序,需要倒序;
-        paths = reversed(self.pathParams.paths)
-        for level in paths:
-            found = False
-            for parent in self.pathParams.paths[level]:
-                # print parent,self.pathParams.paths[level][parent],'\r\n'
-                for item in self.pathParams.paths[level][parent]["value"]:
-                    # print item
-                    if item["option"].lower() == option.lower():
-                        pp[level] = {
-                            "parent": parent,
-                            "move_key": self.pathParams.paths[level][parent]["move_key"],
-                            "enter_key": self.pathParams.paths[level][parent]["enter_key"],
-                            "others": self.pathParams.paths[level][parent]["others"],
-                            "option": item["option"],
-                            "option_for_ocr": item["option_for_ocr"].split(';'),
-                            "option_move_key": item["option_move_key"],
-                            "option_enter_key": item["option_enter_key"],
-                            "option_others": item["option_others"]
-                        }
-                        option = parent
-                        found = True
-                        break
-                if found:
-                    break
-                else:
-                    if parent == option:
-                        for item in self.pathParams.paths[level][parent]["value"]:
-                            # print item
-                            if item["option"].lower() == value.lower():
-                                pp[level] = {
-                                    "parent": parent,
-                                    "move_key": self.pathParams.paths[level][parent]["move_key"],
-                                    "enter_key": self.pathParams.paths[level][parent]["enter_key"],
-                                    "others": self.pathParams.paths[level][parent]["others"],
-                                    "option": item["option"],
-                                    "option_for_ocr": item["option_for_ocr"].split(';'),
-                                    "option_move_key": item["option_move_key"],
-                                    "option_enter_key": item["option_enter_key"],
-                                    "option_others": item["option_others"]
-                                }
-                                option = parent
-                                found = True
-                                break
-                            # endif
-                        # endfor
-                        break
-                    # endif
-        # 需要对path倒序使用;
-        return vp, pp
-
-    def get_option_paths(self, option):
-        # pp必须不排序;
-        pp = OrderedDict()
-        # 首先,字典不排序,需要倒序;
-        paths = reversed(self.pathParams.paths)
-        for level in paths:
-            found = False
-            for parent in self.pathParams.paths[level]:
-                # print parent,self.pathParams.paths[level][parent],'\r\n'
-                for item in self.pathParams.paths[level][parent]["value"]:
-                    # print item
-                    if item["option"].lower() == option.lower():
-                        pp[level] = {
-                            "parent": parent,
-                            "move_key": self.pathParams.paths[level][parent]["move_key"],
-                            "enter_key": self.pathParams.paths[level][parent]["enter_key"],
-                            "others": self.pathParams.paths[level][parent]["others"],
-                            "option": item["option"],
-                            "option_for_ocr": item["option_for_ocr"].split(';'),
-                            "option_move_key": item["option_move_key"],
-                            "option_enter_key": item["option_enter_key"],
-                            "option_others": item["option_others"]
-                        }
-                        option = parent
-                        found = True
-                        break
-                if found:
-                    break
-                else:
-                    if parent == option:
-                        for item in self.pathParams.paths[level][parent]["value"]:
-                            # print item
-                            if item["option"].lower() == option.lower():
-                                pp[level] = {
-                                    "parent": parent,
-                                    "move_key": self.pathParams.paths[level][parent]["move_key"],
-                                    "enter_key": self.pathParams.paths[level][parent]["enter_key"],
-                                    "others": self.pathParams.paths[level][parent]["others"],
-                                    "option": item["option"],
-                                    "option_for_ocr": item["option_for_ocr"].split(';'),
-                                    "option_move_key": item["option_move_key"],
-                                    "option_enter_key": item["option_enter_key"],
-                                    "option_others": item["option_others"]
-                                }
-                                option = parent
-                                found = True
-                                break
-                            # endif
-                        # endfor
-                        break
-                    # endif
-            # endfor
-        # endfor
-        # 需要对path倒序使用;
-        # dict_pp = OrderedDict()
-        # # 逆序路径key;
-        # revpp = reversed(pp)
-        # for path in revpp:
-        #     dict_pp[path] = {"parent": pp[path]['parent'],"move_key": pp[path]['move_key'],"enter_key": pp[path]['enter_key'],"others":pp[path]['others'],"option": pp[path]['option'],"option_for_ocr": pp[path]['option_for_ocr']}
-        # # 返回逆序后的结果;
-        # return dict_pp
-        return pp
-
-    # 获取键对值
-    def get_pair_values(self, name, option=True):
-        if type(name) == str:
-            name = unicode(name)
-        pairs = []
-        if option is True:
-            find = False
-            for level in self.pathParams.paths:
-                for item in self.pathParams.paths[level]:
-                    if item.lower() == name.lower():
-                        find = True
-                        for item in self.pathParams.paths[level][name]["value"]:
-                            pairs.append({item['option']: item['option_for_ocr'].split(';')})
+                oneRow = tuple(sheet.row_values(i))
+                rowDict = {}
+                for index in range(oneRow.__len__()):
+                    item = oneRow[index]
+                    rowDict[pKeys[index]] = item
+                if rowDict[TreeConst.Value_Name] is None or rowDict[TreeConst.Value_Name].__len__() < 1:
+                    if parentName is None:
+                        error(self.cls, "parse_excel", "Level %s error row %s:" % (sheet.name, str(oneRow)), ERROR)
                         break
-                # endfor
-                if find is True:
-                    break
-            # endfor
-        else:
-            if name in self.valueParams.values:
-                for item in self.valueParams.values[name]["value"]:
-                    pairs.append({item['value']: item['value_for_ocr'].split(';')})
-        # endif
-        return pairs
-
-    # 获取指定层级的path或value的xxx_for_ocr列表;
-    def get_ocr_list(self, level, name, option, is_option=True):
-        if type(name) == str:
-            name = unicode(name)
-        if type(option) == str:
-            option = unicode(option)
-        list_ocr = []
-        if is_option is True:
-            find = False
-            for item in self.pathParams.paths[level]:
-                if item.lower() == name.lower():
-                    find = True
-                    for item in self.pathParams.paths[level][name]["value"]:
-                        if str(option).lower() != str(item["option"]).lower():
-                            list_ocr.append(item['option_for_ocr'].split(';'))
-                    break
-            # endfor
-        else:
-            if name in self.valueParams.values:
-                for item in self.valueParams.values[name]["value"]:
-                    list_ocr.append(item['value_for_ocr'].split(';'))
-        # endif
-        return list_ocr
-
-    # 获取指定value_name所在菜单项的全部同级菜单项ocr列表;
-    def get_parent_ocr_list(self, option):
-        # 编码转换;
-        if type(option) == str:
-            option = unicode(option)
-
-        found = False
-        list_ocr = []
-        # 首先,字典不排序,需要倒序;
-        paths = reversed(self.pathParams.paths)
-        for level in paths:
-            for parent in self.pathParams.paths[level]:
-                for vals in self.pathParams.paths[level][parent]["value"]:
-                    if vals['option'].lower() == option.lower():
-                        found = True
-                        break
-                # endfor
-                # 找到退出;
-                if found is True:
-                    break
-            # endfor
-            # 找到退出;
-            if found is True:
-                break
-        # endfor
-
-        # 遍历value列表;
-        if found is True:
-            for val in self.pathParams.paths[level][parent]["value"]:
-                list_ocr.extend(val['option_for_ocr'].split(';'))
-        # 按长度排序;
-        list_ocr.sort(key=lambda i: len(i), reverse=True)
-        # 返回结果;
-        return list_ocr
-
-    # 当value_sheet = False,表示获取path表里的option层级的所有option_for_ocr:option
-    # 当value_sheet = True,表示获取value表里的value_name层级的所有value_for_ocr:value
-    def get_parent_ocr_dict(self, option, value_sheet=False):
-        print "get_parent_ocr_dict.option:", option
-        # 编码转换;
-        if type(option) == str:
-            option = unicode(option)
-
-        found = False
-        dict_ocr = {}
-        list_ocr = []
-        if value_sheet is False:
-            # 首先,字典不排序,需要倒序;
-            paths = reversed(self.pathParams.paths)
-            for level in paths:
-                for parent in self.pathParams.paths[level]:
-                    for vals in self.pathParams.paths[level][parent]["value"]:
-                        if vals['option'].lower() == option.lower():
-                            found = True
-                            break
-                    # endfor
-                    # 找到退出;
-                    if found is True:
-                        break
-                # endfor
-                # 找到退出;
-                if found is True:
-                    break
-
-            # 遍历value列表;
-            if found is True:
-                for val in self.pathParams.paths[level][parent]["value"]:
-                    list_ocr = val['option_for_ocr'].split(';')
-                    for ocr in list_ocr:
-                        dict_ocr[ocr.lower()] = val['option']
-        else:
-            if option in self.valueParams.values:
-                for val in self.valueParams.values[option]["value"]:
-                    list_ocr = val['value_for_ocr'].split(';')
-                    for ocr in list_ocr:
-                        dict_ocr[ocr.lower()] = val['value']
-
-        print 'unsorted=', dict_ocr
-        # 按长度排序;
-        list_ocr = sorted(dict_ocr.keys(), key=lambda key: len(key), reverse=True)
-        dict_reuslt = OrderedDict()
-        for ocr in list_ocr:
-            dict_reuslt[ocr] = dict_ocr[ocr]
-        # 返回结果;
-        return dict_reuslt
-
-    def get_option_ocr(self, option):
-        # 编码转换;
-        if type(option) == str:
-            option = unicode(option)
-
-        found = False
-        list_ocr = []
-        # 首先,字典不排序,需要倒序;
-        paths = reversed(self.pathParams.paths)
-        for level in paths:
-            for parent in self.pathParams.paths[level]:
-                for vals in self.pathParams.paths[level][parent]["value"]:
-                    if vals['option'].lower() == option.lower():
-                        list_ocr = vals['option_for_ocr'].split(';')
-                        found = True
-                        break
-                # endfor
-                # 找到退出;
-                if found is True:
-                    break
-            # endfor
-            # 找到退出;
-            if found is True:
-                break
-        # endfor
-        # 返回结果;
-        return list_ocr
-
-    def get_value(self, option, value=""):
-        # 编码转换;
-        if type(option) == str:
-            option = unicode(option)
-        xlsValue = self.valueParams.values[option]["value"]
-        valueList = []
-        valueOcrList = []
-        for item in xlsValue:
-            valueList.append(item["value"])
-            valueOcrList.append(item["value_for_ocr"])
-        vp = {}
-        if option in self.valueParams.values:
-            vp = {"option": option, "value": valueList, "value_for_ocr": valueOcrList,
-                  "enter_key": self.valueParams.values[option]["enter_key"],
-                  "move_key": self.valueParams.values[option]["move_key"],
-                  "others": self.valueParams.values[option]['others']}
-            # 找到value对应的ocr;
-            if value != "":
-                vp["value"] = value
-                for item in self.valueParams.values[option]["value"]:
-                    if "range(" in item["value"]:
-                        vp["value_for_ocr"] = item["value_for_ocr"].split(';')
-                        break
-                    elif item["value"].lower() == value.lower():
-                        vp["value_for_ocr"] = item["value_for_ocr"].split(';')
-                        break
-                # endfor
-            # endif
-        # endif
-        # 返回结果;
-        return vp
-
-    # 获取option层级内容;
-    def get_option(self, option):
-        # 编码转换;
-        if type(option) == str:
-            option = unicode(option)
-
-        found = False
-        layers = 0
-        dict_option = {}
-        # 首先,字典不排序,需要倒序;
-        paths = reversed(self.pathParams.paths)
-        for level in paths:
-            for parent in self.pathParams.paths[level]:
-                for vals in self.pathParams.paths[level][parent]["value"]:
-                    if vals['option'].lower() == option.lower():
-                        if dict_option.__len__() == 0:
-                            found = True
-                            dict_option['level'] = level
-                            dict_option['parent'] = parent
-                            dict_option['others'] = self.pathParams.paths[level][parent]['others']
-                            dict_option['enter_key'] = self.pathParams.paths[level][parent]['enter_key']
-                            dict_option['move_key'] = self.pathParams.paths[level][parent]['move_key']
-                            dict_option['option_ocr'] = vals['option_for_ocr'].split(';')
-                            dict_option['option_move_key'] = vals['option_move_key']
-                            dict_option['option_enter_key'] = vals['option_enter_key']
-                            dict_option['option_others'] = vals['option_others']
-                        option = parent
-                        layers += 1  # 层数;
-                        break
-                # endfor
-            # endfor
-        # endfor
-        if found is True:
-            dict_option['layers'] = layers
-            # first层次的parent名称;
-            dict_option['first_parent'] = option
-        # 返回结果;
-        return found, dict_option
+                    else:
+                        rowDict[TreeConst.Value_Name] = parentName
+                        self.UITree.valueParams.addOption(rowDict)
+                elif rowDict[TreeConst.Value_Name].__len__() > 0:
+                    parentName = rowDict[TreeConst.Value_Name]
+                    self.UITree.valueParams.addParent(rowDict)
+        elif "Dialog" == sheet.name:
+            self.parsePath(sheet, pKeys, self.UITree.dialogParams)
+        else:  # 路径;
+            self.parsePath(sheet,pKeys, self.UITree.pathParams)
 
-    #
-    def getRepeatValueName_ValueSheet(self):
-        wb = xlrd.open_workbook(filename=self.xls_path)
-        valueSheet = wb.sheet_by_name("Value")
-        rows = valueSheet.nrows  # 获取行数
-        all_value_option_list = []
-        RepeatValueName_ValueSheet_List = []
 
-        for i in range(1, rows):
+    def parsePath(self, sheet,pKeys, treeParams):
+        parentName = None
+        for i in range(1, sheet.nrows):
             # 获取每行内容;
-            rows = tuple(valueSheet.row_values(i))
-            if rows[0].__len__() > 0:
-                if rows[0] in all_value_option_list:
-                    RepeatValueName_ValueSheet_List.append([rows[0], "Value"])
+            oneRow = tuple(sheet.row_values(i))
+            rowDict = {}
+            for index in range(oneRow.__len__()):
+                item = oneRow[index]
+                rowDict[pKeys[index]] = item
+            if rowDict[TreeConst.Parent_Name] is None or rowDict[TreeConst.Parent_Name].__len__() < 1:
+                if parentName is None:
+                    error(self.cls, "parse_excel", "Level %s error row %s:" % (sheet.name, str(oneRow)), ERROR)
+                    break
                 else:
-                    all_value_option_list.append(rows[0])
-        print "RepeatValueName_ValueSheet_List:", RepeatValueName_ValueSheet_List
-        return RepeatValueName_ValueSheet_List
+                    rowDict[TreeConst.Parent_Name] = parentName
+                    treeParams.addOption(sheet.name, rowDict)
+            elif rowDict[TreeConst.FLevel_Params[0]].__len__() > 0:
+                parentName = rowDict[TreeConst.Parent_Name]
+                treeParams.addParent(sheet.name, rowDict)
 
-    def getRepeatOption_otherSheet(self):
-        wb = xlrd.open_workbook(filename=self.xls_path)
-        all_option_list = []
-        repeatOption_otherSheet_List = []
-        for sh_name in wb.sheet_names():
-            sheet = wb.sheet_by_name(sh_name)
-            if u"Value" == sheet.name:
-                pass
-            else:  # 路径;
-                for i in range(1, sheet.nrows):
-                    # 获取每行内容;
-                    rows = tuple(sheet.row_values(i))
-                    if rows[1].__len__() > 0:
-                        if rows[1] in all_option_list:
-                            repeatOption_otherSheet_List.append([rows[1], sheet.name])
-                            # print "rows[1]:", rows[1], "sheetName:", sheet.name
-                        else:
-                            all_option_list.append(rows[1])
-        print "repeatOption_otherSheet_List:", repeatOption_otherSheet_List
-        return repeatOption_otherSheet_List
-
-    def getRepeatOptionList(self):
-        RepeatOptionList = []
-        repeatValueName_ValueSheet = self.getRepeatValueName_ValueSheet()
-        repeatOption_otherSheet = self.getRepeatOption_otherSheet()
-        RepeatOptionList = repeatOption_otherSheet + repeatValueName_ValueSheet
-        print "RepeatOptionList:", RepeatOptionList
-        return RepeatOptionList
-
-    def getValueSheetOptionList(self):
-        wb = xlrd.open_workbook(filename=self.xls_path)
-        valueSheet = wb.sheet_by_name("Value")
-        rows = valueSheet.nrows  # 获取行数
-        all_value_option_list = []
-
-        for i in range(1, rows):
-            # 获取每行内容;
-            rows = tuple(valueSheet.row_values(i))
-            if rows[0].__len__() > 0:
-                all_value_option_list.append(rows[0])
-        print "all_value_option_list:", all_value_option_list
-        return all_value_option_list
-
-    def checkOptionPath(self, optionName):
-        optionPath = ""
-        optionPathResult = "Fail"
-        path_params = self.get_option_paths(optionName)
-        # 如果传入的option不存在则直接返回
-        if path_params.__len__() <= 0:
-            optionPathResult = "NoExit"
-            optionPath = u"表格中不存在到达Option:   %s   的路径" % str(optionName)
-            return optionPath, optionPathResult
-        else:
-            optionPath = str(path_params)
-            # 逆序路径key;
-            revpp = reversed(path_params)
-            level_count = 0
-            for level in revpp:
-                if str(level) == str(g_level[level_count]):
-                    level_count = level_count + 1
-                else:
-                    # 如果执行路径不是按照First、Second......执行则返回执行出错
-                    return optionPath, optionPathResult
-            optionPathResult = "Pass"
-            return optionPath, optionPathResult
-
-    def checkRunOptionPath(self, path_params):
-        optionPathResult = "Fail"
-        # 如果传入的option不存在则直接返回
-        if path_params.__len__() <= 0:
-            optionPathResult = "NoExit"
-            return optionPathResult
-        else:
-            optionPath = str(path_params)
-            # 逆序路径key;
-            revpp = reversed(path_params)
-            level_count = 0
-            for level in revpp:
-                if str(level) == str(g_level[level_count]):
-                    level_count = level_count + 1
-                else:
-                    # 如果执行路径不是按照First、Second......执行则返回执行出错
-                    return optionPathResult
-            optionPathResult = "Pass"
-            return optionPathResult
-
-    def getCheckOptionPathExcelData(self):
-        checkOptionPathExcelData = []
-        checkOptionPathExcelData_Fail = []
-        checkOptionPathExcelData_NoExit = []
-        checkOptionPathExcelData_Pass = []
-        valueSheetOptionList = self.getValueSheetOptionList()
-        for optionName in valueSheetOptionList:
-            optionPath, optionPathResult = self.checkOptionPath(optionName)
-            if str(optionPathResult) == "Fail":
-                checkOptionPathExcelData_Fail.append([optionName, optionPathResult, optionPath])
-            if str(optionPathResult) == "NoExit":
-                checkOptionPathExcelData_NoExit.append([optionName, optionPathResult, optionPath])
-            if str(optionPathResult) == "Pass":
-                checkOptionPathExcelData_Pass.append([optionName, optionPathResult, optionPath])
-
-            # checkOptionPathExcelData.append([optionName, optionPathResult, optionPath])
-        checkOptionPathExcelData = checkOptionPathExcelData_Fail + checkOptionPathExcelData_NoExit + checkOptionPathExcelData_Pass
-        return checkOptionPathExcelData
+    # endfun
 
     def saveExcelData(self, checkOptionPathExcelData, repeatOptionList, all_UI_TestLanguagePath):
 
@@ -731,69 +227,6 @@ class CExcelParser():
     #     # print "valueList:", valueList, type(valueList)
     #     return valueList
 
-    # 获取表格Value层级中,value_name下包含的value列表
-    def getSubValueList(self, value_name):
-        valueList = []
-        if self.valueParams.values.has_key(value_name):
-            # print parser.valueParams.values["source"]
-            # print parser.valueParams.values["source"]["value"]
-            valueDictList = self.valueParams.values[value_name]["value"]
-            for valueDict in valueDictList:
-                valueList.append(valueDict["value"])
-        # print "valueList:", valueList, type(valueList)
-        if valueList.__len__() == 1 and "range(" in valueList[0]:
-            value_for_ocr_low = str(valueList[0]).lower()
-            str_num = value_for_ocr_low.replace("range", "")
-            list_num = eval(str_num)
-            min_num = list_num[0]
-            max_num = list_num[1]
-            return [min_num, max_num]
-
-        return valueList
-
-    # 获取表格First~Sixth层级中,parent下包含的option列表
-    def getSubOptionList(self, parent):
-        optionList = []
-        paths = self.pathParams.paths
-        for level in paths:
-            if paths[level].has_key(parent):
-                optionDictList = paths[level][parent]["value"]
-                for optionDict in optionDictList:
-                    optionList.append(optionDict["option"])
-        # print "optionList:", optionList, type(optionList)
-        return optionList
-
-    # 获取表格Value层级中,value_name下的value的ocr列表
-    def getValueTextList(self, value_name, value):
-        valueTextList = []
-        if self.valueParams.values.has_key(value_name):
-            # print parser.valueParams.values["source"]
-            # print parser.valueParams.values["source"]["value"]
-            valueDictList = self.valueParams.values[value_name]["value"]
-            for valueDict in valueDictList:
-                if valueDict["value"] == value:
-                    value_for_ocr = valueDict["value_for_ocr"]
-                    # print "value_for_ocr:", value_for_ocr, type(value_for_ocr)
-                    valueTextList = value_for_ocr.split(';')
-
-        # print "valueTextList:", valueTextList, type(valueTextList)
-        return valueTextList
-
-    # 获取表格First~Sixth层级中,parent下的option的ocr列表
-    def getOptionTextList(self, parent, option):
-        optionTextList = []
-        paths = self.pathParams.paths
-        for level in paths:
-            if paths[level].has_key(parent):
-                optionDictList = paths[level][parent]["value"]
-                for optionDict in optionDictList:
-                    if optionDict["option"] == option:
-                        option_for_ocr = optionDict["option_for_ocr"]
-                        # print "option_for_ocr:", option_for_ocr, type(option_for_ocr)
-                        optionTextList = option_for_ocr.split(';')
-        # print "optionList:", optionTextList, type(optionTextList)
-        return optionTextList
-
 
 if __name__ == "__main__":
     # path = r'E:\svn\SAT\项目资料\第四期-推广使用和画面检测\06-设计文档\01-蓝图设计\UiTree3.0方案\MenuTree_MS6586_EU.xls'

+ 2 - 2
ssat_sdk/MenuTree3/TFocus.py

@@ -20,12 +20,12 @@ g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth',
 
 
 class TFocus():
-    def __init__(self, project_path, xlsparser=None, screen=[1920, 1080], icon_shape=[1920, 1080]):
+    def __init__(self, project_path, uitRunner=None, screen=[1920, 1080], icon_shape=[1920, 1080]):
         self.params_path = project_path
         self.rgbColor = RGBColor()
         self.CIE = CIEluvCaculator()
         self.feature_detect = FeatureDetect()
-        self.xlsparser = xlsparser
+        self.xlsparser = uitRunner.uitPathManage
         # icon分辨率width*height;
         self.icon_shape = icon_shape
         # 当前屏幕分辨率;

+ 43 - 54
ssat_sdk/MenuTree3/TMenu.py

@@ -6,6 +6,7 @@ from ssat_sdk.utils.string_util import getDigitFromString
 from ssat_sdk.device_manage.capturecard_manager import CCardManager
 
 from ssat_sdk.MenuTree3.TExcelParser import CExcelParser
+from ssat_sdk.MenuTree3.UIT_runner import UITRunner
 from ssat_sdk import getMenuTree3SelectedProjectCfgPath, OCRConvert, getSATTmpDIR, ImageCMP, \
     getMenuTree3SelectedPExcelPath, getMenuTree3SelectedTvExcelPath
 from ssat_sdk.MenuTree3.TFocus import TFocus
@@ -27,32 +28,20 @@ class CTMenu():
     # def __init__(self, ocrDict={"lan": "CHN_ENG", "type": 10000}):
     def __init__(self, ocrDict=[{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253},
                                 {"lan": "ChinesePRC+English", "type": 10001}]):
-        # excel路径,根据界面选择的项目来确定;
-        # 非tv表格
-        self.xlspath = getMenuTree3SelectedPExcelPath()
-        #tv表格
-        self.tv_xlspath = getMenuTree3SelectedTvExcelPath()
-        printLog(u"构建CTMenu对象!非tv表格路径:%s" % str(self.xlspath))
-        printLog(u"tv表格路径:%s" % str(self.tv_xlspath))
-        # print "self.xlspath :", self.xlspath
+        self.uitRunner = UITRunner()
+        self.uitPathManage = self.uitRunner.uitPathManage
+
         # 创建视频采集对象
         self.ccard = CCardManager()
         # 创建OCR对象
         self.ocr = OCRConvert()
         # 图片切割对象
         self.imgCMP = ImageCMP()
-        # excel解析器对象;
-        self.xlsparser = CExcelParser(self.xlspath)
-        # 解析非tv的menutree表格;
-        self.xlsparser.read_excel()
-        # 解析tv的menutree表格(存在tv menutree时才进行解析);
-        if self.xlspath != self.tv_xlspath:
-            self.xlsparser.read_excel(self.tv_xlspath)
         # 读取excel并解析出内容;
         # 红老鼠遥控对象;
         self.redRat3 = TvOperator()
         # 配置文件;
-        self.tconfig = TConfig(getMenuTree3SelectedProjectCfgPath() + "\\MenuTree.ini")
+        self.tconfig = self.uitRunner.uitData.tConfig
         self.icon_shape = [1920, 1080]
         if self.tconfig.has_option('Screen', 'shape'):
             self.icon_shape = self.tconfig.get_value_dict('Screen', 'shape')
@@ -66,13 +55,13 @@ class CTMenu():
                 self.Screen = [img.shape[1], img.shape[0]]
 
         # 创建获取聚焦区域对象
-        self.tFocus = TFocus(getMenuTree3SelectedProjectCfgPath(), self.xlsparser, self.Screen, self.icon_shape)
+        self.tFocus = TFocus(getMenuTree3SelectedProjectCfgPath(), self.uitRunner, self.Screen, self.icon_shape)
         self.ocrDict = ocrDict
         # 某数据是否读取过;
         self.got_dict = {}
         # 22293
         self.sourceInput = SourceGenInput()
-        self.tSource = TSourceImpl(self.ocr, self.ccard, self.redRat3, self.tFocus, self.tconfig, self.xlsparser)
+        self.tSource = TSourceImpl(self.ocr, self.ccard, self.redRat3, self.tFocus, self.tconfig, self.uitRunner)
 
     def currentTime(self):
         return time.strftime('_%Y-%m-%d_%H_%M_%S', time.localtime(time.time()))
@@ -81,11 +70,11 @@ class CTMenu():
         # OCR识别参数字典   默认值为:百度中英文免费类型
         ini_path = os.path.join(getMenuTree3SelectedProjectCfgPath(), "menutree.ini")
         if os.path.exists(ini_path) is True:
-            tconfig = TConfig(ini_path)
+            tconfig = self.uitRunner.uitData.tConfig
             # if tconfig.has_option(level, parent + u'.ocr'):
             #     self.ocrDict = tconfig.get_dict(tconfig.get_value(level, parent + u'.ocr'))
             #     return
-            result, path = self.xlsparser.get_option(option)
+            result, path = self.uitRunner.uitData.UITree.get_option(option)
             print u"get_ocr_list, path:",path
             if result:
                 # 从当前层逐层往上遍历,寻找ocr参数列表
@@ -213,7 +202,7 @@ class CTMenu():
         self.imgCMP.saveCropPic(src_pic, text_pic, (contourRect[0], contourRect[1], contourRect[2], contourRect[3]))
         # 获取ocr_list;
         cur_parent, cur_option = paths['parent'], paths['option']
-        ocr_list = self.xlsparser.get_ocr_list(level, cur_parent, cur_option,
+        ocr_list = self.uitRunner.uitData.UITree.get_ocr_list(level, cur_parent, cur_option,
                                                True if cur_parent == cur_option else False)
         print u"%s,%s,%s =>ocr_list=%s" % (level, cur_parent, cur_option, str(ocr_list))
         # 遍历ocr类型;
@@ -231,9 +220,9 @@ class CTMenu():
             ocr_str = unicode(ocr_str).lower()
 
             if is_for_value:
-                parent_ocr_dict = self.xlsparser.get_parent_ocr_dict(cur_parent, value_sheet=True)
+                parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(cur_parent, value_sheet=True)
             else:
-                parent_ocr_dict = self.xlsparser.get_parent_ocr_dict(cur_option)
+                parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(cur_option)
 
             print u"getCurrentFocusTextEx.parent_ocr_dict:", parent_ocr_dict
             list_parent_ocr_value = list(parent_ocr_dict.keys())
@@ -313,7 +302,7 @@ class CTMenu():
     def getOCRStrListByOptionList(self, optionList):
         OCRStrList = []
         for option in optionList:
-            hasOption, optionDict = self.xlsparser.get_option(option)
+            hasOption, optionDict = self.uitRunner.uitData.UITree.get_option(option)
             if hasOption:
                 optionStrList = optionDict["option_ocr"]
                 OCRStrList.extend(optionStrList)
@@ -322,7 +311,7 @@ class CTMenu():
     def getOCRStrDictByOptionList(self, optionList):
         OCRStrDict = {}
         for option in optionList:
-            hasOption, optionDict = self.xlsparser.get_option(option)
+            hasOption, optionDict = self.uitRunner.uitData.UITree.get_option(option)
             if hasOption:
                 optionStrList = optionDict["option_ocr"]
                 OCRStrDict[option] = optionStrList
@@ -479,7 +468,7 @@ class CTMenu():
         # ocr识别;
         ocr_result = ''
         # 获取ocr列表;
-        hasOption, path = self.xlsparser.get_option(option)
+        hasOption, path = self.uitRunner.uitData.UITree.get_option(option)
         if hasOption:
             self.get_ocr_list(path['level'], option)
         for orc_item in self.ocrDict:
@@ -554,7 +543,7 @@ class CTMenu():
 
             # print "self.ocrDict:", self.ocrDict
             # 获取ocr_list;
-            ocr_list = self.xlsparser.get_ocr_list(level, cur_parent, option, True if cur_parent == option else False)
+            ocr_list = self.uitRunner.uitData.UITree.get_ocr_list(level, cur_parent, option, True if cur_parent == option else False)
             print u"%s,%s,%s =>ocr_list=%s" % (level, cur_parent, option, str(ocr_list))
 
             # 获取ocr列表;
@@ -573,9 +562,9 @@ class CTMenu():
 
                 if isSource is False:
                     if isForValue:
-                        parent_ocr_dict = self.xlsparser.get_parent_ocr_dict(cur_parent, value_sheet=True)
+                        parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(cur_parent, value_sheet=True)
                     else:
-                        parent_ocr_dict = self.xlsparser.get_parent_ocr_dict(option)
+                        parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(option)
                     print u"getCurrentFocusTextEx.parent_ocr_dict:", parent_ocr_dict
                     list_parent_ocr_value = list(parent_ocr_dict.keys())
                     print u"getCurrentFocusTextEx.list_parent_ocr_value:", list_parent_ocr_value
@@ -784,7 +773,7 @@ class CTMenu():
         # 正向寻找的次数计数和最大次数
         count = 0
         parent = paths['parent']
-        option_list = self.xlsparser.getSubOptionList(parent)
+        option_list = self.uitRunner.uitData.UITree.getSubOptionList(parent)
         if option_list.__len__() != 0:
             Max_Try = option_list.__len__()
             print u"move2TargetNode.%s option_list:"%parent, option_list
@@ -912,7 +901,7 @@ class CTMenu():
 
         isMarquee = False
         marquee_dict = {}
-        leaf_data = self.xlsparser.get_value(option)
+        leaf_data = self.uitRunner.uitData.UITree.get_value(option)
         if leaf_data["others"].__len__():
             data_other = json.loads(leaf_data["others"])
             # 是否有跑马灯文本;
@@ -1000,7 +989,7 @@ class CTMenu():
                     break
                 if isMarquee is True:
                     # 跑马灯函数需要cur_parent的参数,把cur_parent参数加入到leaf_data中再传进去
-                    result, paths = self.xlsparser.get_option(option)
+                    result, paths = self.uitRunner.uitData.UITree.get_option(option)
                     leaf_data['parent'] = paths['parent']
                     leaf_data['option_for_ocr'] = leaf_data['value_for_ocr']
                     isFind, text = self.getFocusBoxMarqueeText(marquee_dict, level, first_parent, leaf_data)
@@ -1085,11 +1074,11 @@ class CTMenu():
         # 寻路结果;
         result = False
         # 获取menu path;
-        value_params, path_params = self.xlsparser.get_menu_paths(option, value)
+        value_params, path_params = self.uitPathManage.get_menu_paths(option, value)
         printLog(u"获取到达option:%s的路径字典path_params:%s" % (str(option), str(path_params)))
         printLog(u"获取设置value:%s的值字典value_params:%s" % (str(value), str(value_params)))
 
-        checkRunOptionPathResult = self.xlsparser.checkRunOptionPath(path_params)
+        checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
         if str(checkRunOptionPathResult) == "NoExit":
             printLog(u"表格中不存在到达Option:   %s   的路径,在表格中排查到达该Option路径" % str(option))
             return False
@@ -1270,11 +1259,11 @@ class CTMenu():
         # 寻路结果;
         result = False
         # 获取menu path;
-        value_params, path_params = self.xlsparser.get_menu_paths(option, value)
+        value_params, path_params = self.uitPathManage.get_menu_paths(option, value)
         printLog(u"获取到达option:%s的路径字典path_params:%s" % (str(option), str(path_params)))
         printLog(u"获取检测value:%s的值字典value_params:%s" % (str(value), str(value_params)))
 
-        checkRunOptionPathResult = self.xlsparser.checkRunOptionPath(path_params)
+        checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
         if str(checkRunOptionPathResult) == "NoExit":
             printLog(u"表格中不存在到达Option:   %s   的路径,在表格中排查到达该Option路径" % str(option))
             return False
@@ -1645,11 +1634,11 @@ class CTMenu():
         self.sourceInput.setPattern(11)
         # 获取menu path;
         print "openOption start >>>"
-        path_params = self.xlsparser.get_option_paths(option)
+        path_params = self.uitPathManage.get_option_paths(option)
         # print 'openOption=path_params:', path_params
         printLog('openOption=path_params:%s' % str(path_params))
 
-        checkRunOptionPathResult = self.xlsparser.checkRunOptionPath(path_params)
+        checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
         if str(checkRunOptionPathResult) == "NoExit":
             printLog(u"表格中不存在到达Option:   %s   的路径,在表格中排查到达该Option路径" % str(option))
             return False
@@ -1791,11 +1780,11 @@ class CTMenu():
         # 寻路结果;
         result = False
         # 获取menu path;
-        value_params, path_params = self.xlsparser.get_menu_paths(option, value)
+        value_params, path_params = self.uitPathManage.get_menu_paths(option, value)
         printLog(u"获取到达option:%s的路径字典path_params:%s" % (str(option), str(path_params)))
         printLog(u"获取聚焦value:%s的值字典value_params:%s" % (str(value), str(value_params)))
 
-        checkRunOptionPathResult = self.xlsparser.checkRunOptionPath(path_params)
+        checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
         if str(checkRunOptionPathResult) == "NoExit":
             printLog(u"表格中不存在到达Option:   %s   的路径,在表格中排查到达该Option路径" % str(option))
             return False
@@ -2052,7 +2041,7 @@ class CTMenu():
         # 切黑场;
         self.sourceInput.setPattern(11)
         # 获取路径参数;
-        result, option_data = self.xlsparser.get_option(option)
+        result, option_data = self.uitRunner.uitData.UITree.get_option(option)
         if result is False:
             print(u"getOptionValue.获取option菜单内容失败")
             return False, ''
@@ -2098,7 +2087,7 @@ class CTMenu():
         txt_pic = os.path.join(getSATTmpDIR(), "meuttree_area_text.png")
         self.imgCMP.saveCropPic(current_uiPic, txt_pic, (cur_box[0], cur_box[1], cur_box[2], cur_box[3]))
         if is_value_sheet is True:
-            value_paramters = self.xlsparser.get_value(option, '')
+            value_paramters = self.uitRunner.uitData.UITree.get_value(option, '')
             isRangeType = False
             # 判断设置值的类型 是rang类型还是str类型
             if value_paramters['value_for_ocr'].__len__() and "range(" in value_paramters['value_for_ocr'][0].lower():
@@ -2106,7 +2095,7 @@ class CTMenu():
 
             if isRangeType is True:
                 # 获取ocr列表;
-                hasOption,path = self.xlsparser.get_option(option)
+                hasOption,path = self.uitRunner.uitData.UITree.get_option(option)
                 if hasOption:
                     self.get_ocr_list(path['level'], option)
                 for orc_item in self.ocrDict:
@@ -2167,7 +2156,7 @@ class CTMenu():
         return waitTime
 
     def getOptionWaitTime(self, option):
-        result, option_data = self.xlsparser.get_option(option)
+        result, option_data = self.uitRunner.uitData.UITree.get_option(option)
         print u"getOptionWaitTime.option_data:",option_data
         if result:
             try:
@@ -2181,7 +2170,7 @@ class CTMenu():
         return waitTime
 
     def getLeafWaitTime(self, option):
-        leaf_data = self.xlsparser.get_value(option)
+        leaf_data = self.uitRunner.uitData.UITree.get_value(option)
         print u"getLeafWaitTime.option_data:",leaf_data
         try:
             others = json.loads(leaf_data['others'])
@@ -2225,11 +2214,11 @@ class CTMenu():
         self.sourceInput.setPattern(11)
         # 获取menu path;
         print u"focusOption start >>>"
-        path_params = self.xlsparser.get_option_paths(option)
+        path_params = self.uitPathManage.get_option_paths(option)
         # print 'openOption=path_params:', path_params
         printLog('focusOption=path_params:%s' % str(path_params))
 
-        checkRunOptionPathResult = self.xlsparser.checkRunOptionPath(path_params)
+        checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
         if str(checkRunOptionPathResult) == "NoExit":
             printLog(u"表格中不存在到达Option:   %s   的路径,在表格中排查到达该Option路径" % str(option))
             return False
@@ -2356,11 +2345,11 @@ class CTMenu():
         # self.sourceInput.setPattern(11)
         # 获取menu path;
         print "moveToOption start >>>"
-        path_params = self.xlsparser.get_option_paths(option)
+        path_params = self.uitPathManage.get_option_paths(option)
         # print 'openOption=path_params:', path_params
         printLog('moveToOption=path_params:%s' % str(path_params))
 
-        checkRunOptionPathResult = self.xlsparser.checkRunOptionPath(path_params)
+        checkRunOptionPathResult = self.uitPathManage.checkRunOptionPath(path_params)
         if str(checkRunOptionPathResult) == "NoExit":
             printLog(u"表格中不存在到达Option:   %s   的路径,在表格中排查到达该Option路径" % str(option))
             return False
@@ -2490,14 +2479,14 @@ if __name__ == "__main__":
     # ThresholdDict = tmenu.tconfig.getThresholdDict("factory")
     # ThresholdDict = tmenu.tconfig.getThresholdDict("setting")
     # print "ThresholdDict:", ThresholdDict, type(ThresholdDict)
-    # tmenu.getOptionValue("picture_preset")
+    # tmenu.getOptionValue("picture_preset")value
     # parent_ocr_dict = tmenu.xlsparser.get_parent_ocr_dict("automatic_search_analogue")
     # print "parent_ocr_dict:",parent_ocr_dict
      # 获取menu path;
-    value_params, path_params = tmenu.xlsparser.get_menu_paths('av', '')
-    print value_params, path_params
-    tmenu.redRat3.sendKey('home')
-    tmenu.move2TargetGridNode_matchTemp('First', 'home', path_params['First'], 1)
+    # value_params, path_params = tmenu.xlsparser.get_menu_paths('av', '')
+    # print value_params, path_params
+    # tmenu.redRat3.sendKey('home')
+    # tmenu.move2TargetGridNode_matchTemp('First', 'home', path_params['First'], 1)
     # isSuccessed = tmenu.setOptionValue("picture_preset", "stadium")
     # isSuccessed = tmenu.setOptionValue("backlight", 50)
 

+ 8 - 9
ssat_sdk/MenuTree3/TSourceImpl.py

@@ -9,7 +9,7 @@ import json
 
 
 class TSourceImpl():
-    def __init__(self, ocr, ccard, tvOperator, tfocus, tconfig, xlsparser, \
+    def __init__(self, ocr, ccard, tvOperator, tfocus, tconfig, uitRunner, \
                  ocrDict=[{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253}, \
                           {"lan": "ChinesePRC+English", "type": 10001}]):
         self.ocr = ocr
@@ -17,7 +17,7 @@ class TSourceImpl():
         self.tvOperator = tvOperator
         self.tFocus = tfocus
         self.tConfig = tconfig
-        self.xlsParser = xlsparser
+        self.uitRunner = uitRunner
         self.imgCMP = ImageCMP()
         if not self.get_ocr_list():
             self.ocrDict = ocrDict
@@ -63,7 +63,6 @@ class TSourceImpl():
     '''
     检测信源界面是否存在,分成两部分:1 检测焦点框;2 检测文字(可选 checkOCR控制)。
     '''
-
     def checkSourceView(self, level, first_parent, parent, option, value_for_ocr, isForValue=False, checkOCR=False):
         print "checkSourceView:", level, first_parent, parent, option
         current_uiPic = self.getCurrentUIPath()
@@ -100,7 +99,7 @@ class TSourceImpl():
 
         # print "self.ocrDict:", self.ocrDict
         # 获取ocr_list;
-        ocr_list = self.xlsParser.get_ocr_list(level, parent, option, True if parent == option else False)
+        ocr_list = self.uitRunner.uitData.UITree.get_ocr_list(level, parent, option, True if parent == option else False)
         print "%s,%s,%s =>ocr_list=%s" % (level, parent, option, str(ocr_list))
         # 遍历ocr类型;
         for item in self.ocrDict:
@@ -114,7 +113,7 @@ class TSourceImpl():
             # print(u"getCurrentFocusTextEx.ocr_str land = %s, type =%d, ocr_str=%s:"%(item["lan"], item["type"], ocr_str.encode('GB18030')))
             ocr_str = unicode(ocr_str).lower()
             if isSource is False:
-                parent_ocr_dict = self.xlsParser.get_parent_ocr_dict(option)
+                parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(option)
                 print "getCurrentFocusTextEx.parent_ocr_dict:", parent_ocr_dict
                 list_parent_ocr_value = list(parent_ocr_dict.keys())
                 print "getCurrentFocusTextEx.list_parent_ocr_value:", list_parent_ocr_value
@@ -194,7 +193,7 @@ class TSourceImpl():
 
             # print "self.ocrDict:", self.ocrDict
             # 获取ocr_list;
-            ocr_list = self.xlsParser.get_ocr_list(level, parent, option, True if parent == option else False)
+            ocr_list = self.uitRunner.uitData.UITree.get_ocr_list(level, parent, option, True if parent == option else False)
             print "%s,%s,%s =>ocr_list=%s" % (level, parent, option, str(ocr_list))
             # 遍历ocr类型;
             for item in self.ocrDict:
@@ -208,7 +207,7 @@ class TSourceImpl():
                 # print(u"getCurrentFocusTextEx.ocr_str land = %s, type =%d, ocr_str=%s:"%(item["lan"], item["type"], ocr_str.encode('GB18030')))
                 ocr_str = unicode(ocr_str).lower()
                 if isSource is False:
-                    parent_ocr_dict = self.xlsParser.get_parent_ocr_dict(option)
+                    parent_ocr_dict = self.uitRunner.uitData.UITree.get_parent_ocr_dict(option)
                     print "getCurrentFocusTextEx.parent_ocr_dict:", parent_ocr_dict
                     list_parent_ocr_value = list(parent_ocr_dict.keys())
                     print "getCurrentFocusTextEx.list_parent_ocr_value:", list_parent_ocr_value
@@ -343,7 +342,7 @@ class TSourceImpl():
         printLog(u"开始执行setSourceValue。option:%s  value:%s" % (str(option), str(value)))
         # self.get_ocr_list('First', 'source')
         # 获取menu path;
-        value_params, path_params = self.xlsParser.get_menu_paths(option, value)
+        value_params, path_params = self.uitRunner.uitPathManage.get_menu_paths(option, value)
         # print "value_params:", value_params
         printLog(u"获取设置信源value:%s的值字典value_params:%s" % (str(value), str(value_params)))
         value_for_ocr = value_params['value_for_ocr']
@@ -356,7 +355,7 @@ class TSourceImpl():
         # 正向寻找的次数计数和最大次数
         count = 0
         # 读取menutree中的信源数量
-        source_list = self.xlsParser.getSubOptionList(option)
+        source_list = self.uitRunner.uitData.UITree.getSubOptionList(option)
         printLog(u"setSourceValue.%s source_list:%s" % (option, source_list))
         if source_list.__len__() != 0:
             Max_Try = source_list.__len__()

+ 41 - 0
ssat_sdk/MenuTree3/UIT_FileManage.py

@@ -0,0 +1,41 @@
+# -*- coding:utf-8 -*-
+from ssat_sdk.sat_environment import getMenuTree3SelectedProjectCfgPath,getMenuTree3SelectedPExcelPath,getMenuTree3SelectedTvExcelPath
+from UIT_log import debug,info,error
+
+import os, sys, time
+
+DEBUG = True
+INFO = True
+ERROR = True
+class UITFileManage():
+    cls="UITFileManage"
+    def __init__(self):
+        self.UITreeDir = getMenuTree3SelectedProjectCfgPath()
+        info(self.cls, "__init__", "UITreeDir:" + str(self.UITreeDir), INFO)
+        # excel路径,根据界面选择的项目来确定;
+        # 非tv表格
+        self.xlspath = getMenuTree3SelectedPExcelPath()
+        # tv表格
+        self.tv_xlspath = getMenuTree3SelectedTvExcelPath()
+        info(self.cls, "__init__", u"构建CTMenu对象!非tv表格路径:%s" % str(self.xlspath),INFO)
+        info(self.cls, "__init__", u"tv表格路径:%s" % str(self.tv_xlspath),INFO)
+        # print "self.xlspath :", self.xlspath
+
+    def getUITreeList(self):
+        fileList = os.listdir(self.UITreeDir)
+        treeList = []
+        treeList.append(self.xlspath)
+        treeList.append(self.tv_xlspath)
+        for filePath in fileList:
+            if filePath.lower().startswith("uitree") and (filePath.lower().endswith(".xls") or filePath.lower().endswith(".xlsx")):
+                treeList.append(os.path.join(self.UITreeDir, filePath))
+        return treeList
+
+    def getKeyCodeFile(self):
+        fileList = os.listdir(self.UITreeDir)
+        keyCodeFile = None
+        for filePath in fileList:
+            if filePath.lower() == "eventkey_code.xlsx":
+                keyCodeFile = os.path.join(self.UITreeDir, filePath)
+                break
+        return keyCodeFile

+ 213 - 0
ssat_sdk/MenuTree3/UIT_PathManage.py

@@ -0,0 +1,213 @@
+# -*- coding:utf-8 -*-
+from TData import CTData
+from UIT_tree import UITTree
+from UIT_treeConstant import TreeConst
+from ssat_sdk.utils.string_util import strcmp
+from UIT_log import error,info,debug
+import os, sys, time
+from collections import OrderedDict
+
+DEBUG = True
+INFO = True
+ERROR = True
+g_level = TreeConst.G_LEVEL
+class UITPathManage():
+    def __init__(self, uitData):
+        self.uitData = uitData
+        self.valueParams = self.uitData.UITree.valueParams
+        self.pathParams = self.uitData.UITree.pathParams
+
+    def get_menu_paths(self, option, value):
+        if type(option) == str:
+            option = unicode(option)
+        if type(value) == str:
+            value = unicode(value)
+        # pp必须不排序;
+        vp, pp = {}, OrderedDict()
+        if option in self.valueParams.values:
+            vp = {"option": option, "value": value, "enter_key": self.valueParams.values[option]["enter_key"],
+                  "move_key": self.valueParams.values[option]["move_key"]}
+            # 找到value对应的ocr;
+            for item in self.valueParams.values[option]["value"]:
+                if "range(" in item["value"]:
+                    vp["value_for_ocr"] = item["value_for_ocr"].split(';')
+                    break
+                elif item["value"].lower() == value.lower():
+                    vp["value_for_ocr"] = item["value_for_ocr"].split(';')
+                    break
+
+        # 首先,字典不排序,需要倒序;
+        paths = reversed(self.pathParams.paths)
+        for level in paths:
+            found = False
+            for parent in self.pathParams.paths[level]:
+                # print parent,self.pathParams.paths[level][parent],'\r\n'
+                for item in self.pathParams.paths[level][parent]["value"]:
+                    # print item
+                    if item["option"].lower() == option.lower():
+                        pp[level] = {
+                            "parent": parent,
+                            "move_key": self.pathParams.paths[level][parent][TreeConst.Option_MoveKey],
+                            "enter_key": self.pathParams.paths[level][parent][TreeConst.Option_EnterKey],
+                            "others": self.pathParams.paths[level][parent][TreeConst.Option_Others],
+                            "option": item[TreeConst.Option_Name],
+                            "option_for_ocr": item[TreeConst.Option_ForOCR].split(';'),
+                            "option_move_key": item[TreeConst.Option_MoveKey],
+                            "option_enter_key": item[TreeConst.Option_EnterKey],
+                            "option_others": item[TreeConst.Option_Others]
+                        }
+                        option = parent
+                        found = True
+                        break
+                if found:
+                    break
+                else:
+                    if parent == option:
+                        for item in self.pathParams.paths[level][parent]["value"]:
+                            # print item
+                            if item["option"].lower() == value.lower():
+                                pp[level] = {
+                                    "parent": parent,
+                                    "move_key": self.pathParams.paths[level][parent][TreeConst.Option_MoveKey],
+                                    "enter_key": self.pathParams.paths[level][parent][TreeConst.Option_EnterKey],
+                                    "others": self.pathParams.paths[level][parent][TreeConst.Option_Others],
+                                    "option": item["option"],
+                                    "option_for_ocr": item["option_for_ocr"].split(';'),
+                                    "option_move_key": item[TreeConst.Option_MoveKey],
+                                    "option_enter_key": item[TreeConst.Option_EnterKey],
+                                    "option_others": item[TreeConst.Option_Others]
+                                }
+                                option = parent
+                                found = True
+                                break
+                            # endif
+                        # endfor
+                        break
+                    # endif
+        # 需要对path倒序使用;
+        return vp, pp
+
+    def get_option_paths(self, option):
+        # pp必须不排序;
+        pp = OrderedDict()
+        # 首先,字典不排序,需要倒序;
+        paths = reversed(self.pathParams.paths)
+        for level in paths:
+            found = False
+            for parent in self.pathParams.paths[level]:
+                # print parent,self.pathParams.paths[level][parent],'\r\n'
+                for item in self.pathParams.paths[level][parent]["value"]:
+                    # print item
+                    if item["option"].lower() == option.lower():
+                        pp[level] = {
+                            "parent": parent,
+                            "move_key": self.pathParams.paths[level][parent][TreeConst.Option_MoveKey],
+                            "enter_key": self.pathParams.paths[level][parent][TreeConst.Option_EnterKey],
+                            "others": self.pathParams.paths[level][parent][TreeConst.Option_Others],
+                            "option": item[TreeConst.Option_Name],
+                            "option_for_ocr": item[TreeConst.Option_ForOCR].split(';'),
+                            "option_move_key": item[TreeConst.Option_MoveKey],
+                            "option_enter_key": item[TreeConst.Option_EnterKey],
+                            "option_others": item[TreeConst.Option_Others]
+                        }
+                        option = parent
+                        found = True
+                        break
+                if found:
+                    break
+                else:
+                    if parent == option:
+                        for item in self.pathParams.paths[level][parent]["value"]:
+                            # print item
+                            if item["option"].lower() == option.lower():
+                                pp[level] = {
+                                    "parent": parent,
+                                    "move_key": self.pathParams.paths[level][parent][TreeConst.Option_MoveKey],
+                                    "enter_key": self.pathParams.paths[level][parent][TreeConst.Option_EnterKey],
+                                    "others": self.pathParams.paths[level][parent][TreeConst.Option_Others],
+                                    "option": item[TreeConst.Option_Name],
+                                    "option_for_ocr": item[TreeConst.Option_ForOCR].split(';'),
+                                    "option_move_key": item[TreeConst.Option_MoveKey],
+                                    "option_enter_key": item[TreeConst.Option_EnterKey],
+                                    "option_others": item[TreeConst.Option_Others]
+                                }
+                                option = parent
+                                found = True
+                                break
+                            # endif
+                        # endfor
+                        break
+                    # endif
+            # endfor
+        # endfor
+        # 需要对path倒序使用;
+        # dict_pp = OrderedDict()
+        # # 逆序路径key;
+        # revpp = reversed(pp)
+        # for path in revpp:
+        #     dict_pp[path] = {"parent": pp[path]['parent'],"move_key": pp[path]['move_key'],"enter_key": pp[path]['enter_key'],"others":pp[path]['others'],"option": pp[path]['option'],"option_for_ocr": pp[path]['option_for_ocr']}
+        # # 返回逆序后的结果;
+        # return dict_pp
+        return pp
+
+    def checkOptionPath(self, optionName):
+        optionPath = ""
+        optionPathResult = "Fail"
+        path_params = self.get_option_paths(optionName)
+        # 如果传入的option不存在则直接返回
+        if path_params.__len__() <= 0:
+            optionPathResult = "NoExit"
+            optionPath = u"表格中不存在到达Option:   %s   的路径" % str(optionName)
+            return optionPath, optionPathResult
+        else:
+            optionPath = str(path_params)
+            # 逆序路径key;
+            revpp = reversed(path_params)
+            level_count = 0
+            for level in revpp:
+                if str(level) == str(g_level[level_count]):
+                    level_count = level_count + 1
+                else:
+                    # 如果执行路径不是按照First、Second......执行则返回执行出错
+                    return optionPath, optionPathResult
+            optionPathResult = "Pass"
+            return optionPath, optionPathResult
+
+    def checkRunOptionPath(self, path_params):
+        optionPathResult = "Fail"
+        # 如果传入的option不存在则直接返回
+        if path_params.__len__() <= 0:
+            optionPathResult = "NoExit"
+            return optionPathResult
+        else:
+            optionPath = str(path_params)
+            # 逆序路径key;
+            revpp = reversed(path_params)
+            level_count = 0
+            for level in revpp:
+                if str(level) == str(g_level[level_count]):
+                    level_count = level_count + 1
+                else:
+                    # 如果执行路径不是按照First、Second......执行则返回执行出错
+                    return optionPathResult
+            optionPathResult = "Pass"
+            return optionPathResult
+
+if __name__ == "__main__":
+    uiData = CTData()
+    pathManage = UITPathManage(uiData)
+    vp,pp = pathManage.get_menu_paths("hdmi1","hdmi1")
+    vp,pp = pathManage.get_menu_paths("dynamic_contrast","on")
+    print "vp:", vp
+    print "pp:",pp
+    chkPP=pathManage.checkRunOptionPath(pp)
+    print "check pp:",chkPP
+
+    pp = pathManage.get_option_paths("dynamic_contrast")
+    print "pp:",pp
+    chkPP = pathManage.checkRunOptionPath(pp)
+    print "check pp:",chkPP
+
+    optionPath, optionPathResult = pathManage.checkOptionPath("dynamic_contrast")
+    print "optionPath:",optionPath
+    print "optionPathResult:", optionPathResult

+ 23 - 0
ssat_sdk/MenuTree3/UIT_log.py

@@ -0,0 +1,23 @@
+# -*- coding:utf-8 -*-
+import os, sys, time
+from ssat_sdk.utils.LoggingUtil import printLog
+
+TAG = "UITree:"
+DEBUG = True
+INFO = True
+ERROR = True
+
+def debug(cls, fun, msg, enable):
+    if DEBUG and enable:
+        pstr = "Debug:" + TAG + cls + "[" + fun + "]" + msg
+        printLog(pstr)
+
+def info(cls, fun, msg, enable):
+    if INFO and enable:
+        pstr = "Info:" + TAG + cls + "[" + fun + "]" + msg
+        printLog(pstr)
+
+def error(cls, fun, msg, enable):
+    if ERROR and enable:
+        pstr = "Error:" + TAG + cls + "[" + fun + "]" + msg
+        printLog(pstr)

+ 18 - 0
ssat_sdk/MenuTree3/UIT_runner.py

@@ -0,0 +1,18 @@
+# -*- coding:utf-8 -*-
+import os, sys, time
+from UIT_runnerCommand import UITRunnerCommand
+from UIT_PathManage import UITPathManage
+from TData import CTData
+from UIT_log import error, debug, info
+
+DEBUG = True
+INFO =True
+ERROR = True
+class UITRunner():
+    cls = "UATRunner"
+    def __init__(self):
+        self.uitData = CTData()
+        self.uitPathManage = UITPathManage(self.uitData)
+        self.runnerCmd = UITRunnerCommand(self.uitPathManage)
+        # setOptionValue之后需要一个退回的pathlist来退出菜单
+        self.executedPath = []

+ 27 - 0
ssat_sdk/MenuTree3/UIT_runnerCommand.py

@@ -0,0 +1,27 @@
+# -*- coding:utf-8 -*-
+import cv2 as cv
+
+from UIT_log import error,debug,info
+from ssat_sdk.utils import  string_util
+from ssat_sdk.tv_operator import TvOperator
+
+from ssat_sdk.device_manage.capturecard_manager import CCardManager
+from ssat_sdk.sat_environment import getSATTmpDIR
+from ssat_sdk.pic_tool import ImageCMP
+from ssat_sdk.ocr_convert import OCRConvert
+from ssat_sdk.utils.string_util import strcmp, getDigitFromString
+import os, sys, time
+
+DEBUG = True
+INFO =True
+ERROR = True
+
+class UITRunnerCommand():
+    cls = "UATRunnerCommand"
+    def __init__(self, uitPathManage):
+        self.uitPathManage = uitPathManage
+        self.tvOperator = TvOperator()
+
+        self.CC = CCardManager()
+        self.imgCMP = ImageCMP()
+        self.ocrConvert = OCRConvert()

+ 390 - 0
ssat_sdk/MenuTree3/UIT_tree.py

@@ -0,0 +1,390 @@
+# -*- coding:utf-8 -*-
+from collections import OrderedDict
+from ssat_sdk.utils.string_util import strToList
+from UIT_log import error,info,debug
+from UIT_treeConstant import TreeConst
+from TConfig import TConfig
+DEBUG = True
+INFO = True
+ERROR = True
+
+g_level = TreeConst.G_LEVEL
+
+
+def parseMoveKey(keyStr):
+    return strToList(keyStr,";")
+
+class CPathParams():
+    def __init__(self):
+        self.paths = OrderedDict()
+
+    def addParent(self,level, pDict):
+        if level not in self.paths:
+            self.paths[level] = {}
+        # endif
+        pDict["value"]=[]
+        pDict[TreeConst.Option_MoveKey] = parseMoveKey(pDict[TreeConst.Option_MoveKey])
+        # print "CPathParams,addParent:", pDict
+        if pDict[TreeConst.Parent_Name] in self.paths:
+            error(self.cls, "addParent", "Parent %s conflict."%(pDict[TreeConst.Parent_Name]),ERROR)
+        self.paths[level][pDict[TreeConst.Parent_Name]] = pDict
+
+    def addOption(self,level, pDict):
+        # print "CPathParams,addOption:", pDict
+        if level in self.paths:
+            if pDict[TreeConst.Parent_Name] in self.paths[level]:
+                if pDict[TreeConst.Option_Name].__len__() > 0:
+                    self.paths[level][pDict[TreeConst.Parent_Name]]["value"].append(pDict)
+            else:
+                error(self.cls, "addOption", "Parent %s not exist." % (pDict[TreeConst.Parent_Name]), ERROR)
+        else:
+            error(self.cls, "addOption", "Level %s not exist." % (level), ERROR)
+
+
+class CValueParams():
+    cls = "CValueParams"
+    def __init__(self):
+        self.values = OrderedDict()
+
+    def addParent(self, pDict):
+        if pDict[TreeConst.Value_Name] in self.values:
+            error(self.cls, "addParent", "Parent %s conflict."%(pDict[TreeConst.Value_Name]),ERROR)
+        pDict["value"]=[]
+        pDict[TreeConst.Value_MoveKey] = parseMoveKey(pDict[TreeConst.Value_MoveKey])
+        # print "CValueParams,addParent:", pDict
+        self.values[pDict[TreeConst.Value_Name]] = pDict
+
+    def addOption(self, pDict):
+        # print "CValueParams,addOption:", pDict
+        if pDict[TreeConst.Value_Name] in self.values:
+            if pDict[TreeConst.Value_Value].__len__() > 0:
+                self.values[pDict[TreeConst.Value_Name]]["value"].append(pDict)
+        else:
+            error(self.cls, "addOption", "Parent %s not exist." % (pDict[TreeConst.Value_Name]), ERROR)
+
+class CDialogParams():
+    cls = "CDialogParams"
+    def __init__(self):
+        self.dialogs = OrderedDict()
+
+    def addParent(self,level, pDict):
+        # endif
+        if pDict[TreeConst.Parent_Name] in self.dialogs:
+            error(self.cls, "addParent","Parent %s conflict."%(pDict[TreeConst.Parent_Name]), ERROR)
+        pDict["value"] = []
+        pDict[TreeConst.Option_MoveKey] = parseMoveKey(pDict[TreeConst.Option_MoveKey])
+        # print "CDialogParams,addParent:", pDict
+        self.dialogs[pDict[TreeConst.Parent_Name]] = pDict
+
+    def addOption(self,level,pDict):
+        # print "CDialogParams,addOption:", pDict
+        if pDict[TreeConst.Parent_Name] in self.dialogs:
+            if pDict[TreeConst.Option_Name].__len__() > 0:
+                self.dialogs[pDict[TreeConst.Parent_Name]]["value"].append(pDict)
+        else:
+            error(self.cls, "addOption","Parent %s not exist.", ERROR)
+
+class UITTree():
+    def __init__(self,tConfig):
+        self.pathParams = CPathParams()
+        self.valueParams = CValueParams()
+        self.dialogParams = CDialogParams()
+        self.tConfig = tConfig
+        self.cls = "UITTree"
+
+    # 获取键对值
+    def get_pair_values(self, name, option=True):
+        if type(name) == str:
+            name = unicode(name)
+        pairs = []
+        if option is True:
+            find = False
+            for level in self.pathParams.paths:
+                for item in self.pathParams.paths[level]:
+                    if item.lower() == name.lower():
+                        find = True
+                        for item in self.pathParams.paths[level][name]["value"]:
+                            pairs.append({item['option']: item['option_for_ocr'].split(';')})
+                        break
+                # endfor
+                if find is True:
+                    break
+            # endfor
+        else:
+            if name in self.valueParams.values:
+                for item in self.valueParams.values[name]["value"]:
+                    pairs.append({item['value']: item['value_for_ocr'].split(';')})
+        # endif
+        return pairs
+
+    # 获取指定层级的path或value的xxx_for_ocr列表;
+    def get_ocr_list(self, level, name, option, is_option=True):
+        if type(name) == str:
+            name = unicode(name)
+        if type(option) == str:
+            option = unicode(option)
+        list_ocr = []
+        if is_option is True:
+            find = False
+            for item in self.pathParams.paths[level]:
+                if item.lower() == name.lower():
+                    find = True
+                    for item in self.pathParams.paths[level][name]["value"]:
+                        if str(option).lower() != str(item["option"]).lower():
+                            list_ocr.append(item['option_for_ocr'].split(';'))
+                    break
+            # endfor
+        else:
+            if name in self.valueParams.values:
+                for item in self.valueParams.values[name]["value"]:
+                    list_ocr.append(item['value_for_ocr'].split(';'))
+        # endif
+        return list_ocr
+
+    # 获取指定value_name所在菜单项的全部同级菜单项ocr列表;
+    def get_parent_ocr_list(self, option):
+        # 编码转换;
+        if type(option) == str:
+            option = unicode(option)
+
+        found = False
+        list_ocr = []
+        # 首先,字典不排序,需要倒序;
+        paths = reversed(self.pathParams.paths)
+        for level in paths:
+            for parent in self.pathParams.paths[level]:
+                for vals in self.pathParams.paths[level][parent]["value"]:
+                    if vals['option'].lower() == option.lower():
+                        found = True
+                        break
+                # endfor
+                # 找到退出;
+                if found is True:
+                    break
+            # endfor
+            # 找到退出;
+            if found is True:
+                break
+        # endfor
+
+        # 遍历value列表;
+        if found is True:
+            for val in self.pathParams.paths[level][parent]["value"]:
+                list_ocr.extend(val['option_for_ocr'].split(';'))
+        # 按长度排序;
+        list_ocr.sort(key=lambda i: len(i), reverse=True)
+        # 返回结果;
+        return list_ocr
+
+    # 当value_sheet = False,表示获取path表里的option层级的所有option_for_ocr:option
+    # 当value_sheet = True,表示获取value表里的value_name层级的所有value_for_ocr:value
+    def get_parent_ocr_dict(self, option, value_sheet=False):
+        print "get_parent_ocr_dict.option:", option
+        # 编码转换;
+        if type(option) == str:
+            option = unicode(option)
+
+        found = False
+        dict_ocr = {}
+        list_ocr = []
+        if value_sheet is False:
+            # 首先,字典不排序,需要倒序;
+            paths = reversed(self.pathParams.paths)
+            for level in paths:
+                for parent in self.pathParams.paths[level]:
+                    for vals in self.pathParams.paths[level][parent]["value"]:
+                        if vals['option'].lower() == option.lower():
+                            found = True
+                            break
+                    # endfor
+                    # 找到退出;
+                    if found is True:
+                        break
+                # endfor
+                # 找到退出;
+                if found is True:
+                    break
+
+            # 遍历value列表;
+            if found is True:
+                for val in self.pathParams.paths[level][parent]["value"]:
+                    list_ocr = val['option_for_ocr'].split(';')
+                    for ocr in list_ocr:
+                        dict_ocr[ocr.lower()] = val['option']
+        else:
+            if option in self.valueParams.values:
+                for val in self.valueParams.values[option]["value"]:
+                    list_ocr = val['value_for_ocr'].split(';')
+                    for ocr in list_ocr:
+                        dict_ocr[ocr.lower()] = val['value']
+
+        print 'unsorted=', dict_ocr
+        # 按长度排序;
+        list_ocr = sorted(dict_ocr.keys(), key=lambda key: len(key), reverse=True)
+        dict_reuslt = OrderedDict()
+        for ocr in list_ocr:
+            dict_reuslt[ocr] = dict_ocr[ocr]
+        # 返回结果;
+        return dict_reuslt
+
+    def get_option_ocr(self, option):
+        # 编码转换;
+        if type(option) == str:
+            option = unicode(option)
+
+        found = False
+        list_ocr = []
+        # 首先,字典不排序,需要倒序;
+        paths = reversed(self.pathParams.paths)
+        for level in paths:
+            for parent in self.pathParams.paths[level]:
+                for vals in self.pathParams.paths[level][parent]["value"]:
+                    if vals['option'].lower() == option.lower():
+                        list_ocr = vals['option_for_ocr'].split(';')
+                        found = True
+                        break
+                # endfor
+                # 找到退出;
+                if found is True:
+                    break
+            # endfor
+            # 找到退出;
+            if found is True:
+                break
+        # endfor
+        # 返回结果;
+        return list_ocr
+
+    def get_value(self, option, value=""):
+        # 编码转换;
+        if type(option) == str:
+            option = unicode(option)
+        xlsValue = self.valueParams.values[option]["value"]
+        valueList = []
+        valueOcrList = []
+        for item in xlsValue:
+            valueList.append(item["value"])
+            valueOcrList.append(item["value_for_ocr"])
+        vp = {}
+        if option in self.valueParams.values:
+            vp = {"option": option, "value": valueList, "value_for_ocr": valueOcrList,
+                  "enter_key": self.valueParams.values[option]["enter_key"],
+                  "move_key": self.valueParams.values[option]["move_key"],
+                  "others": self.valueParams.values[option]['others']}
+            # 找到value对应的ocr;
+            if value != "":
+                vp["value"] = value
+                for item in self.valueParams.values[option]["value"]:
+                    if "range(" in item["value"]:
+                        vp["value_for_ocr"] = item["value_for_ocr"].split(';')
+                        break
+                    elif item["value"].lower() == value.lower():
+                        vp["value_for_ocr"] = item["value_for_ocr"].split(';')
+                        break
+                # endfor
+            # endif
+        # endif
+        # 返回结果;
+        return vp
+
+    # 获取option层级内容;
+    def get_option(self, option):
+        # 编码转换;
+        if type(option) == str:
+            option = unicode(option)
+
+        found = False
+        layers = 0
+        dict_option = {}
+        # 首先,字典不排序,需要倒序;
+        paths = reversed(self.pathParams.paths)
+        for level in paths:
+            for parent in self.pathParams.paths[level]:
+                for vals in self.pathParams.paths[level][parent]["value"]:
+                    if vals['option'].lower() == option.lower():
+                        if dict_option.__len__() == 0:
+                            found = True
+                            dict_option['level'] = level
+                            dict_option['parent'] = parent
+                            dict_option['others'] = self.pathParams.paths[level][parent]['others']
+                            dict_option['enter_key'] = self.pathParams.paths[level][parent]['enter_key']
+                            dict_option['move_key'] = self.pathParams.paths[level][parent]['move_key']
+                            dict_option['option_ocr'] = vals['option_for_ocr'].split(';')
+                            dict_option['option_move_key'] = vals['option_move_key']
+                            dict_option['option_enter_key'] = vals['option_enter_key']
+                            dict_option['option_others'] = vals['option_others']
+                        option = parent
+                        layers += 1  # 层数;
+                        break
+                # endfor
+            # endfor
+        # endfor
+        if found is True:
+            dict_option['layers'] = layers
+            # first层次的parent名称;
+            dict_option['first_parent'] = option
+        # 返回结果;
+        return found, dict_option
+
+    # 获取表格Value层级中,value_name下包含的value列表
+    def getSubValueList(self, value_name):
+        valueList = []
+        if self.valueParams.values.has_key(value_name):
+            # print parser.valueParams.values["source"]
+            # print parser.valueParams.values["source"]["value"]
+            valueDictList = self.valueParams.values[value_name]["value"]
+            for valueDict in valueDictList:
+                valueList.append(valueDict["value"])
+        # print "valueList:", valueList, type(valueList)
+        if valueList.__len__() == 1 and "range(" in valueList[0]:
+            value_for_ocr_low = str(valueList[0]).lower()
+            str_num = value_for_ocr_low.replace("range", "")
+            list_num = eval(str_num)
+            min_num = list_num[0]
+            max_num = list_num[1]
+            return [min_num, max_num]
+
+        return valueList
+
+    # 获取表格First~Sixth层级中,parent下包含的option列表
+    def getSubOptionList(self, parent):
+        optionList = []
+        paths = self.pathParams.paths
+        for level in paths:
+            if paths[level].has_key(parent):
+                optionDictList = paths[level][parent]["value"]
+                for optionDict in optionDictList:
+                    optionList.append(optionDict["option"])
+        # print "optionList:", optionList, type(optionList)
+        return optionList
+
+    # 获取表格Value层级中,value_name下的value的ocr列表
+    def getValueTextList(self, value_name, value):
+        valueTextList = []
+        if self.valueParams.values.has_key(value_name):
+            # print parser.valueParams.values["source"]
+            # print parser.valueParams.values["source"]["value"]
+            valueDictList = self.valueParams.values[value_name]["value"]
+            for valueDict in valueDictList:
+                if valueDict["value"] == value:
+                    value_for_ocr = valueDict["value_for_ocr"]
+                    # print "value_for_ocr:", value_for_ocr, type(value_for_ocr)
+                    valueTextList = value_for_ocr.split(';')
+
+        # print "valueTextList:", valueTextList, type(valueTextList)
+        return valueTextList
+
+    # 获取表格First~Sixth层级中,parent下的option的ocr列表
+    def getOptionTextList(self, parent, option):
+        optionTextList = []
+        paths = self.pathParams.paths
+        for level in paths:
+            if paths[level].has_key(parent):
+                optionDictList = paths[level][parent]["value"]
+                for optionDict in optionDictList:
+                    if optionDict["option"] == option:
+                        option_for_ocr = optionDict["option_for_ocr"]
+                        # print "option_for_ocr:", option_for_ocr, type(option_for_ocr)
+                        optionTextList = option_for_ocr.split(';')
+        # print "optionList:", optionTextList, type(optionTextList)
+        return optionTextList

+ 25 - 0
ssat_sdk/MenuTree3/UIT_treeConstant.py

@@ -0,0 +1,25 @@
+# -*- coding:utf-8 -*-
+import os, sys, time
+
+class TreeConst():
+    G_LEVEL = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth', 'Tenth',
+               'Eleventh', 'Twelfth']
+    Parent_Name = u'parent'
+    Parent_ShortKey = u'shortcut_key'
+    Parent_ToParentKey = u'toparent_key'
+    Parent_Layout = u'layout'
+    Option_Name = u'option'
+    Option_ForOCR = u'option_for_ocr'
+    Option_MoveKey = u'move_key'
+    Option_EnterKey = u'enter_key'
+    Option_Others = u'others'
+    Value_Name = u'value_name'
+    Value_Value = u'value'
+    Value_ForOCR = u'value_for_ocr'
+    Value_MoveKey = u'move_key'
+    Value_EnterKey = u'enter_key'
+    Value_Others = u'others'
+    FLevel_Params=[Parent_Name, Parent_ShortKey, Parent_ToParentKey, Parent_Layout, Option_Name, Option_ForOCR, Option_MoveKey, Option_EnterKey, Option_Others]
+    NLevel_Params=[Parent_Name, Parent_ToParentKey, Parent_Layout, Option_Name, Option_ForOCR, Option_MoveKey, Option_EnterKey, Option_Others]
+    VLevel_Params=[Value_Name, Value_Value, Value_ForOCR, Value_MoveKey,Value_EnterKey, Value_Others]
+    DLevel_Params = NLevel_Params