[socal-piggies] Py2exe, PyGTK TextView encoding problem nightmare hassle annoyance ...

Greg McClure gmcclure at gmail.com
Wed Feb 23 16:05:13 PST 2005


Hello my fellow Piggies!

I've copied the text of a message I posted to the PyGTK mailing list
in hopes that someone in our group might have some experience with
PyGTK and would have an inkling of what I'm doing incorrectly. I feel
like I'm missing something plain because my problem seems as though it
would be fairly common if what was trying to do was really tricky. It
seems like a fairly straightforward, common task.

In short, I'm extracting some character data from an XML file, much of
which is in Spanish or French or German, whatever, and writing the
data to a TextBuffer obtained from a PyGTK TextView. The app works
fine when run under the Python interpreter, but when I run the app
through py2exe, well, the app starts up just fine and processes ascii
text all right, but chokes on any latin characters, like 'í', 'ó' or
'ñ'.

Argh!

I've checked the PyGTK docs and, offhand, I don't seem to be missing
any TextView or TextBuffer properties which would futz with the
encoding. Also, GTK 2.0+ handles UTF-8 by default, right?

Any insights would be appreciated.

All best,
Greg

------------

I have an app writing data from an XML file to a TextBuffer obtained
in the usual way:

tv = gtk.TextView()
buffer = tv.get_buffer()

self._buff_ref = buffer

and then ...

def write_buffer(self, buffer, text):
   buffer.set_text(text)
   tag = buffer.create_tag(None, size_points=20.0)
   start, end = buffer.get_bounds()
   buffer.apply_tag(tag, start, end)

and then later on there'll be something like

self.write_buffer(self._buff_ref, 'Happy happy joy joy')

My problem is that when the app runs as a Python application
everything works fine, and latin characters like 'í', 'ó' and 'ñ'
display as they should. This normally wouldn't be a problem except
that when I compile the app with py2exe and run the .exe file in
dist/, normal ascii text displays just fine but the latin characters
make the app choke that the character is outside the ascii range.

Yah!!! Help!!! If I do something like:

buffer.set(text.encode('utf-8'))

this doesn't help me out, the py2exe .exe file complains that it can't
find the encoder. I must be missing something straightforward. Any
help would be deeply appreciated.




More information about the socal-piggies mailing list