在PyGTK中设置光标位置(对于Gedit插件) [英] Setting the cursor position in PyGTK (for a Gedit plugin)

查看:124
本文介绍了在PyGTK中设置光标位置(对于Gedit插件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基于PyGTK的Gedit插件.我试图弄清楚如何以编程方式告诉光标要去哪里.例如,我希望光标自动移到第一个"|"之前(管道)在当前行中.

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.

有什么想法或出发点吗?到目前为止,我一直在使用Gedit API(就在这里),这很有帮助在大多数情况下,但没有提及任何有关操纵光标位置的事情.

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.

推荐答案

看gedit插件API,看起来gedit.DocumentGtkSourceBuffer的子类,它本身又是GtkTextBuffer的子类,最后一个具有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 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.

这篇关于在PyGTK中设置光标位置(对于Gedit插件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆