tags:

views:

17

answers:

1

At the moment, when one right clicks in a TextView, a popup menu is brought up, but the cursor doesn't actually change position to where one is right clicking, it just leaves the cursor alone. For me, whom is trying to implement a spell checking menu, this isn't good since I have to click THEN right click in order to get the cursor in the right spot. So, my question is if there is any way to modify this behavior somehow so that it actually does this somehow?

A: 

Well, I stumbled across gtk.TextView.get_iter_at_location, which lead me to gtk.TextView.get_pointer and gtk.TextView.window_to_buffer_coords. Basically, to get this working, I did this:

    x, y = self.textView.get_pointer()
    x, y = self.textView.window_to_buffer_coords(gtk.TEXT_WINDOW_WIDGET, x, y)
    if self.textView.get_iter_at_location(x, y).has_tag(self.errTag):
        # Code here

Basically, it gets the pointer's position (relative to the window), transforms it to buffer coordinates (I find that gtk.TEXT_WINDOW_TEXT gives the same coordinates as gtk.TEXT_WINDOW_WIDGET, but I thought I'd err on the side of caution and use the widget's window), and then gets an iter at that location. Works wonderfully.

Smartboy