def set_setpoints_buttons(self): self.setpoints_sb = [] self.currpoints_sb = [] for ind_set in range(self.model_class.Nsetpoints): self.setpoints_sb.append(SpinBox()) self.setpoints_sb[-1].setMinimumHeight(40) font = self.setpoints_sb[-1].font() font.setPointSizeF(20) self.setpoints_sb[-1].setFont(font) self.setpoints_sb[-1].setDecimals(6) self.toolbar_layout.addWidget(self.setpoints_sb[-1], 3, 2+ind_set, 1, 1) self.setpoints_sb[-1].valueChanged.connect(self.update_runner_setpoints) self.currpoints_sb.append(SpinBox()) self.currpoints_sb[-1].setMinimumHeight(40) self.currpoints_sb[-1].setReadOnly(True) self.currpoints_sb[-1].setDecimals(6) self.currpoints_sb[-1].setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons) font = self.currpoints_sb[-1].font() font.setPointSizeF(20) self.currpoints_sb[-1].setFont(font) self.toolbar_layout.addWidget(self.currpoints_sb[-1], 4, 2+ind_set, 1, 1) self.setpoints_signal.connect(self.setpoints_external)
def initUI(self, *args, **kwargs): """ Init the User Interface. """ self.vlayout = QtWidgets.QVBoxLayout() self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal) self.slider.setMinimumWidth(50) self.slider.setMinimum(0) self.slider.setMaximum(100) if 'value' in kwargs: value = kwargs.pop('value') else: if 'bounds' in kwargs: value = kwargs['bounds'][0] else: value = 1 self.spinbox = SpinBox(parent=None, value=value, **kwargs) self.vlayout.addWidget(self.slider) self.vlayout.addWidget(self.spinbox) self.vlayout.setSpacing(0) self.vlayout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.vlayout) self.slider.valueChanged.connect(self.update_spinbox) self.spinbox.valueChanged.connect(self.update_slide)
class WideSpanVNAWidget(VNAWidget): def __init__(self): super(WideSpanVNAWidget, self).__init__() self.start_spin = SpinBox(value=3e9) self.form_layout.addRow("Start Frequency", self.start_spin) self.stop_spin = SpinBox(value=9e9) self.form_layout.addRow("Stop Frequency", self.stop_spin) self.step_spin = SpinBox(value=1e6) self.form_layout.addRow("Delta Frequency", self.step_spin) self.progress_bar = QProgressBar() self.form_layout.addRow(self.progress_bar) def grab_trace(self): vna = self.get_vna() n_points_per_trace = vna.get_points() start = self.start_spin.value() stop = self.stop_spin.value() step = self.step_spin.value() span = stop - start n_traces = int(ceil(span / (step * n_points_per_trace))) trace_size = span / n_traces trace_starts = [start + i * trace_size for i in range(n_traces)] trace_ends = [start + (i + 1) * trace_size for i in range(n_traces)] self.freqs = [] self.mags = [] for i, (start_f, stop_f) in enumerate(zip(trace_starts, trace_ends)): self.progress_bar.setValue(int((100.0 * (1 + i)) / n_traces)) vna.set_start_freq(start_f) vna.set_stop_freq(stop_f) self.freqs.extend(vna.do_get_xaxis()) m, _ = vna.do_get_data(opc=True) self.mags.extend(m) self.replot() QApplication.instance().processEvents() self.progress_bar.setValue(0)
class MTFTickMenu(QtGui.QMenu): def __init__(self, tick, sliderItem): QtGui.QMenu.__init__(self) self.tick = weakref.ref(tick) self.sliderItem = weakref.ref(sliderItem) self.removeAct = self.addAction( "Remove Tick", lambda: self.sliderItem().removeTick(tick)) if (not self.tick().removeAllowed) or len(self.sliderItem().ticks) < 3: self.removeAct.setEnabled(False) positionMenu = self.addMenu("Set Position") w = QtGui.QWidget() l = QtGui.QGridLayout() w.setLayout(l) value = sliderItem.tickValue(tick) self.fracPosSpin = SpinBox() self.fracPosSpin.setOpts(value=value, bounds=(0.0, 1.0), step=0.01, decimals=2) #self.dataPosSpin = SpinBox(value=dataVal) #self.dataPosSpin.setOpts(decimals=3, siPrefix=True) l.addWidget(QtGui.QLabel("Position:"), 0, 0) l.addWidget(self.fracPosSpin, 0, 1) #l.addWidget(QtGui.QLabel("Position (data units):"), 1, 0) #l.addWidget(self.dataPosSpin, 1,1) #if self.sliderItem().dataParent is None: # self.dataPosSpin.setEnabled(False) a = QtGui.QWidgetAction(self) a.setDefaultWidget(w) positionMenu.addAction(a) self.fracPosSpin.sigValueChanging.connect(self.fractionalValueChanged) #self.dataPosSpin.valueChanged.connect(self.dataValueChanged) colorAct = self.addAction( "Set Color", lambda: self.sliderItem().raiseColorDialog(self.tick())) if not self.tick().colorChangeAllowed: colorAct.setEnabled(False) def fractionalValueChanged(self, x): self.sliderItem().setTickValue(self.tick(), self.fracPosSpin.value())
def makeWidget(self): """Copy of SpinBox from PyQtGraph 0.9.10 & later, which adds special parameters we hack on""" opts = self.param.opts defs = { 'value': 0, 'min': None, 'max': None, 'int': True, 'step': 1.0, 'minStep': 1.0, 'dec': False, 'siPrefix': False, 'suffix': '' } defs.update(opts) if 'limits' in opts: defs['bounds'] = opts['limits'] w = SpinBox() # This hack ensures compatibility between 0.9.10 and later for k in opts: w.opts[k] = opts[k] w.setOpts(**defs) w.sigChanged = w.sigValueChanged w.sigChanging = w.sigValueChanging return w
def makeLayout(self): self.sigs = SigStuff() opts = self.param.opts defs = { 'value': 0, 'min': None, 'max': None, 'int': True, 'step': 1.0, 'minStep': 1.0, 'dec': False, 'fixedsize':0, 'siPrefix': False, 'suffix': '' } defs.update(opts) if 'limits' in opts: defs['bounds'] = opts['limits'] wlow = SpinBox() wlow.setOpts(**defs) whigh = SpinBox() whigh.setOpts(**defs) whigh.sigValueChanged.connect(self.svChangedEmit) whigh.sigValueChanging.connect(self.svHighChanging) wlow.sigValueChanged.connect(self.svChangedEmit) wlow.sigValueChanging.connect(self.svLowChanging) l = QtGui.QHBoxLayout() l.setContentsMargins(0,0,0,0) l.addWidget(wlow) l.addWidget(QtGui.QLabel(" : ")) l.addWidget(whigh) self.wlow = wlow self.whigh = whigh return l
def __init__(self): super(WideSpanVNAWidget, self).__init__() self.start_spin = SpinBox(value=3e9) self.form_layout.addRow("Start Frequency", self.start_spin) self.stop_spin = SpinBox(value=9e9) self.form_layout.addRow("Stop Frequency", self.stop_spin) self.step_spin = SpinBox(value=1e6) self.form_layout.addRow("Delta Frequency", self.step_spin) self.progress_bar = QProgressBar() self.form_layout.addRow(self.progress_bar)
def makeLayout(self): self.sigs = SigStuff() opts = self.param.opts defs = { 'value': 0, 'min': None, 'max': None, 'int': True, 'step': 1.0, 'minStep': 1.0, 'dec': False, 'fixedsize': 0, 'siPrefix': False, 'suffix': '' } defs.update(opts) if 'limits' in opts: defs['bounds'] = opts['limits'] wlow = SpinBox() wlow.setOpts(**defs) whigh = SpinBox() whigh.setOpts(**defs) whigh.sigValueChanged.connect(self.svChangedEmit) whigh.sigValueChanging.connect(self.svHighChanging) wlow.sigValueChanged.connect(self.svChangedEmit) wlow.sigValueChanging.connect(self.svLowChanging) l = QtGui.QHBoxLayout() l.setContentsMargins(0, 0, 0, 0) l.addWidget(wlow) l.addWidget(QtGui.QLabel(" : ")) l.addWidget(whigh) self.wlow = wlow self.whigh = whigh return l
def makeWidget(self): """ Return a single widget that should be placed in the second tree column. The widget must be given three attributes: ========== ============================================================ sigChanged a signal that is emitted when the widget's value is changed value a function that returns the value setValue a function that sets the value ========== ============================================================ This is a good function to override in subclasses. """ opts = self.param.opts t = opts['type'] if t == 'int': defs = { 'value': 0, 'min': None, 'max': None, 'int': True, 'step': 1.0, 'minStep': 1.0, 'dec': False, 'siPrefix': False, 'suffix': '' } defs.update(opts) if 'limits' in opts: defs['bounds'] = opts['limits'] w = SpinBox() w.setOpts(**defs) w.sigChanged = w.sigValueChanged w.sigChanging = w.sigValueChanging elif t == 'float': defs = { 'value': 0, 'min': None, 'max': None, 'step': 1.0, 'dec': False, 'siPrefix': False, 'suffix': '' } defs.update(opts) if 'limits' in opts: defs['bounds'] = opts['limits'] w = SpinBox() w.setOpts(**defs) w.sigChanged = w.sigValueChanged w.sigChanging = w.sigValueChanging elif t == 'bool': w = QtGui.QCheckBox() w.sigChanged = w.toggled w.value = w.isChecked w.setValue = w.setChecked self.hideWidget = False elif t == 'str': w = QtGui.QLineEdit() w.sigChanged = w.editingFinished w.value = lambda: asUnicode(w.text()) w.setValue = lambda v: w.setText(asUnicode(v)) w.sigChanging = w.textChanged elif t == 'color': w = ColorButton() w.sigChanged = w.sigColorChanged w.sigChanging = w.sigColorChanging w.value = w.color w.setValue = w.setColor self.hideWidget = False w.setFlat(True) elif t == 'colormap': from pyqtgraph.widgets.GradientWidget import GradientWidget ## need this here to avoid import loop w = GradientWidget(orientation='bottom') w.sigChanged = w.sigGradientChangeFinished w.sigChanging = w.sigGradientChanged w.value = w.colorMap w.setValue = w.setColorMap self.hideWidget = False else: raise Exception("Unknown type '%s'" % asUnicode(t)) return w
def generateUi(opts): """Convenience function for generating common UI types""" widget = QtGui.QWidget() l = QtGui.QFormLayout() l.setSpacing(0) widget.setLayout(l) ctrls = {} row = 0 for opt in opts: if len(opt) == 2: k, t = opt o = {} elif len(opt) == 3: k, t, o = opt else: raise Exception("Widget specification must be (name, type) or (name, type, {opts})") if t == 'intSpin': w = QtGui.QSpinBox() if 'max' in o: w.setMaximum(o['max']) if 'min' in o: w.setMinimum(o['min']) if 'value' in o: w.setValue(o['value']) elif t == 'doubleSpin': w = QtGui.QDoubleSpinBox() if 'max' in o: w.setMaximum(o['max']) if 'min' in o: w.setMinimum(o['min']) if 'value' in o: w.setValue(o['value']) elif t == 'spin': w = SpinBox() w.setOpts(**o) elif t == 'check': w = QtGui.QCheckBox() if 'checked' in o: w.setChecked(o['checked']) elif t == 'combo': w = QtGui.QComboBox() for i in o['values']: w.addItem(i) #elif t == 'colormap': #w = ColorMapper() elif t == 'color': w = ColorButton() else: raise Exception("Unknown widget type '%s'" % str(t)) if 'tip' in o: w.setToolTip(o['tip']) w.setObjectName(k) l.addRow(k, w) if o.get('hidden', False): w.hide() label = l.labelForField(w) label.hide() ctrls[k] = w w.rowNum = row row += 1 group = WidgetGroup(widget) return widget, group, ctrls
class SliderSpinBox(QtWidgets.QWidget): def __init__(self, *args, subtype='lin', **kwargs): super().__init__() self.subtype = subtype self.initUI(*args, **kwargs) self.valueChanged = self.spinbox.valueChanged # (value) for compatibility with QSpinBox self.sigValueChanged = self.spinbox.sigValueChanged # (self) self.sigValueChanging = self.spinbox.sigValueChanging # (self, value) sent immediately; no delay. self.sigChanged = self.spinbox.sigValueChanged @property def opts(self): return self.spinbox.opts @opts.setter def opts(self, **opts): self.setOpts(**opts) def setOpts(self, **opts): self.spinbox.setOpts(**opts) if 'visible' in opts: self.slider.setVisible(opts['visible']) def insert_widget(self, widget, row=0): self.vlayout.insertWidget(row, widget) def initUI(self, *args, **kwargs): """ Init the User Interface. """ self.vlayout = QtWidgets.QVBoxLayout() self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal) self.slider.setMinimumWidth(50) self.slider.setMinimum(0) self.slider.setMaximum(100) if 'value' in kwargs: value = kwargs.pop('value') else: if 'bounds' in kwargs: value = kwargs['bounds'][0] else: value = 1 self.spinbox = SpinBox(parent=None, value=value, **kwargs) self.vlayout.addWidget(self.slider) self.vlayout.addWidget(self.spinbox) self.vlayout.setSpacing(0) self.vlayout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.vlayout) self.slider.valueChanged.connect(self.update_spinbox) self.spinbox.valueChanged.connect(self.update_slide) def update_spinbox(self, val): """ val is a percentage [0-100] used in order to set the spinbox value between its min and max """ min_val = float(self.opts['bounds'][0]) max_val = float(self.opts['bounds'][1]) if self.subtype == 'log': val_out = scroll_log(val, min_val, max_val) else: val_out = scroll_linear(val, min_val, max_val) try: self.slider.valueChanged.disconnect(self.update_spinbox) self.spinbox.valueChanged.disconnect(self.update_slide) except Exception: pass self.spinbox.setValue(val_out) self.slider.valueChanged.connect(self.update_spinbox) self.spinbox.valueChanged.connect(self.update_slide) def update_slide(self, val): """ val is the spinbox value between its min and max """ min_val = float(self.opts['bounds'][0]) max_val = float(self.opts['bounds'][1]) try: self.slider.valueChanged.disconnect(self.update_spinbox) self.spinbox.valueChanged.disconnect(self.update_slide) except Exception: pass if self.subtype == 'linear': value = int((val - min_val) / (max_val - min_val) * 100) else: value = int((np.log10(val) - np.log10(min_val)) / (np.log10(max_val) - np.log10(min_val)) * 100) self.slider.setValue(value) self.slider.valueChanged.connect(self.update_spinbox) self.spinbox.valueChanged.connect(self.update_slide) def setValue(self, val): self.spinbox.setValue(val) def value(self): return self.spinbox.value()
def generateUi(opts): """Convenience function for generating common UI types""" if len(opts) == 0: return None, None, None, None widget = QtGui.QWidget() layout = QtGui.QFormLayout() # layout.setSpacing(0) widget.setLayout(layout) ctrls = {} row = 0 widgetgroup = WidgetGroup() groupboxes = {} default_values = {} focused = False for opt in opts: if len(opt) == 2: k, t = opt o = {} elif len(opt) == 3: k, t, o = opt else: raise Exception( "Widget specification must be (name, type) or (name, type, {opts})" ) hidden = o.pop('hidden', False) tip = o.pop('tip', None) val = o.get('value', None) parent = None if 'group' in o: name = o['group'] if name not in groupboxes: groupbox = QtWidgets.QGroupBox(parent=widget) groupbox_layout = QtGui.QFormLayout() groupbox.setLayout(groupbox_layout) groupboxes[name] = (groupbox, groupbox_layout) groupbox.setTitle(name) layout.addWidget(groupbox) ctrls[name] = {'groupbox': groupbox} default_values[name] = {} groupbox, groupbox_layout = groupboxes[name] parent = groupbox else: parent = widget if t == 'intSpin': w = QtGui.QSpinBox(parent=parent) if 'max' in o: w.setMaximum(o['max']) else: w.setMaximum(MAX) if 'min' in o: w.setMinimum(o['min']) else: w.setMinimum(-MAX) if 'value' in o: w.setValue(o['value']) else: val = 0 elif t == 'doubleSpin': w = ScientificDoubleSpinBox(parent=parent) if 'max' in o: w.setMaximum(o['max']) if 'min' in o: w.setMinimum(o['min']) if 'value' in o: w.setValue(o['value']) else: val = 0.0 elif t == 'spin': w = SpinBox(parent=widget) w.setOpts(**o) elif t == 'check': w = QtGui.QCheckBox(parent=parent) w.setFocus() if 'checked' in o: val = o['checked'] w.setChecked(o['checked']) else: val = False elif t == 'combo': w = QtGui.QComboBox(parent=parent) for i in o['values']: w.addItem(str(i), i) if 'value' in o: w.setCurrentText(o['value']) elif t == 'color': w = ColorButton(parent=parent) if 'value' in o: w.setColor(o['value']) elif t == 'text': w = QtGui.QLineEdit(parent=parent) if 'placeholder' in o: w.setPlaceholderText(o['placeholder']) if 'value' in o: w.setText(o['value']) else: raise Exception("Unknown widget type '%s'" % str(t)) if tip is not None: w.setToolTip(tip) w.setObjectName(k) if t != 'text' and not focused: w.setFocus() focused = True if 'group' in o: name = o['group'] groupbox, groupbox_layout = groupboxes[name] groupbox_layout.addRow(k, w) ctrls[name][k] = w widgetgroup.addWidget(w, name=k, group=name) default_values[name][k] = val else: layout.addRow(k, w) if hidden: w.hide() label = layout.labelForField(w) label.hide() w.rowNum = row ctrls[k] = w default_values[k] = val widgetgroup.addWidget(w, k) row += 1 return widget, widgetgroup, ctrls, default_values
def setupUI(self): customLayout = QtWidgets.QVBoxLayout(self) customLayout.addWidget( QtWidgets.QLabel('type: {}, name: {}'.format(self.type, self.name))) buttons = QtWidgets.QWidget() buttonsly = QtWidgets.QGridLayout(buttons) self.initButton = QtWidgets.QPushButton('interface') self.initButton.setToolTip('launch interactive interface') self.initButton.clicked.connect(lambda: self.customInit()) buttonsly.addWidget(self.initButton) self.startupButton = QtWidgets.QPushButton('startup') self.startupButton.setEnabled(False) self.startupButton.clicked.connect(lambda: self.customStartup()) self.startupButton.setToolTip( 'reset the device, which can solve most problems') buttonsly.addWidget(self.startupButton) self.restoreButton = QtWidgets.QPushButton('restore') self.restoreButton.setToolTip('restore to initial position') self.restoreButton.setEnabled(False) self.restoreButton.clicked.connect(lambda: self.customRestore()) buttonsly.addWidget(self.restoreButton) self.moveButton = QtWidgets.QPushButton('move') self.moveButton.setEnabled(False) self.moveButton.clicked.connect(lambda: self.customMove()) buttonsly.addWidget(self.moveButton) customLayout.addWidget(buttons) self.axesSpinBox = [] self.singleMoveButton = [] for i in range(self._info['numaxes']): customLayout.addWidget(QtWidgets.QLabel('Axis {}:'.format(str(i)))) single = QtWidgets.QWidget() singlely = QtWidgets.QHBoxLayout(single) axis = SpinBox(step=1, decimals=15) axis.setEnabled(False) axis.valueChanged.connect(lambda v, n=i: self.posChanged(v, n)) self.axesSpinBox.append(axis) singlely.addWidget(axis) button = QtWidgets.QPushButton('move') button.setEnabled(False) button.clicked.connect(lambda x, y=i: self.customSingleMove(y)) singlely.addWidget(button) customLayout.addWidget(single) self.singleMoveButton.append(button) customLayout.addWidget(QtWidgets.QLabel('Range:')) self.rangeInfoLine = QtWidgets.QLineEdit() self.rangeInfoLine.setEnabled(False) self.rangeInfoLine.setText(str(self._info['range'])) customLayout.addWidget(self.rangeInfoLine) customLayout.addWidget(QtWidgets.QLabel('Start Point:')) self.startPositionInfoLine = QtWidgets.QLineEdit() self.startPositionInfoLine.setEnabled(False) self.startPositionInfoLine.setText(str(self._info['startPosition'])) customLayout.addWidget(self.startPositionInfoLine) customLayout.addWidget(QtWidgets.QLabel('Position:')) self.positionInfoLine = QtWidgets.QLineEdit() self.positionInfoLine.setEnabled(False) self.positionInfoLine.setText(str(self._info['position'])) customLayout.addWidget(self.positionInfoLine) customLayout.addWidget(QtWidgets.QLabel('Deviation:')) self.deviationInfoLine = QtWidgets.QLineEdit() self.deviationInfoLine.setEnabled(False) self.deviationInfoLine.setText(str(self._info['deviation'])) customLayout.addWidget(self.deviationInfoLine)
def __init__(self, **opts): SpinBox.__init__(self, **opts)