views:

196

answers:

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?

EDIT: 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()
...
+3  A: 

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.

Ned Batchelder
Interesting... so the wxWidgets error message could be improved. It's assuming a pipe symbol is missing, but it's as likely there is one too many!
Peter Hansen