Ubuntu – How to make a Gtk.Iconview react to single click instead of double click

application-developmentgtkpython

I use a Gtk.IconView widget in my app to select different types of elements. The way the IconView works is the following:

  • Do one click to select the item
  • Do an additional double-click to activate the item

I've always found it confusing that an additional double click is needed, when most button-like widgets in the desktop just require a single click. Now I've just had feedback from a couple of users that find it confusing (someone thought it was a bug that clicking on the button "did nothing"), so I've decided to look into how to change that behaviour.

Ideally, I'd like the IconView to behave as follows:

  • Hover to select an item (optional)
  • Single-click activates the item

Now I haven't found anything obvious in the widget's properties to make it behave like that. Does anyone know how or if that could be achieved?

Gtk.IconView in action

Best Answer

One solution (but only for the single click activation) is of cause to use the selection_changed signal of the IconView (because the IconView selection is single click based).

A sample that assumes a working on_item_activated signal would be:

def on_icon_view_selection_changed(self, widget):
        self.on_item_activated(widget, widget.get_selected_items()[0])