def __call__(self, label, options, store): '''Return a qt widget from *item*.''' tooltip = None if label is not None: settings_widget = QtWidgets.QGroupBox(label) else: settings_widget = QtWidgets.QWidget() settings_widget.setLayout(QtWidgets.QVBoxLayout()) if tooltip: settings_widget.setToolTip(tooltip) if isinstance(options, QtWidgets.QWidget): settings_widget.layout().addWidget(options) else: settings_widget.layout().addWidget( ActionSettingsWidget(store, options)) return settings_widget
def __init__(self, parent=None, session=None, context=None): super(BuildAssetTrackDialog, self).__init__(parent) self.setWindowTitle("Build Track") if not session: session = FnAssetAPI.SessionManager.currentSession() self.__session = session if not context: context = session.createContext() self.__context = context self.__selection = [] self.__entities = [] self.__ignoreClips = False self.__lastIgnoreClips = None self.__lastParentRef = None layout = QtWidgets.QVBoxLayout() self.setLayout(layout) # Asset Manager Widget self.__relationshipWidget = session.getManagerWidget( kWorkflowRelationshipWidgetId, args=[context,]) layout.addWidget(self.__relationshipWidget) # Stretch layout.addStretch() # Options optionsBox = QtWidgets.QGroupBox("Options") optionsLayout = QtWidgets.QVBoxLayout() optionsBox.setLayout(optionsLayout) layout.addWidget(optionsBox) self.__trackName = QtWidgets.QLineEdit() trackNameLayout = QtWidgets.QHBoxLayout() trackNameLayout.addWidget(QtWidgets.QLabel("Track Name")) trackNameLayout.addWidget(self.__trackName) optionsLayout.addLayout(trackNameLayout) self.__useClipsRadio = QtWidgets.QRadioButton("Match by Clip") self.__useShotsRadio = QtWidgets.QRadioButton("Match by Shot") optionsLayout.addWidget(self.__useClipsRadio) optionsLayout.addWidget(self.__useShotsRadio) ## @todo Use the project entityReferences Parent if we have one? context.access = context.kReadMultiple context.retention = context.kTransient specification = specifications.ShotSpecification() self.__shotParentPicker = self.__session.getManagerWidget( FnAssetAPI.ui.constants.kInlinePickerWidgetId, args=[specification, context]) optionsLayout.addWidget(self.__shotParentPicker) # Buttons ## @todo disable the ok button if using shots and no valid entity ref self.__buttons = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel) self.__buttons.button(QtWidgets.QDialogButtonBox.Ok).setText('Build') layout.addWidget(self.__buttons) # Connections self.__buttons.accepted.connect(self.accept) self.__buttons.rejected.connect(self.reject) self.__useShotsRadio.toggled.connect(self.__modeChanged) self.__useClipsRadio.toggled.connect(self.__modeChanged) self.__relationshipWidget.criteriaChanged.connect(self.__syncUI) # This might be better on editingFinished, but there is only one text field # some of the time so loosing focus might not happen as required self.__trackName.textChanged.connect(self.__syncUI) self.__shotParentPicker.selectionChanged.connect(self.__parentChanged) self.__syncUI() # Make sure the name field is ready for editing as we can't create without self.__trackName.setFocus()
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)
def __init__(self, session, error_data, missing_assets_types, duplicated_components): '''Return a validator widget for the given *error_data* and *missing_assets_types*.''' super(FtrackSettingsValidator, self).__init__() self.setWindowTitle('Validation error') self._session = session self.logger = logging.getLogger(__name__ + '.' + self.__class__.__name__) ftrack_icon = QtGui.QIcon(':/ftrack/image/default/ftrackLogoLight') self.setWindowIcon(ftrack_icon) layout = QtWidgets.QVBoxLayout() self.setLayout(layout) box = QtWidgets.QGroupBox( 'An error occured in the current schema configuration.') self.layout().addWidget(box) box_layout = QtWidgets.QVBoxLayout() box.setLayout(box_layout) form_layout = TaskUIFormLayout() box_layout.addLayout(form_layout) if duplicated_components: form_layout.addDivider( '{} Duplicated components name have been found'.format( len(duplicated_components))) for component_name, task in duplicated_components: ui_property = UIPropertyFactory.create( type(component_name), key='component_name', value=component_name, dictionary=task._preset.properties()['ftrack'], label='Component ' + ':', tooltip='Duplicated component name') ui_property.update(True) form_layout.addRow('Duplicated component' + ':', ui_property) if component_name != task.component_name(): component_index = duplicated_components.index( (task.component_name(), task)) duplicated_components.pop(component_index) for processor, values in error_data.items(): form_layout.addDivider('Wrong {0} presets'.format( processor.__class__.__name__)) for attribute, valid_values in values.items(): valid_values.insert(0, '- select a value -') key, value, label = attribute, valid_values, ' '.join( attribute.split('_')) tooltip = 'Set {0} value'.format(attribute) ui_property = UIPropertyFactory.create( type(value), key=key, value=value, dictionary=processor._preset.properties()['ftrack'], label=label + ':', tooltip=tooltip) form_layout.addRow(label + ':', ui_property) ui_property.update(True) if missing_assets_types: form_layout.addDivider('Missing asset types') for missing_asset in missing_assets_types: create_asset_button = QtWidgets.QPushButton( missing_asset.capitalize()) create_asset_button.clicked.connect(self.create_missing_asset) form_layout.addRow('Create asset: ', create_asset_button) buttons = QtWidgets.QDialogButtonBox() buttons.setOrientation(QtCore.Qt.Horizontal) buttons.addButton('Cancel', QtWidgets.QDialogButtonBox.RejectRole) buttons.addButton('Accept', QtWidgets.QDialogButtonBox.AcceptRole) buttons.accepted.connect(self.accept) buttons.rejected.connect(self.reject) self.layout().addWidget(buttons)