OSDN Git Service

Elements list: catch wxPython::invalid item exception when text in the filter field...
authorJoseph Lee <joseph.lee22590@gmail.com>
Tue, 18 Sep 2018 00:04:58 +0000 (17:04 -0700)
committerMichael Curran <michaelDCurran@users.noreply.github.com>
Tue, 18 Sep 2018 00:04:58 +0000 (10:04 +1000)
Regression: when a user enters text into the filter field and no elements are found, wxPython returns 'invalid item' when attempting to obtain selection from the search tree. Thus coerce this to default element (initial element).

source/browseMode.py

index f516a7e..6f7d800 100644 (file)
@@ -887,7 +887,11 @@ class ElementsListDialog(wx.Dialog):
        def filter(self, filterText, newElementType=False):\r
                # If this is a new element type, use the element nearest the cursor.\r
                # Otherwise, use the currently selected element.\r
-               defaultElement = self._initialElement if newElementType else self.tree.GetItemData(self.tree.GetSelection())\r
+               # #8753: wxPython 4 returns "invalid tree item" when the tree view is empty, so use initial element if appropriate.\r
+               try:\r
+                       defaultElement = self._initialElement if newElementType else self.tree.GetItemData(self.tree.GetSelection())\r
+               except:\r
+                       defaultElement = self._initialElement\r
                # Clear the tree.\r
                self.tree.DeleteChildren(self.treeRoot)\r
 \r