在GtkSourceView窗口中找到光标位置

时间:2011-08-21 16:49:05

标签: python pygtk

我想显示一个带有自动完成组合的弹出窗口,如何识别当前光标屏幕位置以设置自动完成弹出窗口?

1 个答案:

答案 0 :(得分:2)

找到解决gtk源完成代码的解决方案:

def get_iter_pos(text_view, iter):
      iter_location = text_view.get_iter_location(iter)
      win_location = text_view.buffer_to_window_coords(
            Gtk.TextWindowType.WIDGET, iter_location.x, iter_location.y)                

        win = text_view.get_window (Gtk.TextWindowType.WIDGET);
        view_pos = win.get_position()

        xx = win_location[0] + view_pos[0]
        yy = win_location[1]+ view_pos[1] + iter_location.height;           
        return (xx, yy, iter_location.height)
buffer = view.get_buffer()
insert_iter = buffer.get_iter_at_mark(buffer.get_insert())
x, y, height = get_iter_pos(widget, insert_iter)
top_x, top_y = widget.get_toplevel().get_position()
mywindow.move(top_x+x, top_y+y)