[pygtk] Treeview/model: Problems with Expanding and Selecting Rows

darethehair darethehair at gmail.com
Wed Jan 28 00:16:47 WST 2009


John Finlay wrote:
> darethehair wrote:
>> Hello Folks!
>>
>> The PyGTK tutorial example named 'basictreeview.py' works fine for me.
>> When I click on the 'expander' arrow for a row, it instantly expands to
>> show the child rows under it.
>>
>> In my case, I am using a 'lazy treeview' to only populate the child rows
>> as I need to do so -- mostly because of time, but also because I want to
>> allow unlimited 'nesting'.  My problem is two-fold:
>>
>> 1) When I use a 'row-expanded' signal detector, I have to click two or
>> three times on the 'expander' arrow in order for the child rows to
>> actually show up.  In fact, out of desperation I have even added the
>> following to my routine to 'force' the issue:
>>
>>                 self.treeview.expand_to_path(path)
>>                 self.treeview.expand_row(path, True)
>>
>> 2) When I add a selection 'changed' signal, it works, but it 'gets in
>> the way' of my 'row-expanded' detector i.e. even if I am very careful to
>> click just the 'expand arrow' on a row, it triggers my 'changed'
>> selection routine the first time I touch a row.
>>
>> I would appreciate any tips to produce the desired behavior! :)
>>   
> Connect to the "test-expand-row" signal and add the rows in the 
> callback. You have to put a dummy child row to get the expander to 
> show and replace it with the real children in the callback.
>
> John
Thanks for the tip!  I wonder why my original signal caller did not work:

    self.treeview.connect('row-expanded', self.on_row_expanded)

...but your suggestion works much better:

    self.treeview.connect('test-expand-row', self.on_row_expanded)

I also had to remove my 'extra' calls after making your change, since
they were now incompatible:

                self.treeview.expand_to_path(path)
                self.treeview.expand_row(path, True)

Even though this makes me extremely happy, I am still left with problem
#2 i.e. activating a 'changed' selection routine causes every initial
row expansion to be ignored -- and instead my code for row selection
kicks into effect:

                selection = self.treeview.get_selection()
                selection.set_mode(gtk.SELECTION_SINGLE)
                selection.connect('changed', self.on_selection_changed)

I do not understand why my mouse clicks on the 'expansion' arrow is
interpreted as an entire 'row selection' instead :(



More information about the pygtk mailing list