def on_actionSetLimits_triggered(self): dlg = dialogFromUi(self, 'panels/devices_limits.ui') dlg.descLabel.setText('Adjust user limits of %s:' % self.devname) dlg.limitMin.setText(self.limitMin.text()) dlg.limitMax.setText(self.limitMax.text()) abslimits = self.client.getDeviceParam(self.devname, 'abslimits') offset = self.client.getDeviceParam(self.devname, 'offset') if offset is not None: abslimits = abslimits[0] - offset, abslimits[1] - offset dlg.limitMinAbs.setText(str(abslimits[0])) dlg.limitMaxAbs.setText(str(abslimits[1])) target = DeviceParamEdit(dlg, dev=self.devname, param='userlimits') target.setClient(self.client) btn = dlg.buttonBox.addButton('Reset to maximum range', QDialogButtonBox.ResetRole) def callback(): self.device_panel.exec_command('resetlimits(%s)' % self.devrepr) dlg.reject() btn.clicked.connect(callback) dlg.targetLayout.addWidget(target) res = dlg.exec_() if res != QDialog.Accepted: return newlimits = target.getValue() if newlimits[0] < abslimits[0] or newlimits[1] > abslimits[1]: QMessageBox.warning( self, 'Error', 'The entered limits are not ' 'within the absolute limits for the device.') # retry self.on_actionSetLimits_triggered() return self.device_panel.exec_command('set(%s, "userlimits", %s)' % (self.devrepr, newlimits))
class Configure(Cmdlet): name = 'Configure' category = 'Device' def __init__(self, parent, client): Cmdlet.__init__(self, parent, client, 'cmdlets/configure.ui') self.paraminfo = {} self.paramvalues = {} self.target = DeviceParamEdit(self) self.target.setClient(self.client) self.target.valueModified.connect(self.changed) self.hlayout.insertWidget(5, self.target) self.device.addItems(self._getDeviceList()) self.on_device_change(self.device.currentText()) self.device.currentIndexChanged[str].connect(self.on_device_change) self.parameter.currentIndexChanged[str].connect( self.on_parameter_change) def on_device_change(self, text): self.paraminfo = self.client.getDeviceParamInfo(text) self.paramvalues = dict(self.client.getDeviceParams(text)) self.parameter.clear() self.parameter.addItems( sorted(p for p in self.paraminfo if self.paraminfo[p]['settable'] and self.paraminfo[p]['userparam'])) self.target.dev = text self.on_parameter_change(self.parameter.currentText()) self.changed() def on_parameter_change(self, text): self.target.param = text self.changed() def getValues(self): return { 'dev': self.device.currentText(), 'param': self.parameter.currentText(), 'paramvalue': self.target.getValue() } def setValues(self, values): self._setDevice(values) if 'param' in values: idx = self.parameter.findText(values['param']) if idx > -1: self.parameter.setCurrentIndex(idx) # DeviceValueEdit doesn't support setValue (yet) # if 'paramvalue' in values: # self.target.setValue(values['paramvalue']) def isValid(self): return self.markValid(self.target, True) def generate(self, mode): values = self.getValues() if mode == 'simple': return 'set %(dev)s %(param)s %(paramvalue)r' % values values['dev'] = self._getDeviceRepr(values['dev']) return 'set(%(dev)s, %(param)r, %(paramvalue)r)' % values