4
class TestFrame(wx.Frame):
6
wx.Frame.__init__(self, None,
7
title="simple tree with icons", 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,
16
wx.ART_OTHER, (16,16)))
17
self.fldropenidx = il.Add(
18
wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN,
19
wx.ART_OTHER, (16,16)))
20
self.fileidx = il.Add(
21
wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE,
22
wx.ART_OTHER, (16,16)))
26
self.tree = wx.TreeCtrl(self)
27
# Give it the image list
28
self.tree.AssignImageList(il)
29
root = self.tree.AddRoot("wx.Object")
30
self.tree.SetItemImage(root, self.fldridx,
31
wx.TreeItemIcon_Normal)
32
self.tree.SetItemImage(root, self.fldropenidx,
33
wx.TreeItemIcon_Expanded)
35
self.AddTreeNodes(root, data.tree)
36
self.tree.Expand(root)
39
def AddTreeNodes(self, parentItem, items):
42
newItem = self.tree.AppendItem(parentItem, item)
43
self.tree.SetItemImage(newItem, self.fileidx,
44
wx.TreeItemIcon_Normal)
46
newItem = self.tree.AppendItem(parentItem, item[0])
47
self.tree.SetItemImage(newItem, self.fldridx,
48
wx.TreeItemIcon_Normal)
49
self.tree.SetItemImage(newItem, self.fldropenidx,
50
wx.TreeItemIcon_Expanded)
52
self.AddTreeNodes(newItem, item[1])
55
def GetItemText(self, item):
57
return self.tree.GetItemText(item)
61
app = wx.PySimpleApp(redirect=True)