Skip to content

Instantly share code, notes, and snippets.

@tatarize
Created March 10, 2020 08:34
Show Gist options
  • Save tatarize/919921f6e77db9912784df27c01453b5 to your computer and use it in GitHub Desktop.
Save tatarize/919921f6e77db9912784df27c01453b5 to your computer and use it in GitHub Desktop.
Test code for Tree Selection Problem.
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((400, 300))
self.tree = wx.TreeCtrl(self, wx.ID_ANY, style=wx.TR_MULTIPLE)
self.root = self.tree.AddRoot("My Tree")
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(self.tree, 1, wx.EXPAND, 0)
self.SetSizer(sizer_1)
self.Layout()
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_tree_selection, self.tree)
for j in range(20):
for k in range(5):
self.tree.AppendItem(self.root, str(k))
self.tree.ExpandAll()
def on_tree_selection(self, event):
label = self.tree.GetItemText(self.tree.GetFocusedItem())
h = self.tree.GetFirstChild(self.root)[0]
while h.IsOk():
if label == self.tree.GetItemText(h):
self.tree.SelectItem(h, True)
h = self.tree.GetNextSibling(h)
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment