]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-15/tree_simple.py
4 class TestFrame(wx
.Frame
):
6 wx
.Frame
.__init
__(self
, None, title
="simple tree", size
=(400,500))
9 self
.tree
= wx
.TreeCtrl(self
)
12 root
= self
.tree
.AddRoot("wx.Object")
14 # Add nodes from our data set
15 self
.AddTreeNodes(root
, data
.tree
)
17 # Bind some interesting events
18 self
.Bind(wx
.EVT_TREE_ITEM_EXPANDED
, self
.OnItemExpanded
, self
.tree
)
19 self
.Bind(wx
.EVT_TREE_ITEM_COLLAPSED
, self
.OnItemCollapsed
, self
.tree
)
20 self
.Bind(wx
.EVT_TREE_SEL_CHANGED
, self
.OnSelChanged
, self
.tree
)
21 self
.Bind(wx
.EVT_TREE_ITEM_ACTIVATED
, self
.OnActivated
, self
.tree
)
23 # Expand the first level
24 self
.tree
.Expand(root
)
27 def AddTreeNodes(self
, parentItem
, items
):
29 Recursively traverses the data structure, adding tree nodes to
34 self
.tree
.AppendItem(parentItem
, item
)
36 newItem
= self
.tree
.AppendItem(parentItem
, item
[0])
37 self
.AddTreeNodes(newItem
, item
[1])
39 def GetItemText(self
, item
):
41 return self
.tree
.GetItemText(item
)
45 def OnItemExpanded(self
, evt
):
46 print "OnItemExpanded: ", self
.GetItemText(evt
.GetItem())
48 def OnItemCollapsed(self
, evt
):
49 print "OnItemCollapsed:", self
.GetItemText(evt
.GetItem())
51 def OnSelChanged(self
, evt
):
52 print "OnSelChanged: ", self
.GetItemText(evt
.GetItem())
54 def OnActivated(self
, evt
):
55 print "OnActivated: ", self
.GetItemText(evt
.GetItem())
58 app
= wx
.PySimpleApp(redirect
=True)