]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/TreeListCtrl.py
Undo part of lst change
[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
19 #| wx.TR_NO_LINES
648d396c
RD
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
1fded56b 27 )
648d396c 28
1fded56b 29 isz = (16,16)
8fa876ca
RD
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))
3a9becbd 33 fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz))
1fded56b
RD
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)
8fa876ca
RD
50 self.tree.SetItemImage(self.root, fldridx, which = wx.TreeItemIcon_Normal)
51 self.tree.SetItemImage(self.root, fldropenidx, which = wx.TreeItemIcon_Expanded)
1fded56b
RD
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)
8fa876ca
RD
59 self.tree.SetItemImage(child, fldridx, which = wx.TreeItemIcon_Normal)
60 self.tree.SetItemImage(child, fldropenidx, which = wx.TreeItemIcon_Expanded)
1fded56b
RD
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)
8fa876ca
RD
67 self.tree.SetItemImage(last, fldridx, which = wx.TreeItemIcon_Normal)
68 self.tree.SetItemImage(last, fldropenidx, which = wx.TreeItemIcon_Expanded)
1fded56b
RD
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)
8fa876ca
RD
75 self.tree.SetItemImage(item, fileidx, which = wx.TreeItemIcon_Normal)
76 self.tree.SetItemImage(item, smileidx, which = wx.TreeItemIcon_Selected)
1fded56b
RD
77
78
79 self.tree.Expand(self.root)
80
8fa876ca 81 self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
b01fc892
RD
82
83
84 def OnRightUp(self, evt):
b01fc892 85 pos = evt.GetPosition()
b01fc892
RD
86 item, flags, col = self.tree.HitTest(pos)
87 if item:
00a5e5a9
RD
88 self.log.write('Flags: %s, Col:%s, Text: %s' %
89 (flags, col, self.tree.GetItemText(item, col)))
b01fc892 90
1fded56b
RD
91 def OnSize(self, evt):
92 self.tree.SetSize(self.GetSize())
93
94
95#----------------------------------------------------------------------
96
97def runTest(frame, nb, log):
98 win = TestPanel(nb, log)
99 return win
100
101#----------------------------------------------------------------------
102
103
104
105overview = """<html><body>
95bfd958 106<h2><center>TreeListCtrl</center></h2>
1fded56b 107
95bfd958 108The TreeListCtrl is essentially a wx.TreeCtrl with extra columns,
8fa876ca 109such that the look is similar to a wx.ListCtrl.
1fded56b
RD
110
111</body></html>
112"""
113
114
1fded56b
RD
115if __name__ == '__main__':
116 #raw_input("Press enter...")
117 import sys,os
118 import run
8eca4fef 119 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1fded56b 120