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
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 editParam(self, pname): if not self.paraminfo[pname]['settable'] or self.client.viewonly: return mainunit = self.paramvalues.get('unit', 'main') punit = (self.paraminfo[pname]['unit'] or '').replace('main', mainunit) dlg = dialogFromUi(self, 'panels/devices_param.ui') dlg.target = DeviceParamEdit(self, dev=self.devname, param=pname) dlg.target.setClient(self.client) dlg.paramName.setText('Parameter: %s.%s' % (self.devname, pname)) dlg.paramDesc.setText(self.paraminfo[pname]['description']) dlg.paramValue.setText(str(self.paramvalues[pname]) + ' ' + punit) dlg.targetLayout.addWidget(dlg.target) dlg.resize(dlg.sizeHint()) dlg.target.setFocus() if dlg.exec_() != QDialog.Accepted: return try: new_value = dlg.target.getValue() except ValueError: self.log.exception('invalid value for typed value') # shouldn't happen, but if it does, at least give an indication that # something went wrong QMessageBox.warning( self, 'Error', 'The entered value is invalid ' 'for this parameter.') return if self.devrepr == self.devname: self.device_panel.exec_command('%s.%s = %r' % (self.devname, pname, new_value)) else: self.device_panel.exec_command( 'set(%s, %s, %r)' % (self.devrepr, srepr(pname), new_value))