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