當前位置: 首頁>>代碼示例>>Python>>正文


Python QFileDialog.getOpenFileNames方法代碼示例

本文整理匯總了Python中qtpy.QtWidgets.QFileDialog.getOpenFileNames方法的典型用法代碼示例。如果您正苦於以下問題:Python QFileDialog.getOpenFileNames方法的具體用法?Python QFileDialog.getOpenFileNames怎麽用?Python QFileDialog.getOpenFileNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在qtpy.QtWidgets.QFileDialog的用法示例。


在下文中一共展示了QFileDialog.getOpenFileNames方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: do_load_bragg_file

# 需要導入模塊: from qtpy.QtWidgets import QFileDialog [as 別名]
# 或者: from qtpy.QtWidgets.QFileDialog import getOpenFileNames [as 別名]
def do_load_bragg_file(main_window):
    """
    Load Bragg files including GSAS, NeXus, 3-column ASCii.
    """
    # get file
    ext = 'GSAS (*.gsa *.gda *.gss);;Processed Nexus (*.nxs);;dat (*.dat);;All (*.*)'

    # get default dir
    if main_window._currDataDir is None:
        default_dir = os.getcwd()
    else:
        default_dir = getDefaultDir(main_window, sub_dir='GSAS')

    bragg_file_names = QFileDialog.getOpenFileNames(main_window, 'Choose Bragg File', default_dir, ext)
    if isinstance(bragg_file_names, tuple):
        bragg_file_names = bragg_file_names[0]
    if bragg_file_names is None or bragg_file_names == '' or len(bragg_file_names) == 0:
        return
    bragg_file_names = [str(bragg_file_name) for bragg_file_name in bragg_file_names]

    # update stored data directory
    try:
        main_window._currDataDir = os.path.split(os.path.abspath(bragg_file_names[0]))[0]
    except IndexError as index_err:
        err_message = 'Unable to get absolute path of {0} due to {1}'.format(bragg_file_names, index_err)
        print(err_message)

    check_in_fixed_dir_structure(main_window, sub_dir='GSAS')

    # load file
    try:
        gss_ws_names = list()
        for bragg_file_name in bragg_file_names:
            gss_ws_name, bank_angles = main_window._myController.load_bragg_file(bragg_file_name)
            gss_ws_names.append(gss_ws_name)
            banks_list = list()
            for i, angle in enumerate(bank_angles):
                banks_list.append('Bank {} - {}'.format(i + 1, angle))

            # add to tree
            main_window.rietveld_ui.treeWidget_braggWSList.add_bragg_ws_group(gss_ws_name, banks_list)

        # get plot mode
        if len(bragg_file_names) == 1:
            main_window.rietveld_ui.graphicsView_bragg.set_to_single_gss(True)
            main_window.rietveld_ui.radioButton_multiBank.setChecked(True)
            main_window.rietveld_ui.radioButton_multiGSS.setChecked(False)
        else:
            main_window.rietveld_ui.graphicsView_bragg.set_to_single_gss(False)
            main_window.rietveld_ui.radioButton_multiBank.setChecked(False)
            main_window.rietveld_ui.radioButton_multiGSS.setChecked(True)

        multi_bank_mode = main_window.rietveld_ui.radioButton_multiBank.isChecked()

        if multi_bank_mode:
            # single-GSS/multi-bank mode
            # rename bank
            for bank_id in main_window._braggBankWidgets:
                bank_check_box = main_window._braggBankWidgets[bank_id]

                if bank_id > len(bank_angles) or bank_angles[bank_id - 1] is None:
                    bank_check_box.setText('Bank %d' % bank_id)
                else:
                    bank_check_box.setText('Bank %.1f' % bank_angles[bank_id - 1])
                    # END-IF
                # END-IF-ELSE
            # END-FOR

            # clear all previous lines
            main_window.rietveld_ui.graphicsView_bragg.reset()
        # END-IF

        # banks
        main_window._onCanvasGSSBankList = get_bragg_banks_selected(main_window)
        if len(main_window._onCanvasGSSBankList) == 0:
            # select bank 1 as default
            main_window._noEventBankWidgets = True
            main_window.rietveld_ui.checkBox_bank1.setChecked(True)
            main_window._noEventBankWidgets = False
            main_window._onCanvasGSSBankList = get_bragg_banks_selected(main_window)

        # while in multiple-gss mode, no change will be made on the canvas at all

        # prepare to plot new Bragg
        plot_data_dict = dict()
        for gss_ws_name in gss_ws_names:
            plot_data_dict[gss_ws_name] = main_window._onCanvasGSSBankList[:]

        # plot
        # FIXME/ISSUE/NOW - get a summary on calling to plot_banks
        main_window.rietveld_ui.graphicsView_bragg.plot_banks(plot_data_dict, main_window._currBraggXUnit)

        # reset unit
        reset_bragg_data_range(main_window, main_window._currBraggXUnit)

    except RuntimeError as e:
        print('Encountered exception')
        print(e)

        main_window.setStyleSheet("QStatusBar{padding-left:8px;color:red;font-weight:bold;}")
#.........這裏部分代碼省略.........
開發者ID:neutrons,項目名稱:FastGR,代碼行數:103,代碼來源:event_handler.py


注:本文中的qtpy.QtWidgets.QFileDialog.getOpenFileNames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。