[Urwid] Fwd: unicode symbols and whitespaces

Patrick Totzke patricktotzke at googlemail.com
Wed Aug 17 11:14:41 EDT 2011


-------------- next part --------------
Hi!

I'm currently seing strange behaviour with Text widgets in combination with
utf-8 and unicode strings:
For certain symbols, like '颖', urwid craches when displaying them (stacktrace below).
But if i encode this to utf08 before handing it to urwid.Text,
Its length gets calculated falsely:
>s=u'\u9896'.encode('utf-8')
> len(s) = 3
so I get two whitespaces after the symbol on my screen..
Best,
/p





   self.mainloop.run()
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/main_loop.py", line 271, in run
    self.screen.run_wrapper(self._run)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/raw_display.py", line 228, in run_wrapper
    return fn()
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/main_loop.py", line 292, in _run
    self.event_loop.run()
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/main_loop.py", line 667, in run
    self._loop()
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/main_loop.py", line 696, in _loop
    self._entering_idle()
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/main_loop.py", line 617, in _entering_idle
    callback()
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/main_loop.py", line 482, in entering_idle
    self.draw_screen()
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/main_loop.py", line 493, in draw_screen
    canvas = self._topmost_widget.render(self.screen_size, focus=True)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/widget.py", line 131, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/container.py", line 586, in render
    focus and self.focus_part == 'body')
  File "/home/pazz/projects/alot/alot/buffer.py", line 41, in render
    return self.body.render(size, focus)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/widget.py", line 131, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/listbox.py", line 346, in render
    focus_canvas = focus_widget.render((maxcol,), focus=focus)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/widget.py", line 131, in cached_render
    canv = fn(self, size, focus=focus)
  File "/home/pazz/projects/alot/alot/widgets.py", line 89, in render
    return urwid.AttrMap.render(self, size, focus)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/widget.py", line 131, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/decoration.py", line 208, in render
    canv = self._original_widget.render(size, focus=focus)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/widget.py", line 131, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/container.py", line 1218, in render
    focus = focus and self.focus_col == i)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/widget.py", line 131, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/decoration.py", line 208, in render
    canv = self._original_widget.render(size, focus=focus)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/widget.py", line 131, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/widget.py", line 622, in render
    return apply_text_layout(text, attr, trans, maxcol)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/canvas.py", line 1249, in apply_text_layout
    s = LayoutSegment(seg)
  File "/usr/local/lib/python2.7/dist-packages/urwid-1.0.0-py2.7-linux-x86_64.egg/urwid/text_layout.py", line 259, in __init__
    assert self.sc > 0, repr(seg)
AssertionError: (0, 0, 0)



More information about the Urwid mailing list