Updates:
Summary: Exception when attributed text with mixed bold / nonbold is
entirely deleted
Status: Accepted
Comment #4 on issue 429 by oresmus: Exception when attributed text with
mixed bold / nonbold is entirely deleted
http://code.google.com/p/pyglet/issues/detail?id=429
Here's a variant of that code sample which generates a similar traceback
for me:
import pyglet
doc = pyglet.text.decode_attributed('{bold True}Hello{bold False}\n\n\n\n')
doc2 = pyglet.text.decode_attributed('{bold True}Goodbye{bold
False}\n\n\n\n')
layout = pyglet.text.layout.IncrementalTextLayout(doc, 100, 10)
layout.document = doc2
layout.document.delete_text(0, len(layout.document.text))
This is using pyglet 1.2dev (the current hg head) on Mac OS 10.6.3, using
Python
2.6.2 installed from
python.org. (FYI, I have no problems running that
combination of
pyglet, python, and Mac OS in general, in spite of reported issues with
similar
combinations but pyglet 1.1.3, e.g. in issue 438.)
I think the real issue isn't the document replacement or the newlines, but
deleting
all text when there are mixed font styles, since the following simpler
example also
gives a similar traceback:
import pyglet
doc2 = pyglet.text.decode_attributed('{bold True}a{bold False}b')
layout = pyglet.text.layout.IncrementalTextLayout(doc2, 100, 10)
layout.document.delete_text(0, len(layout.document.text))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyglet/text/document.py",
line 445, in delete_text
self.dispatch_event('on_delete_text', start, end)
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyglet/event.py",
line 340, in dispatch_event
if handler(*args):
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyglet/text/layout.py",
line 1804, in on_delete_text
self._update()
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyglet/text/layout.py",
line 1837, in _update
font = self.document.get_font(0, dpi=self._dpi)
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyglet/text/document.py",
line 660, in get_font
return iter[position]
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyglet/text/document.py",
line 719, in __getitem__
font_name, font_size, bold, italic = self.zip_iter[index]
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyglet/text/runlist.py",
line 403, in __getitem__
return [i[index] for i in self.range_iterators]
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyglet/text/runlist.py",
line 293, in __getitem__
self.start, self.end, self.value = self.next()
StopIteration
A possible clue to the cause (but no guarantee, since it's different code):
in a
larger editor example (not posted here), doing the same thing manually gets
a similar
traceback, and a subsequent click in the text widget gets the following
additional
traceback:
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 295, in 'calling callback function'
File "/Applications/pyglet/pyglet-hg/pyglet/window/carbon/__init__.py",
line 797,
in _on_mouse_down
self.dispatch_event('on_mouse_press', x, y, button, modifiers)
File "/Applications/pyglet/pyglet-hg/pyglet/window/__init__.py", line
1150, in
dispatch_event
if EventDispatcher.dispatch_event(self, *args) != False:
File "/Applications/pyglet/pyglet-hg/pyglet/event.py", line 369, in
dispatch_event
event_type, args, getattr(self, event_type))
File "/Applications/pyglet/pyglet-hg/pyglet/event.py", line 365, in
dispatch_event
if getattr(self, event_type)(*args):
File "edithack1.py", line 363, in on_mouse_press
self.focus.caret.on_mouse_press(x, y, button, modifiers)
File "/Applications/pyglet/pyglet-hg/pyglet/text/caret.py", line 552, in
on_mouse_press
self.move_to_point(x, y)
File "/Applications/pyglet/pyglet-hg/pyglet/text/caret.py", line 322, in
move_to_point
line = self._layout.get_line_from_point(x, y)
File "/Applications/pyglet/pyglet-hg/pyglet/text/layout.py", line 2272, in
get_line_from_point
if y > line.y + line.descent:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
(Since this provides a repeatable example, I'm unblocking the bug. I'm also
revising
the summary to fit my guess about the true cause.)
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups "pyglet-issues" group.
To post to this group, send email to
pyglet...@googlegroups.com.
To unsubscribe from this group, send email to
pyglet-issue...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/pyglet-issues?hl=en.