]>
Commit | Line | Data |
---|---|---|
1 | # 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net) | |
2 | # | |
3 | # o Updated for wx namespace | |
4 | # | |
5 | ||
6 | import wx | |
7 | import wx.gizmos as gizmos | |
8 | ||
9 | import images | |
10 | ||
11 | #---------------------------------------------------------------------- | |
12 | ||
13 | class TestPanel(wx.Panel): | |
14 | def __init__(self, parent, log): | |
15 | self.log = log | |
16 | wx.Panel.__init__(self, parent, -1) | |
17 | self.Bind(wx.EVT_SIZE, self.OnSize) | |
18 | ||
19 | self.tree = gizmos.TreeListCtrl(self, -1, style = wx.TR_DEFAULT_STYLE | |
20 | #| wx.TR_ROW_LINES | |
21 | #| wx.TR_NO_LINES | |
22 | #| wx.TR_TWIST_BUTTONS | |
23 | ) | |
24 | isz = (16,16) | |
25 | il = wx.ImageList(isz[0], isz[1]) | |
26 | fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz)) | |
27 | fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz)) | |
28 | fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_REPORT_VIEW, wx.ART_OTHER, isz)) | |
29 | smileidx = il.Add(images.getSmilesBitmap()) | |
30 | ||
31 | self.tree.SetImageList(il) | |
32 | self.il = il | |
33 | ||
34 | # create some columns | |
35 | self.tree.AddColumn("Main column") | |
36 | self.tree.AddColumn("Column 1") | |
37 | self.tree.AddColumn("Column 2") | |
38 | self.tree.SetMainColumn(0) # the one with the tree in it... | |
39 | self.tree.SetColumnWidth(0, 175) | |
40 | ||
41 | ||
42 | self.root = self.tree.AddRoot("The Root Item") | |
43 | self.tree.SetItemText(self.root, "col 1 root", 1) | |
44 | self.tree.SetItemText(self.root, "col 2 root", 2) | |
45 | self.tree.SetItemImage(self.root, fldridx, which = wx.TreeItemIcon_Normal) | |
46 | self.tree.SetItemImage(self.root, fldropenidx, which = wx.TreeItemIcon_Expanded) | |
47 | ||
48 | ||
49 | for x in range(15): | |
50 | txt = "Item %d" % x | |
51 | child = self.tree.AppendItem(self.root, txt) | |
52 | self.tree.SetItemText(child, txt + "(c1)", 1) | |
53 | self.tree.SetItemText(child, txt + "(c2)", 2) | |
54 | self.tree.SetItemImage(child, fldridx, which = wx.TreeItemIcon_Normal) | |
55 | self.tree.SetItemImage(child, fldropenidx, which = wx.TreeItemIcon_Expanded) | |
56 | ||
57 | for y in range(5): | |
58 | txt = "item %d-%s" % (x, chr(ord("a")+y)) | |
59 | last = self.tree.AppendItem(child, txt) | |
60 | self.tree.SetItemText(last, txt + "(c1)", 1) | |
61 | self.tree.SetItemText(last, txt + "(c2)", 2) | |
62 | self.tree.SetItemImage(last, fldridx, which = wx.TreeItemIcon_Normal) | |
63 | self.tree.SetItemImage(last, fldropenidx, which = wx.TreeItemIcon_Expanded) | |
64 | ||
65 | for z in range(5): | |
66 | txt = "item %d-%s-%d" % (x, chr(ord("a")+y), z) | |
67 | item = self.tree.AppendItem(last, txt) | |
68 | self.tree.SetItemText(item, txt + "(c1)", 1) | |
69 | self.tree.SetItemText(item, txt + "(c2)", 2) | |
70 | self.tree.SetItemImage(item, fileidx, which = wx.TreeItemIcon_Normal) | |
71 | self.tree.SetItemImage(item, smileidx, which = wx.TreeItemIcon_Selected) | |
72 | ||
73 | ||
74 | self.tree.Expand(self.root) | |
75 | ||
76 | self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp) | |
77 | ||
78 | ||
79 | def OnRightUp(self, evt): | |
80 | # Convert the position from being relative to the subwindow to | |
81 | # being relative to the outer treelist window so HitTest will | |
82 | # have the point it is expecting. | |
83 | pos = evt.GetPosition() | |
84 | pos = self.tree.GetMainWindow().ClientToScreen(pos) | |
85 | pos = self.tree.ScreenToClient(pos) | |
86 | item, flags, col = self.tree.HitTest(pos) | |
87 | ||
88 | if item: | |
89 | print flags, col, self.tree.GetItemText(item, col) | |
90 | ||
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>wxTreeListCtrl</center></h2> | |
108 | ||
109 | The wx.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])]) | |
121 |