Mercurial > fife-parpg
changeset 264:ea85ddce2b36
* Fixed a bug where resizing a listbox with non-ascii characters would give errors
* New pychan function: gui2str, useful for converting unicode objects to string objects which can be used by swig functions
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 13 Jun 2009 14:54:42 +0000 |
parents | 10e0687a4cec |
children | 043d71a192b5 |
files | engine/extensions/pychan/widgets/common.py engine/extensions/pychan/widgets/listbox.py |
diffstat | 2 files changed, 14 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/extensions/pychan/widgets/common.py Thu Jun 11 17:12:12 2009 +0000 +++ b/engine/extensions/pychan/widgets/common.py Sat Jun 13 14:54:42 2009 +0000 @@ -30,6 +30,19 @@ Translates the encoded string into a unicode object. """ return unicode(text,"utf8",*get_manager().unicodePolicy) + +def gui2str(text): + """ + This function returns an 8-bit representation of the + unicode string. This is useful for passing strings + to SWIG functions. + """ + try: + return text.__str__() + except: + # String contains non-ascii characters + return text.encode("utf-8") + def isLayouted(widget): from layout import LayoutBase
--- a/engine/extensions/pychan/widgets/listbox.py Thu Jun 11 17:12:12 2009 +0000 +++ b/engine/extensions/pychan/widgets/listbox.py Sat Jun 13 14:54:42 2009 +0000 @@ -59,7 +59,7 @@ def resizeToContent(self,recurse=True): # We append a minimum value, so max() does not bail out, # if no items are in the list - _item_widths = map(self.real_font.getWidth,map(str,self._items)) + [0] + _item_widths = map(self.real_font.getWidth,map(gui2str,self._items)) + [0] max_w = max(_item_widths) self.width = max_w self.height = (self.real_font.getHeight() + 2) * len(self._items)