[wxPython-users] ANN: GUI2Exe for wxPython :-D

Kevin Ollivier kevino at theolliviers.com
Sun Apr 1 18:30:31 PDT 2007


Hi Andrea,

On Apr 1, 2007, at 5:36 PM, Andrea Gavana wrote:

[snip]

>
> Yeah, that's my fault, on my machines I still have ansi build... I
> know I know, my bad :-D . By the way, I got rid of the ansi builds and
> installed the unicode one. Well, I don't know if this is the right
> solution or not, but I inserted at the beginning of GUI2Exe.py these
> lines:
>
> # This is *really* ugly
> import sys
> reload(sys)
> sys.setdefaultencoding('utf-8')
> del sys.setdefaultencoding
>
> And then used wx.SetDefaultPyEncoding("utf-8"), I am not sure "utf-8"
> will be enough for all the cases (probably not), but the world of
> encodings is still a bit obscure to me.

This will probably stop the UnicodeEncodeErrors, but in this case the  
big question is - does bsddb expect that the string it's given is in  
UTF-8 encoding? (My guess is that it doesn't.) This becomes a problem  
because it might do something like pass that UTF-8 string straight to  
Windows, which probably won't expect a string in UTF-8, so it will  
treat the string like it was encoded in whatever locale Windows is  
set to. (e.g. ASCII, Latin-1, Shift-JIS, etc., etc.) The end result  
is that it may give "file not found" errors, or write the file to  
disk using garbled folder names. A better fix for the problem in  
Windows would probably be to grab the Windows locale (there's  
functions for this in the locale module, IIRC) then in DataBase.py,  
change the line:

self.db = bsddb.btopen(dbName, "c")

to

self.db = bsddb.btopen(dbName.encode(myWinLocale), "c")

This way you don't have to make global script changes. You should  
also do this anytime you store user-supplied data in bsddb, although  
since you're probably almost always grabbing data from the GUI in  
those cases, calling wx.SetDefaultPyEncoding(myWinLocale) might take  
care of those issues. (I always get nervous about setting it globally  
like that though...)

In any case, this is just my two cents, but an API that cannot handle  
Unicode in this day and age is likely to cause lots of problems now  
and in the future, particularly since it doesn't sound like there's a  
plan to Unicode enable it. (not to mention it leaves all the  
conversion issues in your lap to deal with.) Also, IIUC, the current  
database approach sort of assumes these projects are only managed by  
one user - but what if you want to store your GUI2Exe projects in  
your project's CVS/SVN so others can build exe's and installers? As  
an alternative, you might want to look into either a simple XML  
project format, or perhaps just pickling the Python objects instead.

Regards,

Kevin

> In any case, noting that bsddb
> doesn't like unicode objects as keys, I just encode()d them before
> passing to it. I don't think it's an elegant solution, but at the
> moment I am short of ideas...
> I re-uploaded the new source and installer in the usual place. I don't
> think it will make any difference, but if someone could try it I would
> ben very happy :-D
>
> Thank you.
>
> Andrea.
>
> "Imagination Is The Only Weapon In The War Against Reality."
> http://xoomer.virgilio.it/infinity77/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users- 
> help at lists.wxwidgets.org
>





More information about the wxpython-users mailing list