wxPython 文件对话框错误:缺少“|";在通配符字符串中! [英] wxPython file dialog error: missing "|" in the wildcard string!

查看:35
本文介绍了wxPython 文件对话框错误:缺少“|";在通配符字符串中!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows7 上,使用 Python 2.6 和 wxPython 2.8.10.1.我试图让这个打开文件对话框工作,但遇到了一个奇怪的错误.这对我来说似乎是一个有效的通配符字符串,但是每当我选择一个文件并在文件对话框中单击确定"时,我都会得到这个:

I am on Windows7, using Python 2.6 and wxPython 2.8.10.1. I am trying to get this Open File dialog to work but am running into a weird error. This looks like a valid wildcard string to me, but whenever I choose a file and click 'Ok' on the File Dialog, I get this:

Traceback (most recent call last):
File "D:\Projects\python\wxTest.py", line 92, in OnOpen
self.__DoOpen()
File "D:\Projects\python\wxTest.py", line 101, in __DoOpen
if open_dlg.ShowModal() == wx.ID_OK:
File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py", line 711, in       ShowModal
return _windows_.Dialog_ShowModal(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed at 
  ..\..\src\common\filefn.cpp(1746) in wxParseCommonDialogsFilter(): 
  missing '|' in the wildcard string!

当对话框打开时,一切看起来都很好.有什么想法吗?

When the dialog is open everything looks fine. Any ideas?

输入太快,忘记包含有问题的通配符字符串!对不起...

typing too fast, forgot to include the wildcard string in question! sorry...

wcd = "All files(*.*)|*.*|Text files (*.txt)|*.txt|"
open_dlg = wx.FileDialog(self, message='Choose a file', defaultDir=directory, defaultFile='', style=wx.OPEN | wx.CHANGE_DIR)
open_dlg.SetWildcard(wcd)
if open_dlg.ShowModal() == wx.ID_OK:
        path = open_dlg.GetPath()
...

推荐答案

通配符字符串有一种古怪的格式,借鉴自 Win32:

The wildcard string has a quirky format, borrowed from Win32:

Desc1|wildcard1|Desc2|wildcard2 ...

应该有奇数个管道,以便管道分隔的部分形成对、描述和通配符.例如:

There should be an odd number of pipes, so that the pipe-separated pieces form pairs, a description, and a wildcard. For example:

Spreadsheet (*.xls)|*.xls|Plain-old text (*.txt)|*.txt|Random noise|*.dat

请注意,描述通常包含一个括号通配符,只是为了显示目的.

Note that the description often contains a parenthetical wildcard just for display purposes.

您的问题是尾随管道符号.删除它.

Your problem is the trailing pipe symbol. Remove it.

这篇关于wxPython 文件对话框错误:缺少“|";在通配符字符串中!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆