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