2009-12-23 65 views
2

我在Windows7上,使用Python 2.6和wxPython 2.8.10.1。我试图让这个打开文件对话框工作,但运行到一个奇怪的错误。这看起来像一个有效的通配符字符串给我,但每当我选择一个文件,然后单击“确定”在文件对话框中,我得到这个:wxPython文件对话框错误:缺少“|”在通配符字符串中!

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! 

当对话框打开时一切都看起来不错。有任何想法吗?

编辑:打字太快,忘记包括通配符字符串问题!遗憾...

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() 
... 
+0

你能告诉我们你使用的通配符字符串吗? – 2009-12-23 02:58:07

回答

7

通配符串具有古怪格式,从Win32的借用:

Desc1|wildcard1|Desc2|wildcard2 ... 

应该有奇数个管,以使得管分隔件形成对,一描述和通配符。例如:

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

请注意,该描述通常包含一个括号通配符,仅用于显示目的。

你的问题是拖尾管符号。去掉它。

+0

有趣...所以wxWidgets错误消息可以改善。假设一个管道符号丢失,但它可能有太多! – 2009-12-23 17:06:14