Hi all,
I'm using Python 2.6.7, wxPython 2.9.4.0, and py2app 0.7.3 on OS X 10.7.5. However, I have reason to believe the same issues occurs with Python 2.6.6, wxPython 2.8.12.0, and bundlebuilder.
In my application, I use wxProcess to call FFMpeg to do media conversion. I recently noticed that once I have opened a wxFileDialog, my FFMpeg call stops working with Unicode file names, that is, those with accented characters. I found this to be true when I had used py2app to package my application into a distributable bundle, but not when I am running from source code. And only on OS X, not Windows.
I have created a radically simplified sample app to demonstrate the underlying problem.
Test.py, the main program, shows two buttons. One calls up a test window (described next) and the other simply opens a wxFileDialog. This wxFileDialog doesn't DO anything, but it doesn't need to.
MediaConvertTest.py shows a TextCtrl with unicode text sample in it and automatically calls a very simple OS call using wxProcess. This call simply passes the unicode text sample to the OS's "echo" command and reads the result. The unicode text sample is encoded to utf-8 during the wxProcess call.
setup_TEST.py is a py2app setup script for packaging test.py. "python setup_TEST.py py2app", of course.
Build and run test.app on OS X. (The problem doesn't occur on Windows.) Press the Open Test Window button. You see that echo is called, and what is returned is a string of length 9 with the utf-8-encoded string representation of the unicode test sample. This is exactly what I expect.
Close the Test Window. Now press the Open a File Dialog button and press Cancel on the File Dialog. We've done nothing but open a wxFileDialog and closed it again.
Now press Open Test Window again. It, of course, does exactly the same thing it did before. But this time, it returns a string of length 8, and the unicode character in our unicode text sample is NOT encoded using utf8. We get character 246, which is the correct character for the unencoded unicode character, what we get with unichr(246), instead of the utf8-encoded character combination chr(195) + chr(182) for that character. I want to re-iterate, we have a STRING object here, not a unicode object, with an unencoded unicode character in it. Even though I explicitly encode the unicode sample text to a utf-8 string as part of the wxProcess call.
You can run from source code and you won't see this. You can run the test repeatedly without opening the File Dialog and you won't see this. You will only see this when you've built an app bundle and have opened a wxFileDialog. So using the wxFileDialog in a bundled app somehow alters the way character encoding is handled, at least when using wxProcess to interact with the operating system. Encoding the text sample before the process call doesn't change the results.
For me, the practical implication is that I can't access my FFMpeg program to convert files with unicode characters in the file names any more once a wxFileDialog call has been made somewhere in my program.
Can anyone suggest a work-around?
Thanks for your time,
David
Test.zip (4.44 KB)