# HG changeset patch # User cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1244904882 0 # Node ID ea85ddce2b365af2effa66c4b67aae4f3f32e50c # Parent 10e0687a4cec66da86ccac7b909f7696904b089e * 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 diff -r 10e0687a4cec -r ea85ddce2b36 engine/extensions/pychan/widgets/common.py --- 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 diff -r 10e0687a4cec -r ea85ddce2b36 engine/extensions/pychan/widgets/listbox.py --- 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)