Esempio n. 1
0
 def outputIndexAs(self):
     widget = QApplication.focusWidget()
     extensions = []
     for extension, desc in EXPORT_EXTENSIONS.items():
         extensions.append("{} (*{})".format(desc, extension))
     with Lib.Qt.DisableUI(*self.window.widgets(), forModalDialog=True):
         form = QFileDialog(
             self.window,
             "Output As — {}".format(QApplication.applicationName()))
         form.setNameFilters(extensions)
         form.setAcceptMode(QFileDialog.AcceptSave)
         form.setDirectory(self.state.outputPath)
         form.selectFile(str(pathlib.Path(self.state.model.filename).stem))
         if form.exec_():
             filename = form.selectedFiles()[0]
             extension = form.selectedNameFilter()
             if filename:  # Must have some extension
                 if not re.match(r"^.*[.].+$", filename):
                     if extension:
                         filename += EXTENSION_EXTRACT_RX.sub(
                             r"\1", extension)
                     else:
                         filename += ".rtf"
                 self._outputIndex(filename, widget)
     Lib.restoreFocus(widget)
Esempio n. 2
0
    def on_browse(self, *_):
        dialog = QFileDialog(self)
        dialog.setFileMode(QFileDialog.DirectoryOnly)
        dialog.setViewMode(QFileDialog.Detail)
        dialog.setDirectory(self.le_output.text())

        if dialog.exec_():
            self.le_output.setText(dialog.selectedFiles()[0])
Esempio n. 3
0
 def save(self):
     dialog = QFileDialog(self)
     dialog.setFileMode(QFileDialog.AnyFile)
     dialog.setAcceptMode(QFileDialog.AcceptSave)
     dialog.setDefaultSuffix("avi")
     dialog.setDirectory(os.getcwd())
     dialog.setNameFilter(self.tr("Video Files [.avi] (*.avi)"))
     if dialog.exec_():
         output_file_name = dialog.selectedFiles()[0]
         correlate(self.clip_filename, self.audio_filename, output_file_name)
Esempio n. 4
0
 def save(self):
     dialog = QFileDialog(self)
     dialog.setFileMode(QFileDialog.AnyFile)
     dialog.setAcceptMode(QFileDialog.AcceptSave)
     dialog.setDefaultSuffix("avi")
     dialog.setDirectory(os.getcwd())
     dialog.setNameFilter(self.tr("Video Files [.avi] (*.avi)"))
     if dialog.exec_():
         output_file_name = dialog.selectedFiles()[0]
         correlate(self.clip_filename, self.audio_filename,
                   output_file_name)
Esempio n. 5
0
    def cmd_getPath(self):

        defaultPath = self.lineEdit.text()
        dialog = QFileDialog(self)
        dialog.setDirectory(defaultPath)
        fileName = dialog.getOpenFileName()[0]
        fileName = fileName.replace('\\', '/')
        if fileName: self.lineEdit.setText(fileName)
        self.save_lineEdit_info()

        self.parentWidget().w_textEditor.load_leftScript()
        self.parentWidget().w_textEditor.load_convertedText()
Esempio n. 6
0
    def loadGeo(self, *args):
        dialog = QFileDialog(self)
        #dialog.setFileMode(QFileDialog.AnyFile)
        if not self.fileName:
            dialog.setDirectory('meshes')
        else:
            dialog.setDirectory(os.path.dirname(self.fileName))

        dialog.setNameFilter("Images (*.obj *.stl)")

        if dialog.exec_():
            self.fileName = str(dialog.selectedFiles()[0])

            self.refreshMesh()
Esempio n. 7
0
    def open_input_file_dialog(self):
        ''' Opens and input file dialog and sets the output based on that.

            The output file path will be the same as the input, but renamed
            .csv instead of .txt.
        '''

        dialog = QFileDialog(self)
        # TODO - While testing anyway
        dialog.setDirectory('.')
        dialog.setFileMode(QFileDialog.ExistingFile)
        dialog.setNameFilter('Text files (*.txt)')

        if dialog.exec_():
            input_files = dialog.selectedFiles()
            input_file = input_files[0]
            self.input_path.setText(input_file)

            out_path = generate_output_file(input_file)

            self.output_path.setText(out_path)
Esempio n. 8
0
    def getBasePath(self):

        if int(cmds.about(v=1)) < 2017:
            import shiboken
            from PySide.QtGui import QFileDialog, QWidget, QDialog
        else:
            import shiboken2 as shiboken
            from PySide2.QtWidgets import QFileDialog, QWidget, QDialog

        winName = "dialog_getDirectory"
        mayaWin = shiboken.wrapInstance(
            long(maya.OpenMayaUI.MQtUtil.mainWindow()), QWidget)

        existing_widgets = mayaWin.findChildren(QDialog, winName)
        if existing_widgets: map(lambda x: x.deleteLater(), existing_widgets)

        dialog = QFileDialog(mayaWin)
        dialog.setObjectName(winName)
        dialog.setDirectory(os.path.splitext(cmds.file(q=1, sceneName=1))[0])
        choosedFolder = dialog.getExistingDirectory()
        if choosedFolder: self.lineEdit.setText(choosedFolder)

        self.cmd_loadList()
Esempio n. 9
0
    def set_backup_directory(self):
        dialog = QFileDialog(self)
        dialog.setFileMode(QFileDialog.Directory)
        dialog.setOption(QFileDialog.ShowDirsOnly, True)
        dialog.setWindowTitle("Please select a backup directory")

        if configuration.get("Backup", "backup_directory"):
            dialog.setDirectory(configuration.get("Backup",
                                                  "backup_directory"))

        if dialog.exec_():
            mainlog.debug(dialog.selectedFiles())
            directory = dialog.selectedFiles()[0]

            self._log("Testing the backup directory")
            try:
                f = open(os.path.join(directory, "test_file"), "w")
                f.write("TestBackup")
                f.close()
            except Exception as ex:
                box = QMessageBox(
                    QMessageBox.Warning,
                    "Unable to write into the backup directory",
                    u"I can't write in the backup directory you selected. Have I the necessary permissions  on that directory ({})? The error was : {}"
                    .format(directory, str(ex)))
                box.exec_()
                return

            self.backup_directory_edit.setText(directory)

            configuration.set("Backup", "backup_directory", directory)

            self._log("Saving the backup directory in the configuration")
            configuration.save()

        dialog.close()
Esempio n. 10
0
    def restore_backup(self):

        self._clear_log()
        self._log("Restore procedure started")

        url = self.url_edit.text()
        psql_path = configuration.get("Commands", "psql")

        if not psql_path:
            self._log_error(
                "The Commands/psql path is not set in the server.cfg")
            self._log("Please fix the configuration file (on the right)")
            return

        if not configuration.get("Commands", "pg_restore"):
            self._log_error(
                "The Commands/pg_restore path is not set in the server.cfg")
            self._log("Please fix the configuration file (on the right)")
            return

        if not configuration.get("Backup", "backup_directory"):

            self._log(
                "The Backup/backup_directory path is not set in the server.cfg"
            )
            self._log("I'm setting it myself.")

            configuration.set("Backup", "backup_directory", get_data_dir())
            configuration.set("DocumentsDatabase", "documents_root",
                              os.path.join(get_data_dir(), "documents"))
            configuration.save()
            self.edit_config.load_configuration()

        login_clt, password_clt, dummy, dummy, dummy = self._extract_db_params_from_url(
            configuration.get("Database", "url"))
        login_adm, password_adm, dbname, host, port = self._extract_db_params_from_url(
            configuration.get("Database", "admin_url"))

        self._log("{} / {}".format(login_adm, password_adm))

        full_path_backup = None
        d = ""
        if configuration.get("Backup", "backup_directory"):
            d = configuration.get("Backup", "backup_directory")

        if platform.system() == "Windows":

            if configuration.get("Backup", "backup_directory"):
                d = configuration.get("Backup", "backup_directory")

            # Using the static method gives a more native FileDialog.
            # with support for network
            backup_file = QFileDialog.getOpenFileName(
                self, _("Please select a backup file"), d,
                "{} database backup (*.pgbackup)".format(
                    configuration.get("Globals", "name")))[0]

            if not backup_file:
                self._log("Restore aborted")
                return

            full_path_backup = backup_file
            if not os.path.isdir(full_path_backup):
                self._log(
                    "{} is not a directory, so I'll go up a level".format(
                        full_path_backup))
                full_path_backup = os.path.dirname(full_path_backup)

                if not os.path.isdir(full_path_backup):
                    self._log_error(
                        "{} is not a directory either. Aborting restore.".
                        format(full_path_backup))
                    return

        elif platform.system() == "Linux":

            d = AskWindowsShare(None)
            d.exec_()
            if d.result() == QDialog.Accepted:

                # //192.168.0.6/postgresqlbackup

                script_path = "/tmp/horse_mount.sh"
                script = open(script_path, "w")
                script.write("""#!/bin/bash
echo "Creating transfer directory"
mkdir /tmp/backup_win
echo "Unmounting previous transfer directory (can fail)"
umount /tmp/backup_win
echo "Mouting the backup directory"
mount -t cifs -ousername={},password={} {} /tmp/backup_win
                """.format(d.user.text().strip(),
                           d.password.text().strip(),
                           d.address.text().strip()))
                script.close()

                import stat
                os.chmod(script_path,
                         stat.S_IEXEC | stat.S_IWRITE | stat.S_IREAD)

                cmd = [
                    'gksudo', '--sudo-mode', '--message',
                    'Allow Koi to connect to the backup server.', script_path
                ]

                # gksudo seems to like to have the DISPLAY set. So I basically copy
                # it from the calling environment.

                ret, dummy, dummy = self._run_shell(
                    cmd, {'DISPLAY': os.environ.get('DISPLAY')})

                if ret > 0:
                    self._log_error(
                        "The mount operation failed. Please review the parameters you've given."
                    )
                    self._log_error(
                        "Network address : {}, windows user name : {}".format(
                            d.address.text() or "?",
                            d.user.text() or "?"))
                    return

                full_path_backup = "/tmp/backup_win"
            else:
                dialog = QFileDialog(self)
                dialog.setFileMode(QFileDialog.Directory)
                dialog.setNameFilters(['Koi database backup (*.pgbackup)'])
                dialog.setWindowTitle("Please select a backup file")
                if configuration.get("Backup", "backup_directory"):
                    dialog.setDirectory(
                        configuration.get("Backup", "backup_directory"))
                if dialog.exec_():
                    full_path_backup = dialog.selectedFiles()[0]
                else:
                    self._log_error(
                        "Without proper source directory, I can't continue !")
                    return
        else:
            self._log_error("Unsupported operating system")

        # At this poitn full_path_backup is the path to the backup
        # directory of Horse that we want to restore.
        # It is different than the current backup directory.

        if full_path_backup:
            full_restore(configuration, full_path_backup, backup_file, True,
                         mainlog)
            self._log_success("Backup successfully restored !")
Esempio n. 11
0
 def getFolderFromBrowser(parent, defaultPath=''):
     dialog = QFileDialog(parent)
     dialog.setDirectory(defaultPath)
     choosedFolder = dialog.getExistingDirectory()
     return choosedFolder.replace('\\', '/')