# HG changeset patch # User Björn Ricks # Date 1352808732 -3600 # Node ID ccd47a2d37a6f49708080a3729c86f28989ed903 # Parent 9e853f9e63ad853b7ddfdf7d8a3dc5edc1aa3022 Carefully handle non unicode strings for urwid Urwid seems to have some issues with latin1 and unicode conversion when setting a text box. Therefore be sure to pass only unicode strings to urwid. diff -r 9e853f9e63ad -r ccd47a2d37a6 getan/project.py --- a/getan/project.py Tue Nov 13 13:11:04 2012 +0100 +++ b/getan/project.py Tue Nov 13 13:12:12 2012 +0100 @@ -8,6 +8,8 @@ # This is Free Software licensed unter the terms of GPLv3 or later. # For details see LICENSE coming with the source of 'getan'. +import locale + from datetime import datetime, timedelta class Project(object): @@ -69,6 +71,11 @@ self.end = end self.desc = desc + # carefully handle non unicode string + # urwid seems to have some issue with plain str + if not isinstance(self.desc, unicode): + self.desc = unicode(self.desc, locale.getpreferredencoding()) + def duration(self): return (self.end - self.start) diff -r 9e853f9e63ad -r ccd47a2d37a6 getan/states.py --- a/getan/states.py Tue Nov 13 13:11:04 2012 +0100 +++ b/getan/states.py Tue Nov 13 13:12:12 2012 +0100 @@ -9,6 +9,7 @@ # +import locale import logging import signal from datetime import datetime, timedelta @@ -291,7 +292,13 @@ def insert(self, key): logger.debug("Enter key: %r" % key) - self.footer.insert_text(key[0]) + text = "".join(key) + # check for unicode here + # urwid (at least up to version 1.0.2) will crash if a non-unicode + # string with a char > 128 is passed here + if not isinstance(text, unicode): + text = unicode(text, locale.getpreferredencoding()) + self.footer.insert_text(text) return self