tags:

views:

178

answers:

2

I have a gtk.TextBuffer which is supposed to be cleared after pressing Enter, similar to the input box on most chat programs. I'm just setting the buffer back to a blank string. The newline character from Enter isn't removed though, and a blank line ends up above the cursor during the next input. Moving the cursor to the first gtk.Iter doesn't help.

+1  A: 

Are you sure you're trigger on the proper event? Also try connecting it after.

Vadi
+2  A: 

By default, "gobject.connect()" callback is called before the default handler. You need to use "gobject.connect_after()".

def insert_text_cb(text_buffer, position, text, lenght):
    if text == '\n':
        text_buffer.set_text('')

text_view = gtk.TextView()
text_view.get_buffer().connect_after('insert-text', insert_text_cb)
Ivan Baldin
Thanks, this worked.
wodemoneke