[pygtk] Need ToolButton to only be sensitive when TreeView has a selection

Robert Park rbpark at exolucere.ca
Tue Aug 31 07:33:48 WST 2010


Hi guys, another simple one today.

I have a button that acts upon selected items in a TreeView/ListStore,
so I'd like for this button to be disabled when there are no
selections in my TreeView. So far I have this code:

		self.apply_button = gtk.ToolButton(gtk.STOCK_APPLY)
		self.apply_button.set_sensitive(False) #Defaults unsensitive because
nothing will be selected when app loads
		...
		self.treeview.connect("select-cursor-row", lambda x, y:
self.apply_button.set_sensitive(True))

So what this does is that if I click on a row in the TreeView and then
press the Enter key on my keyboard, the apply button becomes
sensitive. What I want is to have it simply become sensitive as soon
as the selection is clicked, but I've been reading through the
reference manuals and I just can't seem to find the right signal name
for this. selection-received and selection-request-event seemed like
the obvious choices for this but they don't seem to work.

Also, I'm gonna need to know how to again de-sensitize the button
after the selection is cleared.

Thanks in advance guys.

-- 
http://exolucere.ca


More information about the pygtk mailing list