当前位置: 首页>>代码示例>>Python>>正文


Python QFileDialog.getOpenFileName方法代码示例

本文整理汇总了Python中qtpy.QtWidgets.QFileDialog.getOpenFileName方法的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog.getOpenFileName方法的具体用法?Python QFileDialog.getOpenFileName怎么用?Python QFileDialog.getOpenFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qtpy.QtWidgets.QFileDialog的用法示例。


在下文中一共展示了QFileDialog.getOpenFileName方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open_file_dialog

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def open_file_dialog(line_edit, filter_text, directory):
    file_name = QFileDialog.getOpenFileName(None, 'Open', directory, filter_text)
    if not file_name:
        return
    if isinstance(file_name, tuple):
        file_name = file_name[0]
    line_edit.setText(file_name)
开发者ID:samueljackson92,项目名称:mantid,代码行数:9,代码来源:gui_common.py

示例2: browse_file

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
    def browse_file(self, type='calibration'):

        if type == 'calibration':
            _current_folder = self.parent.calibration_folder
            _filter = "calib (*.h5);;all (*.*)"
            _caption = "Select Calibration File"
            _output_ui = self.parent.ui.mantid_calibration_value
        else:
            _current_folder = self.parent.characterization_folder
            _filter = "characterization (*-rietveld.txt);;all (*.*)"
            _caption = "Select Characterization File"
            _output_ui = self.parent.ui.mantid_characterization_value

        _file = QFileDialog.getOpenFileName(parent=self.parent,
                                            filter=_filter,
                                            caption=_caption,
                                            directory=_current_folder)
        if not _file:
            return
        if isinstance(_file, tuple):
            _file = _file[0]

        _output_ui.setText(str(_file))
        _path = os.path.dirname(str(_file))

        if type == 'calibration':
            self.parent.calibration_current_folder = _path
        else:
            self.parent.characterization_current_folder = _path
开发者ID:neutrons,项目名称:FastGR,代码行数:31,代码来源:browse_file_folder_handler.py

示例3: open_file

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
 def open_file(self):
     # todo: when more file types are added this should
     # live in its own type
     filepath, _ = QFileDialog.getOpenFileName(self, "Open File...", "", "Python (*.py)")
     if not filepath:
         return
     self.editor.open_file_in_new_tab(filepath)
开发者ID:DanNixon,项目名称:mantid,代码行数:9,代码来源:mainwindow.py

示例4: request_config_file_name

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
    def request_config_file_name(self, open_flag=True):
        _caption = 'Select or Define a Configuration File Name'
        _current_folder = self.parent.configuration_folder
        if open_flag:
            _file = QFileDialog.getOpenFileName(parent=self.parent,
                                                filter='config (*.cfg)',
                                                caption=_caption,
                                                directory=_current_folder)
            if isinstance(_file, tuple):
                _file = _file[0]
        else:
            _file, _ = get_save_file(parent=self.parent,
                                     filter={'config (*.cfg)':'cfg'},
                                     caption=_caption,
                                     directory=_current_folder)

        if not _file:
            self.filename = ''
            return

        _new_path = os.path.dirname(_file)
        self.parent.configuration_folder = _new_path
        o_file_handler = FileHandler(filename=_file)
        o_file_handler.check_file_extension(ext_requested='cfg')
        self.filename = o_file_handler.filename
开发者ID:neutrons,项目名称:FastGR,代码行数:27,代码来源:config_file_name_handler.py

示例5: _on_load_from_file

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
    def _on_load_from_file(self):
        filename = QFileDialog.getOpenFileName(
            self, caption='Load Model',
            filter=SPECVIZ_MODEL_FILE_FILTER)[0]
        if not filename:
            return

        self._load_model_from_file(filename)
开发者ID:nmearl,项目名称:specviz,代码行数:10,代码来源:model_editor.py

示例6: grouping_button

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
 def grouping_button(self, key=None, grouping_type='input'):
     message = "Select {} grouping".format(grouping_type)
     ext = 'Grouping (*.txt);;All (*.*)'
     file_name = QFileDialog.getOpenFileName(self.main_window,
                                             message,
                                             self.main_window.calibration_folder,
                                             ext)
     if file_name is None:
         return
开发者ID:neutrons,项目名称:FastGR,代码行数:11,代码来源:table_row_handler.py

示例7: browse_File

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
    def browse_File(self):
        """ Open a file dialog to get file
        """
        filename = QFileDialog.getOpenFileName(self, 'Input File Dialog',
                                               self._defaultdir, "Data (*.nxs *.dat);;All files (*)")
        if isinstance(filename, tuple):
            filename = filename[0]

        self.ui.lineEdit.setText(filename)

        Logger("Filter_Events").information('Selected file: "{}"'.format(filename))
开发者ID:mantidproject,项目名称:mantid,代码行数:13,代码来源:eventFilterGUI.py

示例8: show_opencfg_dlg

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
    def show_opencfg_dlg(self):
        # show file dialog
        filename, _ = QFileDialog.getOpenFileName(
            self, self.tr("Open configuration file..."),
            directory=os.path.expanduser("~"),
            filter=self.tr("Json file (*.json);;All files (*.*)")
        )

        # load config file
        if filename:
            self.load_file(filename)
开发者ID:MrLeeh,项目名称:jsonwatchqt,代码行数:13,代码来源:mainwindow.py

示例9: load_tool

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
    def load_tool(self, checked):
        try:
            curr_dir = os.path.dirname(self.current_file())
        except IndexError:
            logger.error("The display manager does not have a display loaded. Suggesting current work directory.")
            curr_dir = os.getcwd()
        filename = QFileDialog.getOpenFileName(self, 'Load tool...', curr_dir, 'PyDM External Tool Files (*_tool.py)')
        filename = filename[0] if isinstance(filename, (list, tuple)) else filename

        if filename:
            filename = str(filename)
            tools.install_external_tool(filename)
            self.update_tools_menu()
开发者ID:slaclab,项目名称:pydm,代码行数:15,代码来源:main_window.py

示例10: _file_open

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
    def _file_open(self, *argv):
        """
            File chooser for loading UI parameters
        """
        fname = QFileDialog.getOpenFileName(self, "Reduction settings - Choose a settings file",
                                            self._last_directory,
                                            "Settings files (*.xml)")
        if not fname:
            return

        if isinstance(fname, tuple):
            fname = fname[0]
        fname = str(QFileInfo(fname).filePath())
        # Store the location of the loaded file
        self._last_directory = str(QFileInfo(fname).path())
        self.open_file(fname)
开发者ID:samueljackson92,项目名称:mantid,代码行数:18,代码来源:reduction_application.py

示例11: browse_file

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
    def browse_file(self):
        _ascii_file = QFileDialog.getOpenFileName(parent=self.parent_no_ui,
                                                  caption='Select file to display',
                                                  directory=self.current_folder)
        if not _ascii_file:
            return
        if isinstance(_ascii_file, tuple):
            _ascii_file = _ascii_file[0]
        _ascii_file = str(_ascii_file)

        o_file_handler = FileHandler(filename=_ascii_file)
        o_file_handler.retrieve_contain()
        text_contain = o_file_handler.file_contain

        o_preview = PreviewAsciiWindow(parent=self.parent_no_ui, text=text_contain, filename=_ascii_file)
        o_preview.show()
开发者ID:neutrons,项目名称:FastGR,代码行数:18,代码来源:step3_gui_handler.py

示例12: openfilecheck

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def openfilecheck(open_mode, file_name='', file_ext='', file_type=''):
    """
    :param open_mode: {str} method to open the file (e.g., 'rb' for binary read only)
    :param file_name: [optional] {str} full path of file to open
    :param file_ext:  [optional] {str} file extension (e.g., '.nev')
    :param file_type: [optional] {str} file type for use when browsing for file (e.g., 'Blackrock NEV Files')
    :return: {file} opened file
    """

    while True:
        if not file_name:  # no file name passed
            from qtpy.QtWidgets import QFileDialog, QApplication
            # Ask user to specify a file path or browse
            file_name = input("Enter complete " + file_ext + " file path or hit enter to browse: ")

            if not file_name:
                if 'app' not in locals(): app = QApplication([])
                if not file_ext: file_type = 'All Files'
                file_name = QFileDialog.getOpenFileName(QFileDialog(), "Select File", getcwd(),
                                                        file_type + " (*" + file_ext + ")")

        # Ensure file exists (really needed for users type entering)
        if path.isfile(file_name):
            # Ensure given file matches file_ext
            if file_ext:
                _, fext = path.splitext(file_name)

                # check for * in extension
                if file_ext[-1] == '*': test_extension = file_ext[:-1]
                else:                   test_extension = file_ext

                if fext[0:len(test_extension)] != test_extension:
                    file_name = ''
                    print("\n*** File given is not a " + file_ext + " file, try again ***\n")
                    continue
            break
        else:
            file_name = ''
            print("\n*** File given does exist, try again ***\n")

    print('\n' + file_name.split('/')[-1] + ' opened')
    return open(file_name, open_mode)
开发者ID:carmenalab,项目名称:brain-python-interface,代码行数:44,代码来源:brMiscFxns.py

示例13: open_file_action

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
    def open_file_action(self, checked):
        modifiers = QApplication.keyboardModifiers()
        try:
            curr_file = self.current_file()
            folder = os.path.dirname(curr_file)
        except IndexError:
            folder = os.getcwd()

        filename = QFileDialog.getOpenFileName(self, 'Open File...', folder, 'PyDM Display Files (*.ui *.py)')
        filename = filename[0] if isinstance(filename, (list, tuple)) else filename

        if filename:
            filename = str(filename)
            try:
                if modifiers == Qt.ShiftModifier:
                    self.app.new_window(filename)
                else:
                    self.open_file(filename)
            except (IOError, OSError, ValueError, ImportError) as e:
                self.handle_open_file_error(filename, e)
开发者ID:slaclab,项目名称:pydm,代码行数:22,代码来源:main_window.py

示例14: _import

# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileName [as 别名]
    def _import(self):
        _current_folder = self.main_window.current_folder
        [_table_file, _] = QFileDialog.getOpenFileName(parent=self.main_window,
                                                       caption="Select File",
                                                       directory=_current_folder,
                                                       filter=("text (*.txt);; All Files (*.*)"))

        if not _table_file:
            return
        if isinstance(_table_file, tuple):
            _table_file = _table_file[0]
        new_path = os.path.dirname(_table_file)
        self.main_window.current_folder = new_path

        self._clear_table()

        _import_handler = ImportTable(filename=_table_file, parent=self.main_window)
        _import_handler.run()

        _pop_back_wdg = PopulateBackgroundWidgets(main_window=self.main_window)
        _pop_back_wdg.run()

        _o_gui = addie.processing.idl.step2_gui_handler.Step2GuiHandler(main_window=self.main_window)
        _o_gui.check_gui()
开发者ID:neutrons,项目名称:FastGR,代码行数:26,代码来源:table_handler.py


注:本文中的qtpy.QtWidgets.QFileDialog.getOpenFileName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。