python类QFileDialog()的实例源码

gui.py 文件源码 项目:dottorrent-gui 作者: kz26 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def createTorrent(self):
        if os.path.isfile(self.inputEdit.text()):
            save_fn = os.path.splitext(
                os.path.split(self.inputEdit.text())[1])[0] + '.torrent'
        else:
            save_fn = self.inputEdit.text().split(os.sep)[-1] + '.torrent'
        if self.last_output_dir and os.path.exists(self.last_output_dir):
            save_fn = os.path.join(self.last_output_dir, save_fn)
        fn = QtWidgets.QFileDialog.getSaveFileName(
            self.MainWindow, 'Save torrent', save_fn,
            filter=('Torrent file (*.torrent)'))[0]
        if fn:
            self.last_output_dir = os.path.split(fn)[0]
            self.creation_thread = CreateTorrentQThread(
                self.torrent,
                fn)
            self.creation_thread.started.connect(
                self.creation_started)
            self.creation_thread.progress_update.connect(
                self._progress_update)
            self.creation_thread.finished.connect(
                self.creation_finished)
            self.creation_thread.onError.connect(
                self._showError)
            self.creation_thread.start()
notepad.py 文件源码 项目:notepad 作者: lfsando 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def save_dialog(self):

        try:
            save_dialog = QtWidgets.QFileDialog()
            save_dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave)
            file_path = save_dialog.getSaveFileName(self, 'Save as... File', './',
                                                    filter='All Files(*.*);; Text Files(*.txt)')

            if file_path[0]:
                self.file_path = file_path
                file_open = open(self.file_path[0], 'w')
                self.file_name = (self.file_path[0].split('/'))[-1]
                self.statusBar().showMessage('Saved at: {}'.format(self.file_path[0]))
                self.setWindowTitle("{} - Notepad".format(self.file_name))
                with file_open:
                    file_open.write(self.text_widget.toPlainText())
                    self.need_saving(False)

        except FileNotFoundError as why:
            self.error_box(why)
            pass
gui.py 文件源码 项目:dottorrent-gui 作者: kz26 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def export_profile(self):

        fn = QtWidgets.QFileDialog.getSaveFileName(
            self.MainWindow, 'Save profile', self.last_output_dir,
            filter=('JSON configuration file (*.json)'))[0]
        if fn:
            exclude = self.excludeEdit.toPlainText().strip().splitlines()
            trackers = self.trackerEdit.toPlainText().strip().split()
            web_seeds = self.webSeedEdit.toPlainText().strip().split()
            private = self.privateTorrentCheckBox.isChecked()
            compute_md5 = self.md5CheckBox.isChecked()
            source = self.sourceEdit.text()
            data = {
                'exclude': exclude,
                'trackers': trackers,
                'web_seeds': web_seeds,
                'private': private,
                'compute_md5': compute_md5,
                'source': source
            }
            with open(fn, 'w') as f:
                json.dump(data, f, indent=4, sort_keys=True)
            self._statusBarMsg("Profile saved to " + fn)
gui.py 文件源码 项目:dottorrent-gui 作者: kz26 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def import_profile(self):
        fn = QtWidgets.QFileDialog.getOpenFileName(
            self.MainWindow, 'Open profile', self.last_input_dir,
            filter=('JSON configuration file (*.json)'))[0]
        if fn:
            with open(fn) as f:
                data = json.load(f)
            exclude = data.get('exclude', [])
            trackers = data.get('trackers', [])
            web_seeds = data.get('web_seeds', [])
            private = data.get('private', False)
            compute_md5 = data.get('compute_md5', False)
            source = data.get('source', '')
            try:
                self.excludeEdit.setPlainText(os.linesep.join(exclude))
                self.trackerEdit.setPlainText(os.linesep.join(trackers))
                self.webSeedEdit.setPlainText(os.linesep.join(web_seeds))
                self.privateTorrentCheckBox.setChecked(private)
                self.md5CheckBox.setChecked(compute_md5)
                self.sourceEdit.setText(source)
            except Exception as e:
                self._showError(str(e))
                return
            self._statusBarMsg("Profile {} loaded".format(
                os.path.split(fn)[1]))
wb_pick_path_dialogs.py 文件源码 项目:scm-workbench 作者: barry-scott 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def pickExecutable( parent, executable ):
    file_browser = QtWidgets.QFileDialog( parent )
    file_browser.setFileMode( file_browser.ExistingFile )
    file_browser.setOption( file_browser.ReadOnly, True )
    file_browser.setOption( file_browser.DontResolveSymlinks, True )
    file_browser.setViewMode( file_browser.Detail )
    # Without Readable will not return a Executable image
    file_browser.setFilter( QtCore.QDir.Files|QtCore.QDir.Executable|QtCore.QDir.Readable )

    if executable is not None and executable.name != '':
        file_browser.setDirectory( str( executable.parent ) )
        file_browser.selectFile( str( executable.name ) )

    else:
        file_browser.setDirectory( str(wb_platform_specific.getDefaultExecutableFolder()) )

    if file_browser.exec_():
        all_files = file_browser.selectedFiles()
        assert len(all_files) == 1
        return all_files[0]

    else:
        return None
main.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _select_file(self):
        graphical_image_filters = [' '.join(el) for el in self._extension_filters] + ['All files (*)']

        open_file, used_filter = QFileDialog().getSaveFileName(caption='Select the output file',
                                                               filter=';;'.join(graphical_image_filters))

        if not any(open_file.endswith(el[0]) for el in self._extension_filters):
            extension_from_filter = list(filter(lambda v: ' '.join(v) == used_filter, self._extension_filters))
            if extension_from_filter:
                extension = extension_from_filter[0][0]
            else:
                extension = self._extension_filters[0][0]

            open_file += '.{}'.format(extension)

        if open_file:
            self.outputFile_box.setText(open_file)
            self._update_ok_button()
main_window.py 文件源码 项目:Enibar 作者: ENIB 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def csv_import_fnc(self, _):
        """ Open a CsvImportWindow
        """
        if self.try_locking("notes_management"):
            self._close_window()
            path, _ = QtWidgets.QFileDialog().getOpenFileName(
                self,
                "Imported",
                "",
                "CSV Files (*.csv)"
            )

            if path:
                try:
                    self.cur_window = CsvImportWindow(path)
                    self._connect_window("notes_management")
                except csv.Error:
                    api.redis.unlock("notes_management")
            else:
                api.redis.unlock("notes_management")
Visualizer.py 文件源码 项目:Visualization 作者: nwrush 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _save_visualization(self):
        current_tab = self._tabs[self.ui.tabWidget.currentIndex()]
        if isinstance(current_tab, PreprocessorController):
            return

        dialog = QtWidgets.QFileDialog(self)
        dialog.setFileMode(QtWidgets.QFileDialog.AnyFile)
        dialog.setNameFilters(["Processed data file (*.p)", "All Files (*)"])
        dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave)
        dialog.setDefaultSuffix(".p")
        dialog.exec()

        fname = dialog.selectedFiles()[0]
        success = current_tab.save_data(fname)
        if not success:
            QtWidgets.QMessageBox.about(self, "Save Error",
                                        "An error occured saving the file\nCheck the log for more details")
mainframe.py 文件源码 项目:fomod-validator 作者: GandaG 项目源码 文件源码 阅读 102 收藏 0 点赞 0 评论 0
def path_button_clicked(self):
        """
        Called when the user clicks the button next to the line edit - the path choosing button.

        First checks if there is text in the line edit and uses that for the initial search directory. If not, then it
        defaults to the user $HOME directory.

        Once a directory is chosen and the user has not clicked cancel (cancel returns an empty path) it directly sets
        the line edit text.
        """
        open_dialog = QFileDialog()
        if not self.path_text.text():
            button_path = expanduser("~")
        else:
            button_path = self.path_text.text()

        temp_path = open_dialog.getExistingDirectory(self, "Package directory:", button_path)

        if temp_path:
            self.path_text.setText(temp_path)
notepad.py 文件源码 项目:notepad 作者: lfsando 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def open_dialog(self):
        """ Open 'Open Dialog Box' """

        if self.has_changed:
            self.save_box(open=True)

        try:
            self.file_path = QtWidgets.QFileDialog.getOpenFileName(self, 'Open File', './',
                                                         filter="All Files(*.*);;Text Files(*.txt)")

            if self.file_path[0]:
                self.file_name = (self.file_path[0].split('/'))[-1]

                self.setWindowTitle("{} - Notepad".format(self.file_name))

                file_open = open(self.file_path[0], 'r+')
                self.statusBar().showMessage('Open... {}'.format(self.file_path[0]))

                with file_open:
                    content = file_open.read()
                    self.text_widget.setPlainText(content)
                    self.need_saving(False)


        except UnicodeDecodeError as why:
            self.error_box(why)
            pass
gui.py 文件源码 项目:dottorrent-gui 作者: kz26 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def browseInput(self):
        qfd = QtWidgets.QFileDialog(self.MainWindow)
        if self.last_input_dir and os.path.exists(self.last_input_dir):
            qfd.setDirectory(self.last_input_dir)
        if self.inputMode == 'file':
            qfd.setWindowTitle('Select file')
            qfd.setFileMode(QtWidgets.QFileDialog.ExistingFile)
        else:
            qfd.setWindowTitle('Select directory')
            qfd.setFileMode(QtWidgets.QFileDialog.Directory)
        if qfd.exec_():
            fn = qfd.selectedFiles()[0]
            self.inputEdit.setText(fn)
            self.last_input_dir = os.path.split(fn)[0]
            self.initializeTorrent()
gui.py 文件源码 项目:dottorrent-gui 作者: kz26 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def createTorrentBatch(self):
        save_dir = QtWidgets.QFileDialog.getExistingDirectory(
            self.MainWindow, 'Select output directory', self.last_output_dir)
        if save_dir:
            self.last_output_dir = save_dir
            trackers = self.trackerEdit.toPlainText().strip().split()
            web_seeds = self.webSeedEdit.toPlainText().strip().split()
            self.creation_thread = CreateTorrentBatchQThread(
                path=self.inputEdit.text(),
                exclude=self.excludeEdit.toPlainText().strip().splitlines(),
                save_dir=save_dir,
                trackers=trackers,
                web_seeds=web_seeds,
                private=self.privateTorrentCheckBox.isChecked(),
                source=self.sourceEdit.text(),
                comment=self.commentEdit.text(),
                include_md5=self.md5CheckBox.isChecked(),
            )
            self.creation_thread.started.connect(
                self.creation_started)
            self.creation_thread.progress_update.connect(
                self._progress_update_batch)
            self.creation_thread.finished.connect(
                self.creation_finished)
            self.creation_thread.onError.connect(
                self._showError)
            self.creation_thread.start()
controller.py 文件源码 项目:activity-browser 作者: LCA-ActivityBrowser 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def select_bw2_dir_path(self):
        folder_path = QtWidgets.QFileDialog().getExistingDirectory(
            None, "Select a brightway2 database folder")
        # TODO: in case of a directory that does not contain an existing brightway2 database,
        # ask if a new db should be set up
        print(folder_path)
        self.switch_brightway2_dir_path(folder_path)
        return folder_path
file_server.py 文件源码 项目:gui_tool 作者: UAVCAN 项目源码 文件源码 阅读 61 收藏 0 点赞 0 评论 0
def _on_select_path_file(self):
        path = QFileDialog().getOpenFileName(self, 'Add file path to be served by the file server',
                                             os.path.expanduser('~'))
        self._path_bar.setCurrentText(path[0])
file_server.py 文件源码 项目:gui_tool 作者: UAVCAN 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _on_select_path_directory(self):
        path = QFileDialog().getExistingDirectory(self, 'Add directory lookup path for the file server',
                                                  os.path.expanduser('~'))
        self._path_bar.setCurrentText(path)
wb_pick_path_dialogs.py 文件源码 项目:scm-workbench 作者: barry-scott 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def pickFolder( parent, orig_folder ):
    if orig_folder is None or orig_folder == '.':
        orig_folder = wb_platform_specific.getHomeFolder()

    folder = orig_folder

    if folder.exists():
        if not folder.is_dir():
            folder = folder.parent

    else:
        while not orig_folder.exists():
            orig_folder = orig_folder.parent

    file_browser = QtWidgets.QFileDialog( parent )
    file_browser.setFileMode( file_browser.Directory )

    #
    # When ShowDirsOnly is True QFileDialog show a number of
    # bugs:
    # 1. folder double click edits folder name
    # 2. setDirectory does not work, always starts in $HOME
    #
    file_browser.setOption( file_browser.ShowDirsOnly, False )
    file_browser.setOption( file_browser.ReadOnly, True )
    file_browser.setViewMode( file_browser.Detail )
    file_browser.setFilter( QtCore.QDir.Hidden | QtCore.QDir.Dirs )

    file_browser.setDirectory( str( folder ) )
    file_browser.selectFile( str( orig_folder ) )

    if file_browser.exec_():
        all_directories = file_browser.selectedFiles()
        assert len(all_directories) == 1
        return pathlib.Path( all_directories[0] )

    return None
file_browser.py 文件源码 项目:sequana 作者: sequana 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def browse_paired_file(self):
        self.dialog = QW.QFileDialog(self)
        file_path = self.dialog.getOpenFileNames(self,
            "Select a sample", ".", self.filter)[0]

        if not file_path:
            self.set_empty_path()
        elif len(file_path) > 2:
            msg = WarningMessage("You must pick only one sample (1 or 2 files)", self)
            self.set_empty_path()
            msg.exec_()
        else:
            self._set_paired_filenames(file_path)
file_browser.py 文件源码 项目:sequana 作者: sequana 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def browse_file(self):
        try:
            # Set the default path to the previous choice
            if self.paths:
                default = self.paths
            else: 
                default = "."
            file_path = QW.QFileDialog.getOpenFileNames(self, 
                "Single File", default,  self.filter)[0][0]
            self.set_filenames(file_path)
        except IndexError:
            self.set_empty_path()
file_browser.py 文件源码 项目:sequana 作者: sequana 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, parent, title, directory, file_filter):
        super().__init__(parent)
        self.setAcceptMode(QW.QFileDialog.AcceptOpen)
        self.setFileMode(QW.QFileDialog.Directory)
        self.setViewMode(QW.QFileDialog.Detail)
        self.setWindowTitle(title)
        self.setDirectory(directory)
        self.setNameFilter(file_filter)
main.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _set_qdialog_basedir(self):
        if not self._qdialog_basedir_set:
            data = self._controller.get_model().get_data()
            for map_name, file_path in data.get_file_paths().items():
                if file_path:
                    QFileDialog().setDirectory(file_path)
                    self._qdialog_basedir_set = True
                    return
main.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _add_new_files(self):
        new_files = QFileDialog(self).getOpenFileNames(caption='Nifti files',
                                                       filter=';;'.join(image_files_filters))
        if new_files[0]:
            self._add_new_maps(new_files[0])
main.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 52 收藏 0 点赞 0 评论 0
def _save_settings(self):
        """Save the current settings as a text file.

        Args:
            file_name: the filename to write to
        """
        current_model = self._controller.get_model()

        config_file = ['conf (*.conf)', 'All files (*)']
        file_name, used_filter = QFileDialog().getSaveFileName(caption='Select the GUI config file',
                                                               filter=';;'.join(config_file))
        if file_name:
            with open(file_name, 'w') as f:
                f.write(current_model.get_config().to_yaml())
main.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _load_settings(self):
        config_file = ['conf (*.conf)', 'All files (*)']
        file_name, used_filter = QFileDialog().getOpenFileName(caption='Select the GUI config file',
                                                               filter=';;'.join(config_file))
        if file_name:
            with open(file_name, 'r') as f:
                try:
                    self._controller.apply_action(NewConfigAction(MapPlotConfig.from_yaml(f.read())))
                except yaml.parser.ParserError:
                    pass
                except yaml.scanner.ScannerError:
                    pass
                except ValueError:
                    pass
generate_brain_mask_tab.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _select_protocol(self):
        initial_dir = self._shared_state.base_dir
        if self.selectedProtocolText.text() != '':
            initial_dir = self.selectedProtocolText.text()

        open_file, used_filter = QFileDialog().getOpenFileName(
            caption='Select the protocol', directory=initial_dir,
            filter=';;'.join(protocol_files_filters))

        if os.path.isfile(open_file):
            self.selectedProtocolText.setText(open_file)
            self._shared_state.base_dir = os.path.dirname(open_file)
generate_brain_mask_tab.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _select_output(self):
        initial_dir = self._shared_state.base_dir
        if self.selectedOutputText.text() != '':
            initial_dir = self.selectedOutputText.text()

        output_file_name, used_filter = QFileDialog().getSaveFileName(
            caption='Select the output file', directory=initial_dir,
            filter=';;'.join(image_files_filters))

        if output_file_name:
            self.selectedOutputText.setText(output_file_name)
generate_roi_mask_tab.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _select_mask(self):
        initial_dir = self._shared_state.base_dir
        if self.selectedMaskText.text() != '':
            initial_dir = self.selectedMaskText.text()

        open_file, used_filter = QFileDialog().getOpenFileName(
            caption='Select the brain mask', directory=initial_dir,
            filter=';;'.join(image_files_filters))

        if os.path.isfile(open_file):
            self.selectedMaskText.setText(open_file)
            self.mask_file_changed()
            self._shared_state.base_dir = os.path.dirname(open_file)
generate_roi_mask_tab.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _select_output_file(self):
        output_file_name, used_filter = QFileDialog().getSaveFileName(
            caption='Select the output file', directory=self._shared_state.base_dir,
            filter=';;'.join(image_files_filters))

        if output_file_name:
            self.selectedOutputFileText.setText(output_file_name)
fit_model_tab.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _select_dwi(self):
        initial_dir = self._shared_state.base_dir
        if self.selectedDWI.text() != '':
            initial_dir = self.selectedDWI.text()

        open_file, used_filter = QFileDialog().getOpenFileName(
            caption='Select the 4d (diffusion weighted) image', directory=initial_dir,
            filter=';;'.join(image_files_filters))

        if os.path.isfile(open_file):
            self.selectedDWI.setText(open_file)
            self._input_data_info.dwi = open_file
            self._shared_state.base_dir = os.path.dirname(open_file)
            self.update_output_folder_text()
fit_model_tab.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _select_protocol(self):
        initial_dir = self._shared_state.base_dir
        if self.selectedProtocol.text() != '':
            initial_dir = self.selectedProtocol.text()

        open_file, used_filter = QFileDialog().getOpenFileName(
            caption='Select the protocol', directory=initial_dir,
            filter=';;'.join(protocol_files_filters))

        if os.path.isfile(open_file):
            self.selectedProtocol.setText(open_file)
            self._input_data_info.protocol = open_file
            self._shared_state.base_dir = os.path.dirname(open_file)
fit_model_tab.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _select_output(self):
        initial_dir = self._shared_state.base_dir
        if self.selectedOutputFolder.text() != '':
            initial_dir = self.selectedOutputFolder.text()

        output_file_name = QFileDialog().getExistingDirectory(
            caption='Select the output folder', directory=initial_dir)

        if output_file_name:
            self.selectedOutputFolder.setText(output_file_name)


问题


面经


文章

微信
公众号

扫码关注公众号