]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/demo/wxTreeCtrl.py
it is now possible to add custom buttons into wxHtmlHelpFrame's toolbar
[wxWidgets.git] / utils / wxPython / demo / wxTreeCtrl.py
CommitLineData
cf694132
RD
1
2from wxPython.wx import *
3
8bf5d46e
RD
4import string
5
cf694132
RD
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
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))
cf694132
RD
109
110#---------------------------------------------------------------------------
111
112def runTest(frame, nb, log):
113 win = TestTreeCtrlPanel(nb, log)
114 return win
115
116#---------------------------------------------------------------------------
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135overview = """\
136A 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.
137
138wxTreeCtrl()
139-------------------------
140
141Default constructor.
142
143wxTreeCtrl(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")
144
145Constructor, creating and showing a tree control.
146
147Parameters
148-------------------
149
150parent = Parent window. Must not be NULL.
151
152id = Window identifier. A value of -1 indicates a default value.
153
154pos = Window position.
155
156size = Window size. If the default size (-1, -1) is specified then the window is sized appropriately.
157
158style = Window style. See wxTreeCtrl.
159
160validator = Window validator.
161
162name = Window name.
163"""