[pygtk] Need ToolButton to only be sensitive when TreeView has a selection
Robert Park
rbpark at exolucere.ca
Tue Aug 31 07:49:17 WST 2010
D'oh, looks like I asked for help a bit too soon. Got it working with this gem:
self.treeview.get_selection().connect("changed", lambda x:
self.apply_button.set_sensitive(self.treeview.get_selection().count_selected_rows()
> 0))
Although it's a bit unwieldy. Any thoughts on simplifying this?
Thanks guys!
On Mon, Aug 30, 2010 at 5:33 PM, Robert Park <rbpark at exolucere.ca> wrote:
> 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
>
--
http://exolucere.ca
More information about the pygtk
mailing list