]>
Commit | Line | Data |
---|---|---|
cf694132 RD |
1 | |
2 | from wxPython.wx import * | |
3 | ||
8bf5d46e RD |
4 | import string |
5 | ||
cf694132 RD |
6 | #--------------------------------------------------------------------------- |
7 | ||
8 | class TestTreeCtrlPanel(wxPanel): | |
9 | def __init__(self, parent, log): | |
10 | wxPanel.__init__(self, parent, -1) | |
11 | ||
12 | self.log = log | |
13 | tID = NewId() | |
14 | ||
8bf5d46e | 15 | self.tree = wxTreeCtrl(self, tID, wxDefaultPosition, wxDefaultSize, |
b1462dfa | 16 | wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS)# | wxTR_MULTIPLE) |
8bf5d46e | 17 | |
a1df7a95 RD |
18 | #il = wxImageList(16, 16) |
19 | #idx1 = il.Add(wxBitmap('bitmaps/smiles.bmp', wxBITMAP_TYPE_BMP)) | |
20 | #idx2 = il.Add(wxBitmap('bitmaps/open.bmp', wxBITMAP_TYPE_BMP)) | |
21 | #idx3 = il.Add(wxBitmap('bitmaps/new.bmp', wxBITMAP_TYPE_BMP)) | |
22 | #idx4 = il.Add(wxBitmap('bitmaps/copy.bmp', wxBITMAP_TYPE_BMP)) | |
23 | #idx5 = il.Add(wxBitmap('bitmaps/paste.bmp', wxBITMAP_TYPE_BMP)) | |
f17fee68 | 24 | |
a1df7a95 RD |
25 | #self.tree.SetImageList(il) |
26 | #self.il = il | |
9b3d3bc4 | 27 | |
8bf5d46e | 28 | self.root = self.tree.AddRoot("The Root Item") |
a1df7a95 | 29 | #self.tree.SetItemImage(self.root, idx1) |
9b3d3bc4 | 30 | |
cf694132 | 31 | for x in range(15): |
8bf5d46e | 32 | child = self.tree.AppendItem(self.root, "Item %d" % x) |
a1df7a95 RD |
33 | #self.tree.SetItemImage(child, idx2) |
34 | #self.tree.SetItemSelectedImage(child, idx3) | |
cf694132 RD |
35 | for y in range(5): |
36 | last = self.tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y))) | |
a1df7a95 RD |
37 | #self.tree.SetItemImage(last, idx4) |
38 | #self.tree.SetItemSelectedImage(last, idx5) | |
cf694132 RD |
39 | for z in range(5): |
40 | self.tree.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z)) | |
41 | ||
8bf5d46e | 42 | self.tree.Expand(self.root) |
cf694132 RD |
43 | EVT_TREE_ITEM_EXPANDED (self, tID, self.OnItemExpanded) |
44 | EVT_TREE_ITEM_COLLAPSED (self, tID, self.OnItemCollapsed) | |
45 | EVT_TREE_SEL_CHANGED (self, tID, self.OnSelChanged) | |
8bf5d46e RD |
46 | EVT_TREE_BEGIN_LABEL_EDIT(self, tID, self.OnBeginEdit) |
47 | EVT_TREE_END_LABEL_EDIT (self, tID, self.OnEndEdit) | |
cf694132 | 48 | |
bb0054cd RD |
49 | EVT_LEFT_DCLICK(self.tree, self.OnLeftDClick) |
50 | EVT_RIGHT_DOWN(self.tree, self.OnRightClick) | |
51 | EVT_RIGHT_UP(self.tree, self.OnRightUp) | |
52 | ||
53 | def OnRightClick(self, event): | |
b1462dfa RD |
54 | pt = event.GetPosition(); |
55 | item = self.tree.HitTest(pt) | |
bb0054cd RD |
56 | self.log.WriteText("OnRightClick: %s\n" % self.tree.GetItemText(item)) |
57 | self.tree.SelectItem(item) | |
58 | ||
59 | def OnRightUp(self, event): | |
b1462dfa RD |
60 | pt = event.GetPosition(); |
61 | item = self.tree.HitTest(pt) | |
8bf5d46e RD |
62 | self.log.WriteText("OnRightUp: %s (manually starting label edit)\n" |
63 | % self.tree.GetItemText(item)) | |
64 | self.tree.EditLabel(item) | |
65 | ||
66 | ||
67 | ||
68 | def OnBeginEdit(self, event): | |
69 | self.log.WriteText("OnBeginEdit\n") | |
70 | # show how to prevent edit... | |
71 | if self.tree.GetItemText(event.GetItem()) == "The Root Item": | |
72 | wxBell() | |
73 | self.log.WriteText("You can't edit this one...\n") | |
74 | event.Veto() | |
75 | ||
76 | def OnEndEdit(self, event): | |
77 | self.log.WriteText("OnEndEdit\n") | |
78 | # show how to reject edit, we'll not allow any digits | |
79 | for x in event.GetLabel(): | |
80 | if x in string.digits: | |
81 | self.log.WriteText("You can't enter digits...\n") | |
82 | event.Veto() | |
83 | return | |
84 | ||
85 | ||
bb0054cd RD |
86 | |
87 | def OnLeftDClick(self, event): | |
b1462dfa RD |
88 | pt = event.GetPosition(); |
89 | item = self.tree.HitTest(pt) | |
bb0054cd RD |
90 | self.log.WriteText("OnLeftDClick: %s\n" % self.tree.GetItemText(item)) |
91 | ||
cf694132 RD |
92 | |
93 | def OnSize(self, event): | |
94 | w,h = self.GetClientSizeTuple() | |
95 | self.tree.SetDimensions(0, 0, w, h) | |
96 | ||
97 | ||
98 | def OnItemExpanded(self, event): | |
99 | item = event.GetItem() | |
100 | self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item)) | |
101 | ||
102 | def OnItemCollapsed(self, event): | |
103 | item = event.GetItem() | |
104 | self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item)) | |
105 | ||
106 | def OnSelChanged(self, event): | |
8bf5d46e RD |
107 | self.item = event.GetItem() |
108 | self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(self.item)) | |
164b735b RD |
109 | self.log.WriteText("BoundingRect: %s\n" % |
110 | self.tree.GetBoundingRect(self.item, true)) | |
111 | ||
cf694132 RD |
112 | |
113 | #--------------------------------------------------------------------------- | |
114 | ||
115 | def runTest(frame, nb, log): | |
116 | win = TestTreeCtrlPanel(nb, log) | |
117 | return win | |
118 | ||
119 | #--------------------------------------------------------------------------- | |
120 | ||
121 | ||
122 | ||
123 | ||
124 | ||
125 | ||
126 | ||
127 | ||
128 | ||
129 | ||
130 | ||
131 | ||
132 | ||
133 | ||
134 | ||
135 | ||
136 | ||
137 | ||
138 | overview = """\ | |
139 | A tree control presents information as a hierarchy, with items that may be expanded to show further items. Items in a tree control are referenced by wxTreeItemId handles. | |
140 | ||
141 | wxTreeCtrl() | |
142 | ------------------------- | |
143 | ||
144 | Default constructor. | |
145 | ||
146 | wxTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTR_HAS_BUTTONS, const wxValidator& validator = wxDefaultValidator, const wxString& name = "listCtrl") | |
147 | ||
148 | Constructor, creating and showing a tree control. | |
149 | ||
150 | Parameters | |
151 | ------------------- | |
152 | ||
153 | parent = Parent window. Must not be NULL. | |
154 | ||
155 | id = Window identifier. A value of -1 indicates a default value. | |
156 | ||
157 | pos = Window position. | |
158 | ||
159 | size = Window size. If the default size (-1, -1) is specified then the window is sized appropriately. | |
160 | ||
161 | style = Window style. See wxTreeCtrl. | |
162 | ||
163 | validator = Window validator. | |
164 | ||
165 | name = Window name. | |
166 | """ |