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