コード例 #1
0
ファイル: utils.py プロジェクト: 2Minutes/davos-dev
def choosePackages(parent=None, caption="", directory="", selectMode="single"):

    dialog = QFileDialog(parent, caption, osp.normcase(directory))
    dialog.setFileMode(QFileDialog.Directory)
    dialog.setFilter(QDir.NoDotAndDotDot | QDir.Dirs)# | QDir.Files)
    dialog.setNameFilters(["Packages ( pkg_* lyr_* )"])
    dialog.setOption(QFileDialog.ReadOnly)

    bMultiSelect = (selectMode == "multi")

    treeView = dialog.findChild(QTreeView)
    if bMultiSelect:
        treeView.setSelectionMode(QAbstractItemView.ExtendedSelection)

    if bMultiSelect:
        listView = dialog.itemDelegate().parent()
        listView.setSelectionMode(QAbstractItemView.ExtendedSelection)

    treeView.model().setNameFilterDisables(True)

    proxyModel = PackSortProxyModel(dialog)
    dialog.setProxyModel(proxyModel)

    res = dialog.exec_()
    if res and treeView.selectionModel().hasSelection():
        sDirList = dialog.selectedFiles()
        try:
            sDirList.remove(dialog.directory().absolutePath())
        except ValueError:
            pass
        return sDirList if bMultiSelect else sDirList[0]

    return [] if bMultiSelect else ""
コード例 #2
0
    def on_browse(self):
        current_path = self.files_model.rootPath()
        file_dialog = QFileDialog(self, 'Select a Folder', current_path)
        file_dialog.setFileMode(QFileDialog.Directory)
        file_dialog.setOption(QFileDialog.ShowDirsOnly)

        if file_dialog.exec_():
            self.on_change_root_path(file_dialog.selectedFiles()[0])
コード例 #3
0
    def on_browse(self):
        current_path = self.files_model.rootPath()
        file_dialog = QFileDialog(self, 'Select a Folder', current_path)
        file_dialog.setFileMode(QFileDialog.Directory)
        file_dialog.setOption(QFileDialog.ShowDirsOnly)

        if file_dialog.exec_():
            self.on_change_root_path(file_dialog.selectedFiles()[0])
コード例 #4
0
def open_file(parent, filter):
    dialog = QFileDialog()
    dialog.setOption(QFileDialog.DontUseNativeDialog)
    dialog.setAcceptMode(QFileDialog.AcceptOpen)
    dialog.setFilter(QDir.Files)
    dialog.setFileMode(QFileDialog.ExistingFile)
    dialog.setNameFilter(filter)
    res = dialog.exec_()
    if res:
        return dialog.selectedFiles()[0]
コード例 #5
0
    def choose_save_dir(self):
        fname = QFileDialog(self, FILEBROWSER_SAVE_FOLDER_TITLE)
        fname.setFileMode(QFileDialog.Directory)
        looking_label = QFileDialog.DialogLabel(QFileDialog.LookIn)
        filename_label = QFileDialog.DialogLabel(QFileDialog.FileName)
        filetype_label = QFileDialog.DialogLabel(QFileDialog.FileType)
        fname.setLabelText(looking_label, FILEBROWSER_SAVE_FOLDER_LOOKIN)
        fname.setLabelText(filename_label, FILEBROWSER_SAVE_FOLDER_FOLDERNAME)
        fname.setLabelText(filetype_label, FILEBROWSER_SAVE_FOLDER_FOLDERTYPE)
        fname.setOption(QFileDialog.ShowDirsOnly)

        if fname.exec_():
            filename = fname.selectedFiles()[0]
            self.save_folder_editline.setText(filename)
コード例 #6
0
ファイル: mclub.py プロジェクト: Jacksonville/mc_mover
 def destination_chooser(self):
     """Show folder chooser dialog and update lblDestPath with path selected.
     Input:
         None
     Output:
         None"""
     dialog = QFileDialog()
     dialog.setFileMode(QFileDialog.Directory)
     dialog.setOption(QFileDialog.ShowDirsOnly)
     dialog.exec_()
     self.lblDestPath.setEnabled(True)
     self.lblDestPath.setText(os.path.abspath(dialog.directory().absolutePath()))
     self.update_table_view()
     self.copyButton.setEnabled(True)
コード例 #7
0
 def destination_chooser(self):
     """Show folder chooser dialog and update lblDestPath with path selected.
     Input:
         None
     Output:
         None"""
     dialog = QFileDialog()
     dialog.setFileMode(QFileDialog.Directory)
     dialog.setOption(QFileDialog.ShowDirsOnly)
     dialog.exec_()
     self.lblDestPath.setEnabled(True)
     self.lblDestPath.setText(
         os.path.abspath(dialog.directory().absolutePath()))
     self.update_table_view()
     self.copyButton.setEnabled(True)
コード例 #8
0
ファイル: menu.py プロジェクト: team-soran/noisy
class ImportDirAction(QAction):
    def __init__(self, w):
        super(ImportDirAction, self).__init__(
            QIcon('exit.png'), u'&음악 폴더 지정', w)
        self.files = []
        self.setShortcut('Ctrl+O')
        self.dialog = QFileDialog(w)
        self.dialog.setFileMode(QFileDialog.Directory)
        self.dialog.setOption(QFileDialog.ShowDirsOnly)
        self.triggered.connect(self.choose_dir)

    def choose_dir(self):
        if self.dialog.exec_():
            config = NoisyConfig()
            for dir in self.dialog.selectedFiles():
                config.dir = dir
コード例 #9
0
 def importF(self):
     fileBrowser = QFileDialog()
     fileBrowser.setFileMode(QFileDialog.Directory)
     fileBrowser.setViewMode(QFileDialog.Detail)
     fileBrowser.setOption(QFileDialog.ShowDirsOnly, True)
     if fileBrowser.exec_():
         dir = fileBrowser.selectedFiles()
     else:
         print "Cancelled"
         return
     print "Copying data from " + str(dir[0])
     files = os.listdir(str(dir[0]))
     copyOn = True
     print files
     for file in files:
         copyOn = True
         if file.endswith(".json"):
             if os.path.exists(
                     os.path.join(json_reader.buildPath("data"), file)):
                 if popup(
                         "File " + file[:len(file) - 5] +
                         " already exists. Overwrite?", "Warning"):
                     os.remove(json_reader.buildPath("data/" + file))
                 else:
                     copyOn = False
             if copyOn:
                 print "Copying valid file " + file
                 copy(os.path.join(str(dir[0]), file),
                      json_reader.buildPath("data"))
                 if "_link" not in file:
                     try:  #Ugly AF
                         json_reader.readOne(file[:len(file) - 5])
                         json_reader.writeCharNames(file[:len(file) - 5])
                     except:
                         print "Not a Character"
                         try:
                             json_reader.readP(file[:len(file) - 5])
                             json_reader.writePerNames(file[:len(file) - 5])
                         except Exception as e:
                             print "Not a Persona"
                             print e
     print "Successfully copied files"
     popup("Files imported successfully!", "Information")
コード例 #10
0
ファイル: admin_gui.py プロジェクト: wiz21b/koi
    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()
コード例 #11
0
 def export(self):
     fileBrowser = QFileDialog()
     fileBrowser.setFileMode(QFileDialog.Directory)
     fileBrowser.setViewMode(QFileDialog.Detail)
     fileBrowser.setOption(QFileDialog.ShowDirsOnly, True)
     if fileBrowser.exec_():
         dir = fileBrowser.selectedFiles()
     else:
         print "Cancelled"
         return
     print "Copying data to " + str(dir[0]) + "/exportdata"
     try:
         copytree(json_reader.buildPath("data"),
                  str(dir[0]) + "/exportdata")
     except Exception as e:
         print e
         popup(
             "Error in copying files. There is a file in the selected directory that has the same name as a Story Creator file.\n\nFiles are copied to "
             + str(dir[0]) + "/exportdata" +
             ". Please ensure this directory does not already exist.",
             "Critical")
         return
     print "Successfully copied files"
     popup("Files exported successfully!", "Information")