示例#1
0
    def __init__(self, start_frame, end_frame):
        '''Instantiate start and end frame field.'''
        super(StartEndFrameField, self).__init__()
        self.setLayout(QtWidgets.QHBoxLayout())
        self.layout().setContentsMargins(0, 0, 0, 0)

        self.start_frame = QtWidgets.QDoubleSpinBox()
        self.start_frame.setValue(start_frame)
        self.start_frame.setMaximum(sys.maxint)
        self.start_frame.setDecimals(0)
        self.start_frame.valueChanged.connect(self.notify_changed)

        self.end_frame = QtWidgets.QDoubleSpinBox()
        self.end_frame.setValue(end_frame)
        self.end_frame.setMaximum(sys.maxint)
        self.end_frame.setDecimals(0)
        self.end_frame.valueChanged.connect(self.notify_changed)

        self.layout().addWidget(QtWidgets.QLabel('Frame Range'))
        self.layout().addWidget(self.start_frame)
        self.layout().addWidget(self.end_frame)
示例#2
0
    def __init__(self, data_dict, options):
        '''Instanstiate settings from *options*.'''
        super(ActionSettingsWidget, self).__init__()

        self.setLayout(QtWidgets.QFormLayout())
        self.layout().setContentsMargins(0, 0, 0, 0)

        for option in options:
            type_ = option['type']
            label = option.get('label', '')
            name = option['name']
            value = option.get('value')
            empty_text = option.get('empty_text')
            if name in data_dict.get('options', {}):
                value = data_dict['options'][name]

            if value is not None and name not in data_dict:
                # Set default value from options.
                data_dict[name] = value

            field = None

            if type_ == 'group':
                nested_dict = data_dict[name] = dict()
                settings_widget = QtWidgets.QGroupBox(label)
                settings_widget.setLayout(QtWidgets.QVBoxLayout())
                settings_widget.layout().addWidget(
                    ActionSettingsWidget(nested_dict,
                                         option.get('options', [])))
                self.layout().addRow(settings_widget)

            if type_ == 'boolean':
                field = QtWidgets.QCheckBox()
                if value is True:
                    field.setCheckState(QtCore.Qt.Checked)

                field.stateChanged.connect(
                    functools.partial(
                        self.update_on_change, data_dict, field, name,
                        lambda check_box: (check_box.checkState() == QtCore.Qt.
                                           CheckState.Checked)))

            if type_ == 'textarea':
                field = textarea.TextAreaField(empty_text or '')
                if value is not None:
                    field.setPlainText(unicode(value))

                field.value_changed.connect(
                    functools.partial(
                        self.update_on_change, data_dict, field, name,
                        lambda textarea_widget: textarea_widget.value()))

            if type_ == 'text':
                field = QtWidgets.QLineEdit()
                if value is not None:
                    field.insert(unicode(value))

                field.textChanged.connect(
                    functools.partial(self.update_on_change, data_dict, field,
                                      name,
                                      lambda line_edit: line_edit.text()))

            if type_ == 'number':
                field = QtWidgets.QDoubleSpinBox()
                if value is not None:
                    field.setValue(float(value))

                field.setMaximum(sys.maxint)
                field.setMinimum(-sys.maxint)

                field.valueChanged.connect(
                    functools.partial(self.update_on_change, data_dict, field,
                                      name, lambda spin_box: spin_box.value()))

            if type_ == 'enumerator':
                field = QtWidgets.QComboBox()
                for item in option['data']:
                    field.addItem(item['label'])

                field.currentIndexChanged.connect(
                    functools.partial(
                        self.update_on_change, data_dict, field, name,
                        lambda box:
                        (option['data'][box.currentIndex()]['value'])))

            if type_ == 'qt_widget':
                field = option['widget']
                field.value_changed.connect(
                    functools.partial(
                        self.update_on_change, data_dict, field, name,
                        lambda custom_field: (custom_field.value())))

            if field is not None:
                if label:
                    label_widget = QtWidgets.QLabel(label)
                    self.layout().addRow(label_widget, field)
                else:
                    self.layout().addRow(field)
示例#3
0
    def parseOptions(self, rowLayout, optionElements, assetTypeName, enabled):
        '''Parse options.'''
        optionsCount = 0
        for k in range(optionElements.length()):
            optionElement = optionElements.item(k).toElement()
            optionType = optionElement.attribute('type')
            optionValue = optionElement.attribute('value')
            if optionValue == 'True':
                optionValue = True
            elif optionValue == 'False':
                optionValue = False
            optionName = optionElement.attribute('name')
            self.stackedOptions[assetTypeName].append(optionName)

            if optionType == 'float':
                floatBox = QtWidgets.QDoubleSpinBox()
                floatBox.setEnabled(enabled)
                floatBox.setObjectName(optionName)
                floatBox.setSingleStep(0.1)
                floatBox.setMaximum(sys.maxint)
                floatBox.setMinimum(-sys.maxint)
                floatBox.setValue(float(optionValue))
                rowLayout.addWidget(floatBox)
                optionsCount = 1

            if optionType == 'checkbox':
                checkBox = QtWidgets.QCheckBox()
                checkBox.setEnabled(enabled)
                checkBox.setChecked(bool(optionValue))
                checkBox.setObjectName(optionName)
                rowLayout.addWidget(checkBox)
                optionsCount = 1

            if optionType == 'string':
                textBox = QtWidgets.QLineEdit()
                textBox.setEnabled(enabled)
                textBox.setText(optionValue)
                textBox.setObjectName(optionName)
                rowLayout.addWidget(textBox)
                optionsCount = 1

            if optionType == 'combo':
                comboBox = QtWidgets.QComboBox()
                comboBox.setEnabled(enabled)
                optionitemElements = optionElement.elementsByTagName(
                    'optionitem')
                for t in range(optionitemElements.length()):
                    optionitemElement = optionitemElements.item(t).toElement()
                    optionitemValue = optionitemElement.attribute('name')
                    comboBox.addItem(optionitemValue)

                comboBox.setObjectName(optionName)
                rowLayout.addWidget(comboBox)
                optionsCount = optionitemElements.length()

            if optionType == 'radio':
                radioWidget = QtWidgets.QWidget()
                radioLayout = QtWidgets.QVBoxLayout()
                radioLayout.setSpacing(1)
                radioWidget.setLayout(radioLayout)
                optionitemElements = optionElement.elementsByTagName(
                    'optionitem')
                for t in range(optionitemElements.length()):
                    optionitemElement = optionitemElements.item(t).toElement()
                    optionitemValue = optionitemElement.attribute('value')
                    optionitemName = optionitemElement.attribute('name')
                    radioButton = QtWidgets.QRadioButton(optionitemName)
                    if bool(optionitemValue):
                        radioButton.setChecked(True)
                    radioLayout.addWidget(radioButton)
                    radioButton.setEnabled(enabled)

                    radioButton.setObjectName(optionName)
                rowLayout.addWidget(radioWidget)
                optionsCount = optionitemElements.length()
        return optionsCount