[pygtk] URLs in treeviews

Osmo Salomaa otsaloma at cc.hut.fi
Sat Sep 9 16:24:42 WST 2006


pe, 2006-09-08 kello 15:36 -0400, hvastani at vt.edu kirjoitti:
> but how do I make the cursor change to the shape of a hand ( like in
> web browsers ) when I mouse over this text.

You can connect to the text view's motion-notify-event. Then, when the
mouse pointer moves, you can get the pointer's coordinates, get the
gtk.TextIter at that location and get the gtk.TextTags at that iter.
Based on what those tags are, you can change the cursor.

----------------------------------------
def _on_text_view_motion_notify_event(self, text_view, event):
    
    x, y = text_view.get_pointer()
    x, y = text_view.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, x, y)
    tags = text_view.get_iter_at_location(x, y).get_tags()
    window = text_view.get_window(gtk.TEXT_WINDOW_TEXT)
    for tag in tags:
        if tag in self._url_tags:
            window.set_cursor(HAND_CURSOR)
            return
    window.set_cursor(NORMAL_CURSOR)
----------------------------------------

However, this is painfully slow! Maybe someone knows a better way?

-- 
Osmo Salomaa <otsaloma at cc.hut.fi>



More information about the pygtk mailing list