开发者

Find the cursor position on a GtkSourceView window

开发者 https://www.devze.com 2023-03-29 21:02 出处:网络
I want to display a popup window with an auto-complete combo, how do I identify the current cursor scr开发者_JAVA百科een position to setup the auto-complete popup window ?Found the solution looking in

I want to display a popup window with an auto-complete combo, how do I identify the current cursor scr开发者_JAVA百科een position to setup the auto-complete popup window ?


Found the solution looking into the gtk source completion code:

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) 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号