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 = QtWidgets.QCheckBox()
            w.sigChanged = w.toggled
            w.value = w.isChecked
            w.setValue = w.setChecked
            w.setEnabled(not opts.get('readonly', False))
            self.hideWidget = False
        elif t == 'str':
            w = QtWidgets.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)
            w.setEnabled(not opts.get('readonly', False))
        elif t == 'colormap':
            # from pyqtgraph_karl.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 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 = QtWidgets.QCheckBox()
            w.sigChanged = w.toggled
            w.value = w.isChecked
            w.setValue = w.setChecked
            w.setEnabled(not opts.get('readonly', False))
            self.hideWidget = False
        elif t == 'str':
            w = QtWidgets.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)
            w.setEnabled(not opts.get('readonly', False))
        elif t == 'colormap':
            # from pyqtgraph_karl.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
Beispiel #3
0
    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)