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