简体   繁体   中英

scroll TextView in ScrolledWindow so that cursor is visible in pyGTK2

I have a Textview in a ScrolledWindow. I have set up a callback on signal "changed" of textbuffer of the textview. Now I need to scroll the ScrolledWindow to the point of the cursor. How do I do that?

self.outgoing = gtk.ScrolledWindow()
self.outgoing.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.textview = gtk.TextView()
textbuffer=self.textview.get_buffer()
textbuffer.connect("changed",self.scrolltocursor)
self.outgoing.add_with_viewport(self.textview)

def scrolltocursor(self,text_buffer):
    <I don't know what to do here>

Help please.

Well it seems the problem was that I did add_with_viewport to put the textview in the scrolled window. Now I tried self.outgoing.add(self.textview) and it works without any callbacks to change. So yeah. That fixes it.

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