Esempio n. 1
0
    def _updateComponentsNavigator(self, importableComponents=[]):
        '''Update versions navigator to display *importableComponents*.'''
        self._componentsNavigator.setRowCount(0)
        self._componentsNavigator.setRowCount(len(importableComponents))

        for index, component in enumerate(importableComponents):
            text = self._bridge.getEntityName(component.getEntityRef())
            item = QtWidgets.QTableWidgetItem(text)
            item.setData(QtCore.Qt.UserRole, component.getEntityRef())
            self._componentsNavigator.setItem(index, 0, item)

        self._componentsNavigator.setCurrentCell(0, 0)
        self._updateNavigator(importableComponents[0].getEntityRef())
Esempio n. 2
0
    def _populateBookmarks(self):
        '''Populate bookmarks view.'''
        # TODO: Extract bookmarks to separate widget.
        # For now just display non-editable list of projects from ftrack.
        projects = ftrack.getProjects()
        self._bookmarksView.setRowCount(len(projects))

        # Sort projects by display name.
        projects = sorted(projects, key=lambda project: project.getName())

        for index, project in enumerate(projects):
            item = QtWidgets.QTableWidgetItem(project.getName())
            item.setData(QtCore.Qt.UserRole, project.getEntityRef())

            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap(':icon-home'), QtGui.QIcon.Normal,
                           QtGui.QIcon.Off)
            item.setIcon(icon)

            self._bookmarksView.setItem(index, 0, item)
Esempio n. 3
0
    def _updateVersionsNavigator(self, asset):
        '''Update versions navigator to display versions for *asset*.'''
        self._versionsNavigator.setRowCount(0)

        if self._componentNamesFilter:
            versions = asset.getVersions(
                componentNames=self._componentNamesFilter)
        else:
            versions = asset.getVersions()

        self._versionsNavigator.setRowCount(len(versions))
        self._detailView.updateDetails(asset.getEntityRef())

        for index, version in enumerate(reversed(versions)):
            text = self._bridge.getEntityName(version.getEntityRef())
            item = QtWidgets.QTableWidgetItem(text)
            item.setData(QtCore.Qt.UserRole, version.getEntityRef())
            self._versionsNavigator.setItem(index, 0, item)

        self._versionsNavigator.setCurrentCell(0, 0)
        self._updateNavigator(versions[-1].getEntityRef())
Esempio n. 4
0
def ftrackPublishKnobChanged(forceRefresh=False, g=None):
    g = g or nuke.thisNode()

    if 'ftable' in g.knobs():
        header = getHeaderKnob(g)
        nodeAssetType = ''
        if nuke.thisKnob().name() in ['inputChange', 'fscript'
                                      ] or forceRefresh == True:
            thisNodeName = g['name'].value()
            g = nuke.toNode(HelpFunctions.safeString(thisNodeName))
            # Add new labels
            cmdString = ''
            assetType = None
            availableAssetTypes = ['']
            inputMissmatch = None

            tableWidget = g['ftable'].getObject().tableWidget
            tableWidget.setRowCount(0)
            components = []

            for inputNode in range(g.inputs()):
                inNode = g.input(inputNode)

                if inNode:
                    if inNode.Class() in ['Read', 'Write']:
                        nodeAssetType = 'img'
                    elif inNode.Class() in ['WriteGeo']:
                        nodeAssetType = 'geo'
                    else:
                        nodeAssetType = ''

                    if not assetType:
                        assetType = nodeAssetType

                    if assetType != nodeAssetType:
                        inputMissmatch = True

                    if nodeAssetType == 'img':
                        fileComp = str(inNode['file'].value())
                        proxyComp = str(inNode['proxy'].value())
                        nameComp = str(inNode['name'].value()).strip()

                        if inNode.Class() == 'Read':
                            first = str(inNode['first'].value())
                            last = str(inNode['last'].value())
                            if first == '0.0' and last == '0.0':
                                first = str(
                                    int(nuke.root().knob(
                                        "first_frame").value()))
                                last = str(
                                    int(nuke.root().knob(
                                        "last_frame").value()))

                            availableAssetTypes = ['img', 'render']

                        elif inNode.Class() == 'Write':

                            # use the timeline to define the amount of frames
                            first = str(
                                int(nuke.root().knob("first_frame").value()))
                            last = str(
                                int(nuke.root().knob("last_frame").value()))

                            # then in case check if the limit are set
                            if inNode['use_limit'].value():
                                first = str(inNode['first'].value())
                                last = str(inNode['last'].value())

                            # always check how many frames are actually available
                            frames = inNode['file'].value()

                            try:
                                # Try to collect the sequence prefix, padding
                                # and extension. If this fails with a ValueError
                                # we are probably handling a non-sequence file.
                                # If so rely on the first_frame and last_frame
                                # of the root node.
                                prefix, padding, extension = frames.split('.')
                            except ValueError:
                                FnAssetAPI.logging.debug(
                                    'Could not determine prefix, padding '
                                    'and extension from "".'.format(frames))
                                availableAssetTypes = ['render']
                            else:
                                root = os.path.dirname(prefix)
                                files = glob.glob('{0}/*.{1}'.format(
                                    root, extension))
                                collections = clique.assemble(files)

                                for collection in collections[0]:
                                    if prefix in collection.head:
                                        indexes = list(collection.indexes)
                                        first = str(indexes[0])
                                        last = str(indexes[-1])
                                        break

                                availableAssetTypes = ['img']

                        try:
                            compNameComp = inNode['fcompname'].value()
                        except:
                            compNameComp = ''

                        if compNameComp == '':
                            compNameComp = nameComp

                        components.append(
                            (fileComp, compNameComp, first, last, nameComp))
                        if proxyComp != '':
                            components.append(
                                (proxyComp, compNameComp + '_proxy', first,
                                 last, nameComp))

                    elif nodeAssetType == 'geo':
                        fileComp = str(inNode['file'].value())
                        nameComp = str(inNode['name'].value()).strip()
                        first = str(inNode['first'].value())
                        last = str(inNode['last'].value())

                        if first == '0.0' and last == '0.0':
                            first = str(
                                int(nuke.root().knob("first_frame").value()))
                            last = str(
                                int(nuke.root().knob("last_frame").value()))

                        try:
                            compNameComp = inNode['fcompname'].value()
                        except:
                            compNameComp = ''

                        if compNameComp == '':
                            compNameComp = nameComp

                        components.append(
                            (fileComp, compNameComp, first, last, nameComp))

                        availableAssetTypes = ['geo', 'cam']

            rowCount = len(components)

            tableWidget.setRowCount(rowCount)
            if len(components) == 0:
                g.knob('pknob').setEnabled(False)
            else:
                g.knob('pknob').setEnabled(True)

            l = [x[1] for x in components]
            wodup = list(set(l))

            if len(l) != len(wodup):
                g.knob('pknob').setEnabled(False)
                header.setMessage('Components can not have the same name',
                                  'warning')

            rowCntr = 0
            for comp in components:
                cb = QtWidgets.QCheckBox('')
                cb.setChecked(True)
                tableWidget.setCellWidget(rowCntr, 0, cb)

                componentItem = QtWidgets.QTableWidgetItem()
                componentItem.setText(comp[0])
                componentItem.setToolTip(comp[0])
                tableWidget.setItem(rowCntr, 1, componentItem)
                componentItem = QtWidgets.QTableWidgetItem()
                componentItem.setText(comp[1])
                componentItem.setToolTip(comp[1])
                tableWidget.setItem(rowCntr, 2, componentItem)

                try:
                    fileCurrentFrame = nukescripts.replaceHashes(
                        comp[0]) % int(float(comp[2]))
                except:
                    print 'File is not sequence'
                    fileCurrentFrame = comp[0]
                if os.path.isfile(fileCurrentFrame):
                    fileExist = 'T'
                else:
                    fileExist = 'F'

                componentItem = QtWidgets.QTableWidgetItem()
                if fileExist == 'T':
                    componentItem.setBackground(QtGui.QColor(20, 161, 74))
                else:
                    componentItem.setBackground(QtGui.QColor(227, 99, 22))
                componentItem.setToolTip(fileExist)
                tableWidget.setItem(rowCntr, 4, componentItem)

                componentItem = QtWidgets.QTableWidgetItem()
                componentItem.setText(comp[2])
                componentItem.setToolTip(comp[2])
                tableWidget.setItem(rowCntr, 5, componentItem)

                componentItem = QtWidgets.QTableWidgetItem()
                componentItem.setText(comp[3])
                componentItem.setToolTip(comp[3])
                tableWidget.setItem(rowCntr, 6, componentItem)

                componentItem = QtWidgets.QTableWidgetItem()
                componentItem.setText(comp[4])
                componentItem.setToolTip(comp[4])
                tableWidget.setItem(rowCntr, 3, componentItem)

                rowCntr += 1

            g['ftrackassettype'].setValues(availableAssetTypes)

            if inputMissmatch:
                tableWidget.setRowCount(0)
                g['ftrackassettype'].setValues(['Missmatch inputs'])

            if cmdString == '':
                cmdString = 'No inputs connected'

            assetEnums = ['New']
            if nodeAssetType != '':
                # assets = connector.Connector.objectById(os.environ['FTRACK_SHOTID']).getAssets(assetTypes=[g['ftrackassettype'].value()])
                pubto = g.knob('fpubto').getObject().targetTask
                assets = connector.Connector.objectById(pubto).getAssets(
                    assetTypes=[g['ftrackassettype'].value()])
                assets = sorted(assets,
                                key=lambda entry: entry.getName().lower())
                assetEnums = assetEnums + [
                    HelpFunctions.safeString(x.getName()) for x in assets
                ]
                FnAssetAPI.logging.info(assetEnums)
                g['fassetnameexisting'].setValues(assetEnums)

            g = nuke.toNode(HelpFunctions.safeString(thisNodeName))
            g.begin()

            # Add more inputs if full
            realInputCount = 0
            for inputNode in range(g.inputs()):
                if g.input(inputNode):
                    realInputCount += 1
            if realInputCount == g.maxInputs():
                inputNode = nuke.createNode("Input", inpanel=False)
            g.end()
        elif nuke.thisKnob().name() == 'ftrackassettype':
            nodeAssetType = g['ftrackassettype'].value()
            #print nodeAssetType
            assetEnums = ['New']
            if nodeAssetType != '' and nodeAssetType != 'Missmatch inputs':
                # assets = connector.Connector.objectById(os.environ['FTRACK_SHOTID']).getAssets(assetTypes=[nodeAssetType])
                pubto = g.knob('fpubto').getObject().targetTask
                assets = connector.Connector.objectById(pubto).getAssets(
                    assetTypes=[nodeAssetType])
                assetEnums = assetEnums + [
                    HelpFunctions.safeString(x.getName()) for x in assets
                ]
                g['fassetnameexisting'].setValues(assetEnums)
Esempio n. 5
0
    def updateDetails(self, identifier):
        '''Update view for entity referenced by *identifier*.'''
        self.setEnabled(True)

        entity = self._bridge.getEntityById(identifier)

        name = self._bridge.getEntityName(entity.getEntityRef())
        self._propertyTable.setItem(0, 0, QtWidgets.QTableWidgetItem(name))

        assetVersion = None
        thumbnailUrl = None
        if isinstance(entity, ftrack.Asset):
            assetVersion = entity.getVersions()[-1]

        elif isinstance(entity, ftrack.AssetVersion):
            assetVersion = entity

        elif isinstance(entity, ftrack.Component):
            assetVersion = entity.getVersion()

        if assetVersion:
            thumbnailUrl = assetVersion.getThumbnail()
            authorUser = assetVersion.getUser()
            version = str(assetVersion.getVersion())
            comment = assetVersion.getComment()
            date = str(assetVersion.getDate())
            author = authorUser.getName().encode('utf-8')

            self._propertyTable.setRowHidden(1, False)
            self._propertyTable.setRowHidden(2, False)
            self._propertyTable.setRowHidden(3, False)
            self._propertyTable.setRowHidden(4, False)
            self._propertyTable.setRowHidden(5, True)
            self._propertyTable.setRowHidden(6, True)

            self._propertyTable.setItem(0, 1,
                                        QtWidgets.QTableWidgetItem(author))
            self._propertyTable.setItem(0, 3, QtWidgets.QTableWidgetItem(date))
            self._propertyTable.setItem(0, 2,
                                        QtWidgets.QTableWidgetItem(version))
            self._propertyTable.setItem(0, 4,
                                        QtWidgets.QTableWidgetItem(comment))

        else:
            if hasattr(entity, 'getThumbnail'):
                thumbnailUrl = entity.getThumbnail()

            statusName = ''
            if hasattr(entity, 'getStatus'):
                status = entity.getStatus()
                if status:
                    statusName = status.getName()

            priorityName = ''
            if hasattr(entity, 'getPriority'):
                priority = entity.getPriority()
                if priority:
                    priorityName = priority.getName()

            self._propertyTable.setRowHidden(1, True)
            self._propertyTable.setRowHidden(2, True)
            self._propertyTable.setRowHidden(3, True)
            self._propertyTable.setRowHidden(4, True)
            self._propertyTable.setRowHidden(5, False)
            self._propertyTable.setRowHidden(6, False)

            self._propertyTable.setItem(0, 5,
                                        QtWidgets.QTableWidgetItem(statusName))
            self._propertyTable.setItem(
                0, 6, QtWidgets.QTableWidgetItem(priorityName))

        if not thumbnailUrl:
            thumbnailUrl = self._placholderThumbnail

        self._updateThumbnail(self._thumbnail, thumbnailUrl)

        self._propertyTable.resizeRowsToContents()
Esempio n. 6
0
    def _updateNavigator(self, targetReference):
        '''Update navigator to display entries under *targetReference*.'''
        entity = self._bridge.getEntityById(targetReference)

        # Display path to entity.
        self._locationField.setText(
            self._bridge.getEntityPath(targetReference,
                                       slash=True,
                                       includeAssettype=True))

        # Update selection.
        self._currentBrowsingId = targetReference
        entityType = self._bridge.getEntityType(targetReference)
        self._selectionValid = self._isValid(entityType, entity)
        self.clickedIdSignal.emit(self._currentBrowsingId)

        # Update details view.
        self._detailView.updateDetails(self._currentBrowsingId)

        # Update other navigators.
        if hasattr(entity, 'getVersions'):
            if self._showAssetVersions == True:
                self._updateVersionsNavigator(entity)
                self._versionsNavigator.show()
            return

        elif hasattr(entity, 'getComponents'):
            components = entity.getComponents()
            importableComponents = []
            self._componentsNavigator.hide()

            for component in components:
                if self._componentNamesFilter:
                    if not component in self._componentNamesFilter:
                        continue

                if self._metaFilters:
                    metaData = component.getMeta()

                    # img_main to be replaced by settable option
                    for metaFilter in self._metaFilters:
                        if metaFilter in metaData:
                            importableComponents.append(component)

                else:
                    importableComponents.append(component)

            if len(importableComponents) > 1:
                self._updateComponentsNavigator(importableComponents)
                self._componentsNavigator.show()

            elif len(importableComponents) == 1:
                self._updateNavigator(importableComponents[0].getEntityRef())

            return

        elif entityType == 'Task':
            return

        elif isinstance(entity, ftrack.Component):
            return

        else:
            self._versionsNavigator.hide()
            self._componentsNavigator.hide()

        # Update main navigator view.
        self._navigator.setRowCount(0)
        self._versionsNavigator.setRowCount(0)

        self._navigator.setHorizontalHeaderLabels(
            [self._bridge.getEntityName(targetReference)])

        children = []
        tasks = []
        assets = []

        if isinstance(entity, ftrack.Project) or isinstance(
                entity, ftrack.Task):
            children = entity.getChildren()

        if hasattr(entity, 'getTasks') and self._showTasks == True:
            tasks = entity.getTasks()

        if hasattr(entity, 'getAssets'):
            if (not isinstance(entity, ftrack.Project)
                    and entity.getObjectType() in ['Shot', 'Sequence']
                    and self._showAssets == True):
                if self._componentNamesFilter:
                    assets = entity.getAssets(
                        componentNames=self._componentNamesFilter)
                else:
                    assets = entity.getAssets()

        entities = children + tasks + assets
        entities = sorted(entities,
                          key=lambda entity: self._bridge.getEntityName(
                              entity.getEntityRef()).lower())

        self._navigator.setRowCount(len(entities))
        for index, entity in enumerate(entities):
            makeBold = None
            makeItalic = None
            makeDisabled = None

            if (isinstance(entity, ftrack.Task)
                    and entity.getObjectType() in ['Shot', 'Sequence']):
                text = self._bridge.getEntityName(entity.getEntityRef()) + '/'
                makeBold = True

            elif (isinstance(entity, ftrack.Task)
                  and entity.getObjectType() in ['Task']):
                text = self._bridge.getEntityName(entity.getEntityRef())
                makeItalic = True
                if isinstance(entity.getParent(), ftrack.Project):
                    makeDisabled = True

            elif isinstance(entity, ftrack.Asset):
                text = (self._bridge.getEntityName(entity.getEntityRef()) +
                        '.' + entity.getType().getShort())

            else:
                text = self._bridge.getEntityName(entity.getEntityRef())

            if entityType == 'Sequence' and self._shotsEnabled == False:
                makeDisabled = True

            item = QtWidgets.QTableWidgetItem(text)
            item.setData(QtCore.Qt.UserRole, entity.getEntityRef())

            icon = self._getIcon(entity)
            if icon:
                item.setIcon(icon)

            if makeDisabled:
                item.setFlags(QtCore.Qt.NoItemFlags)

            self._navigator.setItem(index, 0, item)

            if makeBold:
                font = QtGui.QFont()
                font.setBold(True)
                self._navigator.item(index, 0).setFont(font)

            elif makeItalic:
                font = QtGui.QFont()
                font.setItalic(True)
                self._navigator.item(index, 0).setFont(font)