]>
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 RD |
17 | |
18 | self.root = self.tree.AddRoot("The Root Item") | |
cf694132 | 19 | for x in range(15): |
8bf5d46e | 20 | child = self.tree.AppendItem(self.root, "Item %d" % x) |
b1462dfa | 21 | #self.tree.SelectItem(child) |
cf694132 RD |
22 | for y in range(5): |
23 | last = self.tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y))) | |
24 | for z in range(5): | |
25 | self.tree.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z)) | |
26 | ||
8bf5d46e | 27 | self.tree.Expand(self.root) |
cf694132 RD |
28 | EVT_TREE_ITEM_EXPANDED (self, tID, self.OnItemExpanded) |
29 | EVT_TREE_ITEM_COLLAPSED (self, tID, self.OnItemCollapsed) | |
30 | EVT_TREE_SEL_CHANGED (self, tID, self.OnSelChanged) | |
8bf5d46e RD |
31 | EVT_TREE_BEGIN_LABEL_EDIT(self, tID, self.OnBeginEdit) |
32 | EVT_TREE_END_LABEL_EDIT (self, tID, self.OnEndEdit) | |
cf694132 | 33 | |
bb0054cd RD |
34 | EVT_LEFT_DCLICK(self.tree, self.OnLeftDClick) |
35 | EVT_RIGHT_DOWN(self.tree, self.OnRightClick) | |
36 | EVT_RIGHT_UP(self.tree, self.OnRightUp) | |
37 | ||
38 | def OnRightClick(self, event): | |
b1462dfa RD |
39 | pt = event.GetPosition(); |
40 | item = self.tree.HitTest(pt) | |
bb0054cd RD |
41 | self.log.WriteText("OnRightClick: %s\n" % self.tree.GetItemText(item)) |
42 | self.tree.SelectItem(item) | |
43 | ||
44 | def OnRightUp(self, event): | |
b1462dfa RD |
45 | pt = event.GetPosition(); |
46 | item = self.tree.HitTest(pt) | |
8bf5d46e RD |
47 | self.log.WriteText("OnRightUp: %s (manually starting label edit)\n" |
48 | % self.tree.GetItemText(item)) | |
49 | self.tree.EditLabel(item) | |
50 | ||
51 | ||
52 | ||
53 | def OnBeginEdit(self, event): | |
54 | self.log.WriteText("OnBeginEdit\n") | |
55 | # show how to prevent edit... | |
56 | if self.tree.GetItemText(event.GetItem()) == "The Root Item": | |
57 | wxBell() | |
58 | self.log.WriteText("You can't edit this one...\n") | |
59 | event.Veto() | |
60 | ||
61 | def OnEndEdit(self, event): | |
62 | self.log.WriteText("OnEndEdit\n") | |
63 | # show how to reject edit, we'll not allow any digits | |
64 | for x in event.GetLabel(): | |
65 | if x in string.digits: | |
66 | self.log.WriteText("You can't enter digits...\n") | |
67 | event.Veto() | |
68 | return | |
69 | ||
70 | ||
bb0054cd RD |
71 | |
72 | def OnLeftDClick(self, event): | |
b1462dfa RD |
73 | pt = event.GetPosition(); |
74 | item = self.tree.HitTest(pt) | |
bb0054cd RD |
75 | self.log.WriteText("OnLeftDClick: %s\n" % self.tree.GetItemText(item)) |
76 | ||
cf694132 RD |
77 | |
78 | def OnSize(self, event): | |
79 | w,h = self.GetClientSizeTuple() | |
80 | self.tree.SetDimensions(0, 0, w, h) | |
81 | ||
82 | ||
83 | def OnItemExpanded(self, event): | |
84 | item = event.GetItem() | |
85 | self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item)) | |
86 | ||
87 | def OnItemCollapsed(self, event): | |
88 | item = event.GetItem() | |
89 | self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item)) | |
90 | ||
91 | def OnSelChanged(self, event): | |
8bf5d46e RD |
92 | self.item = event.GetItem() |
93 | self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(self.item)) | |
cf694132 RD |
94 | |
95 | #--------------------------------------------------------------------------- | |
96 | ||
97 | def runTest(frame, nb, log): | |
98 | win = TestTreeCtrlPanel(nb, log) | |
99 | return win | |
100 | ||
101 | #--------------------------------------------------------------------------- | |
102 | ||
103 | ||
104 | ||
105 | ||
106 | ||
107 | ||
108 | ||
109 | ||
110 | ||
111 | ||
112 | ||
113 | ||
114 | ||
115 | ||
116 | ||
117 | ||
118 | ||
119 | ||
120 | overview = """\ | |
121 | 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. | |
122 | ||
123 | wxTreeCtrl() | |
124 | ------------------------- | |
125 | ||
126 | Default constructor. | |
127 | ||
128 | 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") | |
129 | ||
130 | Constructor, creating and showing a tree control. | |
131 | ||
132 | Parameters | |
133 | ------------------- | |
134 | ||
135 | parent = Parent window. Must not be NULL. | |
136 | ||
137 | id = Window identifier. A value of -1 indicates a default value. | |
138 | ||
139 | pos = Window position. | |
140 | ||
141 | size = Window size. If the default size (-1, -1) is specified then the window is sized appropriately. | |
142 | ||
143 | style = Window style. See wxTreeCtrl. | |
144 | ||
145 | validator = Window validator. | |
146 | ||
147 | name = Window name. | |
148 | """ |