Esempio n. 1
0
class RenameMarkers(PluginDecorator):

    #--------------------------------------------------------------------------
    # object
    #--------------------------------------------------------------------------

    def __init__(self):
        self.fileService = fileService
        self.rePath = RepathDefault()
        self.fileServiceLocal = flix.fileServices.fileLocal.FileLocal()
        self.serverFlixFunctions = ServerFlixFunctions()

        self.shotList = ''

        # load the icon
        iconPath = Mode().get(
            '[FLIX_CONFIG_FOLDER]') + '/plugins/icons/custom_icon.png'
        icon = self.fileService.loadByteArray(iconPath)

        self.init(label='Rename Markers',
                  icon=icon,
                  tooltip='Rename Markers',
                  group='Export',
                  pluginPath='flixConfig.plugins.renameMarkers.RenameMarkers')

    def execute(self, shotCutList, selection, additionalData=None):
        self.shotList = flix.core2.shotCutList.ShotCutList.fromFile(
            shotCutList.defaultPath())
        self.mode = self.shotList.mode

        shotNumber = int(self.mode.get(kMarkerNameIncrement))
        data = []
        data.append('<Recipies>')
        for shot in self.shotList:
            if shot.isMarker():
                recipe = shot.recipe
                properties = recipe.getProperties()
                newName = self.mode.get(kMarkerNameRegex) % shotNumber
                poses = recipe.getPoses()
                poseXML = poses[0]['poseXML']
                poseXML.attrib['dialogue'] = newName
                recipe.saveRecipeFiles()
                data.append(
                    '<Setup show="%(show)s" sequence="%(sequence)s" beat="%(beat)s" setup="%(setup)s" version="%(version)s">'
                    % recipe.getProperties())
                data.append(
                    ET.tostring(recipe.getMultiTrackXML()) + "</Setup>")
                shotNumber += int(self.mode.get(kMarkerNameIncrement))
        data.append("</Recipies>")
        dataString = "".join(data)
        log("DATASTRING: %s" % dataString)
        self.serverFlixFunctions.addFeedback('reloadSetupsMultiTracks',
                                             dataString)
class ImportDialogue(PluginDecorator):

    #--------------------------------------------------------------------------
    # object
    #--------------------------------------------------------------------------

    def __init__(self):
        self.fileService = fileService
        self.rePath = RepathDefault()

        self.shotList = ''
        self.serverFlixFunctions = ServerFlixFunctions()

        # load the icon
        iconPath = Mode().get(
            '[FLIX_CONFIG_FOLDER]') + '/plugins/icons/custom_icon.png'
        icon = self.fileService.loadByteArray(iconPath)

        self.init(
            label='Import Dialogue',
            icon=icon,
            tooltip='Import dialogue to current edit',
            group='Export',
            pluginPath='flixConfig.plugins.importDialogue.ImportDialogue')

    #--------------------------------------------------------------------------
    # executions
    #--------------------------------------------------------------------------

    def execute(self, shotCutList, selection, additionalData=None):
        self.shotList = flix.core2.shotCutList.ShotCutList.fromFile(
            shotCutList.defaultPath())
        newDialogue = "whatever"
        data = []
        data.append('<Recipies>')
        for panel in self.shotList:
            recipe = panel.recipe
            if not panel.isMarker():
                poses = recipe.getPoses()
                poseXML = poses[0]['poseXML']
                poseXML.attrib['dialogue'] = newDialogue
                recipe.saveRecipeFiles()
                data.append(
                    '<Setup show="%(show)s" sequence="%(sequence)s" beat="%(beat)s" setup="%(setup)s" version="%(version)s">'
                    % recipe.getProperties())
                data.append(
                    ET.tostring(recipe.getMultiTrackXML()) + "</Setup>")
        data.append("</Recipies>")
        dataString = "".join(data)
        log("DATASTRING: %s" % dataString)
        self.serverFlixFunctions.addFeedback('reloadSetupsMultiTracks',
                                             dataString)
Esempio n. 3
0
    def __init__(self):
        self.fileService = fileService
        self.rePath = RepathDefault()

        self.shotList = ''
        self.serverFlixFunctions = ServerFlixFunctions()

        # load the icon
        iconPath = Mode().get(
            '[FLIX_CONFIG_FOLDER]') + '/plugins/icons/custom_icon.png'
        icon = self.fileService.loadByteArray(iconPath)

        self.init(
            label='Import Dialogue',
            icon=icon,
            tooltip='Import dialogue to current edit',
            group='Export',
            pluginPath='flixConfig.plugins.importDialogue.ImportDialogue')
Esempio n. 4
0
    def __init__(self):
        self.fileService = fileService
        self.rePath = RepathDefault()
        self.fileServiceLocal = flix.fileServices.fileLocal.FileLocal()
        self.serverFlixFunctions = ServerFlixFunctions()

        self.shotList = ''

        # load the icon
        iconPath = Mode().get(
            '[FLIX_CONFIG_FOLDER]') + '/plugins/icons/custom_icon.png'
        icon = self.fileService.loadByteArray(iconPath)

        self.init(label='Rename Markers',
                  icon=icon,
                  tooltip='Rename Markers',
                  group='Export',
                  pluginPath='flixConfig.plugins.renameMarkers.RenameMarkers')
Esempio n. 5
0
class ImportDialogue(PluginDecorator):

    #--------------------------------------------------------------------------
    # object
    #--------------------------------------------------------------------------

    def __init__(self):
        self.fileService = fileService
        self.rePath = RepathDefault()

        self.shotList = ''
        self.serverFlixFunctions = ServerFlixFunctions()

        # load the icon
        iconPath = Mode().get(
            '[FLIX_CONFIG_FOLDER]') + '/plugins/icons/custom_icon.png'
        icon = self.fileService.loadByteArray(iconPath)

        self.init(
            label='Import Dialogue',
            icon=icon,
            tooltip='Import dialogue to current edit',
            group='Export',
            pluginPath='flixConfig.plugins.importDialogue.ImportDialogue')

    #--------------------------------------------------------------------------
    # executions
    #--------------------------------------------------------------------------

    def execute(self, shotCutList, selection, additionalData=None):
        dialogueFile = self.loadFileBrowser()
        if not dialogueFile or not os.path.exists(
                dialogueFile) or not dialogueFile[-4:] == ".txt":
            raise flix.exceptions.FlixException("No valid text file selected.")
        self.shotList = flix.core2.shotCutList.ShotCutList.fromFile(
            shotCutList.defaultPath())
        panels = self.getPanelSetupList()
        with open(dialogueFile) as f:
            dialogueFileContent = f.readlines()
        panelDialogueLines = self.getPanelDialogueLines(
            panels, dialogueFileContent)
        data = []
        data.append('<Recipies>')
        for panel in self.shotList:
            recipe = panel.recipe
            if not panel.isMarker():
                dialogueLines = panelDialogueLines[recipe.getShortLabelName()]
                if not dialogueLines == [-1]:
                    newDialogue = u""
                    for line in range(dialogueLines[0], dialogueLines[1] + 1):
                        newDialogue += dialogueFileContent[line].strip("\t")
                    poses = recipe.getPoses()
                    poseXML = poses[0]['poseXML']
                    poseXML.attrib['dialogue'] = newDialogue
                    recipe.saveRecipeFiles()
                    data.append(
                        '<Setup show="%(show)s" sequence="%(sequence)s" beat="%(beat)s" setup="%(setup)s" version="%(version)s">'
                        % recipe.getProperties())
                    data.append(
                        ET.tostring(recipe.getMultiTrackXML()) + "</Setup>")
        data.append("</Recipies>")
        dataString = "".join(data)
        log("DATASTRING: %s" % dataString)
        self.serverFlixFunctions.addFeedback('reloadSetupsMultiTracks',
                                             dataString)

    def loadFileBrowser(self):
        output = OSUtils.runFileBrowser(kBrowseTypeLoadFiles,
                                        'Select the text file', '/',
                                        'dialogue')
        return escape(output[0].decode('utf-8'))

    def getPanelSetupList(self):
        """ Returns a list of panels with their 'short label name' (e.g. '0010-2' for 'hum_p_0010_v2')
        """
        panelSetupList = []
        for panel in self.shotList:
            panelSetupList.append(panel.recipe.getShortLabelName())
        return panelSetupList

    def getPanelDialogueLines(self, panels, dialogueFileContent):
        """ Returns a dictionary listing the first and last dialogue lines for each panel
        """
        panelDialogueLines = {}
        previousPanel = None
        for panel in panels:
            # Panels with no dialogue get set to -1
            panelDialogueLines[panel] = [-1]
            # Ignore Markers
            if "marker" in panel:
                continue
            panelName = "%s:\n" % panel
            # If this panel has dialogue associated to it in the text file
            if panelName in dialogueFileContent:
                # Record the first line of dialogue for this panel
                panelDialogueLines[panel] = [
                    dialogueFileContent.index(panelName) + 1
                ]
                if previousPanel is not None:
                    # Record the last line of dialogue for the previous panel
                    panelDialogueLines[previousPanel].append(
                        dialogueFileContent.index(panelName) - 2)
                if panel == panels[-1]:
                    panelDialogueLines[panel].append(
                        len(dialogueFileContent) - 1)
                else:
                    previousPanel = panel
        log("PANELDIALOGUELINES: %s" % panelDialogueLines)
        return panelDialogueLines
Esempio n. 6
0
class PictureInPicture(PluginDecorator):

    #--------------------------------------------------------------------------
    # object
    #--------------------------------------------------------------------------

    def __init__(self):
        self.fileService = fileService
        self.rePath = RepathDefault()
        self.fileServiceLocal = flix.fileServices.fileLocal.FileLocal()
        self.serverFlixFunctions = ServerFlixFunctions()

        self.shotList = ''

        # load the icon
        iconPath = Mode().get(
            '[FLIX_CONFIG_FOLDER]') + '/plugins/icons/custom_icon.png'
        icon = self.fileService.loadByteArray(iconPath)

        self.init(
            label='Picture In Picture',
            icon=icon,
            tooltip='Picture In Picture',
            group='Maya',
            pluginPath='flixConfig.plugins.pictureInPicture.PictureInPicture')

    #--------------------------------------------------------------------------
    # executions
    #--------------------------------------------------------------------------

    def execute(self, shotCutList, selection, additionalData=None):
        setattr(self, 'selection', selection)

        self.shotList = flix.core2.shotCutList.ShotCutList.fromFile(
            shotCutList.defaultPath())
        self.mode = self.shotList.mode

        # For each selected panel
        for p in self.selection:
            shot = self.shotList[p]
            if shot.isMarker():
                continue
            # Get the path to the layout panel's jpeg (thumbnail)
            layoutPanelJpegPath = self._getPanelFilePath(shot)
            # Find which version is the latest board (i.e. not from Maya)
            latestBoard = self._getLatestStoryVersion(shot)
            if latestBoard is None:
                log("%s has no non-Maya version." % shot)
                continue
            log("latestBoard: %s" % latestBoard)
            # Get the path to the story panel's jpeg (thumbnail)
            latestBoardJpegPath = self._getPanelFilePath(latestBoard)
            # Create nk script using the paths to both jpeg files
            self.renderPip(layoutPanelJpegPath, latestBoardJpegPath,
                           int(self.mode.get('[yResolution]')),
                           int(self.mode.get('[xResolution]')))
            # Refresh the cache and thumbnail in Flix
            self.fileServiceLocal.refreshCache(layoutPanelJpegPath)
            log('__renderCallback:: Reloading image %s' %
                self.rePath.localize(layoutPanelJpegPath))
            self.serverFlixFunctions.addFeedback("reloadImages",
                                                 [layoutPanelJpegPath])

    #--------------------------------------------------------------------------
    # methods
    #--------------------------------------------------------------------------
    def _getPanelFilePath(self, shot):
        """ Get the path to the shot's thumbnail jpeg
        """
        kargs = {
            'beat': shot.beat,
            'setup': shot.setup,
            'version': shot.version,
            'frame': "%04d" % shot.markInFrame
        }
        return self.shotList.mode.get('[recipeCompedFile]', kargs)

    def _getLatestStoryVersion(self, shot):
        """ Get the latest story version of a panel (i.e. not coming from Maya)
        """
        for v in self._getRelatedVersions(shot):
            if v["version"] == shot.version:
                continue
            s = flix.core2.shot.Shot(shot.show, shot.sequence, v["beat"],
                                     v["setup"], v["version"])
            # Right now we assume if the panel's got a thirdPartyMetaData.json file, it comes from Maya and if not, it comes from story
            if not self.fileServiceLocal.exists(
                    s.recipe.getThirdPartyMetaDataPath()):
                return s
        return None

    def _getRelatedVersions(self, shot):
        """ Get all the related versions for the given panel
        """
        versions = FlixCore().getRelatedVersion(shot)
        versions.reverse()
        return versions

    @flix.remote.autoRemote(flix.remote.kProcGroupNuke)
    def renderPip(self, read1, read2, yRes, xRes):
        """ Create the Nuke script and execute it to render the new thumbnail
        """
        # Clear the nk script
        FlixNuke().clearScript()
        # Tweak this parameter for the pic in pic to be smaller(down to 0) or bigger (up to 1)
        scale = 0.25
        # Create the read nodes for both the layout and board panels
        readNode1 = nuke.createNode("Read",
                                    "file {%s}" % self.rePath.localize(read1))
        readNode2 = nuke.createNode("Read",
                                    "file {%s}" % self.rePath.localize(read2))
        # Create the transform node to resize and move the board to the bottom right hand corner
        transformNode = nuke.createNode("Transform")
        transformNode.setInput(0, readNode2)
        transformNode["scale"].setValue(scale)
        ytranslate = yRes * (scale - 1) / 2
        xtranslate = xRes * (1 - scale) / 2
        transformNode["translate"].setValue([xtranslate, ytranslate])
        # Create the merge node that puts the board over the layout panel
        mergeNode = nuke.createNode("Merge2")
        mergeNode.setInput(1, transformNode)
        mergeNode.setInput(0, readNode1)
        # Create the Write node to render the thumbnail
        writeNode = nuke.createNode("Write")
        writeNode["file"].setValue(self.rePath.localize(read1))
        # Execute the script to render the thumbnail
        nuke.execute(writeNode["name"].getValue(), 1, 1, 1)
        # Comment out to actually save the nk script to troubleshoot or modify
        # nuke.scriptSave(self.rePath.localize(read1.replace(".jpg", ".nk")))
        # Clear the nk script
        FlixNuke().clearScript()