[wxPython-users] wx.TreeCtrl.GetSelections() not working as expected

Tal Einat taleinat at gmail.com
Fri Jun 1 06:52:24 PDT 2007


On 6/1/07, Edgar Poth <epmlist at 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 ?

Made your modifications and it's working fine.

WinXP, Python2.5, wxPython 2.8.3.0




More information about the wxpython-users mailing list