ANN Re: [pygtk] Text widget that allows for adding annotations

Samuel Abels newsgroups at debain.org
Wed Jun 11 01:32:08 WST 2008


On Sun, 2008-06-08 at 22:01 +0200, Samuel Abels wrote:
> I am looking for a hopefully painless way to create a text widget that
> supports annotations similar to the ones found on this picture:
> 
> http://words.ibritt.com/images/loremIpsumSampleDoc.gif

Alright, I hacked one of my own. This is what it looks like:
http://debain.org/stuff/annotated_text_view.png

The colors of the annotations are configurable, and annotations are
editable.
For example usage, see tests/SpiffGtkWidgets/show_text_view.py.

Known caveat: The widget does not work when used in a scrolled window
without a viewport. Since the widget can no longer automatically scroll
when used in a viewport, this means you will have to find a way to do
the scrolling manually. This is due to the following documented
misbehavior in the gtk.TextView:

"The child coordinates are given relative to the gtk.gdk.Window
specified by which_window, and these coordinates have no sane
relationship to scrolling. [...]"

http://www.pygtk.org/docs/pygtk/class-gtktextview.html#method-gtktextview--add-child-in-window

Here is the code:
http://dl.debain.org/spiff_gtkwidgets/spiff_gtkwidgets.tar.bz2

I will package this into a more official release with documentation in a
few weeks, possibly with some additional polish.

Enjoy,
-Samuel




More information about the pygtk mailing list