def __init__(self, parent, typ, curvalue, fmtstr='%.4g', minmax=None, allow_enter=False): QLineEdit.__init__(self, parent) self._typ = typ if typ is float: val = DoubleValidator(self) if minmax: # setRange doesn't work correctly in some Qt versions... val.setBottom(minmax[0]) if minmax[1] is not None: val.setTop(minmax[1]) self.setValidator(val) self.setText(fmtstr % curvalue) elif typ is int: val = QIntValidator(self) if minmax: val.setRange(minmax[0], minmax[1]) self.setValidator(val) self.setText(str(curvalue)) else: self.setText(str(curvalue)) self.textChanged.connect(lambda txt: self.valueModified.emit()) if allow_enter: self.returnPressed.connect( lambda: self.valueChosen.emit(self._typ(self.text())))
def __init__(self, parent, client): Cmdlet.__init__(self, parent, client, self.uiName) self.device.addItems(self._getDeviceList()) self.on_device_change(self.device.currentText()) self.device.currentIndexChanged[str].connect(self.on_device_change) self.start.setValidator(DoubleValidator(self)) self.step.setValidator(DoubleValidator(self)) self.start.textChanged.connect(self.on_range_change) self.step.textChanged.connect(self.on_range_change) self.numpoints.valueChanged.connect(self.on_range_change) self.seconds.valueChanged.connect(self.changed) self.contBox.toggled.connect(self.changed)
def __init__(self, parent, client): Cmdlet.__init__(self, parent, client, 'cmdlets/contscan.ui') self.device.addItems(self._getDeviceList('hasattr(d, "speed")')) self.on_device_change(self.device.currentText()) self.device.currentIndexChanged[str].connect(self.on_device_change) self.start.setValidator(DoubleValidator(self)) self.stop.setValidator(DoubleValidator(self)) self.speed.setValidator(DoubleValidator(self)) self.delta.setValidator(DoubleValidator(self)) self.start.textChanged.connect(self.on_range_change) self.stop.textChanged.connect(self.on_range_change) self.speed.textChanged.connect(self.on_range_change) self.delta.textChanged.connect(self.on_range_change)
def __init__(self, parent, client): Cmdlet.__init__(self, parent, client, findResource('nicos_mlz/maria/gui/kscan.ui')) self.device.addItems(self._getDeviceList('hasattr(d, "speed")')) self.on_device_change(self.device.currentText()) self.device.currentIndexChanged[str].connect(self.on_device_change) self.start.setValidator(DoubleValidator(self)) self.step.setValidator(DoubleValidator(self)) self.speed.setValidator(DoubleValidator(self)) self.start.textChanged.connect(self.on_range_change) self.step.textChanged.connect(self.on_range_change) self.speed.textChanged.connect(self.on_range_change) self.numpoints.valueChanged.connect(self.on_range_change)
def __init__(self, parent, client): Cmdlet.__init__(self, parent, client, findResource('nicos_mlz/maria/gui/sscan.ui')) self.device.addItems(self._getDeviceList()) self.on_device_change(self.device.currentText()) self.device.currentIndexChanged[str].connect(self.on_device_change) self.start.setValidator(DoubleValidator(self)) self.stop.setValidator(DoubleValidator(self)) self.step.setValidator(DoubleValidator(self)) self.delta.setValidator(DoubleValidator(self)) self.start.textChanged.connect(self.on_range_change) self.stop.textChanged.connect(self.on_range_change) self.step.textChanged.connect(self.on_range_change) self.delta.textChanged.connect(self.on_range_change)
def __init__(self, parent, client, instrument, configs, config=None): QDialog.__init__(self, parent) self.instrument = instrument self.configs = configs self.client = client self.setWindowTitle('Sample configuration') layout = QVBoxLayout() self.frm = QFrame(self) loadUi(self.frm, findResource('nicos_mlz/kws1/gui/sampleconf_one.ui')) self.frm.addDevBtn.clicked.connect(self.on_addDevBtn_clicked) self.frm.delDevBtn.clicked.connect(self.on_delDevBtn_clicked) self.frm.readDevsBtn.clicked.connect(self.on_readDevsBtn_clicked) self.frm.readApBtn.clicked.connect(self.on_readApBtn_clicked) box = QDialogButtonBox(self) box.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) box.accepted.connect(self.maybeAccept) box.rejected.connect(self.reject) layout.addWidget(self.frm) layout.addWidget(box) self.setLayout(layout) for box in [self.frm.offsetBox, self.frm.thickBox, self.frm.factorBox, self.frm.apXBox, self.frm.apYBox, self.frm.apWBox, self.frm.apHBox]: box.setValidator(DoubleValidator(self)) if config is not None: configToFrame(self.frm, config)
def __init__(self, parent, client, instrument, configs, config=None): QDialog.__init__(self, parent) self.instrument = instrument self.configs = configs self.client = client self.setWindowTitle('Sample configuration') layout = QVBoxLayout() self.frm = QFrame(self) loadUi(self.frm, findResource('nicos_ess/loki/gui/ui_files/sampleconf_one.ui')) self.frm.addDevBtn.clicked.connect(self.on_addDevBtn_clicked) self.frm.delDevBtn.clicked.connect(self.on_delDevBtn_clicked) self.frm.readDevsBtn.clicked.connect(self.on_readDevsBtn_clicked) box = QDialogButtonBox(self) box.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) box.accepted.connect(self.maybeAccept) box.rejected.connect(self.reject) layout.addWidget(self.frm) layout.addWidget(box) self.setLayout(layout) self.frm.thickBox.setValidator(DoubleValidator(self)) if config is not None: configToFrame(self.frm, config) # Apply local customisations to the stylesheet self.setStyleSheet(ConfigEditDialog_QSS) if not config: self.frm.whatLbl.setText('New sample configuration')
def createWidget(self, parent, client): if self.value is None: self.value = 10.0 self._widget = QLineEdit(parent) self._widget.setValidator(DoubleValidator(parent)) self._widget.setText('%g' % self.value) self._widget.textChanged.connect(self._updateValue) return self._widget
def __init__(self, parent): QDialog.__init__(self, parent) loadUi(self, findResource('nicos_ess/loki/gui/ui_files/rtconfig.ui')) self.progBox.setValidator(DoubleValidator(self)) self.chanBox.valueChanged.connect(self._update_time) self.intervalBox.valueChanged.connect(self._update_time) self.intervalUnitBox.currentIndexChanged.connect(self._update_time) self.linBtn.toggled.connect(self._update_time) self.progBtn.toggled.connect(self._update_time) self.progBox.textChanged.connect(self._update_time)
def __init__(self, parent, client, **settings): QDialog.__init__(self, parent) loadUi(self, 'tools/calculator.ui') self.closeBtn.clicked.connect(self.doclose) self.braggfmlLabel.setPixmap(QPixmap( path.join(path.dirname(__file__), 'calculator_images', 'braggfml.png'))) for fld in bragg_fields: getattr(self, 'chk' + fld).toggled.connect(self.gen_checked(fld)) self._miezesettings = settings.get('mieze', []) if not self._miezesettings: self.tabWidget.removeTab(1) else: self.mzwavelengthInput.textChanged.connect(self.mzcalc) self.mzdistanceInput.textChanged.connect(self.mzcalc) self.mzformulaLabel.setPixmap(QPixmap( path.join(path.dirname(__file__), 'calculator_images', 'miezefml.png'))) self.mztimeTable.setHeaderLabels(['Setting', u'MIEZE time τ']) for setting in self._miezesettings: self.mztimeTable.addTopLevelItem(QTreeWidgetItem([setting, ''])) for fld in neutron_fields: getattr(self, 'prop' + fld).textEdited.connect(self.n_calc) self.presets = DlgPresets('nicoscalctool', [ (self.tabWidget, 0), (self.mzwavelengthInput, '10'), (self.mzdistanceInput, '100'), (self.inputLambda, '4.5'), (self.input2Theta, '0'), (self.inputD, '10'), (self.inputN, '1'), (self.inputQ, '0'), (self.chkLambda, 1), (self.chk2Theta, 0), (self.chkN, 1), (self.chkD, 1), (self.chkQ, 0), (self.chkSampleDet, 1), (self.inputSampleDet, '0'), (self.propL, '1.8'), (self.propK, '3.4907'), (self.propE, '25.2482'), (self.propNy, '6.1050'), (self.propT, '292.9934'), (self.propV, '2197.80'), ]) self.presets.load() self.braggcalc() self.n_calc('') dblval = DoubleValidator(self) for fld in bragg_fields: inputbox = getattr(self, 'input'+fld) inputbox.textChanged.connect(self.braggcalc) inputbox.setValidator(dblval)
def on_actionGenerate_triggered(self): def read_axes(): ax1, ax2 = dlg._info[2], dlg._info[4] for (ax, box) in [(ax1, dlg.ax1Box), (ax2, dlg.ax2Box)]: if not ax: continue x = self.client.eval('%s.read()' % ax, None) if x is None: QMessageBox.warning(dlg, 'Error', 'Could not read %s.' % ax) return box.setText('%.1f' % x) def btn_toggled(checked): if checked: dlg._info = dlg.sender()._info ax1, ax2 = dlg._info[2], dlg._info[4] for ax, lbl, box, revbox in [ (ax1, dlg.ax1Lbl, dlg.ax1Box, dlg.ax1RevBox), (ax2, dlg.ax2Lbl, dlg.ax2Box, None) ]: if ax: lbl.setText(ax) lbl.show() box.show() if revbox: revbox.show() revbox.setText('%s starts at far end' % ax) else: lbl.hide() box.hide() if revbox: revbox.hide() dlg = dialogFromUi(self, findResource( 'nicos_mlz/kws1/gui/sampleconf_gen.ui')) dlg.ax1Box.setValidator(DoubleValidator(self)) dlg.ax2Box.setValidator(DoubleValidator(self)) dlg.readBtn.clicked.connect(read_axes) nrows = int(math.ceil(len(self.holder_info) / 2.0)) row, col = 0, 0 for name, info in self.holder_info: btn = QRadioButton(name, dlg) btn._info = info btn.toggled.connect(btn_toggled) dlg.optionFrame.layout().addWidget(btn, row, col) if (row, col) == (0, 0): btn.setChecked(True) row += 1 if row == nrows: row = 0 col += 1 if not dlg.exec_(): return rows, levels, ax1, dax1, ax2, dax2 = dlg._info sax1 = float(dlg.ax1Box.text()) if ax1 else 0 sax2 = float(dlg.ax2Box.text()) if ax2 else 0 if dlg.ax1RevBox.isChecked(): dax1 = -dax1 n = 0 for i in range(levels): for j in range(rows): n += 1 position = {} if ax1: position[ax1] = round(sax1 + j * dax1, 1) if ax2: position[ax2] = round(sax2 + i * dax2, 1) config = dict( name = str(n), comment = '', detoffset = -335.0, thickness = 1.0, timefactor = 1.0, aperture = (0, 0, 10, 10), position = position, ) self.configs.append(config) firstitem = None for config in self.configs: newitem = QListWidgetItem(config['name'], self.list) firstitem = firstitem or newitem # select the first item self.list.setCurrentItem(firstitem) self.on_list_itemClicked(firstitem) self.fileGroup.setEnabled(False) self.sampleGroup.setEnabled(True) self.dirty = True
def on_actionGenerate_triggered(self): def read_axes(): ax1, ax2 = dlg._info[2], dlg._info[4] for (ax, box) in [(ax1, dlg.ax1Box), (ax2, dlg.ax2Box)]: if not ax: continue x = self.client.eval('%s.read()' % ax, None) if x is None: QMessageBox.warning(dlg, 'Error', f'Could not read {ax}.') return box.setText(f'x:.1f') def btn_toggled(checked): if checked: dlg._info = dlg.sender()._info ax1, ax2 = dlg._info[2], dlg._info[4] for ax, lbl, box, revbox in [ (ax1, dlg.ax1Lbl, dlg.ax1Box, dlg.ax1RevBox), (ax2, dlg.ax2Lbl, dlg.ax2Box, None) ]: if ax: lbl.setText(ax) lbl.show() box.show() if revbox: revbox.show() revbox.setText(f'{ax} starts at far end') else: lbl.hide() box.hide() if revbox: revbox.hide() if not self.holder_info: self.showError('Cannot auto-generate sample list as no sample ' 'changers are defined') return dlg = dialogFromUi( self, findResource('nicos_ess/loki/gui/ui_files/sampleconf_gen.ui')) dlg.ax1Box.setValidator(DoubleValidator(self)) dlg.ax2Box.setValidator(DoubleValidator(self)) dlg.readBtn.clicked.connect(read_axes) n_rows = int(math.ceil(len(self.holder_info) / 2.0)) row, col = 0, 0 for name, info in self.holder_info: btn = QRadioButton(name, dlg) btn._info = info btn.toggled.connect(btn_toggled) dlg.optionFrame.layout().addWidget(btn, row, col) if (row, col) == (0, 0): btn.setChecked(True) row += 1 if row == n_rows: row = 0 col += 1 if dlg.exec_() != QDialog.Accepted: return self._generate_configs(dlg) first_item = None for config in self.configs: new_item = QListWidgetItem(config['name'], self.list) first_item = first_item or new_item # select the first item self.list.setCurrentItem(first_item) self.on_list_itemClicked(first_item) self.sampleGroup.setEnabled(True) self.applyBtn.setEnabled(True)
def test_double_validator(): inf = float('inf') # valid cases validator = DoubleValidator() for args in [ ('0', -inf, inf), ('0.0', -inf, inf), ('0.0e0', -inf, inf), ('-0.0', -inf, inf), ('1.23456789123456789e130', -inf, inf), ('0', -1, 1), ('0', 0, inf), ('0', -inf, 0), ]: validator.setBottom(args[1]) validator.setTop(args[2]) assert validator.validate(args[0], 0)[0] == QValidator.Acceptable # intermediate cases for args in [ ('4', 10, 50), ('-4', -50, -10), ('1.0e', -inf, inf), ('0', 10, 20), ]: validator.setBottom(args[1]) validator.setTop(args[2]) assert validator.validate(args[0], 0)[0] == QValidator.Intermediate # invalid cases for args in [ ('-15', 10, 20), ('-1', 10, 20), ('+15', -20, -10), ('+1', -20, -10), ('1,5', 0, 10), ]: validator.setBottom(args[1]) validator.setTop(args[2]) assert validator.validate(args[0], 0)[0] == QValidator.Invalid
def __init__(self, parent, client, **settings): QDialog.__init__(self, parent) loadUi(self, 'tools/scan.ui') self.scanButtonGroup = QButtonGroup() self.scanButtonGroup.addButton(self.scanSingle) self.scanButtonGroup.addButton(self.scanCentered) self.qscanButtonGroup = QButtonGroup() self.qscanButtonGroup.addButton(self.qscanSingle) self.qscanButtonGroup.addButton(self.qscanCentered) self.qscanButtonGroup.addButton(self.qscanRandom) self.qscanButtonGroup.addButton(self.qscanLong) self.qscanButtonGroup.addButton(self.qscanTrans) self.presetButtonGroup = QButtonGroup() self.presetButtonGroup.addButton(self.presetTime) self.presetButtonGroup.addButton(self.presetMonitor) self.scanButtonGroup.buttonClicked.connect(self.updateCommand) self.qscanButtonGroup.buttonClicked.connect(self.updateCommand) self.presetButtonGroup.buttonClicked.connect(self.updateCommand) self.stepsInput.valueChanged.connect(self.updateCommand) self.timeInput.valueChanged.connect(self.updateCommand) self.monitorInput.valueChanged.connect(self.updateCommand) self.deviceList.itemSelectionChanged.connect(self.updateCommand) self.scanPreset.textChanged.connect(self.updateCommand) self.scanNumsteps.textChanged.connect(self.updateCommand) self.scanStep.textChanged.connect(self.updateCommand) self.scanStart.textChanged.connect(self.updateCommand) self.deviceName.textChanged.connect(self.updateCommand) self.scanRange.textChanged.connect(self.updateCommand) self.hInput.textChanged.connect(self.updateCommand) self.kInput.textChanged.connect(self.updateCommand) self.lInput.textChanged.connect(self.updateCommand) self.EInput.textChanged.connect(self.updateCommand) self.deltahInput.textChanged.connect(self.updateCommand) self.deltakInput.textChanged.connect(self.updateCommand) self.deltalInput.textChanged.connect(self.updateCommand) self.deltaEInput.textChanged.connect(self.updateCommand) self.deltaqInput.textChanged.connect(self.updateCommand) self.generateBtn.clicked.connect(self.createCommand) self.clearAllBtn.clicked.connect(self.clearAll) self.quitBtn.clicked.connect(self.close) self.scanCalc.clicked.connect(self.calc_scan) self.qscanCalc.clicked.connect(self.calc_qscan) self.qscanSingle.clicked.connect(self.set_qlabels) self.qscanCentered.clicked.connect(self.set_qlabels) self.qscanLong.clicked.connect(self.set_qlabels) self.qscanTrans.clicked.connect(self.set_qlabels) self.qscanRandom.clicked.connect(self.set_qlabels) self._devices = sorted( parent.client.eval( '[(dev.name, dev.unit) ' 'for (name, dev) in session.devices.items() ' 'if name in session.explicit_devices and hasattr(dev, "maw")]', [])) self.tabWidget.setTabEnabled(0, self._devices != []) for name, unit in self._devices: self.deviceList.addItem("%s [%s]" % (name, unit)) dval = DoubleValidator(self) ival = QIntValidator(self) # qscan tab self.hInput.setValidator(dval) self.kInput.setValidator(dval) self.lInput.setValidator(dval) self.EInput.setValidator(dval) self.deltahInput.setValidator(dval) self.deltakInput.setValidator(dval) self.deltalInput.setValidator(dval) self.deltaEInput.setValidator(dval) self.deltaqInput.setValidator(dval) # disabled for now self.qscanRandom.setVisible(False) self.qscanTrans.setVisible(False) self.qscanLong.setVisible(False) # scan/cscan tab self.scanStart.setValidator(dval) self.scanStep.setValidator(dval) self.scanNumsteps.setValidator(ival) self.scanPreset.setValidator(dval) self.scanMovetime.setValidator(dval) self.presets = DlgPresets( 'scaninput', [ # qscan tab (self.qscanSingle, 1), (self.qscanCentered, 0), (self.qscanLong, 0), (self.qscanTrans, 0), (self.qscanRandom, 0), (self.monitorInput, 10000), (self.timeInput, 120), (self.presetTime, 1), (self.presetMonitor, 0), (self.hInput, '0.0'), (self.kInput, '0.0'), (self.lInput, '0.0'), (self.EInput, '0.0'), (self.deltahInput, '0.0'), (self.deltakInput, '0.0'), (self.deltalInput, '0.0'), (self.deltaEInput, '0.0'), (self.deltaqInput, '0.0'), (self.stepsInput, 10), # scan tab (self.scanSingle, 1), (self.scanCentered, 0), (self.scanStart, '0.0'), (self.scanStep, '0.0'), (self.scanNumsteps, '0'), (self.scanPreset, '0.0'), (self.deviceList, 'om [deg]'), (self.deviceName, ''), (self.scanMovetime, '0'), # the tab itself (self.tabWidget, 0), ]) self.presets.load() self.set_qlabels()