Example #1
0
def _project_save_as(project):
    """
    A save as wrapper for the current session.

    :param path: Optional path to save the current session as.
    """
    # TODO: consider moving to engine

    # import here since the hooks are imported into nuke and nukestudio.
    # hiero module is only available in later versions of nuke
    import hiero

    # nuke studio/hiero don't appear to have a "save as" dialog accessible via
    # python. so open our own Qt file dialog.
    file_dialog = QtGui.QFileDialog(parent=hiero.ui.mainWindow(),
                                    caption="Save As",
                                    directory=project.path(),
                                    filter="Nuke Studio Files (*.hrox)")
    file_dialog.setLabelText(QtGui.QFileDialog.Accept, "Save")
    file_dialog.setLabelText(QtGui.QFileDialog.Reject, "Cancel")
    file_dialog.setOption(QtGui.QFileDialog.DontResolveSymlinks)
    file_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog)
    if not file_dialog.exec_():
        return
    path = file_dialog.selectedFiles()[0]
    project.saveAs(path)
Example #2
0
    def _on_browse(self):
        """
        Opens a file dialog to browse to files for publishing
        """
        # passG
        file_dialog = QtGui.QFileDialog(
            parent=self,
            caption="Browse files to publish"
        )
        file_dialog.setLabelText(QtGui.QFileDialog.Accept, "Select")
        file_dialog.setLabelText(QtGui.QFileDialog.Reject, "Cancel")
        file_dialog.setOption(QtGui.QFileDialog.DontResolveSymlinks)
        file_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog)
        file_dialog.setFileMode(QtGui.QFileDialog.ExistingFiles)
        if not file_dialog.exec_():
            return

        files = file_dialog.selectedFiles()
        # print files

        """Adds info to main_struct """
        self.main_struct[:] = []
        for f in files:
            f_path, f_name = os.path.split(f)
            tag_list = []
            tag_list.append(os.path.basename(f_path))
            self.main_struct.append(
                self.create_main_struct_entry(os.path.splitext(f_name)[0], str(self._combo_entity_type.currentText()),
                                              os.path.basename(f_path), tag_list, f_path, f_name, None))
            # PrettyPrinter(indent=4).pprint(self.main_struct)
            self._lbl_display_folder.setText(f_path)
        return True
Example #3
0
    def open_save_as_dialog(self):
        """
        Launch a Qt file browser to select a file, then save the supplied
        project to that path.
        """
        # Alias doesn't appear to have a "save as" dialog accessible via
        # python. so open our own Qt file dialog.
        file_dialog = QtGui.QFileDialog(
            parent=self.get_parent_window(),
            caption="Save As",
            directory=os.path.expanduser("~"),
            filter="Alias file (*.wire)",
        )
        file_dialog.setLabelText(QtGui.QFileDialog.Accept, "Save")
        file_dialog.setLabelText(QtGui.QFileDialog.Reject, "Cancel")
        file_dialog.setOption(QtGui.QFileDialog.DontResolveSymlinks)
        file_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog)
        if not file_dialog.exec_():
            return
        path = file_dialog.selectedFiles()[0]

        if os.path.splitext(path)[-1] != ".wire":
            path = "{0}.wire".format(path)

        if path:
            self.save_file(path)
    def save(self, start_path=None):
        """Save the current contents to a file.

        :param path: A path to a file to save or dir to browse.
        """

        save_dialog = QtGui.QFileDialog(
            parent=QtGui.QApplication.activeWindow(),
            caption="Save Python Script",
            directory=start_path,
            filter="*.py",
        )
        save_dialog.setOption(QtGui.QFileDialog.DontResolveSymlinks, True)
        save_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog, True)
        save_dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave)
        save_dialog.setViewMode(QtGui.QFileDialog.Detail)
        save_path = None
        if save_dialog.exec_():
            save_path = save_dialog.selectedFiles()[0]

        if not save_path:
            return False

        # write the contents of the editor to a file.
        python_script = str(self.toPlainText())
        fh = open(save_path, "w")
        try:
            fh.write(python_script)
        except Exception, e:
            QtGui.QMessageBox.warning(
                self,
                "Failed to Save Python Script",
                "There was an error saving the python script:\n\n%s" %
                (str(e)),
            )
 def _browse(self):
     """
     Shows a file browser
     """
     dialog = QtGui.QFileDialog()
     dialog.setOption(QtGui.QFileDialog.ShowDirsOnly)
     dialog.setFileMode(QtGui.QFileDialog.Directory)
     result = dialog.exec_()
     if result == QtGui.QDialog.Accepted:
         files = dialog.selectedFiles()
         if len(files) > 0:
             path = files[0]
             self.ui.path.setText(path)
Example #6
0
 def loadFilesForReview(self):
     """
     """
     filter = "Images (*.jpg *.png *.exr)"
     file_name = QtGui.QFileDialog()
     file_name.setFileMode(QtGui.QFileDialog.ExistingFiles)
     names = file_name.getOpenFileNames(self, "Open files", "C:\\Temp",
                                        filter)[0]
     if names:
         for _file in names:
             #itm = QtGui.QListWidgetItem(_file)
             if not self.ui.lw_FileList.findItems(_file,
                                                  QtCore.Qt.MatchExactly):
                 self.ui.lw_FileList.addItem(_file)
Example #7
0
    def _on_browse(self):
        """Opens a file dialog to browse to files for publishing."""

        file_dialog = QtGui.QFileDialog(parent=self,
                                        caption="Browse files to publish")
        file_dialog.setLabelText(QtGui.QFileDialog.Accept, "Select")
        file_dialog.setLabelText(QtGui.QFileDialog.Reject, "Cancel")
        file_dialog.setOption(QtGui.QFileDialog.DontResolveSymlinks)
        file_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog)
        file_dialog.setFileMode(QtGui.QFileDialog.ExistingFiles)
        if not file_dialog.exec_():
            return

        files = file_dialog.selectedFiles()
        if files:
            # simulate dropping the files into the dialog
            self._on_drop(files)
Example #8
0
    def _select_edl_file(self):
        """Select edl file and parse it via self._edl_parse
        :return: None
        """
        logger.info('Starting EDL file selection')
        self.ui.label_status.setText('Selecting EDL file')

        start_path = '~'
        if self.last_edl_file_path:
            start_path = self.last_edl_file_path
        else:
            # 'darwin'  'linux'  'win32'
            if sys.platform == 'win32':
                start_path = 'C:\\'
        try:
            dial = QtGui.QFileDialog().getOpenFileName(self, u"Choose file",
                                                       start_path, "*.edl")
        except IOError:
            msg = 'ERROR: failed to get path from file dialog.'
            logger.info(msg)
            self.ui.label_status.setText(msg)
            return

        if dial and dial[0]:
            self.last_edl_file_path = os.path.dirname(dial[0])
            edl_file_path = self._fix_line_terminators(dial[0])
            if edl_file_path:
                if not os.path.exists(edl_file_path):
                    msg = 'ERROR: eld file path does not exist.'
                    logger.info(msg)
                    self.ui.label_status.setText(msg)
                    return
                # success, parse edl file
                self._parse_edl(edl_file_path)
                return
            else:
                msg = 'ERROR: failed to get eld file path.'
                logger.info(msg)
                self.ui.label_status.setText(msg)
                return
        else:
            msg = 'WARNING: no path from file dialog. User may have canceled.'
            logger.info(msg)
            self.ui.label_status.setText('')
            return
Example #9
0
    def _select_files(self):

        # if we are starting over, delete table rows from last run
        if self.table_rows_need_to_be_deleted:
            self._delete_table_rows()

        start_path = '~'

        if self.last_edl_file_path:
            start_path = self.last_edl_file_path
        else:
            # 'darwin'  'linux'  'win32'
            if sys.platform == 'win32':
                start_path = 'C:\\'

        try:
            result = QtGui.QFileDialog().getOpenFileNames(self, u'Select Files', start_path, "*.xlsx")
        except IOError:
            msg = 'ERROR: failed to get items from file dialog.'
            logger.info(msg)
            self.label_status.setText(msg)
            return

        if result and result[0]:
            # check file path
            xl_file_list = result[0]
            for xl_file_path in xl_file_list:
                if not os.path.exists(xl_file_path):
                    msg = 'ERROR: excel file path does not exist: {}'.format(xl_file_path)
                    logger.info(msg)
                    self.label_status.setText(msg)
                    return
                # success
                self.last_edl_file_path = os.path.dirname(xl_file_list[0])
                logger.info('Selected file: {}'.format(xl_file_path))
                self._open_file(xl_file_path)
        else:
            msg = 'WARNING: no path from file dialog. User may have canceled.'
            logger.info(msg)
            return

        self.button_file_open.hide()
        self.button_shotgun_import.show()
Example #10
0
    def open_save_as_dialog(self):
        """
        Try to open tk-multi-workfiles2 Save As... dialog if it exists otherwise
        launch a Qt file browser for the Save As...
        """
        open_dialog_func = None
        kwargs = {}
        workfiles = self.apps.get("tk-multi-workfiles2", None)

        if workfiles:
            if hasattr(workfiles, "show_file_save_dlg"):
                open_dialog_func = workfiles.show_file_save_dlg
                kwargs["use_modal_dialog"] = True

        if open_dialog_func:
            open_dialog_func(**kwargs)

        else:
            # Alias doesn't appear to have a "save as" dialog accessible via
            # python. so open our own Qt file dialog.

            from sgtk.platform.qt import QtGui

            file_dialog = QtGui.QFileDialog(
                parent=self.get_parent_window(),
                caption="Save As",
                directory=os.path.expanduser("~"),
                filter="Alias file (*.wire)",
            )
            file_dialog.setLabelText(QtGui.QFileDialog.Accept, "Save")
            file_dialog.setLabelText(QtGui.QFileDialog.Reject, "Cancel")
            file_dialog.setOption(QtGui.QFileDialog.DontResolveSymlinks)
            file_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog)
            if not file_dialog.exec_():
                return
            path = file_dialog.selectedFiles()[0]

            if os.path.splitext(path)[-1] != ".wire":
                path = "{0}.wire".format(path)

        if path:
            self.save_file_as(path)
Example #11
0
def _set_project():
    """
    Pop up a Qt file browser to select a path. Then set that as the project root
    """

    # max doesn't provide the set project browser via python, so open our own
    # Qt file dialog.
    file_dialog = QtGui.QFileDialog(
        parent=QtGui.QApplication.activeWindow(),
        caption="Save As",
        directory=MaxPlus.PathManager.GetProjectFolderDir(),
        filter="3dsMax Files (*.max)")
    file_dialog.setFileMode(QtGui.QFileDialog.DirectoryOnly)
    file_dialog.setLabelText(QtGui.QFileDialog.Accept, "Set")
    file_dialog.setLabelText(QtGui.QFileDialog.Reject, "Cancel")
    file_dialog.setOption(QtGui.QFileDialog.DontResolveSymlinks)
    file_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog)
    if not file_dialog.exec_():
        return
    path = file_dialog.selectedFiles()[0]
    MaxPlus.PathManager.SetProjectFolderDir(path)
Example #12
0
    def save_as(self):
        """
        Open a file dialog to choose a file path to save the current session to
        """

        from sgtk.platform.qt import QtGui

        # houdini doesn't appear to have a "save as" dialog accessible via
        # python. so open our own Qt file dialog.
        file_dialog = QtGui.QFileDialog(
            parent=self._get_dialog_parent(),
            caption="Save As",
            directory=hou.hipFile.path(),
            filter="Houdini Files (*.hip, *.hipnc)")
        file_dialog.setLabelText(QtGui.QFileDialog.Accept, "Save")
        file_dialog.setLabelText(QtGui.QFileDialog.Reject, "Cancel")
        file_dialog.setOption(QtGui.QFileDialog.DontResolveSymlinks)
        file_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog)
        if not file_dialog.exec_():
            return
        path = file_dialog.selectedFiles()[0]
        hou.hipFile.save(file_name=path)
Example #13
0
    def open(self, path=None):
        """Open an external python script to edit.

        :param path: A path to a directory to browse or file to open.
        """

        # browse to a file to open
        if not path or os.path.isdir(path):
            open_dialog = QtGui.QFileDialog(
                parent=QtGui.QApplication.activeWindow(),
                caption="Open Python Script",
                directory=path,
                filter="*.py",
            )
            open_dialog.setFileMode(QtGui.QFileDialog.ExistingFile)
            open_dialog.setOption(QtGui.QFileDialog.DontResolveSymlinks, True)
            open_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog, True)
            open_dialog.setViewMode(QtGui.QFileDialog.Detail)
            if open_dialog.exec_():
                path = open_dialog.selectedFiles()[0]

        if not path:
            return

        # clear the contents, open and load the file
        fh = open(path)
        try:
            python_script = "".join(fh.readlines())
            index = self.tabs.add_tab(
                name=os.path.split(path)[-1],
                contents=python_script,
            )
            widget = self.tabs.widget(index)
            widget.input_widget.setPlainText(python_script)
        finally:
            fh.close()