Przeglądaj źródła

COptionAction
1、isOnTargetNode添加参数,用于source信源此类菜单消失过快的情况。

CTMenu
1、新增__move2SourceNode、setSourceValue、__exitUsbSource函数。
其中:__exitUsbSource函数未完成。

scbc.sat2 5 lat temu
rodzic
commit
1a26154597
2 zmienionych plików z 138 dodań i 13 usunięć
  1. 28 6
      ssat_sdk/MenuTree3/OptionAction.py
  2. 110 7
      ssat_sdk/MenuTree3/TMenu.py

+ 28 - 6
ssat_sdk/MenuTree3/OptionAction.py

@@ -111,6 +111,10 @@ class COptionAction(CBaseLog):
     def optionValueText(self):
         return self.__optionValueText
 
+    @property
+    def optionValueInfo(self):
+        return self.__optionValueInfo
+
     '''
     函数:截图并返回截图路径;
     参数:无
@@ -264,12 +268,13 @@ class COptionAction(CBaseLog):
         每次移动到下一目标节点(option)上时,self.__pos + 1,表示移动到下一层路径。
         当self.__pos >= self.__optionPaths.__len__()时,表示到达value表格;
         所以,该类的重点在self.__pos的移动;
-    参数:无
+    参数:
+        staticPic      静态图片路径。
     返回:Boolean, 识别的文本/数字;
     示例:
     '''
 
-    def isOnTargetNode(self):
+    def isOnTargetNode(self, staticPic=None):
         # 是否在value表中;
         isValueSheet = self.isOnValueSheet()
         self.info(u"当前层级在:%s" % ("value表" if isValueSheet else "路径表"))
@@ -324,7 +329,9 @@ class COptionAction(CBaseLog):
                                             ocrThreshold, curOthers['marquee'],
                                             isNumberText, isValueSheet)
         else:
-            return self.__getStaticPicText(self.takePicture(), curOption, optionTextList, siblingTextList,
+            return self.__getStaticPicText(self.takePicture() if staticPic is None else staticPic, curOption,
+                                           optionTextList,
+                                           siblingTextList,
                                            ocrConfigList,
                                            ocrThreshold,
                                            isNumberText, isValueSheet)
@@ -470,7 +477,15 @@ class COptionAction(CBaseLog):
             # 进入下层,自增
             self.__pos += 1
         else:
-            self.info(u"节点已在value上,无法再进入")
+            if not self.__isEnterKeyInValue:
+                self.info(u"节点已在value上,且没有触发过enter key")
+                # waitTime = self.__optionConfig.getParentWaitTime(self.__curOptionInfo['parent'])
+                enterKey = self.__optionValueInfo['enter_key']
+                if enterKey != "default":
+                    self.__isEnterKeyInValue = True
+                    self.sendKey(enterKey, 1, 0.1)
+            else:
+                self.info(u"节点已在value上,已触发过enter key")
 
     '''
     函数:设置当前节点位置;
@@ -587,6 +602,11 @@ class COptionAction(CBaseLog):
                 return False
             self.__curOptionInfo = outData
 
+            # 特殊情况:如果只一层且该层与value相同(信源source,要在value表中配置一份相同配置)。
+            # if self.__curOptionInfo['first_parent'] == self.__curOptionName:
+            #     # 自动进入value表;
+            #     self.__pos += 1
+
         return True
 
     '''
@@ -954,6 +974,8 @@ if __name__ == "__main__":
     exData = CExtraData()
     optionExcel = COptionExcel(exData)
     optionConfig = COptionConfig(exData, optionExcel)
-    optionAction = COptionAction('picture', '', optionConfig, optionExcel)
+    optionAction = COptionAction('source', None, optionConfig, optionExcel)
+    # print optionAction.optionValueInfo
+    print optionAction.curOptionInfo
     # ====================================== #
-    optionAction.callFirstOptionShortCutKey()
+    # optionAction.callFirstOptionShortCutKey()

+ 110 - 7
ssat_sdk/MenuTree3/TMenu.py

@@ -110,6 +110,65 @@ class CTMenu(CBaseLog):
 
         return isOnTargetNode, targetText
 
+    '''
+    函数:退出 usb 信源界面;
+    参数:
+        opa     COptionAction对象;
+    返回:
+    '''
+    def __exitUsbSource(self, opa):
+        pass
+
+    '''
+    函数:移动到目标信源节点上。
+    参数:
+        opa                 COptionAction对象;
+        moveDirection       移动方向,True表示调用move_key[1](向下或向右), False表示调用move_key[0]。
+        maxTry              最大移动次数,防止死循环。
+    返回:Boolean是否在目标节点上, 文本或数值。
+    '''
+    def __move2SourceNode(self, opa, moveDirection, maxTry=15):
+        tryCount = 0
+        # 目标节点聚焦状态;
+        targetFocus = False
+        # 目标文本或数值;
+        targetText = None
+        # 移动到目标节点;
+        while True:
+            # 截图,截图完后马上进入信源;
+            pic = self.takePicture()
+            # 有些信源,需要手动enter
+            enterKey = opa.curOptionInfo['enter_key']
+            if enterKey != "default":
+                self.redRat3.sendKey(enterKey)
+
+            # 判断是否移动成功;
+            targetFocus, targetText = opa.isOnTargetNode(pic)
+            if targetFocus is True:
+                self.info(u"===========到达目标信源节点===========")
+                break
+            # endif
+
+            # 如果是usb信源,特殊处理;
+            if 'usb' in targetText.lower():
+                self.__exitUsbSource(opa)
+
+            # 因为信源界面消失了,需要再调用一次.
+            opa.callFirstOptionShortCutKey()
+            # 移动到下/上一节点;
+            if moveDirection:
+                opa.move2NextSiblingNode()
+            else:
+                opa.move2PrevSiblingNode()
+
+            tryCount += 1
+            if tryCount > maxTry:
+                self.warn(u"已%s遍历超过%d次,仍未找到焦点" % ("正向" if moveDirection else "逆向", maxTry))
+                break
+        # end-while
+
+        return targetFocus, targetText
+
     '''
     函数:聚焦到指定option中。
     参数:
@@ -125,7 +184,7 @@ class CTMenu(CBaseLog):
 
         # 首先,调用根菜单;
         opa.callFirstOptionShortCutKey()
-        time.sleep(1)
+        # time.sleep(1)
         if opa.isOnFirstOption() is False:
             self.error(u"未聚焦到根节点上,退出")
             self.__back2Home(opa)
@@ -265,6 +324,9 @@ class CTMenu(CBaseLog):
         optionName
         optionValue
     返回:
+    
+    注意:如果optionValue是数值类型,将不会变更值。
+          如optionValue=10,实现该optionName的value是100,则不变更其值。
     '''
     def focusOptionValue(self, optionName, optionValue):
         self.info(u"【%s】【%s】" % (optionName, optionValue))
@@ -360,9 +422,11 @@ class CTMenu(CBaseLog):
         return True
 
     '''
-    函数:
+    函数:检测输入的频道列表,是否都存在,返回不存在的频道列表。
     参数:
-    返回:
+        channelList         要检测的目标频道列表。
+    返回:Boolean, []
+        如果有频道没找到,返回False,并返回没找到的频道列表。如果全部找到返回True。
     '''
     def checkChannelList(self, channelList, maxTry=15):
         failChannelList = []
@@ -386,9 +450,12 @@ class CTMenu(CBaseLog):
         return checkResult, failChannelList
 
     '''
-    函数:
+    函数:移动到黑屏的频道。
     参数:
-    返回:
+        channelCount           要查找多少次频道。
+        blackThreshold         黑屏阈值。
+        blackRate              黑屏比率。
+    返回:Boolean。找到返回True。
     '''
     def getBlackChannel(self, channelCount, blackThreshold=20, blackRate=2.0):
         result = False
@@ -411,6 +478,37 @@ class CTMenu(CBaseLog):
 
         return result
 
+    '''
+    函数:设置信源。
+    参数:
+        optionName      目标信源;
+    返回:
+    
+    注意:切换信源是特殊的情况处理:
+        1、信源菜单消失过快,会导致ocr识别完成后,菜单已消失。
+        2、usb信源下,可能会调用source按键失败,所以需要调用其他退出键(ok、exit、return)
+    '''
+    def setSourceValue(self, optionName):
+        self.info(u"【%s】" % optionName)
+        CTMenu.sourceInput.setPattern(11)
+        sourceList = self.__optionExcel.getOptionAllChildItemName(optionName)
+        opa = COptionAction(optionName, None, self.__optionConfig, self.__optionExcel)
+
+        # 检测路径是否有效;
+        if not opa.checkRunOptionPath():
+            return False
+
+        # 首先,调用根菜单;
+        opa.callFirstOptionShortCutKey()
+        # 遍历到目标option中;
+        if self.__move2SourceNode(opa, True, sourceList.__len__()*1.5)[0] is False:
+            if self.__move2SourceNode(opa, False, sourceList.__len__()*1.5)[0] is False:
+                self.__back2Home(opa)
+                return False
+
+        self.info(u"成功进入指定信源:%s" % optionName)
+        return True
+
 
 if __name__ == "__main__":
     ml = CTMenu()
@@ -567,9 +665,14 @@ if __name__ == "__main__":
         time.sleep(st)
         ml.getOptionValue('picture_preset')
 
-    ml.getBlackChannel(10)
-    if 1:
+    if 0:
         ml.openOption('picture')
         ml.moveToOption('brightness')
         ml.moveToOption('picture_reset')
         ml.moveToOption('picture_preset')
+
+    if 1:
+        # ml.setSourceValue('hdmi1')
+        ml.setSourceValue('hdmi2')
+        # ml.setSourceValue('dtv')
+        # ml.setSourceValue('av')