Beispiel #1
0
    def ajouter_parametre(self, parametre, panel, sizer):
        type_ = parametre.type
        psizer = QHBoxLayout()
        if type_ is not bool:
            psizer.addWidget(QLabel(parametre.texte + ' :'))

        if type_ is bool:
            widget = QCheckBox(parametre.texte, panel)
        elif type_ in (file, str):
            widget = QLineEdit(panel)
            widget.setMinimumWidth(200)
        elif isinstance(type_, tuple):
            widget = QSpinBox(panel)
            widget.setRange(*type_)
        elif isinstance(type_, list):
            widget = QComboBox(panel)
            widget.addItems(type_)
        else:
            print type_
            raise NotImplementedError
        self.widgets[parametre.nom] = widget
        widget.parametre = parametre
        self.set_value(widget, parametre.valeur)
        psizer.addWidget(widget)
        if type_ is file:
            parcourir = QPushButton(u'Parcourir', clicked=partial(self.parcourir, widget))
            psizer.addWidget(parcourir)
        return psizer
Beispiel #2
0
    def valToWidgetContainer(self, attr, val):
        """
        construct a widget container for the specified attribute
        """
        options = self.getRequiredOptionsListForAttribute(attr)
        # the default container type is the more general one
        if type(val) is bool:
            # create a new check box with checked state set to val

            widget = QCheckBox(self)
            widget.setText("")
            widget.setChecked(val)
            self.connect(widget, SIGNAL("stateChanged(int)"),
                         self.reactOnUserInput)
            if self.isErrorKey(attr):
                widget.setStyleSheet(self.ERRORSTYLE.format("QCheckBox"))
            valueCallable = widget.isChecked

        elif options is not None:
            # use a combobox to represent a list of options
            widget = OptionsComboBox(self)
            widget.addItems(options)
            if val is not None:
                widget.setCurrentIndex(options.index(str(val)))
            self.connect(widget, SIGNAL("currentIndexChanged(int)"),
                         self.reactOnUserInput)
            if self.isErrorKey(attr):
                widget.setStyleSheet(self.ERRORSTYLE.format("OptionsComboBox"))
            valueCallable = widget.currentText

        else:
            # use a simple line edit if options are undefined
            widget = QLineEdit(self)
            widget.setText(self.convertToText(val))
            self.connect(widget, SIGNAL("editingFinished()"),
                         self.reactOnUserInput)
            if self.isErrorKey(attr):
                widget.setStyleSheet(self.ERRORSTYLE.format("QLineEdit"))
            valueCallable = widget.text

        return EditableAttributeWidgetContainer(attr, widget, valueCallable)