]> git.saurik.com Git - wxWidgets.git/blame_incremental - utils/wxPython/demo/wxTreeCtrl.py
Fixed bug in DnD. wxDragSource will now delete itself when done.
[wxWidgets.git] / utils / wxPython / demo / wxTreeCtrl.py
... / ...
CommitLineData
1
2from wxPython.wx import *
3
4import string
5
6#---------------------------------------------------------------------------
7
8class TestTreeCtrlPanel(wxPanel):
9 def __init__(self, parent, log):
10 wxPanel.__init__(self, parent, -1)
11
12 self.log = log
13 tID = NewId()
14
15 self.tree = wxTreeCtrl(self, tID, wxDefaultPosition, wxDefaultSize,
16 wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS)# | wxTR_MULTIPLE)
17
18 self.root = self.tree.AddRoot("The Root Item")
19 for x in range(15):
20 child = self.tree.AppendItem(self.root, "Item %d" % x)
21 #self.tree.SelectItem(child)
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
27 self.tree.Expand(self.root)
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)
31 EVT_TREE_BEGIN_LABEL_EDIT(self, tID, self.OnBeginEdit)
32 EVT_TREE_END_LABEL_EDIT (self, tID, self.OnEndEdit)
33
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):
39 pt = event.GetPosition();
40 item = self.tree.HitTest(pt)
41 self.log.WriteText("OnRightClick: %s\n" % self.tree.GetItemText(item))
42 self.tree.SelectItem(item)
43
44 def OnRightUp(self, event):
45 pt = event.GetPosition();
46 item = self.tree.HitTest(pt)
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
71
72 def OnLeftDClick(self, event):
73 pt = event.GetPosition();
74 item = self.tree.HitTest(pt)
75 self.log.WriteText("OnLeftDClick: %s\n" % self.tree.GetItemText(item))
76
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):
92 self.item = event.GetItem()
93 self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(self.item))
94
95#---------------------------------------------------------------------------
96
97def 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
120overview = """\
121A 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
123wxTreeCtrl()
124-------------------------
125
126Default constructor.
127
128wxTreeCtrl(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
130Constructor, creating and showing a tree control.
131
132Parameters
133-------------------
134
135parent = Parent window. Must not be NULL.
136
137id = Window identifier. A value of -1 indicates a default value.
138
139pos = Window position.
140
141size = Window size. If the default size (-1, -1) is specified then the window is sized appropriately.
142
143style = Window style. See wxTreeCtrl.
144
145validator = Window validator.
146
147name = Window name.
148"""