Esempio n. 1
0
 def _setupStartButton(self):
     """Set up "Start/Stop" - button."""
     self.startStopBtn = QPushButton()
     self.startStopBtn.setCheckable(True)
     self.startStopBtn.clicked[bool].connect(self.onStartStopClick)
     btnLayout = QHBoxLayout()
     btnLayout.setContentsMargins(0, 0, 0, 0)
     self.startStopBtn.setSizePolicy(QSizePolicy.Maximum,
                                     QSizePolicy.Maximum)
     btnLayout.addWidget(self.startStopBtn)
     btnWidget = QWidget(self)
     btnWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
     btnWidget.setLayout(btnLayout)
     return btnWidget
Esempio n. 2
0
    def makeSetting(self, param, activeBtns=False):
        """Creates an input widget for the provided Parameter and configures
        it appropriately.
        """
        if param is None:
            return None
        widget = QWidget(self)
        layout = QHBoxLayout(widget)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addStretch()

        try:
            suffix = param.suffix()
        except AttributeError:
            suffix = None

        if suffix is None:
            layout.addWidget(self._makeLabel(param.displayName()))
        else:
            layout.addWidget(
                self._makeLabel(u"{} ({})".format(param.displayName(),
                                                  suffix)))

        widget.setLayout(layout)
        if isString(param.__doc__):
            # word wrapping by rich text: https://stackoverflow.com/a/4796057
            txt = "<span>{0}</span>".format(param.__doc__)
            # add description as tooltip if available for parameter
            widget.setToolTip(txt)

        # create scalar value input widget with min/max limits
        minmaxValue, widgets = None, []
        if isinstance(param, ParameterNumerical):
            minmaxValue = param.min(), param.max()
        if isinstance(param, ParameterFloat):
            minmaxValue = param.displayValueRange()
        decimals = None
        if hasattr(param, "decimals"):
            decimals = param.decimals()
        w = self._makeEntry(param.name(),
                            param.dtype,
                            param.displayValue(),
                            decimals=decimals,
                            minmax=minmaxValue,
                            parent=widget)
        try:  # set special value text for lower bound, simple solution
            special = param.displayValues(w.minimum())
            w.setSpecialValueText(special)
        except:
            pass
        w.setFixedWidth(FIXEDWIDTH)
        widgets.insert(old_div(len(widgets), 2), w)

        # Special widget settings for active fitting parameters:
        activeBtns = activeBtns and isinstance(param, FitParameterBase)
        if activeBtns:
            # create input boxes for user specified active fitting range
            # within default upper/lower from class definition
            # minmaxValue = type(param).min(), type(param).max()
            activeRange = {
                "min": param.displayActiveRange()[0],
                "max": param.displayActiveRange()[1]
            }
            for bound in "min", "max":
                w = self._makeEntry(param.name() + bound,
                                    param.dtype,
                                    activeRange[bound],
                                    decimals=decimals,
                                    minmax=minmaxValue,
                                    parent=widget)
                w.setPrefix(bound + ": ")
                w.setFixedWidth(FIXEDWIDTH)
                widgets.append(w)
            # create *active* buttons for FitParameters only
            w = self._makeEntry(param.name() + "active",
                                bool,
                                param.isActive(),
                                widgetType=QPushButton,
                                parent=widget)
            w.setText("Active")
            w.setFixedWidth(FIXEDWIDTH * .5)
            widgets.append(w)

        # add input widgets to the layout
        for w in widgets:
            layout.addWidget(w)
            # store the parameter name
            w.parameterName = param.name()
        # configure UI accordingly (hide/show widgets)
        # no backend update, ui was just built, data is still in sync
        self.updateParam(param, emitBackendUpdated=False)
        return widget