pygtk read-only gtk.TextView (make it ignore mouse clicks)

I need a way to make a gtk.TextView ignore mouse clicks in a pygtk GUI.

I have set the ‘editable’ property to false to prent user input, but it still responts to mouse clicks.

This textview displays some output from other commands, so if the user clicks anywhere on it, it moves the cursor to the clicked location. I need to avoid that.

I need something similar to the set_property(‘sensitive’, False) results, but without graying out the widget. It just needs to sit there and ignore all kinds of user input.

Anyone have any ideas how to accomplish this?

Thanks in advance.

Answer

Found the answer. For anyone who is interested, here it goes.

The truth is, there is no way to make it ignore the mouse clicks. What you can do when you want a read-only kind of text view, you set the ‘editable’ property to False. This ignores the keyboard input.

The other thing is when inserting text, you want to use the insert method rather than the insert_at_cursor method.

Sample

tview = gtk.TextView()
tview.set_property('editable', False)


# Insert text at the end on the textview.
buffer = tview.get_buffer()
buffer.insert(buffer.get_end_iter(), 'This text goes at the end of the existing text')

HTH

Leave a Reply

Your email address will not be published. Required fields are marked *