简体   繁体   中英

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

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.

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 (eg, 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM