]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/TreeListCtrl.py
Missing include.
[wxWidgets.git] / wxPython / demo / TreeListCtrl.py
1
2 import wx
3 import wx.gizmos as gizmos
4
5 import images
6
7 #----------------------------------------------------------------------
8
9 class TestPanel(wx.Panel):
10 def __init__(self, parent, log):
11 self.log = log
12 wx.Panel.__init__(self, parent, -1)
13 self.Bind(wx.EVT_SIZE, self.OnSize)
14
15 self.tree = gizmos.TreeListCtrl(self, -1, style =
16 wx.TR_DEFAULT_STYLE
17 #wx.TR_TWIST_BUTTONS
18 #| wx.TR_ROW_LINES
19 #| wx.TR_NO_LINES
20 | wx.TR_FULL_ROW_HIGHLIGHT
21
22 # By default the style will be adjusted on
23 # Mac to use twisty buttons and no lines. If
24 # you would rather control this yourself then
25 # add this style.
26 #| wx.TR_DONT_ADJUST_MAC
27 )
28
29 isz = (16,16)
30 il = wx.ImageList(isz[0], isz[1])
31 fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz))
32 fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz))
33 fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_REPORT_VIEW, wx.ART_OTHER, isz))
34 smileidx = il.Add(images.getSmilesBitmap())
35
36 self.tree.SetImageList(il)
37 self.il = il
38
39 # create some columns
40 self.tree.AddColumn("Main column")
41 self.tree.AddColumn("Column 1")
42 self.tree.AddColumn("Column 2")
43 self.tree.SetMainColumn(0) # the one with the tree in it...
44 self.tree.SetColumnWidth(0, 175)
45
46
47 self.root = self.tree.AddRoot("The Root Item")
48 self.tree.SetItemText(self.root, "col 1 root", 1)
49 self.tree.SetItemText(self.root, "col 2 root", 2)
50 self.tree.SetItemImage(self.root, fldridx, which = wx.TreeItemIcon_Normal)
51 self.tree.SetItemImage(self.root, fldropenidx, which = wx.TreeItemIcon_Expanded)
52
53
54 for x in range(15):
55 txt = "Item %d" % x
56 child = self.tree.AppendItem(self.root, txt)
57 self.tree.SetItemText(child, txt + "(c1)", 1)
58 self.tree.SetItemText(child, txt + "(c2)", 2)
59 self.tree.SetItemImage(child, fldridx, which = wx.TreeItemIcon_Normal)
60 self.tree.SetItemImage(child, fldropenidx, which = wx.TreeItemIcon_Expanded)
61
62 for y in range(5):
63 txt = "item %d-%s" % (x, chr(ord("a")+y))
64 last = self.tree.AppendItem(child, txt)
65 self.tree.SetItemText(last, txt + "(c1)", 1)
66 self.tree.SetItemText(last, txt + "(c2)", 2)
67 self.tree.SetItemImage(last, fldridx, which = wx.TreeItemIcon_Normal)
68 self.tree.SetItemImage(last, fldropenidx, which = wx.TreeItemIcon_Expanded)
69
70 for z in range(5):
71 txt = "item %d-%s-%d" % (x, chr(ord("a")+y), z)
72 item = self.tree.AppendItem(last, txt)
73 self.tree.SetItemText(item, txt + "(c1)", 1)
74 self.tree.SetItemText(item, txt + "(c2)", 2)
75 self.tree.SetItemImage(item, fileidx, which = wx.TreeItemIcon_Normal)
76 self.tree.SetItemImage(item, smileidx, which = wx.TreeItemIcon_Selected)
77
78
79 self.tree.Expand(self.root)
80
81 self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
82
83
84 def OnRightUp(self, evt):
85 pos = evt.GetPosition()
86 item, flags, col = self.tree.HitTest(pos)
87 if item:
88 self.log.write('Flags: %s, Col:%s, Text: %s' %
89 (flags, col, self.tree.GetItemText(item, col)))
90
91 def OnSize(self, evt):
92 self.tree.SetSize(self.GetSize())
93
94
95 #----------------------------------------------------------------------
96
97 def runTest(frame, nb, log):
98 win = TestPanel(nb, log)
99 return win
100
101 #----------------------------------------------------------------------
102
103
104
105 overview = """<html><body>
106 <h2><center>TreeListCtrl</center></h2>
107
108 The TreeListCtrl is essentially a wx.TreeCtrl with extra columns,
109 such that the look is similar to a wx.ListCtrl.
110
111 </body></html>
112 """
113
114
115 if __name__ == '__main__':
116 #raw_input("Press enter...")
117 import sys,os
118 import run
119 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
120