Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pygtk

gtk

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.

like image 598
M0E-lnx Avatar asked Nov 30 '22 08:11

M0E-lnx


1 Answers

What you did is better for your purposes. For future reference, though, if you actually wanted to just block clicking, you would want to connect the TextView to button-press-event like so:

tview.connect('button-press-event', tviewClicked)

and define the handler function so that it returns True:

def tviewClicked(widget,event):
    return True

Returning True from a handler function tells GTK not to pass it on to anything else, so the click never gets sent to the TextView. The user won't be able to click on it any more.

I know this is an old question, but maybe it'll help someone else who comes to this page.

like image 139
Derek Redfern Avatar answered Dec 05 '22 19:12

Derek Redfern