def build(self): '''Build widgets and layout.''' self.setLayout(QtWidgets.QHBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.thumbnailWidget = QtWidgets.QLabel() self.thumbnailWidget.setFrameStyle(QtWidgets.QFrame.StyledPanel) self.thumbnailWidget.setAlignment(QtCore.Qt.AlignCenter) self.thumbnailWidget.setFixedWidth(240) self.layout().addWidget(self.thumbnailWidget) self.propertyTableWidget = QtWidgets.QTableWidget() self.propertyTableWidget.setEditTriggers( QtWidgets.QAbstractItemView.NoEditTriggers) self.propertyTableWidget.setSelectionMode( QtWidgets.QAbstractItemView.NoSelection) self.propertyTableWidget.setRowCount(len(self.headers)) self.propertyTableWidget.setVerticalHeaderLabels(self.headers) self.propertyTableWidget.setColumnCount(1) horizontalHeader = self.propertyTableWidget.horizontalHeader() horizontalHeader.hide() horizontalHeader.setResizeMode(QtWidgets.QHeaderView.Stretch) verticalHeader = self.propertyTableWidget.verticalHeader() verticalHeader.setResizeMode(QtWidgets.QHeaderView.ResizeToContents) # Fix missing horizontal scrollbar when only single column self.propertyTableWidget.setHorizontalScrollMode( QtWidgets.QAbstractItemView.ScrollPerPixel) for index in range(len(self.headers)): self.propertyTableWidget.setItem(index, 0, QtWidgets.QTableWidgetItem('')) self.layout().addWidget(self.propertyTableWidget)
def create_validate_failed_overlay_widgets(self, label, failed_validators): '''Create overlay widgets to report validation failures.''' congrat_text = '<h2>Validation Failed!</h2>' success_text = 'Your <b>{0}</b> failed to validate.'.format(label) self.activeWidget = QtWidgets.QWidget() self.activeWidget.setLayout(QtWidgets.QVBoxLayout()) self.layout().addWidget(self.activeWidget) main_layout = self.activeWidget.layout() main_layout.addStretch(1) congrat_label = QtWidgets.QLabel(congrat_text) congrat_label.setAlignment(QtCore.Qt.AlignCenter) success_label = QtWidgets.QLabel(success_text) success_label.setAlignment(QtCore.Qt.AlignCenter) main_layout.addWidget(congrat_label) main_layout.addWidget(success_label) validators_table_container = QtWidgets.QWidget() table_layout = QtWidgets.QVBoxLayout() table_layout.setContentsMargins(15, 10, 15, 10) validators_table_container.setLayout(table_layout) validators_table = QtWidgets.QTableWidget() validators_table.setSelectionBehavior( QtWidgets.QAbstractItemView.SelectionBehavior.SelectRows) validators_table.setSelectionMode(QtWidgets.QTableWidget.NoSelection) validators_table.setColumnCount(2) validators_table.setHorizontalHeaderLabels(['Validation', 'Error']) validators_table.horizontalHeader().setResizeMode( 0, QtWidgets.QHeaderView.ResizeToContents) validators_table.horizontalHeader().setSectionResizeMode( QtWidgets.QHeaderView.Stretch) validators_table.horizontalHeader().setVisible(True) validators_table.setRowCount(len(failed_validators)) validators_table.verticalHeader().setVisible(False) icon = QtGui.QIcon(':ftrack/image/dark/remove') font = QtGui.QFont() font.setBold(True) for row, validator in enumerate(failed_validators): item = QtWidgets.QTableWidgetItem(icon, validator[0]) item.setFont(font) validators_table.setItem(row, 0, item) error_msg = validator[1] # Remove quotes from error message, if present. if ((error_msg[0] == error_msg[-1]) and error_msg.startswith( ("'", '"'))): error_msg = error_msg[1:-1] item = QtWidgets.QTableWidgetItem(error_msg) validators_table.setItem(row, 1, item) table_layout.addWidget(validators_table) main_layout.addWidget(validators_table_container) main_layout.addStretch(1) label = QtWidgets.QLabel('See details for more information.') label.setAlignment(QtCore.Qt.AlignCenter) main_layout.addWidget(label) buttons_layout = QtWidgets.QHBoxLayout() main_layout.addLayout(buttons_layout) self.details_button = QtWidgets.QPushButton('Details') buttons_layout.addWidget(self.details_button) self.details_button.clicked.connect(self.on_show_details) self.close_button = QtWidgets.QPushButton('Close') buttons_layout.addWidget(self.close_button) self.close_button.clicked.connect(self.close_window_callback) if self.details_window_callback is None: self.details_button.setDisabled(True)
def setAssetVersion(self, assetVersionId): '''Update list of components for asset version with *assetVersionId*.''' self.clear() query = ( 'select id, asset, asset.type, asset.type.short, components' ' from AssetVersion where id is "{0}"'.format(assetVersionId) ) asset_version = self.session.query(query).one() self.assetType = asset_version['asset']['type']['short'] asset_version_components = asset_version['components'] connectorName = self.connector.getConnectorName() # Temporary alias column = self.columns.index for component in asset_version_components: componentName = component['name'] if ( connectorName == 'nuke' and 'proxy' in componentName ): pass else: rowCount = self.rowCount() self.insertRow(rowCount) componentItem = QtWidgets.QTableWidgetItem(componentName) componentItem.setData(self.COMPONENT_ROLE, component['id']) self.setItem( rowCount, column('Component'), componentItem ) pathItem = QtWidgets.QTableWidgetItem('') self.setItem(rowCount, column('Path'), pathItem) availabilityItem = QtWidgets.QTableWidgetItem('') self.setItem( rowCount, column('Availability'), availabilityItem ) actionItem = QtWidgets.QPushButton() self.setCellWidget(rowCount, column('Action'), actionItem) actionItem.clicked.connect(self.actionSignalMapper.map) self.actionSignalMapper.setMapping(actionItem, rowCount) locationItem = QtWidgets.QComboBox() self.setCellWidget(rowCount, column('Location'), locationItem) # Map version widget to row number to enable simple lookup locationItem.currentIndexChanged[int].connect( self.locationSignalMapper.map ) self.locationSignalMapper.setMapping( locationItem, rowCount ) available_locations = [] for location in self.locations: accessor = location.accessor # Don't show inaccessible locations if accessor is symbol.NOT_SET: continue name = location['name'] location_id = location['id'] locationItem.addItem(name, location_id) available_locations.append(location) picked_location = self.session.pick_location(component) try: location_index = available_locations.index(picked_location) except ValueError: location_index = 0 locationItem.setCurrentIndex(location_index)
def refreshAssetManager(self): '''Refresh assets in asset manager.''' assets = self.connector.getAssets() self.ui.AssertManagerTableWidget.setSortingEnabled(False) self.ui.AssertManagerTableWidget.setRowCount(0) self.ui.AssertManagerTableWidget.setRowCount(len(assets)) component_ids = [] for component_id, _ in assets: if component_id: component_ids.append(component_id) if component_ids: query_string = ( 'select name, version.asset.type.short, version.asset.name, ' 'version.asset.type.name, version.asset.versions.version, ' 'version.id, version.version, version.asset.versions, ' 'version.date, version.comment, version.asset.name, version, ' 'version_id, version.user.first_name, version.user.last_name ' 'from Component where id in ({0})'.format( ','.join(component_ids))) components = self.connector.session.query(query_string).all() asset_ids = set() for component in components: asset_ids.add(component['version']['asset']['id']) if asset_ids: # Because of bug in 3.3.X backend we need to divide the query. The # memory cache will allow using entities without caring about this. preload_string = ( 'select components.name from AssetVersion where ' 'asset_id in ({0})').format(', '.join(list(asset_ids))) self.connector.session.query(preload_string).all() component_map = dict( (component['id'], component) for component in components) else: component_map = {} for i in range(len(assets)): if assets[i][0]: component = component_map[assets[i][0]] asset_version = component['version'] componentNameStr = component['name'] assetVersionNr = asset_version['version'] asset = asset_version['asset'] asset_versions_with_same_component_name = [] for related_version in asset['versions']: for other_component in related_version['components']: if other_component['name'] == componentNameStr: asset_versions_with_same_component_name.append( related_version) asset_versions_with_same_component_name = sorted( asset_versions_with_same_component_name, key=lambda x: x['version']) latest_version_number = ( asset_versions_with_same_component_name[-1]['version']) versionIndicatorButton = QtWidgets.QPushButton('') if assetVersionNr == latest_version_number: versionIndicatorButton.setStyleSheet(''' QPushButton { background-color: #1CBC90; border: none; } ''') self.connector.setNodeColor(applicationObject=assets[i][1], latest=True) else: versionIndicatorButton.setStyleSheet(''' QPushButton { background-color: #E36316; border: none; } ''') self.connector.setNodeColor(applicationObject=assets[i][1], latest=False) self.ui.AssertManagerTableWidget.setCellWidget( i, 0, versionIndicatorButton) componentName = QtWidgets.QTableWidgetItem(componentNameStr) self.ui.AssertManagerTableWidget.setItem(i, 1, componentName) componentId = QtWidgets.QTableWidgetItem(component['id']) self.ui.AssertManagerTableWidget.setItem(i, 2, componentId) assetType = QtWidgets.QTableWidgetItem(asset['type']['short']) self.ui.AssertManagerTableWidget.setItem(i, 3, assetType) assetTypeLong = QtWidgets.QTableWidgetItem( asset['type']['name']) self.ui.AssertManagerTableWidget.setItem(i, 4, assetTypeLong) versionNumberComboBox = QtWidgets.QComboBox() for version in reversed( asset_versions_with_same_component_name): versionNumberComboBox.addItem(str(version['version'])) conName = self.connector.getConnectorName() if conName in self.notVersionable: if componentNameStr in self.notVersionable[conName]: versionNumberComboBox.setEnabled(False) result = versionNumberComboBox.findText(str(assetVersionNr)) versionNumberComboBox.setCurrentIndex(result) self.ui.AssertManagerTableWidget.setCellWidget( i, 5, versionNumberComboBox) versionNumberComboBox.currentIndexChanged.connect( self.changeVersion) latestVersionNumberWidget = QtWidgets.QTableWidgetItem( str(latest_version_number)) self.ui.AssertManagerTableWidget.setItem( i, 6, latestVersionNumberWidget) assetName = QtWidgets.QTableWidgetItem(asset['name']) assetName.setToolTip(asset['name']) self.ui.AssertManagerTableWidget.setItem(i, 7, assetName) assetNameInScene = QtWidgets.QTableWidgetItem(assets[i][1]) assetNameInScene.setToolTip(assets[i][1]) self.ui.AssertManagerTableWidget.setItem( i, 8, assetNameInScene) selectButton = QtWidgets.QPushButton('S') selectButton.setToolTip('Select asset in scene') self.ui.AssertManagerTableWidget.setCellWidget( i, 9, selectButton) selectButton.clicked.connect(self.signalMapperSelect.map) self.signalMapperSelect.setMapping(selectButton, assets[i][1]) replaceButton = QtWidgets.QPushButton('R') self.ui.AssertManagerTableWidget.setCellWidget( i, 10, replaceButton) removeButton = QtWidgets.QPushButton() removeButton.setToolTip('Remove asset from scene') icon = QtGui.QIcon() icon.addPixmap( QtGui.QPixmap(':ftrack/image/integration/trash'), QtGui.QIcon.Normal, QtGui.QIcon.Off) removeButton.setIcon(icon) self.ui.AssertManagerTableWidget.setCellWidget( i, 11, removeButton) removeButton.clicked.connect(self.signalMapperRemove.map) self.signalMapperRemove.setMapping(removeButton, assets[i][1]) assetId = QtWidgets.QTableWidgetItem(str(asset['id'])) self.ui.AssertManagerTableWidget.setItem(i, 12, assetId) assetVersionId = QtWidgets.QTableWidgetItem( str(asset_version['id'])) self.ui.AssertManagerTableWidget.setItem(i, 13, assetVersionId) currentVersionFallback = QtWidgets.QTableWidgetItem( str(assetVersionNr)) self.ui.AssertManagerTableWidget.setItem( i, 14, currentVersionFallback) commentButton = QtWidgets.QPushButton() commentButton.setText('') icon = QtGui.QIcon() icon.addPixmap( QtGui.QPixmap(':ftrack/image/integration/comment'), QtGui.QIcon.Normal, QtGui.QIcon.Off) commentButton.setIcon(icon) fullUserName = (asset_version['user']['first_name'] + ' ' + asset_version['user']['last_name']) pubDate = str(asset_version['date']) comment = asset_version['comment'] tooltipText = '\n'.join([fullUserName, pubDate, comment]) commentButton.setToolTip(tooltipText) self.ui.AssertManagerTableWidget.setCellWidget( i, 15, commentButton) commentButton.clicked.connect(self.signalMapperComment.map) self.signalMapperComment.setMapping(commentButton, str(asset_version['id'])) commentButton.setEnabled(has_webwidgets) self.ui.AssertManagerTableWidget.setHorizontalHeaderLabels( self.columnHeaders)
def updateView(self, ftrackId=None): '''Update to view entity identified by *ftrackId*.''' self.latestFtrackId = ftrackId try: assetHandler = FTAssetHandlerInstance.instance() task = ftrack.Task(ftrackId) assets = task.getAssets(assetTypes=assetHandler.getAssetTypes()) assets = sorted(assets, key=lambda a: a.getName().lower()) self.assetTable.clearContents() self.assetTable.setRowCount(len(assets)) blankRows = 0 for i in range(len(assets)): assetName = assets[i].getName() assetVersions = assets[i].getVersions() # Temporary alias column = self.assetTableColumns.index if assetName != '' and assetVersions: item = QtWidgets.QTableWidgetItem(assetName) item.id = assets[i].getId() item.setToolTip(assetName) j = i - blankRows self.assetTable.setItem(j, column('Asset'), item) self.assetTable.setItem(j, column('Author'), QtWidgets.QTableWidgetItem('')) self.assetTable.setItem(j, column('Date'), QtWidgets.QTableWidgetItem('')) assetType = assets[i].getType() itemType = QtWidgets.QTableWidgetItem(assetType.getShort()) self.assetTable.setItem(j, column('Asset Type Code'), itemType) itemTypeLong = QtWidgets.QTableWidgetItem( assetType.getName()) self.assetTable.setItem(j, column('Asset Type'), itemTypeLong) assetVersions = assets[i].getVersions() versionComboBox = QtWidgets.QComboBox() self.assetTable.setCellWidget(j, column('Version'), versionComboBox) # Populate version list for version in reversed(assetVersions): versionComboBox.addItem(str(version.getVersion()), version) try: authorName = assetVersions[-1].getUser().getName() except ftrack.ftrackerror.FTrackError: # This error can happen if a version does not have an user, # for example if the user has been deleted after publishing # the version. authorName = 'No User Found' author = QtWidgets.QTableWidgetItem(authorName) self.assetTable.setItem(j, column('Author'), author) author = QtWidgets.QTableWidgetItem( assetVersions[-1].getDate().strftime('%Y-%m-%d %H:%M')) self.assetTable.setItem(j, column('Date'), author) # Map version widget to row number to enable simple lookup versionComboBox.currentIndexChanged[int].connect( self.assetTableSignalMapper.map) self.assetTableSignalMapper.setMapping(versionComboBox, j) else: blankRows += 1 self.assetTable.setRowCount(len(assets) - blankRows) except: traceback.print_exc(file=sys.stdout)