]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/TreeListCtrl.py
Fixed upload location, test sending an email when successfully finished
[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
8fa876ca
RD
15 self.tree = gizmos.TreeListCtrl(self, -1, style = wx.TR_DEFAULT_STYLE
16 #| wx.TR_ROW_LINES
17 #| wx.TR_NO_LINES
18 #| wx.TR_TWIST_BUTTONS
4c515845 19 #| wx.TR_FULL_ROW_HIGHLIGHT
1fded56b
RD
20 )
21 isz = (16,16)
8fa876ca
RD
22 il = wx.ImageList(isz[0], isz[1])
23 fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz))
24 fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz))
25 fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_REPORT_VIEW, wx.ART_OTHER, isz))
1fded56b
RD
26 smileidx = il.Add(images.getSmilesBitmap())
27
28 self.tree.SetImageList(il)
29 self.il = il
30
31 # create some columns
32 self.tree.AddColumn("Main column")
33 self.tree.AddColumn("Column 1")
34 self.tree.AddColumn("Column 2")
35 self.tree.SetMainColumn(0) # the one with the tree in it...
36 self.tree.SetColumnWidth(0, 175)
37
38
39 self.root = self.tree.AddRoot("The Root Item")
40 self.tree.SetItemText(self.root, "col 1 root", 1)
41 self.tree.SetItemText(self.root, "col 2 root", 2)
8fa876ca
RD
42 self.tree.SetItemImage(self.root, fldridx, which = wx.TreeItemIcon_Normal)
43 self.tree.SetItemImage(self.root, fldropenidx, which = wx.TreeItemIcon_Expanded)
1fded56b
RD
44
45
46 for x in range(15):
47 txt = "Item %d" % x
48 child = self.tree.AppendItem(self.root, txt)
49 self.tree.SetItemText(child, txt + "(c1)", 1)
50 self.tree.SetItemText(child, txt + "(c2)", 2)
8fa876ca
RD
51 self.tree.SetItemImage(child, fldridx, which = wx.TreeItemIcon_Normal)
52 self.tree.SetItemImage(child, fldropenidx, which = wx.TreeItemIcon_Expanded)
1fded56b
RD
53
54 for y in range(5):
55 txt = "item %d-%s" % (x, chr(ord("a")+y))
56 last = self.tree.AppendItem(child, txt)
57 self.tree.SetItemText(last, txt + "(c1)", 1)
58 self.tree.SetItemText(last, txt + "(c2)", 2)
8fa876ca
RD
59 self.tree.SetItemImage(last, fldridx, which = wx.TreeItemIcon_Normal)
60 self.tree.SetItemImage(last, fldropenidx, which = wx.TreeItemIcon_Expanded)
1fded56b
RD
61
62 for z in range(5):
63 txt = "item %d-%s-%d" % (x, chr(ord("a")+y), z)
64 item = self.tree.AppendItem(last, txt)
65 self.tree.SetItemText(item, txt + "(c1)", 1)
66 self.tree.SetItemText(item, txt + "(c2)", 2)
8fa876ca
RD
67 self.tree.SetItemImage(item, fileidx, which = wx.TreeItemIcon_Normal)
68 self.tree.SetItemImage(item, smileidx, which = wx.TreeItemIcon_Selected)
1fded56b
RD
69
70
71 self.tree.Expand(self.root)
72
8fa876ca 73 self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
b01fc892
RD
74
75
76 def OnRightUp(self, evt):
77 # Convert the position from being relative to the subwindow to
78 # being relative to the outer treelist window so HitTest will
79 # have the point it is expecting.
80 pos = evt.GetPosition()
81 pos = self.tree.GetMainWindow().ClientToScreen(pos)
82 pos = self.tree.ScreenToClient(pos)
83 item, flags, col = self.tree.HitTest(pos)
8fa876ca 84
b01fc892
RD
85 if item:
86 print flags, col, self.tree.GetItemText(item, col)
87
1fded56b
RD
88
89 def OnSize(self, evt):
90 self.tree.SetSize(self.GetSize())
91
92
93#----------------------------------------------------------------------
94
95def runTest(frame, nb, log):
96 win = TestPanel(nb, log)
97 return win
98
99#----------------------------------------------------------------------
100
101
102
103overview = """<html><body>
95bfd958 104<h2><center>TreeListCtrl</center></h2>
1fded56b 105
95bfd958 106The TreeListCtrl is essentially a wx.TreeCtrl with extra columns,
8fa876ca 107such that the look is similar to a wx.ListCtrl.
1fded56b
RD
108
109</body></html>
110"""
111
112
1fded56b
RD
113if __name__ == '__main__':
114 #raw_input("Press enter...")
115 import sys,os
116 import run
8eca4fef 117 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1fded56b 118