scbc.sat2 5 жил өмнө
parent
commit
87846e5486
1 өөрчлөгдсөн 213 нэмэгдсэн , 88 устгасан
  1. 213 88
      UITree3/Option.py

+ 213 - 88
UITree3/Option.py

@@ -1,133 +1,258 @@
 # -*- coding:utf-8 -*-
 
-'''
+"""
 注:私有变量和函数,前面加双下划线(不要在后面也加双下划线);
-'''
+"""
 
+import os
+import sys
+import time
 # 使用inspect模块动态获取当前运行的函数名
 import inspect
+# 日期头文件;
 from datetime import datetime
+# 自动化sdk头;
+from ssat_sdk.sat_environment import getMenuTree3SelectedPExcelPath
+from ssat_sdk.sat_environment import getMenuTree3SelectedProjectCfgPath
+from ssat_sdk.sat_environment import getMenuTree3SelectedTvExcelPath
+from ssat_sdk.sat_environment import getMenuTreeSelectedChannel
+
+
+# 获取运行函数名;
+def get_fun_name():
+    return inspect.stack()[1][3]
+
 
 # 日志基类;
 class CBaseLog:
     def __init__(self):
         pass
 
-    def __log(self, msg):
+    def __printlog(self, msg):
         # 时间/内容;
-        print "%s %s"%( datetime.now().strftime('%Y-%m-%d %H:%M:%S'), msg )
-        
+        print("%s %s") % (datetime.now().strftime('%Y-%m-%d %H:%M:%S'), msg)
+
     def debug(self, fun, msg):
         # 类型/类名:函数/内容
-        logstr = "【DEBUG】%s::%s %s"%( self.__class__.__name__, fun, msg )
-        self.__log(logstr)
-        
+        log_str = "【DEBUG】<%s::%s> %s" % (self.__class__.__name__, fun, msg)
+        self.__printlog(log_str)
+
     def info(self, fun, msg):
         # 类型/类名:函数/内容
-        logstr = "【INFO】%s::%s %s"%( self.__class__.__name__, fun, msg )
-        self.__log(logstr)
-    
+        log_str = "【INFO】<%s::%s> %s" % (self.__class__.__name__, fun, msg)
+        self.__printlog(log_str)
+
+    def warn(self, fun, msg):
+        # 类型/类名:函数/内容
+        log_str = "【WARN】<%s::%s> %s" % (self.__class__.__name__, fun, msg)
+        self.__printlog(log_str)
+
     def error(self, fun, msg):
         # 类型/类名:函数/内容
-        logstr = "【ERROR】%s::%s %s"%( self.__class__.__name__, fun, msg )
-        self.__log(logstr)
-        
-    def printlog(self, msg):
+        log_str = "【ERROR】<%s::%s> %s" % (self.__class__.__name__, fun, msg)
+        self.__printlog(log_str)
+
+    def log(self, msg):
         # 类型/类名/内容
-        logstr = "【LOG】%s %s"%( self.__class__.__name__, msg )
-        self.__log(logstr)
-    
+        log_str = "【LOG】<%s> %s" % (self.__class__.__name__, msg)
+        self.__printlog(log_str)
+
 
 # 外部数据
 class XData(CBaseLog):
-    cls = 'xdata'
     def __init__(self):
         # 配置文件路径;
-        self.ConfigPath = ""
-        # Menutree资源目录(包含了Excel文件路径);
-        self.MenuTreeDir = ""
-        # MenuTree低下的xls或xlsx文件集;
-        self.ListExcelPath = []
+        self.configPath = ""
+        # menu tree资源目录(包含了Excel文件路径);
+        self.menuTreeDir = ""
+        # 默认的excel路径;
+        self.defaultExcelPath = ""
+        # tv excel路径;
+        self.tvExcelPath = ""
+        # enter key excel路径;
+        self.enterKeyExcelPath = ""
+        # menu tree低下的xls或xlsx文件集;
+        self.listAppExcelPath = []
+        # 数据状态(只要menuTreeDir和defaultExcelPath有效即为True);
+        self.status = False
+        # 加载数据;
+        self.loadData()
+
+    # 装载数据;
+    def loadData(self):
+        # 1、加载menu tree 路径;
+        self.menuTreeDir = getMenuTree3SelectedProjectCfgPath()
+        if not os.path.isdir(self.menuTreeDir):
+            self.error(get_fun_name(), "menu tree路径(%s)无效,加载失败!" % tree_path)
+            return
+        # endif
+
+        self.log("menu tree路径存在:%s" % self.menuTreeDir)
+        # 2、加载配置文件路径;
+        self.configPath = os.path.join(self.menuTreeDir, "menutree.ini")
+        if not os.path.exists(self.configPath):
+            self.error(get_fun_name(), "配置文件不存在:%s" % self.configPath)
+        else:
+            self.log("配置文件存在:%s" % self.configPath)
+
+        # 3、加载默认excel文件路径;
+        self.defaultExcelPath = os.path.join(self.menuTreeDir, "menutree.xls")
+        if not os.path.exists(self.defaultExcelPath):
+            self.info(get_fun_name(), "默认menu tree excel文件不存在:%s" % self.defaultExcelPath)
+            self.defaultExcelPath = os.path.join(self.menuTreeDir, "menutree.xlsx")
+
+        # 二次判断是否存在;
+        if os.path.exists(self.defaultExcelPath):
+            self.status = True
+            self.log("默认menu tree excel文件存在:%s" % self.defaultExcelPath)
+        else:
+            self.error("默认menu tree excel文件不存在:%s" % self.defaultExcelPath)
+
+        # 4、加载tv excel文件;
+        channel = getMenuTreeSelectedChannel()
+        if not channel or str(channel) == "":
+            self.tvExcelPath = self.defaultExcelPath
+            self.warn(get_fun_name(), "tv表格不存在,使用默认excel=%s" % self.tvExcelPath)
+        else:
+            self.tvExcelPath = os.path.join(self.menuTreeDir, "menuTree_" + channel + ".xls")
+            if not os.path.exists(self.tvExcelPath):
+                self.tvExcelPath = os.path.join(self.menuTreeDir, "menuTree_" + channel + ".xlsx")
+
+            # 二次判断是否存在;
+            if os.path.exists(self.tvExcelPath):
+                self.log("默认menu tree excel文件存在:%s" % self.tvExcelPath)
+            else:
+                self.error("默认menu tree excel文件不存在:%s" % self.tvExcelPath)
+
+        # 5、加载默认excel文件路径;
+        self.enterKeyExcelPath = os.path.join(self.menuTreeDir, "eventkey_code.xls")
+        if not os.path.exists(self.enterKeyExcelPath):
+            self.info(get_fun_name(), "eventkey_code文件不存在:%s" % self.enterKeyExcelPath)
+            self.enterKeyExcelPath = os.path.join(self.menuTreeDir, "eventkey_code.xlsx")
+
+        # 二次判断是否存在;
+        if os.path.exists(self.enterKeyExcelPath):
+            self.log("eventkey_code文件存在:%s" % self.enterKeyExcelPath)
+        else:
+            self.error(get_fun_name(), "eventkey_code文件不存在:%s" % self.enterKeyExcelPath)
+
+        # 6、加载UITree开头的所有xls或xlsx
+        fileList = os.listdir(self.menuTreeDir)
+        self.listAppExcelPath.append(self.defaultExcelPath)
+        if self.defaultExcelPath != self.tvExcelPath:
+            self.listAppExcelPath.append(self.tvExcelPath)
+        for filePath in fileList:
+            if filePath.lower().startswith("uitree") and (
+                    filePath.lower().endswith(".xls") or filePath.lower().endswith(".xlsx")):
+                self.listAppExcelPath.append(os.path.join(self.menuTreeDir, filePath))
+
 
 # Option数据逻辑类;
 class COptionDataLogic(CBaseLog):
-    cls = 'option_datalogic'
-    def __init__(self):
-        # 配置文件对象;
-        self.__config = None
-        # excel文件对象;
-        self.__excel = None
-        # 
-        
-    def __LoadConfig(self):
+    def __init__(self, xdata):
+        # 路径位置索引;
+        self.__pos = 0
+        if xdata is None:
+            self.error(get_fun_name(), "xdata对象空")
+
+    # 获取当前option名称;
+    def getOptionName(self):
+        pass
+
+    # 获取当前option的xls中的others字段;
+    def getOptionOthers(self, optionName):
+        pass
+
+    def getOptionConfig(self, optionName):
+        pass
+
+    def getOptionMoveKey(self, optionName):
+        pass
+
+    def getOptionBackKey(self, optionName):
+        pass
+
+    def getOptionEnterKey(self, optionName):
         pass
-        
-    def __LoadExcel(self):
+
+    # 获取option的ocr文本;
+    def getOptionText(self, optionName):
+        pass
+
+    # 获取当前option的子项(子option名称集合)
+    def getOptionSubItems(self, optionName):
+        pass
+
+    def getOptionParentName(self, optionName):
+        pass
+
+    def getOptionShortCutKey(self, optionName):
         pass
 
+
 # Option定位逻辑类;
 class COptionFocusLogic(CBaseLog):
     def __init__(self):
         pass
-        
+
 
 # Option的文字识别逻辑类;
 class COptionOCRLogic(CBaseLog):
     def __init__(self):
         pass
 
+
 # Option的动作逻辑类
 class COptionActionLogic(CBaseLog):
-	# 目标节点名称, 目标节点设置值
-	def __init__(self, tagOptionName, tagOptionSetValue):
-		# 私有变量:节点位置,默认根结点(0)
-		self.__pos = 0
-		# 节点路径;
-		self.__paths = None
-		# 加载节点数据;
-		self.__LoadOptionData()
-		
-	def __LoadOptionData(self):
-		pass
-		
-	# 是否在第一节点(根结点)
-	def IsOnFirstOption(self):
-		pass
-		
-	# 调用根节点快捷键(中间节点不需要快捷键;);
-	def CallFirstOptionShortCutKey(self):
-		pass
-		
-	# 调用当前结点的toparent_key;
-	def CallCurOptionBackKey(self):
-		pass
-		
-	# 是否聚集到当前(self.__pos)节点;
-	def IsOnCurOption(self):
-		pass
-	
-	# 从当前节点开始向后移动;
-	def Move2NextOption(self):
-		pass
-		
-	# 从当前节点开始向前返回;
-	def Move2PrevOption(self):
-		pass
-	
-	# 获取当前Option名称;
-	def GetCurOptionName(self):
-		pass
-	
-	# 获取当前Option配置;	
-	def GetCurOptoinConfig(self):
-		pass
-		
-	# 获取当前Option表信息;
-	def GetCurOptionExcelInfo(self):
-		pass
-	
-	
+    # 目标节点名称, 目标节点设置值
+    def __init__(self, tagOptionName, tagOptionSetValue):
+        # 私有变量:节点位置,默认根结点(0)
+        self.__pos = 0
+        # 节点路径;
+        self.__paths = None
+        # 加载节点数据;
+        self.__LoadOptionData()
+
+    def __LoadOptionData(self):
+        pass
+
+    # 是否在第一节点(根结点)
+    def IsOnFirstOption(self):
+        pass
+
+    # 调用根节点快捷键(中间节点不需要快捷键;);
+    def CallFirstOptionShortCutKey(self):
+        pass
+
+    # 调用当前结点的toparent_key;
+    def CallCurOptionBackKey(self):
+        pass
+
+    # 是否聚集到当前(self.__pos)节点;
+    def IsOnCurOption(self):
+        pass
+
+    # 从当前节点开始向后移动;
+    def Move2NextOption(self):
+        pass
+
+    # 从当前节点开始向前返回;
+    def Move2PrevOption(self):
+        pass
+
+    # 获取当前Option名称;
+    def GetCurOptionName(self):
+        pass
+
+    # 获取当前Option配置;
+    def GetCurOptoinConfig(self):
+        pass
+
+    # 获取当前Option表信息;
+    def GetCurOptionExcelInfo(self):
+        pass
+
+
 if __name__ == "__main__":
-    pass
-	
-		
+    xdata = XData()
+    optdatalogic = COptionDataLogic(None)