]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-15/tree_icons.py
pixbuf cursor support is for GTK 2.4.
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-15 / tree_icons.py
1 import wx
2 import data
3
4 class TestFrame(wx.Frame):
5 def __init__(self):
6 wx.Frame.__init__(self, None,
7 title="simple tree with icons", size=(400,500))
8
9 # Create an image list
10 il = wx.ImageList(16,16)
11
12 # Get some standard images from the art provider and add them
13 # to the image list
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)))
23
24
25 # Create the tree
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)
34
35 self.AddTreeNodes(root, data.tree)
36 self.tree.Expand(root)
37
38
39 def AddTreeNodes(self, parentItem, items):
40 for item in items:
41 if type(item) == str:
42 newItem = self.tree.AppendItem(parentItem, item)
43 self.tree.SetItemImage(newItem, self.fileidx,
44 wx.TreeItemIcon_Normal)
45 else:
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)
51
52 self.AddTreeNodes(newItem, item[1])
53
54
55 def GetItemText(self, item):
56 if item:
57 return self.tree.GetItemText(item)
58 else:
59 return ""
60
61 app = wx.PySimpleApp(redirect=True)
62 frame = TestFrame()
63 frame.Show()
64 app.MainLoop()
65