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

Kevin Ollivier kevino at theolliviers.com
Mon Apr 9 13:01:48 PDT 2007


Hi Roee,

On Apr 5, 2007, at 11:47 AM, roee shlomo wrote:

> BTW, which Windows version are you and Roee using? I wonder what
> sys.getfilesystemencoding() is returning that it doesn't work when
> converting to it from a Unicode object?
>
> I'm using XP.
> It returns 'mbcs'

Okay, two more questions:

1) Do or did you ever switch your Windows locale? (i.e. is it  
possible that the 'mbcs' encoding doesn't have some of the characters  
because you wrote those characters while Win was set to a different  
locale?)

2) if you run 'configDb.encode(sys.getfilesystemencoding(),  
'replace')' and print the new value, do each of the (Hebrew?)  
characters show up as '?' in the output?

Thanks,

Kevin

>
> On 4/5/07, Kevin Ollivier <kevino at theolliviers.com> wrote:
> Hi Andrea,
>
> On Apr 5, 2007, at 1:58 AM, Andrea Gavana wrote:
>
> > Hi Robin,
> >
> > On 4/4/07, Robin Dunn wrote:
> >> Andrea Gavana wrote:
> >>
> >> >> And removed
> >> >> wx.SetDefaultPyEncoding("utf-8")
> >> >
> >> > No, don't do that. If you encode everything using UTF-8, I can
> >> enter a
> >> > project name like this:
> >> >
> >> > MyProject (some kind of french/german/russian/whatever non-ascii
> >> > non-cp1252 letter)
> >> >
> >> > And, while the database will recognize them (because you are
> >> encoding
> >> > them as UTF-8), the tree control on the left will not display the
> >> > project names correctly, as wxPython will use
> >> > wx.GetDefaultPyEncoding(), which returns the string encoding
> >> > for the system at the moment. That means, if you send me your
> >> > database, my tree control will probably display a bunch of  
> squares
> >> > instead of the names you have used (if you used hebrew  
> letters, for
> >> > example). I may be wrong here, so please everyone enlight me if
> >> I am
> >> > saying stupid things.
> >>
> >> Just for clarification, the wx.SetDefaultPyEncoding value only
> >> sets the
> >> codec to be used when wxPython needs to convert to/from unicode/
> >> ansi for
> >> wx methods and functions only.  This value usually defaults to
> >> locale.getpreferredencoding () so it matches what Python thinks  
> is the
> >> default for your system as it is currently configured.  It doesn't
> >> have
> >> any effect on any other automatic conversions or coercions that
> >> Python
> >> will try to.
> >
> > Ok, thank you for the explanation.
> >
> >> For example, if you have a Unicode build of wxPython, and pass a
> >> string
> >> object to textctrl.SetValue , then it will use the
> >> wx.GetDefaultPyEncoding() encoding to convert it to a Unicode
> >> object to
> >> pass to the C++ SetValue.  The opposite is also true, if you  
> have an
> >> ansi build of wxPython and pass a Unicode object then that
> >> encoding will
> >> be used to convert it to a string first.
> >
> > Well, let's assume I have an unicode build of wxPython. Then Roee
> > sends me his database of GUI2Exe projects, and he has put in there
> > project names with hebrew letters (or cyrillic or whatever). My
> > database pre-processing will not blink, but on my machines
> > wx.GetDefaultPyEncoding() returns either 'cp1251' (here at work) or
> > 'ascii' at home. Will it harm if I receive Roee's database?
>
> Yes, but only because you're letting byte strings run around your app
> without converting them to Unicode objects first. ;-) The best way to
> handle encoding issues like this, IMHO, is to convert to/from Unicode
> objects when, and only when, setting or receiving data via non-
> Unicode compliant APIs, such as bsddb. Rather than relying on
> libraries to silently convert for you, you should do the conversion
> right when you send and/or receive the data. If a library gives you a
> string, convert it to Unicode ASAP. ;-)  It might seem convenient to
> have Python silently convert string<->Unicode whenever needed, but in
> reality that gets a lot trickier to debug when your global encoding
> doesn't work with a certain set of input data. As you noticed, when
> you're not dealing with ASCII but don't use the right encoding, you
> often won't get encoding errors - just garbled text. Well, actually,
> more likely your user will get garbled text. ;-/
>
> SetDefaultPyEncoding() really should only be used for ANSI builds
> where you always need to convert, and for some reason the value of
> GetDefaultPyEncoding() doesn't match the encoding that wxWidgets
> expects the data to be in. (i.e. you're not telling wxWidgets which
> encoding to use, you're telling wxPython which encoding wxWidgets is
> expecting)
>
> >
> >> For other automatic ansi/unicode conversions that Python does  
> then it
> >> uses the return value of sys.getdefaultencoding() for the encoding.
> >> Python also provides the sys.getfilesystemencoding() value which
> >> specifies what should be used for encoding unicode values into ansi
> >> strings to be used for path and file names on the current system.
> >
> > sys.getdefaultencoding () seems not enough to work with bsddb, also
> > Roee reported the same problem. And I found exactly the same when
> > assigning project names with accented letters (french, german and
> > similar). I saved a project in the database with this strange name,
> > closed GUI2Exe, reopened it and the project name was completely
> > screwed up :-(
>
> BTW, which Windows version are you and Roee using? I wonder what
> sys.getfilesystemencoding() is returning that it doesn't work when
> converting to it from a Unicode object?
>
> Regards,
>
> Kevin
>
> > 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
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users- 
> help at lists.wxwidgets.org
>
>
>
>
> -- 
> http://code.google.com/p/lh-abc

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20070409/7584c0d6/attachment.htm


More information about the wxpython-users mailing list