def test_timeout(qtbot, taurus_test_ds): """Check that the timeout property works""" w = TaurusCommandButton(command='Sleep') qtbot.addWidget(w) try: w.setModel(taurus_test_ds) # set the parameter for the sleep command to 0.2 seconds w.setParameters([.2]) # Create a callback to check the result of the execution def _check_result(res): return res == .2 # Check that the button emits commandExecuted when timeout > exec time w.setTimeout(10) assert w.getTimeout() == 10 with qtbot.waitSignal(w.commandExecuted, check_params_cb=_check_result): qtbot.mouseClick(w, Qt.Qt.LeftButton) # Check that, if timeout < exec time, commandExecuted is NOT emited # and CommunicationFailed is raised w.setTimeout(.1) assert w.getTimeout() == .1 with pytest.raises(CommunicationFailed): with qtbot.assertNotEmitted(w.commandExecuted): # call _onClicked instead of emulating a click to bypass # the @ProtectTaurusMessageBox protection of onClicked() w._onClicked() finally: # just in case this helps avoiding problems at exit w.setModel(None)
def populateButtons(self): """ Create taurus commandbuttons for everything in modelcommand """ for modelcommand in self._modelcommands: button = TaurusCommandButton(self.frame) button.setCommand(modelcommand['command']) if 'model' in modelcommand: button.setModel(modelcommand['model']) else: button.setUseParentModel(True) if 'customtext' in modelcommand: button.setCustomText(modelcommand['customtext']) if 'dangermessage' in modelcommand: button.setDangerMessage(modelcommand['dangermessage']) if 'parameters' in modelcommand: button.setParameters(modelcommand['parameters']) if 'timeout' in modelcommand: button.setTimeout(modelcommand['timeout']) self.connect(button, Qt.SIGNAL('commandExecuted'), self.onCommandExectued) # Make button expand vertically button.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.frame.layout().addWidget(button) self._buttons.append(button)
def _updateCommandWidgets(self, *args): ''' Inserts command buttons and parameter widgets in the layout, according to the commands from the model ''' dev = self.getModelObj() if dev is None: self._clearFrame() return try: commands = sorted(dev.command_list_query(), key=self._sortKey) except Exception as e: self.warning('Problem querying commands from %s. Reason: %s', dev, e) self._clearFrame() return for f in self.getViewFilters(): commands = list(filter(f, commands)) self._clearFrame() layout = self._frame.layout() model = self.getFullModelName() for row, c in enumerate(commands): self.debug('Adding button for command %s' % c.cmd_name) button = TaurusCommandButton(command=c.cmd_name, text=c.cmd_name) layout.addWidget(button, row, 0) button.setModel(model) self._cmdWidgets.append(button) button.commandExecuted.connect(self._onCommandExecuted) import taurus.core.tango.util.tango_taurus as tango_taurus in_type = tango_taurus.FROM_TANGO_TO_TAURUS_TYPE[c.in_type] if in_type is not None: self.debug('Adding arguments for command %s' % c.cmd_name) pwidget = ParameterCB() if c.cmd_name.lower() in self._defaultParameters: for par in self._defaultParameters.get(c.cmd_name.lower(), []): pwidget.addItem(par) #pwidget.setEditable( (self._defaultParameters[c.cmd_name.lower()] or [''])[0] == '' ) if (self._defaultParameters[c.cmd_name.lower()] or [''])[0] == '': pwidget.setEditable(True) else: pwidget.setEditable(False) button.setParameters(self._defaultParameters[ c.cmd_name.lower()][0]) pwidget.editTextChanged.connect(button.setParameters) pwidget.currentIndexChanged['QString'].connect(button.setParameters) pwidget.activated.connect(button.setFocus) button.commandExecuted.connect(pwidget.rememberCurrentText) layout.addWidget(pwidget, row, 1) self._paramWidgets.append(pwidget)
def _updateCommandWidgets(self, *args): ''' Inserts command buttons and parameter widgets in the layout, according to the commands from the model ''' #self.debug('In TaurusCommandsForm._updateCommandWidgets())') dev = self.getModelObj() if dev is None or dev.state != TaurusDevState.Ready: self.debug('Cannot connect to device') self._clearFrame() return commands = sorted(dev.command_list_query(), key=self._sortKey) for f in self.getViewFilters(): commands = filter(f, commands) self._clearFrame() layout = self._frame.layout() for row, c in enumerate(commands): self.debug('Adding button for command %s' % c.cmd_name) button = TaurusCommandButton(command=c.cmd_name, text=c.cmd_name) layout.addWidget(button, row, 0) button.setUseParentModel(True) self._cmdWidgets.append(button) self.connect(button, Qt.SIGNAL('commandExecuted'), self._onCommandExecuted) if c.in_type != PyTango.CmdArgType.DevVoid: self.debug('Adding arguments for command %s' % c.cmd_name) pwidget = ParameterCB() if c.cmd_name.lower() in self._defaultParameters: for par in self._defaultParameters.get( c.cmd_name.lower(), []): pwidget.addItem(par) #pwidget.setEditable( (self._defaultParameters[c.cmd_name.lower()] or [''])[0] == '' ) if (self._defaultParameters[c.cmd_name.lower()] or [''])[0] == '': pwidget.setEditable(True) else: pwidget.setEditable(False) button.setParameters( self._defaultParameters[c.cmd_name.lower()][0]) self.connect(pwidget, Qt.SIGNAL('editTextChanged (const QString&)'), button.setParameters) self.connect(pwidget, Qt.SIGNAL('currentIndexChanged (const QString&)'), button.setParameters) self.connect(pwidget, Qt.SIGNAL('activated (int)'), button.setFocus) self.connect(button, Qt.SIGNAL('commandExecuted'), pwidget.rememberCurrentText) layout.addWidget(pwidget, row, 1) self._paramWidgets.append(pwidget)
def _updateCommandWidgets(self, *args): ''' Inserts command buttons and parameter widgets in the layout, according to the commands from the model ''' #self.debug('In TaurusCommandsForm._updateCommandWidgets())') dev = self.getModelObj() if dev is None or dev.state != TaurusDevState.Ready: self.debug('Cannot connect to device') self._clearFrame() return commands = sorted(dev.command_list_query(), key=self._sortKey) for f in self.getViewFilters(): commands = filter(f, commands) self._clearFrame() layout = self._frame.layout() for row, c in enumerate(commands): self.debug('Adding button for command %s' % c.cmd_name) button = TaurusCommandButton(command=c.cmd_name, text=c.cmd_name) layout.addWidget(button, row, 0) button.setUseParentModel(True) self._cmdWidgets.append(button) button.commandExecuted.connect(self._onCommandExecuted) if c.in_type != PyTango.CmdArgType.DevVoid: self.debug('Adding arguments for command %s' % c.cmd_name) pwidget = ParameterCB() if c.cmd_name.lower() in self._defaultParameters: for par in self._defaultParameters.get(c.cmd_name.lower(), []): pwidget.addItem(par) #pwidget.setEditable( (self._defaultParameters[c.cmd_name.lower()] or [''])[0] == '' ) if (self._defaultParameters[c.cmd_name.lower()] or [''])[0] == '': pwidget.setEditable(True) else: pwidget.setEditable(False) button.setParameters(self._defaultParameters[ c.cmd_name.lower()][0]) pwidget.editTextChanged.connect(button.setParameters) pwidget.currentIndexChanged.connect(button.setParameters) pwidget.activated.connect(button.setFocus) button.commandExecuted.connect(pwidget.rememberCurrentText) layout.addWidget(pwidget, row, 1) self._paramWidgets.append(pwidget)