在 PyGTK 中设置光标位置(对于 Gedit 插件)
我正在开发一个基于 PyGTK 构建的 Gedit 插件。我试图弄清楚如何以编程方式告诉光标要去哪里。例如,我想让光标自动转到第一个“|”之前(管道)在当前行。
有什么想法或出发点吗?到目前为止,我一直在使用 Gedit API(就在这里),这很有帮助大多数情况下,但没有提及任何有关操纵光标位置的内容。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 gedit 插件 API,看起来
gedit.Document
是GtkSourceBuffer
的子类,它本身又是GtkTextBuffer
的子类,最后一个具有你想要的光标操作API。特别是,get_insert()
和place_cursor(where)
给出了移动光标的基础知识。对于其他操作(例如,获取当前行),您需要使用get_iter_at_mark(mark)
转换为GtkTextIter
;光标本质上只是一个特殊的GtkTextMark
。Looking at the gedit plugin API, it looks like
gedit.Document
is a subclass ofGtkSourceBuffer
which itself subclassesGtkTextBuffer
, the last of which has the cursor manipulation API you want. In particular,get_insert()
andplace_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 aGtkTextIter
usingget_iter_at_mark(mark)
; the cursor is essentially just a specialGtkTextMark
.