Setting the cursor position in PyGTK (for a Gedit plugin)

◇◆丶佛笑我妖孽 提交于 2019-12-23 06:06:07

问题


I'm developing a Gedit plugin which is built on PyGTK. I'm trying to figure out how to programatically tell the cursor where to go. For example, I'd like to have the cursor automatically go to right before the first "|" (pipe) in the current line.

Any ideas or starting points? I've been using the Gedit API up until now (right here) which is helpful for the most part but doesn't mention anything about manipulating the cursor position.


回答1:


Looking at the gedit plugin API, it looks like gedit.Document is a subclass of GtkSourceBuffer which itself subclasses GtkTextBuffer, the last of which has the cursor manipulation API you want. In particular, get_insert() and place_cursor(where) give the basics of moving the cursor around. For other operations (e.g., getting the current line) you'll need to convert to a GtkTextIter using get_iter_at_mark(mark); the cursor is essentially just a special GtkTextMark.



来源:https://stackoverflow.com/questions/2283933/setting-the-cursor-position-in-pygtk-for-a-gedit-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!