Ejemplo n.º 1
0
 def createEditor(self, parent, option, index):
     '''
     Creates a editor in the TreeView depending on type of the settings data.
     '''
     item = self._itemFromIndex(index)
     if item.edit_type() == SettingsValueItem.EDIT_TYPE_AUTODETECT:
         if isinstance(item.value(), bool):
             box = QCheckBox(parent)
             box.setFocusPolicy(Qt.StrongFocus)
             box.setAutoFillBackground(True)
             box.stateChanged.connect(self.edit_finished)
             return box
         elif isinstance(item.value(), int):
             box = QSpinBox(parent)
             box.setValue(item.value())
             if not item.value_min() is None:
                 box.setMinimum(item.value_min())
             if not item.value_max() is None:
                 box.setMaximum(item.value_max())
             return box
     elif item.edit_type() == SettingsValueItem.EDIT_TYPE_FOLDER:
         editor = PathEditor(item.value(), parent)
         editor.editing_finished_signal.connect(self.edit_finished)
         return editor
     elif item.edit_type() == SettingsValueItem.EDIT_TYPE_LIST:
         box = QComboBox(parent)
         box.addItems(item.value_list())
         index = box.findText(item.value())
         if index >= 0:
             box.setCurrentIndex(index)
         box.setEditable(False)
         return box
     return QStyledItemDelegate.createEditor(self, parent, option, index)
    def _load_parameter(self,param_index,param_name, param_type,param_value, param_min, param_max, param_desc):
        x_check = 160
        x ,y ,w ,h = 4,4 + 40 * param_index,150,20
        label = QLabel(param_name,self.parameters)
        label.setGeometry(x,y,w,h)
        label.setToolTip(param_desc)
        label.show()
        if param_type == 'Boolean':
            checkbox = QCheckBox('',self.parameters)
            checkbox.setGeometry(x_check,y,w,h)
            checkbox.setChecked(param_value == '1')
            checkbox.setToolTip(param_desc)
            checkbox.stateChanged.connect(partial(self._handle_bool_param_changed,param_name))
            checkbox.show()
        elif param_type == 'Integer':
            if len(param_min) > 0 and len(param_max) > 0 and int(param_max) < 5:
                slider = QSlider(Qt.Horizontal,self.parameters)
                slider.setMinimum(int(param_min))
                slider.setMaximum(int(param_max))
                slider.setValue(int(param_value))
                slider.setTickPosition(QSlider.TicksBelow)
                slider.setGeometry(x_check,y,w,h)
                slider.setToolTip(param_desc)
                slider.setTickInterval(1)
                slider.setSingleStep(1)
                slider.setPageStep(1)
                slider.valueChanged.connect(partial(self._handle_param_changed,param_name))
                slider.show()
            else:
                spin = QSpinBox(self.parameters)
                if len(param_min) > 0:
                    spin.setMinimum(int(param_min))
                if len(param_max) > 0:
                    spin.setMaximum(int(param_max))
                spin.setValue(int(param_value))
                spin.setToolTip(param_desc)
                spin.setGeometry(x_check,y,w,h)
                spin.valueChanged.connect(partial(self._handle_param_changed,param_name))
                spin.show()
        elif param_type == 'Double':
            spin = QDoubleSpinBox(self.parameters)
            if len(param_min) > 0:
                spin.setMinimum(float(param_min))
            if len(param_max) > 0:
                spin.setMaximum(float(param_max))
            spin.setValue(float(param_value))
            spin.valueChanged.connect(partial(self._handle_param_changed,param_name))
            spin.setGeometry(x_check,y,w,h)
            spin.show()
        elif param_type == 'String':
            lineEdit = QLineEdit(self.parameters)
            lineEdit.setText(param_value)
            lineEdit.setToolTip(param_desc)
            lineEdit.setGeometry(x_check,y,w,h)
            lineEdit.textChanged.connect(partial(self._handle_param_changed,param_name))
            lineEdit.show()

        self.parameters.update()