]>
Commit | Line | Data |
---|---|---|
1fded56b RD |
1 | |
2 | from wxPython.wx import * | |
3 | from wxPython.gizmos import wxTreeListCtrl | |
4 | ||
5 | import images | |
6 | ||
7 | #---------------------------------------------------------------------- | |
8 | ||
9 | class TestPanel(wxPanel): | |
10 | def __init__(self, parent, log): | |
11 | self.log = log | |
12 | wxPanel.__init__(self, parent, -1) | |
13 | EVT_SIZE(self, self.OnSize) | |
14 | ||
15 | self.tree = wxTreeListCtrl(self, -1, style = wxTR_DEFAULT_STYLE | |
16 | #| wxTR_ROW_LINES | |
17 | #| wxTR_NO_LINES | wxTR_TWIST_BUTTONS | |
18 | ) | |
19 | isz = (16,16) | |
20 | il = wxImageList(isz[0], isz[1]) | |
21 | fldridx = il.Add(wxArtProvider_GetBitmap(wxART_FOLDER, wxART_OTHER, isz)) | |
22 | fldropenidx = il.Add(wxArtProvider_GetBitmap(wxART_FILE_OPEN, wxART_OTHER, isz)) | |
23 | fileidx = il.Add(wxArtProvider_GetBitmap(wxART_REPORT_VIEW, wxART_OTHER, isz)) | |
24 | smileidx = il.Add(images.getSmilesBitmap()) | |
25 | ||
26 | self.tree.SetImageList(il) | |
27 | self.il = il | |
28 | ||
29 | # create some columns | |
30 | self.tree.AddColumn("Main column") | |
31 | self.tree.AddColumn("Column 1") | |
32 | self.tree.AddColumn("Column 2") | |
33 | self.tree.SetMainColumn(0) # the one with the tree in it... | |
34 | self.tree.SetColumnWidth(0, 175) | |
35 | ||
36 | ||
37 | self.root = self.tree.AddRoot("The Root Item") | |
38 | self.tree.SetItemText(self.root, "col 1 root", 1) | |
39 | self.tree.SetItemText(self.root, "col 2 root", 2) | |
40 | self.tree.SetItemImage(self.root, fldridx, which = wxTreeItemIcon_Normal) | |
41 | self.tree.SetItemImage(self.root, fldropenidx, which = wxTreeItemIcon_Expanded) | |
42 | ||
43 | ||
44 | for x in range(15): | |
45 | txt = "Item %d" % x | |
46 | child = self.tree.AppendItem(self.root, txt) | |
47 | self.tree.SetItemText(child, txt + "(c1)", 1) | |
48 | self.tree.SetItemText(child, txt + "(c2)", 2) | |
49 | self.tree.SetItemImage(child, fldridx, which = wxTreeItemIcon_Normal) | |
50 | self.tree.SetItemImage(child, fldropenidx, which = wxTreeItemIcon_Expanded) | |
51 | ||
52 | for y in range(5): | |
53 | txt = "item %d-%s" % (x, chr(ord("a")+y)) | |
54 | last = self.tree.AppendItem(child, txt) | |
55 | self.tree.SetItemText(last, txt + "(c1)", 1) | |
56 | self.tree.SetItemText(last, txt + "(c2)", 2) | |
57 | self.tree.SetItemImage(last, fldridx, which = wxTreeItemIcon_Normal) | |
58 | self.tree.SetItemImage(last, fldropenidx, which = wxTreeItemIcon_Expanded) | |
59 | ||
60 | for z in range(5): | |
61 | txt = "item %d-%s-%d" % (x, chr(ord("a")+y), z) | |
62 | item = self.tree.AppendItem(last, txt) | |
63 | self.tree.SetItemText(item, txt + "(c1)", 1) | |
64 | self.tree.SetItemText(item, txt + "(c2)", 2) | |
65 | self.tree.SetItemImage(item, fileidx, which = wxTreeItemIcon_Normal) | |
66 | self.tree.SetItemImage(item, smileidx, which = wxTreeItemIcon_Selected) | |
67 | ||
68 | ||
69 | self.tree.Expand(self.root) | |
70 | ||
b01fc892 RD |
71 | EVT_RIGHT_UP(self.tree.GetMainWindow(), self.OnRightUp) |
72 | ||
73 | ||
74 | def OnRightUp(self, evt): | |
75 | # Convert the position from being relative to the subwindow to | |
76 | # being relative to the outer treelist window so HitTest will | |
77 | # have the point it is expecting. | |
78 | pos = evt.GetPosition() | |
79 | pos = self.tree.GetMainWindow().ClientToScreen(pos) | |
80 | pos = self.tree.ScreenToClient(pos) | |
81 | item, flags, col = self.tree.HitTest(pos) | |
82 | if item: | |
83 | print flags, col, self.tree.GetItemText(item, col) | |
84 | ||
1fded56b RD |
85 | |
86 | def OnSize(self, evt): | |
87 | self.tree.SetSize(self.GetSize()) | |
88 | ||
89 | ||
90 | #---------------------------------------------------------------------- | |
91 | ||
92 | def runTest(frame, nb, log): | |
93 | win = TestPanel(nb, log) | |
94 | return win | |
95 | ||
96 | #---------------------------------------------------------------------- | |
97 | ||
98 | ||
99 | ||
100 | overview = """<html><body> | |
101 | <h2><center>wxTreeListCtrl</center></h2> | |
102 | ||
103 | The wxTreeListCtrl is essentially a wxTreeCtrl with extra columns, | |
104 | such that the look is similar to a wxListCtrl. | |
105 | ||
106 | </body></html> | |
107 | """ | |
108 | ||
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])]) | |
117 |