wx.TreeCtrl.GetSelections() not working as expected

Hi,

The number of tree items returned by GetSelections() is not correct in all
situations. When selecting multiple items (holding shift key down)
then GetSelections() is not returning all selected items. If you select n items,

the returned list from GetSelections() is n-1 items long. The missing item is not
the first or last item in the tree. It is item n-1 which is missing !!
Example: If I select “item1, item2, item3, item4” then GetSelections() will

     return "item1, item2, item4"

When deselecting tree items, everything is OK.

Sorry if the above is a bit unclear…

The reproduce the problem you can modify the TreeCtrl-DEMO by:

  • Adding the wx.TR_MULTIPLE style to the TreeCtrl

    self.tree = MyTreeCtrl(self, tID, wx.DefaultPosition, wx.DefaultSize,
    wx.TR_HAS_BUTTONS
    > wx.TR_EDIT_LABELS
    > wx.TR_MULTIPLE
    #| wx.TR_HIDE_ROOT
    , self.log)

  • Modify the OnSelChange method
    def OnSelChanged(self, event):

     self.item = event.GetItem()
     if self.item:
         self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(self.item))
         if wx.Platform == '__WXMSW__':
             self.log.WriteText("BoundingRect: %s\n" %
                                self.tree.GetBoundingRect(self.item, True))
         items = self.tree.GetSelections()
         self.log.WriteText
    

(str(map(self.tree.GetItemText, items)))
event.Skip()

  • Run the DEMO and compare the seleted tree items with the items returned by self.tree.GetSelections()

System: Windows XP, Python 2.5 , wxPython 2.8.1.1

Can somebody confirm this problem ?

Thanks.

Edgar

With your modifications to the demo code, I’m getting the correct behavior.

Windows XP, Python 2.5, wxPython 2.8.3.0

-Frank

···

On 6/1/07, Edgar Poth epmlist@googlemail.com wrote:

Hi,

The number of tree items returned by GetSelections() is not correct in all
situations. When selecting multiple items (holding shift key down)
then GetSelections() is not returning all selected items. If you select n items,

the returned list from GetSelections() is n-1 items long. The missing item is not
the first or last item in the tree. It is item n-1 which is missing !!
Example: If I select “item1, item2, item3, item4” then GetSelections() will

     return "item1, item2, item4"

When deselecting tree items, everything is OK.

Sorry if the above is a bit unclear…

The reproduce the problem you can modify the TreeCtrl-DEMO by:

  • Adding the wx.TR_MULTIPLE style to the TreeCtrl

    self.tree = MyTreeCtrl(self, tID, wx.DefaultPosition, wx.DefaultSize,
    wx.TR_HAS_BUTTONS
    > wx.TR_EDIT_LABELS
    > wx.TR_MULTIPLE
    #| wx.TR_HIDE_ROOT
    , self.log)

  • Modify the OnSelChange method
    def OnSelChanged(self, event):

     self.item = event.GetItem()
     if self.item:
         self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(self.item))
         if wx.Platform == '__WXMSW__':
    
    
             self.log.WriteText("BoundingRect: %s\n" %
                                self.tree.GetBoundingRect(self.item, True))
         items = self.tree.GetSelections()
    
         self.log.WriteText
    

(str(map(self.tree.GetItemText, items)))
event.Skip()

  • Run the DEMO and compare the seleted tree items with the items returned by self.tree.GetSelections()

System: Windows XP, Python 2.5 , wxPython 2.8.1.1

Can somebody confirm this problem ?

Thanks.

Edgar

Made your modifications and it's working fine.

WinXP, Python2.5, wxPython 2.8.3.0

···

On 6/1/07, Edgar Poth <epmlist@googlemail.com> wrote:

Hi,

The number of tree items returned by GetSelections() is not correct in all
situations. When selecting multiple items (holding shift key down)
then GetSelections() is not returning all selected items. If you select n items,
the returned list from GetSelections() is n-1 items long. The missing item is not
the first or last item in the tree. It is item n-1 which is missing !!
Example: If I select "item1, item2, item3, item4" then GetSelections() will
         return "item1, item2, item4"

When deselecting tree items, everything is OK.

Sorry if the above is a bit unclear..

The reproduce the problem you can modify the TreeCtrl-DEMO by:

- Adding the wx.TR_MULTIPLE style to the TreeCtrl

   self.tree = MyTreeCtrl(self, tID, wx.DefaultPosition, wx.DefaultSize,
                               wx.TR_HAS_BUTTONS
                               > wx.TR_EDIT_LABELS
                               > wx.TR_MULTIPLE
                               #| wx.TR_HIDE_ROOT
                               , self.log)

- Modify the OnSelChange method
    def OnSelChanged(self, event):
        self.item = event.GetItem()
        if self.item:
            self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(self.item))
            if wx.Platform == '__WXMSW__':
                 self.log.WriteText("BoundingRect: %s\n" %
                                   self.tree.GetBoundingRect(self.item, True))
            items = self.tree.GetSelections()
            self.log.WriteText (str(map(self.tree.GetItemText, items)))
        event.Skip()

- Run the DEMO and compare the seleted tree items with the items returned by self.tree.GetSelections()

System: Windows XP, Python 2.5 , wxPython 2.8.1.1

Can somebody confirm this problem ?

Tanks for the reply.

OK have upgrade to wxPython 2.8.4.0 but have still the same problem !

Edgar

···

2007/6/1, Frank Tobia < frank.tobia@gmail.com>:

With your modifications to the demo code, I’m getting the correct behavior.

Windows XP, Python 2.5, wxPython 2.8.3.0

-Frank

On 6/1/07, Edgar Poth epmlist@googlemail.com wrote:

Hi,

The number of tree items returned by GetSelections() is not correct in all
situations. When selecting multiple items (holding shift key down)
then GetSelections() is not returning all selected items. If you select n items,

the returned list from GetSelections() is n-1 items long. The missing item is not
the first or last item in the tree. It is item n-1 which is missing !!
Example: If I select “item1, item2, item3, item4” then GetSelections() will

     return "item1, item2, item4"

When deselecting tree items, everything is OK.

Sorry if the above is a bit unclear…

The reproduce the problem you can modify the TreeCtrl-DEMO by:

  • Adding the wx.TR_MULTIPLE style to the TreeCtrl

    self.tree = MyTreeCtrl(self, tID, wx.DefaultPosition, wx.DefaultSize,
    wx.TR_HAS_BUTTONS
    > wx.TR_EDIT_LABELS
    > wx.TR_MULTIPLE
    #| wx.TR_HIDE_ROOT
    , self.log)

  • Modify the OnSelChange method
    def OnSelChanged(self, event):

     self.item = event.GetItem()
     if self.item:
         self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(self.item))
         if wx.Platform == '__WXMSW__':
    
    
    
             self.log.WriteText("BoundingRect: %s\n" %
                                self.tree.GetBoundingRect(self.item, True))
         items = self.tree.GetSelections()
    
    
         self.log.WriteText
    

(str(map(self.tree.GetItemText, items)))
event.Skip()

  • Run the DEMO and compare the seleted tree items with the items returned by self.tree.GetSelections()

System: Windows XP, Python 2.5 , wxPython 2.8.1.1

Can somebody confirm this problem ?

Thanks.

Edgar

Edgar Poth wrote:

Tanks for the reply.

OK have upgrade to wxPython 2.8.4.0 <http://2.8.4.0> but have still the same problem !

I also can't duplicate the problem using my current workspace version (2.8.4.1pre). The items don't always come in the order that I expect, but they are all there.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin,

This is very strange. I have test different wxPython installations on different computers.
All have the same behaviour.

I will try to describe the problem.

  • Select first item (item1)
    GetSelections() return the selected item. This is OK

  • Select the second item (item2) (shift+down)
    GetSelections() return only one item (only item2). This is not OK. Where is item1 ?

  • Select the third item (item3) (shift+down)
    GetSelections() return list with two items [item1,item3]. This is not OK. Where is item2 ?

  • Select the fourth item (item4) (shift+down)
    GetSelections() return list with three items [item1,item2,item4]. This is not OK. Where is item3 ?

  • Deselect item4 (shift+up)
    GetSelections() return list with three items [item1,item2,item3]. This is OK.

  • Deselect item3 (shift+up)
    GetSelections() return list with three items [item1,item2]. This is OK.

I will try tomorrow the same test on Linux.

Thanks for your help.

Edgar

···

2007/6/1, Robin Dunn robin@alldunn.com:

Edgar Poth wrote:

Tanks for the reply.

OK have upgrade to wxPython 2.8.4.0 <http://2.8.4.0> but have still the
same problem !

I also can’t duplicate the problem using my current workspace version
(2.8.4.1pre). The items don’t always come in the order that I expect,
but they are all there.


Robin Dunn

Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Aha, now I’m seeing it. I get proper behavior by using the mouse, but exactly what you describe when using the up/down keys.

-Frank

···

On 6/1/07, Edgar Poth epmlist@googlemail.com wrote:

Robin,

This is very strange. I have test different wxPython installations on different computers.
All have the same behaviour.

I will try to describe the problem.

  • Select first item (item1)
    GetSelections() return the selected item. This is OK

  • Select the second item (item2) (shift+down)
    GetSelections() return only one item (only item2). This is not OK. Where is item1 ?

  • Select the third item (item3) (shift+down)
    GetSelections() return list with two items [item1,item3]. This is not OK. Where is item2 ?

  • Select the fourth item (item4) (shift+down)
    GetSelections() return list with three items [item1,item2,item4]. This is not OK. Where is item3 ?

  • Deselect item4 (shift+up)
    GetSelections() return list with three items [item1,item2,item3]. This is OK.

  • Deselect item3 (shift+up)
    GetSelections() return list with three items [item1,item2]. This is OK.

I will try tomorrow the same test on Linux.

Thanks for your help.

Edgar

2007/6/1, Robin Dunn robin@alldunn.com:

Edgar Poth wrote:

Tanks for the reply.

OK have upgrade to wxPython 2.8.4.0 <
http://2.8.4.0
> but have still the
same problem !

I also can’t duplicate the problem using my current workspace version
(2.8.4.1pre). The items don’t always come in the order that I expect,
but they are all there.


Robin Dunn

Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Frank Tobia wrote:

Aha, now I'm seeing it. I get proper behavior by using the mouse, but exactly what you describe when using the up/down keys.

Yep, me too.

Edgar, please enter a bug report about this with a category od "wxMSW Specific" and be sure to mention that this only happens with keyboard selection.

    I will try tomorrow the same test on Linux.

It doesn't have this problem, but it does have the "feature" that child items within collapsed selected items are part of the selection list. I'm not sure if that should be considered a bug for wxMSW or for wxGTK...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Robin,

Frank Tobia wrote:
> Aha, now I'm seeing it. I get proper behavior by using the mouse, but
> exactly what you describe when using the up/down keys.
>

Yep, me too.

Edgar, please enter a bug report about this with a category od "wxMSW
Specific" and be sure to mention that this only happens with keyboard
selection.

>> I will try tomorrow the same test on Linux.

It doesn't have this problem, but it does have the "feature" that child
items within collapsed selected items are part of the selection list.
I'm not sure if that should be considered a bug for wxMSW or for wxGTK...

I remember someone pointed out in the past this last "bug" (feature?)
about CustomTreeCtrl, which has been fixed a while ago. I don't know
for sure about keyboard selection though... I have to try and see if
CustomTreeCtrl behaves strangely :smiley:

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

···

On 6/2/07, Robin Dunn wrote: