[wxPython-users] 2.7 And Unicode Questions

Robin Dunn robin at alldunn.com
Fri Aug 11 14:40:16 PDT 2006


Andrea Gavana wrote:
> Hello NG,
> 
>    I'm still using 2.6.3.3 at the moment, and I am thinking about
> switching to 2.7 pre-release in the near future (I hope). In the
> meanwhile, I would also try to switch to Python 2.5, if I can find all
> the dependencies updates for Python 2.5 (Numpy, py2exe, Pythonwin and
> so on). I obviously have to forget VTK :-D
> 
> BTW, I have a couple of questions:
> 
> 1) Is there anyone using 2.7 with Python 2.5 that can please share
> some comments about it? Did you encounter any problem?

The only problem with wxPython on Py 2.5 that I am aware of currently is 
the warning on Windows about the locale dir not being a package dir.  I 
haven't installed other packages yet though so I haven't yet tried 
various integration tests.

> 
> 2) As with other versions when they first came out, 2.7 broke PyAUI.
> It doesn't work anymore. I know, I know, PyAUI is dead, I should use
> the wrapped wx.aui from wxPython. However, the development version of
> PyAUI has some nice whistles and bells that I would have liked to
> keep. But I can live with wx.aui without problems :-D

You could always create a patch that adds the bells and whistles to 
wxAUI.  ;-)  Also, Ben is in the process of adding some cool new things 
based on wxAUI, like splittable, draggable notebooks.


> 
> 3) Unicode: well, it seems to me that ANSI versions of wxPython have
> to be forgotten. Ok, have anyone encountered problems in using Unicode
> versions in place of ANSI? I know absolutely *nothing* about unicode,
> and doing a lot of I/O operations in my apps, I could end up in
> rewriting big parts of code.


The ANSI builds aren't totally dead yet, I just didn't make preview 
builds last time in order to cut in half the time it takes to make a 
build.  (Although it is almost totally automated I still need to babysit 
it in case there is a problem 3 or 4 hours into the build that needs 
corrected...)

That said, I would eventually like to be able to drop the ANSI builds. 
My feeling is that they are getting less testing on the wxWidgets side, 
and I know I am not working with them as much myself.  Also, every Linux 
distro I know of that has wxGTK and wxPython packages available has only 
the unicode packages, and in Python 3 the string objects will be 
unicode, and there will be no string type that holds bytes (but there 
will be a bytes type that is not a string but does hold bytes) so it 
seems to be a trend.

The main thing to be aware of in the Unicode wxPython builds is that all 
wxString parameters or return values of the C++ methods or functions are 
  expected to be Python Unicode objects, and are converted to Unicode if 
they are string objects.  The conversion makes the assumption that the 
string is encoded with the encoding that wxPython detected from the 
system's locale as the default when the wx package was imported.  You 
can see what encoding this is with wx.GetDefaultPyEncoding() and set it 
to something else with wx.SetDefaultPyEncoding(name).  If you know that 
the string is in some other encoding then you'll need to decode it to 
Unicode yourself using the right codec and then pass the result to the 
wx method.  You'll also need to do the opposite with the Unicode values 
you get from wx if you need to write them as strings to some external 
medium such as a file or database.  In that case you'll encode the 
unicode object's value into a string object using a codec that can 
represent the values you have.  Hint: UTF-8 is a useful encoding because 
it can represent all of the Unicode character set in an 8-bit string, 
but it does this by using more than one byte for anything that is not in 
the basic ascii encoding.  For example, run this in a unicode PyShell:

 >>> for x in range(256):
...     u = unichr(x)
...     print x, u, `u.encode('utf-8')`


See also http://wiki.wxpython.org/index.cgi/UnicodeBuild

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list