mzGUI_standalone.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:multiplierz 作者: BlaisProteomics 项目源码 文件源码
def file_chooser(title='Choose a file:', default_path = '', default_file = '',
                 mode='r', wildcard='*', parent_obj = None):
    """Provides a file chooser dialog and returns the file path(s) when the file(s) is selected.
    mode option provides file dialog type: read single, read multiple, or save single.
    mode = 'r' creates an 'Open' file dialog for single file read.
    mode = 'm' creates an 'Open' file dialog for multiple files read.
    mode = 'w' creates a 'Save' file dialog.

    wildcard option can be specified as "*.xls"

    Example:
    >> file_chooser(title='Choose a file:', mode='r')

    """

    wildcard = "%s|%s" % (wildcard, wildcard)

    style = { 'r': wx.FD_OPEN,
              'm': wx.FD_MULTIPLE,
              'w': wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT }[mode]

    try:
        file_chooser = wx.FileDialog(parent_obj, title, wildcard=wildcard, style=style,
                                     defaultDir = default_path, defaultFile = default_file)
    except wx._core.PyNoAppError:
        app = mzApp()
        app.launch()
        file_chooser = wx.FileDialog(parent_obj, title, wildcard=wildcard, style=style,
                                     defaultDir = default_path, defaultFile = default_file)


    file_name = None
    if file_chooser.ShowModal() == wx.ID_OK:
        if mode == 'm':
            file_name = file_chooser.GetPaths()
        else:
            file_name = file_chooser.GetPath()
    file_chooser.Destroy()

    return file_name
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号