[Pygui] Native wrappers?

Dan Villiom Podlaski Christiansen danchr at gmail.com
Mon Dec 21 11:05:29 CET 2009


On 21 Dec 2009, at 02:45, Vernon Cole wrote:

> Greg and everyone:
> 
> These days I am trying to make all of my programs super-portable -- CPython2.x, IronPython and Python3 on Windows and Linux.  2/3 of these use ONLY unicode strings.  One of my reasons for migrating to PyGUI is because there are no plans for wxPython to run on any platform other than 2.x.  I am guessing that PyGUI, being more simple, is going to be much easier to convert to the other compilers than its competition.
> 
>   What I am getting at is this advice from a very old programmer... try to make everything work correctly with unicode. It will make life much easier when conversion time comes around.  When you do need byte strings, use a user-written function to produce them, not a built in.  This is one that I have found useful:
> v v v v
> def str2bytes(sval):
>     if sys.version_info < (3,0) and isinstance(sval, str):
>         sval = sval.decode("latin1")
>     return sval.encode("latin1")
> ^ ^ ^ ^

For what it's worth, the NSString in Cocoa class uses UTF-16 internally, and offers a distinct NSData class for anything else. The current implementation of string conversion[1] only accepts ASCII strings in addition to Unicode. (Looking at the code just now, non-ASCII strings will probably cause a null dereference… I should fix that and make it leak less too.) It would simplify things quite a bit if only Unicode strings were accepted, but I can't say whether this would be accepted for backwards compatibility.

I'm a rather young programmer myself, but I can say that my native Cocoa backend is quite far from being actually usable. Who knows, by the time it is, Python 3 could be in widespread usage ;)

[1] The conversion source is here: <https://bitbucket.org/danchr/pygui/src/tip/GUI/Cocoa/Util/PyString.m#cl-71>

--

Dan Villiom Podlaski Christiansen
danchr at gmail.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1943 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pygui/attachments/20091221/320349ec/attachment.bin>


More information about the Pygui mailing list