]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-15/tree_treelist.py
5 class TestFrame(wx
.Frame
):
7 wx
.Frame
.__init
__(self
, None, title
="TreeListCtrl", size
=(400,500))
10 il
= wx
.ImageList(16,16)
12 # Get some standard images from the art provider and add them
14 self
.fldridx
= il
.Add(
15 wx
.ArtProvider
.GetBitmap(wx
.ART_FOLDER
, wx
.ART_OTHER
, (16,16)))
16 self
.fldropenidx
= il
.Add(
17 wx
.ArtProvider
.GetBitmap(wx
.ART_FILE_OPEN
, wx
.ART_OTHER
, (16,16)))
18 self
.fileidx
= il
.Add(
19 wx
.ArtProvider
.GetBitmap(wx
.ART_NORMAL_FILE
, wx
.ART_OTHER
, (16,16)))
23 self
.tree
= wx
.gizmos
.TreeListCtrl(self
, style
=
25 | wx
.TR_FULL_ROW_HIGHLIGHT
)
27 # Give it the image list
28 self
.tree
.AssignImageList(il
)
32 self
.tree
.AddColumn("Class Name")
33 self
.tree
.AddColumn("Description")
34 self
.tree
.SetMainColumn(0) # the one with the tree in it...
35 self
.tree
.SetColumnWidth(0, 200)
36 self
.tree
.SetColumnWidth(1, 200)
38 # Add a root node and assign it some images
39 root
= self
.tree
.AddRoot("wx.Object")
40 self
.tree
.SetItemText(root
, "A description of wx.Object", 1)
41 self
.tree
.SetItemImage(root
, self
.fldridx
,
42 wx
.TreeItemIcon_Normal
)
43 self
.tree
.SetItemImage(root
, self
.fldropenidx
,
44 wx
.TreeItemIcon_Expanded
)
46 # Add nodes from our data set
47 self
.AddTreeNodes(root
, data
.tree
)
49 # Bind some interesting events
50 self
.Bind(wx
.EVT_TREE_ITEM_EXPANDED
, self
.OnItemExpanded
, self
.tree
)
51 self
.Bind(wx
.EVT_TREE_ITEM_COLLAPSED
, self
.OnItemCollapsed
, self
.tree
)
52 self
.Bind(wx
.EVT_TREE_SEL_CHANGED
, self
.OnSelChanged
, self
.tree
)
53 self
.Bind(wx
.EVT_TREE_ITEM_ACTIVATED
, self
.OnActivated
, self
.tree
)
55 # Expand the first level
56 self
.tree
.Expand(root
)
59 def AddTreeNodes(self
, parentItem
, items
):
61 Recursively traverses the data structure, adding tree nodes to
66 newItem
= self
.tree
.AppendItem(parentItem
, item
)
67 self
.tree
.SetItemText(newItem
, "A description of %s" % item
, 1)
68 self
.tree
.SetItemImage(newItem
, self
.fileidx
,
69 wx
.TreeItemIcon_Normal
)
71 newItem
= self
.tree
.AppendItem(parentItem
, item
[0])
72 self
.tree
.SetItemText(newItem
, "A description of %s" % item
[0], 1)
73 self
.tree
.SetItemImage(newItem
, self
.fldridx
,
74 wx
.TreeItemIcon_Normal
)
75 self
.tree
.SetItemImage(newItem
, self
.fldropenidx
,
76 wx
.TreeItemIcon_Expanded
)
78 self
.AddTreeNodes(newItem
, item
[1])
81 def GetItemText(self
, item
):
83 return self
.tree
.GetItemText(item
)
87 def OnItemExpanded(self
, evt
):
88 print "OnItemExpanded: ", self
.GetItemText(evt
.GetItem())
90 def OnItemCollapsed(self
, evt
):
91 print "OnItemCollapsed:", self
.GetItemText(evt
.GetItem())
93 def OnSelChanged(self
, evt
):
94 print "OnSelChanged: ", self
.GetItemText(evt
.GetItem())
96 def OnActivated(self
, evt
):
97 print "OnActivated: ", self
.GetItemText(evt
.GetItem())
100 app
= wx
.PySimpleApp(redirect
=True)