0

I have this code where I get a treeview and a sign when I click or move the up / down over the lines. For my application I need to disable the selection when the user clicks on a row, further I wonder if there's any way to block the selection upwards. Thanks

treeview = builder.get_object('treeview3')
        treeview.set_model(liststore)
        select = treeview.get_selection()
        select.connect("changed", on_tree_selection_changed)

def on_tree_selection_changed(selection):
    model, treeiter = selection.get_selected()
    if treeiter != None:
        print "You selected", model[treeiter][0]
6
  • Is this ubuntu?
    – Tim
    May 22, 2015 at 17:26
  • Well, I'm working on ubuntu and when googled to find some method I found several similar answers here then .. I ask: D
    – alexter42
    May 22, 2015 at 17:30
  • That's fine :) We just have some (strange) rules about what is allowed here and what isn't!
    – Tim
    May 22, 2015 at 17:34
  • This question does not belong to the allowed?
    – alexter42
    May 22, 2015 at 17:36
  • Nah, this is fine! Welcome to Ask Ubuntu - check out the tour if you have a spare minute or 2!
    – Tim
    May 22, 2015 at 17:37

1 Answer 1

3

You could use the Gtk.TreeSelection.set_select_function functionality for this. Basically you give it a function, each time a row is selected this function is called. When it returns False the row can't be selected.

Here's an example:

treeview = builder.get_object("treeview3")
selection = treeview.get_selection()
selection.set_select_function(_select_func, None)

def _select_func(selection, model, path, selected, data):
    return False  # Can't select this row

Not the answer you're looking for? Browse other questions tagged .