def __init__(
        self,
        hwID: str,
        hwNumber: str,
        fact: GuiDeviceFactory,
        dri: TelnetClientDriAsync,
        outputFn,
        trace: CoreTrace,
        errHandler,
        completeFn,
    ):
        uiPyModule = TempFiles.UiPyModule("QConfigMain", "DeviceWidget")
        GuiDeviceWidget.__init__(self, None, uiPyModule, "Ui_DeviceWidget")

        self.dri = TelnetClientDriAsyncQueue(dri, errHandler)
        self.info = CoreDeviceBroadcastInfoGen(hwID, hwNumber)
        self.name = self.info.StaticName
        self.completeFn = completeFn
        self.outputFn = outputFn
        self.processedMonitCmdCount = 0
        self.common = GuiDeviceCommon(self.name, lambda name, text: outputFn(text), trace)
        # check CreateCustomWidget()
        self.custom = fact.CreateCustomWidget(hwID, self.common, self)
        self.Ui.mainLayout.addWidget(self.custom, 3, 0)

        self.conf = None
        self.__CheckCreateConfigAndConfigHandler(hwID, fact)

        # start test
        self.__Step("Test started")
        self.__ExecRunScript()
 def GuiFieldTest(parent : GuiDeviceWidget, meta : GuiFieldWidgetFactory,
                  widget : GuiDeviceWidget):
     f = GuiDeviceConfigField(name, widgetName, defVal, ValidatorInt(), 
                              useInRunScript, useInStopScript, needSaveToFile, 
                              None, toolTip, enum, help)
     f.CustomSetup(parent, meta, None)
     assert not f.IsRuntime()
     
     f.DeviceIsRunning(True)
     assert not widget.isEnabled()
     
     f.DeviceIsRunning(False)
     assert widget.isEnabled()
     
     AssertForException(f.Read, ConverterErr)
     
     f.WriteDefault()
     assert widget.text() == IntToStr(f.Default)
     
     f.SetValue(8)
     f.Write()
     assert widget.text() == '8'
     
     f.Read()
     assert f.Value == 8
     assert f.Default == defVal
     
     assert widget.toolTip() == toolTip
 def CustomSetup(self, parentWidget : GuiDeviceWidget, 
                 meta : GuiFieldWidgetFactory, execDriCmdFn):
     """
     Find widget in 'parentWidget' by name: 'self.widgetName'.
     Initialize widget's Set(), Get(), setEnable() and connect runtime 
     command to changed() slot. 
     'execDriCmdFn' - fn(cmd : str, callback) -> None, check command 
                      retsult AFTER calling 'callback'. It's needed for 
                      runtime changeable field only.                         
     """
     assert not self.IsCustomized()
     self.customized = True
     assert parentWidget
     
     self.help = parentWidget.tr(self.help)
     self.widgetToolTip = parentWidget.tr(self.widgetToolTip)
     
     if not self.widgetName:
         if self.IsRuntime():
             assert 0 and "No widget for runtime field!"
         return
     
     parentDict = parentWidget.Ui.__dict__
     
     if not self.widgetName in parentDict.keys():
         raise AssertionError("Unknown widget name: '{}'".format(self.widgetName))
     
     subWidget = parentDict[self.widgetName]
     self.metaWidget = meta.Create(subWidget, self.Default, self.widgetEnum)
     
     if self.IsRuntime(): self.__LinkDriExecuter(execDriCmdFn)
     self.__LinkWidget(parentWidget)        
Beispiel #4
0
 def __init__(self,
              nameCheckerFn,
              info : CoreDeviceBroadcastInfo,
              confDict : {},
              devConfigDir : str,  
              dri : TelnetClientDriAsync,
              fact : GuiDeviceFactory,
              statusFn, 
              errorHandler, 
              trace : CoreTrace):
     """
     'nameCheckerFn' - fn(name: str, staticNAme : str) -> bool, using to 
                       check that device name is unique within device list,
     'info'          - broadcast info,
     'confDict'      - loaded from file config, can be None,
     'devConfigDir'  - directory using to save device config file,  
     'statusFn'      - fn(name : str, text : str) -> None,
     'errorHandler'  - fn(e : Exception) -> None  
     
     If device created from config file: info == None and 
     info part of widget will be updated on next broadcast.
     If device created from broadcast info: confDict == None, widget 
     will be updated from default config.
     """
     uiPyModule = TempFiles.UiPyModule('QConfigMain', 'DeviceWidget')
     GuiDeviceWidget.__init__(self, None, uiPyModule, 'Ui_DeviceWidget')
     
     self.errorHandler = errorHandler
     
     self.vertScroll = None # to adjust on resize
     self.runButton = None  # QAction, using to change: 'Run' <-> 'Stop'
     self.monitButton = None
     
     self.dri = TelnetClientDriAsyncQueue(dri, self.errorHandler)
     self.nameCheckerFn = nameCheckerFn
     self.processedMonitCmdCount = 0
     self.isRunnning = False
     
     self.info = info
     self.conf = None
     self.name = None
     self.staticName = None
     self.hwNumber = None
     self.hwID = None
     
     self.common = None
     self.custom = None
     
     self.inClosingState = False
             
     self.threadId = threading.current_thread()
     
     self.__InitProperties(info, confDict)
     self.__InitCommonPart(statusFn, trace)
     self.__InitCustomPart(info, confDict, devConfigDir, fact)
     self.__SetupUi(fact)
     self.__RegisterInHwFinder()
     
     if self.info: self.UpdateBroadcastInfo(self.info)
 def RuntimeFieldTest(parent : GuiDeviceWidget, meta : GuiFieldWidgetFactory,
                      widget : GuiDeviceWidget):
     def ExecDriCmdFn(cmd : str, callback):
         pass
     
     f = GuiDeviceConfigField(name, widgetName, defVal, ValidatorInt(), 
                              useInRunScript, useInStopScript, needSaveToFile, 
                              runtimeDriCommand, toolTip, enum, help)
     f.CustomSetup(parent, meta, ExecDriCmdFn)
     assert f.IsRuntime()
     
     f.DeviceIsRunning(True)
     assert widget.isEnabled()
     
     f.DeviceIsRunning(False)
     assert widget.isEnabled()
 
     widget.returnPressed.emit()