file_picker.py 文件源码

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

项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码
def on_browser_button(self, evt):
        cur_entry = self.current_textctrl_GetValue()
        if len(cur_entry) == 0:
            cur_entry = self.default_entry
        cur_entry = os.path.abspath(os.path.expanduser(cur_entry))
        cur_entry_parts = [a for a in ['/'] + cur_entry.split('/') if len(a) > 0]
        while (len(cur_entry_parts) >= 1 and
               not (os.path.isdir(os.path.join(*cur_entry_parts)) or
                    os.path.isfile(os.path.join(*cur_entry_parts)))):
            cur_entry_parts = cur_entry_parts[:-1]
        if len(cur_entry_parts) > 1:
            cur_entry = os.path.join(*cur_entry_parts)
        else:
            cur_entry = os.path.expanduser('~')
        if os.path.isdir(cur_entry):
            cur_basename = ''
            cur_dirname = cur_entry
        else:
            cur_basename = os.path.basename(cur_entry)
            cur_dirname = os.path.dirname(cur_entry)
        if self.is_files_not_dirs:
            dlg = wx.FileDialog(self, "Choose a file:", style=wx.DD_DEFAULT_STYLE,
                                defaultDir=cur_dirname, defaultFile=cur_basename, wildcard=self.allowed_extensions)
            # TODO: defaultFile is not being set to cur_basename in the dialog box
        else:
            dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE, defaultPath=cur_dirname)
        if dlg.ShowModal() == wx.ID_OK:
            self._on_load(dlg.GetPath())
        dlg.Destroy()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号