Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm developing an application using Quickly. I have a Gtk.TreeView with a Gtk.ListStore as its model. The selection mode of the Gtk.SelectionMode is set to Gtk.SelectionMode.MULTIPLE.

The problem is that the Gtk.SelectionMode does not behave as it should:

  • Only one row can be selected at a time.
  • Impossible to select multiple rows using the Ctrl or Shift key.
  • Once a row is selected, it can't be deselected using the Ctrl key.
  • Nothing happens when I press the arrow keys.

The problem can be easily reproduced by creating a new Ubuntu application using Quickly (or you can download a test application below).

$ quickly create ubuntu-application test
$ cd test
$ quickly design

Create a TreeView with a ListStore as its model. Set the mode of the GtkTreeSelection to 'Multiple'. Add some columns and values to the ListStore. Add some TreeViewColumns with CellRendererTexts to the Treeview.

$ quickly run -v

Note you can't select multiple rows.

Some things I've already tried, but did not change anything:

  • Setting the selection mode in the code.

    self.ui.selection.set_mode(Gtk.SelectionMode.MULTIPLE)

    or

    self.ui.treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)

  • Moving the GtkTreeSelection <child> below the GtkTreeViewColumn <child> in the UI file.

  • Deleting the GtkTreeSelection from the UI file and setting the selection with

    self.ui.treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)

Am I overlooking something obvious? Or could this be a bug?

On a side note, if you set the selection to 'Single', it's also not possible to deselect the row.

EDIT

If you'd like to help me out, you can download a test application here instead of creating a new project with Quickly on your own. Please note you need Quickly to run it.

$ cd test
$ quickly run

I've implemented some callbacks for testing purposes in test/test/TestWindow.py. You can find the UI definition in test/data/ui/TestWindow.ui.

share|improve this question

2 Answers 2

I can't give a full answer, but wanted to share it. If asking a programming question, always include a minimal working example so others can quickly (ha, pun intended) run and test in your code. I will have to install Quickly, create a Quickly project and change code just to see what your question is about and try to fix it, which I won't.

That being said, here is a minimal working example which behaves correctly, so my guess is Quickly does some magic somewhere which overrides this behaviour.

from gi.repository import Gtk

class TestWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.resize(400, 400)
        self.connect("delete-event", Gtk.main_quit)

        ls = Gtk.ListStore(str)
        ls.append(["Testrow 1"])
        ls.append(["Testrow 2"])
        ls.append(["Testrow 3"])
        tv = Gtk.TreeView(ls)
        tr = Gtk.CellRendererText()
        col = Gtk.TreeViewColumn("Testcolumn", tr, text=0)
        tv.append_column(col)
        sel = tv.get_selection()
        sel.set_mode(Gtk.SelectionMode.MULTIPLE)

        self.add(tv)
        self.show_all()

if __name__ == "__main__":
    app = TestWindow()
    Gtk.main()

Note that you are using an incorrect treeselection mode in your question, the correct one is Gtk.SelectionMode.MULTIPLE.

share|improve this answer
    
My mistake, thanks for pointing that out. I've corrected the selection mode in the question. In my project I was using the correct one, thankfully. ;-) I'll create an example project tomorrow and upload it somewhere. Thanks for the feedback. –  tectux May 9 '13 at 21:34
    
I've updated my question as you advised and provided an example to download. –  tectux May 10 '13 at 15:02
up vote 0 down vote accepted

I found the solution to my own problem.

The 'can-focus' property of the Gtk.TreeView is set to False by default. Setting this to True fixes the strange selection behavior, as well as other strange behavior that might occur, like not being able to resize a column while its 'resizable' property is set to True.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.