]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/CustomTreeCtrl.py
fix test code
[wxWidgets.git] / wxPython / demo / CustomTreeCtrl.py
CommitLineData
c8f129d0
RD
1import wx
2import string
3import os
4import wx.lib.colourselect as csel
5
6import wx.lib.customtreectrl as CT
7
8from Main import opj
9import images
10
11#---------------------------------------------------------------------------
12
13
14penstyle = ["wx.SOLID", "wx.TRANSPARENT", "wx.DOT", "wx.LONG_DASH", "wx.DOT_DASH", "wx.USER_DASH",
15 "wx.BDIAGONAL_HATCH", "wx.CROSSDIAG_HATCH", "wx.FDIAGONAL_HATCH", "wx.CROSS_HATCH",
16 "wx.HORIZONTAL_HATCH", "wx.VERTICAL_HATCH"]
17
18ArtIDs = [ "None",
19 "wx.ART_ADD_BOOKMARK",
20 "wx.ART_DEL_BOOKMARK",
21 "wx.ART_HELP_SIDE_PANEL",
22 "wx.ART_HELP_SETTINGS",
23 "wx.ART_HELP_BOOK",
24 "wx.ART_HELP_FOLDER",
25 "wx.ART_HELP_PAGE",
26 "wx.ART_GO_BACK",
27 "wx.ART_GO_FORWARD",
28 "wx.ART_GO_UP",
29 "wx.ART_GO_DOWN",
30 "wx.ART_GO_TO_PARENT",
31 "wx.ART_GO_HOME",
32 "wx.ART_FILE_OPEN",
33 "wx.ART_PRINT",
34 "wx.ART_HELP",
35 "wx.ART_TIP",
36 "wx.ART_REPORT_VIEW",
37 "wx.ART_LIST_VIEW",
38 "wx.ART_NEW_DIR",
39 "wx.ART_HARDDISK",
40 "wx.ART_FLOPPY",
41 "wx.ART_CDROM",
42 "wx.ART_REMOVABLE",
43 "wx.ART_FOLDER",
44 "wx.ART_FOLDER_OPEN",
45 "wx.ART_GO_DIR_UP",
46 "wx.ART_EXECUTABLE_FILE",
47 "wx.ART_NORMAL_FILE",
48 "wx.ART_TICK_MARK",
49 "wx.ART_CROSS_MARK",
50 "wx.ART_ERROR",
51 "wx.ART_QUESTION",
52 "wx.ART_WARNING",
53 "wx.ART_INFORMATION",
54 "wx.ART_MISSING_IMAGE",
55 "SmileBitmap"
56 ]
57
58keyMap = {
59 wx.WXK_BACK : "WXK_BACK",
60 wx.WXK_TAB : "WXK_TAB",
61 wx.WXK_RETURN : "WXK_RETURN",
62 wx.WXK_ESCAPE : "WXK_ESCAPE",
63 wx.WXK_SPACE : "WXK_SPACE",
64 wx.WXK_DELETE : "WXK_DELETE",
65 wx.WXK_START : "WXK_START",
66 wx.WXK_LBUTTON : "WXK_LBUTTON",
67 wx.WXK_RBUTTON : "WXK_RBUTTON",
68 wx.WXK_CANCEL : "WXK_CANCEL",
69 wx.WXK_MBUTTON : "WXK_MBUTTON",
70 wx.WXK_CLEAR : "WXK_CLEAR",
71 wx.WXK_SHIFT : "WXK_SHIFT",
72 wx.WXK_ALT : "WXK_ALT",
73 wx.WXK_CONTROL : "WXK_CONTROL",
74 wx.WXK_MENU : "WXK_MENU",
75 wx.WXK_PAUSE : "WXK_PAUSE",
76 wx.WXK_CAPITAL : "WXK_CAPITAL",
77 wx.WXK_PRIOR : "WXK_PRIOR",
78 wx.WXK_NEXT : "WXK_NEXT",
79 wx.WXK_END : "WXK_END",
80 wx.WXK_HOME : "WXK_HOME",
81 wx.WXK_LEFT : "WXK_LEFT",
82 wx.WXK_UP : "WXK_UP",
83 wx.WXK_RIGHT : "WXK_RIGHT",
84 wx.WXK_DOWN : "WXK_DOWN",
85 wx.WXK_SELECT : "WXK_SELECT",
86 wx.WXK_PRINT : "WXK_PRINT",
87 wx.WXK_EXECUTE : "WXK_EXECUTE",
88 wx.WXK_SNAPSHOT : "WXK_SNAPSHOT",
89 wx.WXK_INSERT : "WXK_INSERT",
90 wx.WXK_HELP : "WXK_HELP",
91 wx.WXK_NUMPAD0 : "WXK_NUMPAD0",
92 wx.WXK_NUMPAD1 : "WXK_NUMPAD1",
93 wx.WXK_NUMPAD2 : "WXK_NUMPAD2",
94 wx.WXK_NUMPAD3 : "WXK_NUMPAD3",
95 wx.WXK_NUMPAD4 : "WXK_NUMPAD4",
96 wx.WXK_NUMPAD5 : "WXK_NUMPAD5",
97 wx.WXK_NUMPAD6 : "WXK_NUMPAD6",
98 wx.WXK_NUMPAD7 : "WXK_NUMPAD7",
99 wx.WXK_NUMPAD8 : "WXK_NUMPAD8",
100 wx.WXK_NUMPAD9 : "WXK_NUMPAD9",
101 wx.WXK_MULTIPLY : "WXK_MULTIPLY",
102 wx.WXK_ADD : "WXK_ADD",
103 wx.WXK_SEPARATOR : "WXK_SEPARATOR",
104 wx.WXK_SUBTRACT : "WXK_SUBTRACT",
105 wx.WXK_DECIMAL : "WXK_DECIMAL",
106 wx.WXK_DIVIDE : "WXK_DIVIDE",
107 wx.WXK_F1 : "WXK_F1",
108 wx.WXK_F2 : "WXK_F2",
109 wx.WXK_F3 : "WXK_F3",
110 wx.WXK_F4 : "WXK_F4",
111 wx.WXK_F5 : "WXK_F5",
112 wx.WXK_F6 : "WXK_F6",
113 wx.WXK_F7 : "WXK_F7",
114 wx.WXK_F8 : "WXK_F8",
115 wx.WXK_F9 : "WXK_F9",
116 wx.WXK_F10 : "WXK_F10",
117 wx.WXK_F11 : "WXK_F11",
118 wx.WXK_F12 : "WXK_F12",
119 wx.WXK_F13 : "WXK_F13",
120 wx.WXK_F14 : "WXK_F14",
121 wx.WXK_F15 : "WXK_F15",
122 wx.WXK_F16 : "WXK_F16",
123 wx.WXK_F17 : "WXK_F17",
124 wx.WXK_F18 : "WXK_F18",
125 wx.WXK_F19 : "WXK_F19",
126 wx.WXK_F20 : "WXK_F20",
127 wx.WXK_F21 : "WXK_F21",
128 wx.WXK_F22 : "WXK_F22",
129 wx.WXK_F23 : "WXK_F23",
130 wx.WXK_F24 : "WXK_F24",
131 wx.WXK_NUMLOCK : "WXK_NUMLOCK",
132 wx.WXK_SCROLL : "WXK_SCROLL",
133 wx.WXK_PAGEUP : "WXK_PAGEUP",
134 wx.WXK_PAGEDOWN : "WXK_PAGEDOWN",
135 wx.WXK_NUMPAD_SPACE : "WXK_NUMPAD_SPACE",
136 wx.WXK_NUMPAD_TAB : "WXK_NUMPAD_TAB",
137 wx.WXK_NUMPAD_ENTER : "WXK_NUMPAD_ENTER",
138 wx.WXK_NUMPAD_F1 : "WXK_NUMPAD_F1",
139 wx.WXK_NUMPAD_F2 : "WXK_NUMPAD_F2",
140 wx.WXK_NUMPAD_F3 : "WXK_NUMPAD_F3",
141 wx.WXK_NUMPAD_F4 : "WXK_NUMPAD_F4",
142 wx.WXK_NUMPAD_HOME : "WXK_NUMPAD_HOME",
143 wx.WXK_NUMPAD_LEFT : "WXK_NUMPAD_LEFT",
144 wx.WXK_NUMPAD_UP : "WXK_NUMPAD_UP",
145 wx.WXK_NUMPAD_RIGHT : "WXK_NUMPAD_RIGHT",
146 wx.WXK_NUMPAD_DOWN : "WXK_NUMPAD_DOWN",
147 wx.WXK_NUMPAD_PRIOR : "WXK_NUMPAD_PRIOR",
148 wx.WXK_NUMPAD_PAGEUP : "WXK_NUMPAD_PAGEUP",
149 wx.WXK_NUMPAD_NEXT : "WXK_NUMPAD_NEXT",
150 wx.WXK_NUMPAD_PAGEDOWN : "WXK_NUMPAD_PAGEDOWN",
151 wx.WXK_NUMPAD_END : "WXK_NUMPAD_END",
152 wx.WXK_NUMPAD_BEGIN : "WXK_NUMPAD_BEGIN",
153 wx.WXK_NUMPAD_INSERT : "WXK_NUMPAD_INSERT",
154 wx.WXK_NUMPAD_DELETE : "WXK_NUMPAD_DELETE",
155 wx.WXK_NUMPAD_EQUAL : "WXK_NUMPAD_EQUAL",
156 wx.WXK_NUMPAD_MULTIPLY : "WXK_NUMPAD_MULTIPLY",
157 wx.WXK_NUMPAD_ADD : "WXK_NUMPAD_ADD",
158 wx.WXK_NUMPAD_SEPARATOR : "WXK_NUMPAD_SEPARATOR",
159 wx.WXK_NUMPAD_SUBTRACT : "WXK_NUMPAD_SUBTRACT",
160 wx.WXK_NUMPAD_DECIMAL : "WXK_NUMPAD_DECIMAL",
161 wx.WXK_NUMPAD_DIVIDE : "WXK_NUMPAD_DIVIDE"
162 }
163
164
165
166#---------------------------------------------------------------------------
167# Just A Dialog To Select Pen Styles
168#---------------------------------------------------------------------------
169class PenDialog(wx.Dialog):
170
171 def __init__(self, parent=None, id=-1, title="", pos=wx.DefaultPosition,
172 size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE, oldpen=None,
173 pentype=0):
174
175 wx.Dialog.__init__(self, parent, id, title, pos, size, style)
176
177 self.colourbutton = csel.ColourSelect(self)
178 self.spinwidth = wx.SpinCtrl(self, -1, "1", min=1, max=3, style=wx.SP_ARROW_KEYS)
179
180 self.combostyle = wx.ComboBox(self, -1, choices=penstyle, style=wx.CB_DROPDOWN|wx.CB_READONLY)
181
182 choices = ["[1, 1]", "[2, 2]", "[3, 3]", "[4, 4]"]
183 self.combodash = wx.ComboBox(self, -1, choices=choices, style=wx.CB_DROPDOWN|wx.CB_READONLY)
184
185 self.okbutton = wx.Button(self, wx.ID_OK)
186 self.cancelbutton = wx.Button(self, wx.ID_CANCEL)
187
188 self.oldpen = oldpen
189 self.parent = parent
190 self.pentype = pentype
191
192 self.__set_properties()
193 self.__do_layout()
194
195 self.Bind(wx.EVT_COMBOBOX, self.OnStyle, self.combostyle)
196 self.Bind(wx.EVT_BUTTON, self.OnOk, self.okbutton)
197 self.Bind(wx.EVT_BUTTON, self.OnCancel, self.cancelbutton)
198
199
200 def __set_properties(self):
201
202 self.SetTitle("Pen Dialog Selector")
203 self.colourbutton.SetMinSize((25, 25))
204 self.colourbutton.SetColour(self.oldpen.GetColour())
205
206 style = self.oldpen.GetStyle()
207 for count, st in enumerate(penstyle):
208 if eval(st) == style:
209 self.combostyle.SetSelection(count)
210 if count == 5:
211 self.combodash.Enable(True)
212 else:
213 self.combodash.Enable(False)
214 break
215
216 if self.combodash.IsEnabled():
217 dashes = repr(self.oldpen.GetDashes())
218 self.combodash.SetValue(dashes)
219
220 self.spinwidth.SetValue(self.oldpen.GetWidth())
221 self.okbutton.SetDefault()
222
223 if self.pentype == 1:
224 self.spinwidth.Enable(False)
225
226
227 def __do_layout(self):
228
229 mainsizer = wx.BoxSizer(wx.VERTICAL)
230 bottomsizer = wx.BoxSizer(wx.HORIZONTAL)
231 middlesizer = wx.BoxSizer(wx.VERTICAL)
232 stylesizer = wx.BoxSizer(wx.HORIZONTAL)
233 widthsizer = wx.BoxSizer(wx.HORIZONTAL)
234 coloursizer = wx.BoxSizer(wx.HORIZONTAL)
235 label_1 = wx.StaticText(self, -1, "Please Choose The Pen Settings:")
236 label_1.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
237 mainsizer.Add(label_1, 0, wx.ALL|wx.ADJUST_MINSIZE, 10)
238 label_2 = wx.StaticText(self, -1, "Pen Colour")
239 coloursizer.Add(label_2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
240 coloursizer.Add((5, 5), 1, wx.ADJUST_MINSIZE, 0)
241 coloursizer.Add(self.colourbutton, 0, wx.ALL|wx.ADJUST_MINSIZE, 5)
242 middlesizer.Add(coloursizer, 0, wx.EXPAND, 0)
243 label_3 = wx.StaticText(self, -1, "Pen Width")
244 widthsizer.Add(label_3, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
245 widthsizer.Add((5, 5), 1, wx.ADJUST_MINSIZE, 0)
246 widthsizer.Add(self.spinwidth, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
247 middlesizer.Add(widthsizer, 0, wx.EXPAND, 0)
248 label_4 = wx.StaticText(self, -1, "Pen Style")
249 stylesizer.Add(label_4, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
250 stylesizer.Add((5, 5), 1, wx.ADJUST_MINSIZE, 0)
251 stylesizer.Add(self.combostyle, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
252 stylesizer.Add(self.combodash, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
253 middlesizer.Add(stylesizer, 0, wx.BOTTOM|wx.EXPAND, 5)
254 mainsizer.Add(middlesizer, 1, wx.EXPAND, 0)
255 bottomsizer.Add(self.okbutton, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 20)
256 bottomsizer.Add((20, 20), 1, wx.ADJUST_MINSIZE, 0)
257 bottomsizer.Add(self.cancelbutton, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 20)
258 mainsizer.Add(bottomsizer, 0, wx.EXPAND, 0)
259 self.SetAutoLayout(True)
260 self.SetSizer(mainsizer)
261 mainsizer.Fit(self)
262 mainsizer.SetSizeHints(self)
263 self.Layout()
264 self.Centre()
265
266
267
268
269 def OnStyle(self, event):
270
271 choice = event.GetEventObject().GetValue()
272 self.combodash.Enable(choice==5)
273 event.Skip()
274
275
276 def OnOk(self, event):
277
278 colour = self.colourbutton.GetColour()
279 style = eval(self.combostyle.GetValue())
280 width = int(self.spinwidth.GetValue())
281
282 dashes = None
283 if self.combostyle.GetSelection() == 5:
284 dashes = eval(self.combodash.GetValue())
285
286 pen = wx.Pen(colour, width, style)
287
288 if dashes:
289 pen.SetDashes(dashes)
290
291 pen.SetCap(wx.CAP_BUTT)
292
293 if self.pentype == 0:
294 self.parent.SetConnectionPen(pen)
295 else:
296 self.parent.SetBorderPen(pen)
297
298 self.Destroy()
299 event.Skip()
300
301
302 def OnCancel(self, event):
303
304 self.Destroy()
305 event.Skip()
306
307
308#---------------------------------------------------------------------------
309# Just A Dialog To Select Tree Buttons Icons
310#---------------------------------------------------------------------------
311class TreeButtonsDialog(wx.Dialog):
312
313 def __init__(self, parent=None, id=-1, title="", pos=wx.DefaultPosition,
314 size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE, oldicons=None):
315
316 wx.Dialog.__init__(self, parent, id, title, pos, size, style)
317
318 self.listicons = wx.ListBox(self, -1, choices=["Set 1", "Set 2", "Set 3", "Set 4", "Set 5"], style=wx.LB_SINGLE)
319
320 bitmap_plus = opj("bitmaps/plus" + str(oldicons+1) + ".ico")
321 bitmap_minus = opj("bitmaps/minus" + str(oldicons+1) + ".ico")
322
323 bitmap_plus = wx.Image(bitmap_plus, wx.BITMAP_TYPE_ICO)
324 bitmap_plus.Rescale(24, 24)
325 bitmap_plus = bitmap_plus.ConvertToBitmap()
326 bitmap_minus = wx.Image(bitmap_minus, wx.BITMAP_TYPE_ICO)
327 bitmap_minus.Rescale(24, 24)
328 bitmap_minus = bitmap_minus.ConvertToBitmap()
329
330 self.bitmap_plus = wx.StaticBitmap(self, -1, bitmap_plus)
331 self.bitmap_minus = wx.StaticBitmap(self, -1, bitmap_minus)
332
333 self.okbutton = wx.Button(self, wx.ID_OK)
334 self.cancelbutton = wx.Button(self, wx.ID_CANCEL)
335
336 self.parent = parent
337
338 self.__set_properties()
339 self.__do_layout()
340
341 self.Bind(wx.EVT_BUTTON, self.OnOk, self.okbutton)
342 self.Bind(wx.EVT_BUTTON, self.OnCancel, self.cancelbutton)
343 self.Bind(wx.EVT_LISTBOX, self.OnListBox, self.listicons)
344
345
346 def __set_properties(self):
347
348 self.SetTitle("Tree Buttons Selector")
349 self.listicons.SetSelection(0)
350 self.okbutton.SetDefault()
351
352
353 def __do_layout(self):
354
355 mainsizer = wx.BoxSizer(wx.VERTICAL)
356 bottomsizer = wx.BoxSizer(wx.HORIZONTAL)
357 topsizer = wx.BoxSizer(wx.HORIZONTAL)
358 rightsizer = wx.BoxSizer(wx.VERTICAL)
359 sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
360 sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
361 label_1 = wx.StaticText(self, -1, "Please Choose One Of These Sets Of Icons:")
362 label_1.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
363 mainsizer.Add(label_1, 0, wx.ALL|wx.ADJUST_MINSIZE, 10)
364 topsizer.Add(self.listicons, 0, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 5)
365 label_2 = wx.StaticText(self, -1, "Collapsed")
366 sizer_1.Add(label_2, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 10)
367 sizer_1.Add((20, 20), 1, wx.ALIGN_RIGHT|wx.ADJUST_MINSIZE, 0)
368 sizer_1.Add(self.bitmap_plus, 1, wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 10)
369 rightsizer.Add(sizer_1, 0, wx.EXPAND, 0)
370 label_3 = wx.StaticText(self, -1, "Expanded")
371 sizer_2.Add(label_3, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 10)
372 sizer_2.Add((20, 20), 1, wx.ADJUST_MINSIZE, 0)
373 sizer_2.Add(self.bitmap_minus, 1, wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 10)
374 rightsizer.Add(sizer_2, 0, wx.EXPAND, 0)
375 topsizer.Add(rightsizer, 0, wx.ALL|wx.EXPAND, 5)
376 mainsizer.Add(topsizer, 1, wx.EXPAND, 0)
377 bottomsizer.Add(self.okbutton, 0, wx.ALL|wx.ADJUST_MINSIZE, 20)
378 bottomsizer.Add((20, 20), 1, wx.ADJUST_MINSIZE, 0)
379 bottomsizer.Add(self.cancelbutton, 0, wx.ALL|wx.ADJUST_MINSIZE, 20)
380 mainsizer.Add(bottomsizer, 0, wx.EXPAND, 0)
381 self.SetAutoLayout(True)
382 self.SetSizer(mainsizer)
383 mainsizer.Fit(self)
384 mainsizer.SetSizeHints(self)
385 self.Layout()
386
387
388 def OnListBox(self, event):
389
390 selection = self.listicons.GetSelection()
391 bitmap_plus = opj("bitmaps/plus" + str(selection+1) + ".ico")
392 bitmap_minus = opj("bitmaps/minus" + str(selection+1) + ".ico")
393
394 bitmap_plus = wx.Image(bitmap_plus, wx.BITMAP_TYPE_ICO)
395 bitmap_plus.Rescale(24, 24)
396 bitmap_plus = bitmap_plus.ConvertToBitmap()
397 bitmap_minus = wx.Image(bitmap_minus, wx.BITMAP_TYPE_ICO)
398 bitmap_minus.Rescale(24, 24)
399 bitmap_minus = bitmap_minus.ConvertToBitmap()
400
401 self.bitmap_plus.SetBitmap(bitmap_plus)
402 self.bitmap_minus.SetBitmap(bitmap_minus)
403
404 self.bitmap_plus.Refresh()
405 self.bitmap_minus.Refresh()
406 event.Skip()
407
408
409 def OnOk(self, event):
410
411 selection = self.listicons.GetSelection()
412 self.parent.SetTreeButtons(selection)
413 self.Destroy()
414 event.Skip()
415
416
417 def OnCancel(self, event):
418
419 self.Destroy()
420 event.Skip()
421
422
423#---------------------------------------------------------------------------
424# Just A Dialog To Select Tree Check/Radio Item Icons
425#---------------------------------------------------------------------------
426class CheckDialog(wx.Dialog):
427
428 def __init__(self, parent=None, id=-1, title="", pos=wx.DefaultPosition,
429 size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE):
430
431 wx.Dialog.__init__(self, parent, id, title, pos, size, style)
432
433 self.listicons = wx.ListBox(self, -1, choices=["Set 1", "Set 2"], style=wx.LB_SINGLE)
434
435 bitmap_check = wx.Bitmap(opj("bitmaps/checked.ico"), wx.BITMAP_TYPE_ICO)
436 bitmap_uncheck = wx.Bitmap(opj("bitmaps/notchecked.ico"), wx.BITMAP_TYPE_ICO)
437 bitmap_flag = wx.Bitmap(opj("bitmaps/flagged.ico"), wx.BITMAP_TYPE_ICO)
438 bitmap_unflag = wx.Bitmap(opj("bitmaps/notflagged.ico"), wx.BITMAP_TYPE_ICO)
439
440 self.bitmap_check = wx.StaticBitmap(self, -1, bitmap_check)
441 self.bitmap_uncheck = wx.StaticBitmap(self, -1, bitmap_uncheck)
442 self.bitmap_flag = wx.StaticBitmap(self, -1, bitmap_flag)
443 self.bitmap_unflag = wx.StaticBitmap(self, -1, bitmap_unflag)
444
445 self.okbutton = wx.Button(self, wx.ID_OK)
446 self.cancelbutton = wx.Button(self, wx.ID_CANCEL)
447
448 self.parent = parent
449
450 self.__set_properties()
451 self.__do_layout()
452
453 self.Bind(wx.EVT_BUTTON, self.OnOk, self.okbutton)
454 self.Bind(wx.EVT_BUTTON, self.OnCancel, self.cancelbutton)
455 self.Bind(wx.EVT_LISTBOX, self.OnListBox, self.listicons)
456
457
458 def __set_properties(self):
459
460 self.SetTitle("Check/Radio Icon Selector")
461 self.listicons.SetSelection(0)
462 self.okbutton.SetDefault()
463
464
465 def __do_layout(self):
466
467 mainsizer = wx.BoxSizer(wx.VERTICAL)
468 bottomsizer = wx.BoxSizer(wx.HORIZONTAL)
469 topsizer = wx.BoxSizer(wx.HORIZONTAL)
470 rightsizer = wx.BoxSizer(wx.VERTICAL)
471 sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
472 sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
473 sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
474 sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
475 label_1 = wx.StaticText(self, -1, "Please Choose One Of These Sets Of Icons:")
476 label_1.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
477 mainsizer.Add(label_1, 0, wx.ALL|wx.ADJUST_MINSIZE, 10)
478 topsizer.Add(self.listicons, 0, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 5)
479 label_2 = wx.StaticText(self, -1, "Checked")
480 sizer_1.Add(label_2, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 10)
481 sizer_1.Add((20, 20), 1, wx.ALIGN_RIGHT|wx.ADJUST_MINSIZE, 0)
482 sizer_1.Add(self.bitmap_check, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 10)
483 rightsizer.Add(sizer_1, 0, wx.EXPAND, 0)
484 label_3 = wx.StaticText(self, -1, "Not Checked")
485 sizer_2.Add(label_3, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 10)
486 sizer_2.Add((20, 20), 1, wx.ADJUST_MINSIZE, 0)
487 sizer_2.Add(self.bitmap_uncheck, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 10)
488 rightsizer.Add(sizer_2, 0, wx.EXPAND, 0)
489 label_4 = wx.StaticText(self, -1, "Flagged")
490 sizer_3.Add(label_4, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 10)
491 sizer_3.Add((20, 20), 1, wx.ADJUST_MINSIZE, 0)
492 sizer_3.Add(self.bitmap_flag, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 10)
493 rightsizer.Add(sizer_3, 0, wx.EXPAND, 0)
494 label_5 = wx.StaticText(self, -1, "Not Flagged")
495 sizer_4.Add(label_5, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 10)
496 sizer_4.Add((20, 20), 1, wx.ADJUST_MINSIZE, 0)
497 sizer_4.Add(self.bitmap_unflag, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 10)
498 rightsizer.Add(sizer_4, 0, wx.EXPAND, 0)
499
500 topsizer.Add(rightsizer, 0, wx.ALL|wx.EXPAND, 5)
501 mainsizer.Add(topsizer, 1, wx.EXPAND, 0)
502 bottomsizer.Add(self.okbutton, 0, wx.ALL|wx.ADJUST_MINSIZE, 20)
503 bottomsizer.Add((20, 20), 1, wx.ADJUST_MINSIZE, 0)
504 bottomsizer.Add(self.cancelbutton, 0, wx.ALL|wx.ADJUST_MINSIZE, 20)
505 mainsizer.Add(bottomsizer, 0, wx.EXPAND, 0)
506 self.SetAutoLayout(True)
507 self.SetSizer(mainsizer)
508 mainsizer.Fit(self)
509 mainsizer.SetSizeHints(self)
510 self.Layout()
511
512
513 def OnListBox(self, event):
514
515 selection = self.listicons.GetSelection()
516
517 if selection == 0:
518 bitmap_check = opj("bitmaps/checked.ico")
519 bitmap_uncheck = opj("bitmaps/notchecked.ico")
520 bitmap_flag = opj("bitmaps/flagged.ico")
521 bitmap_unflag = opj("bitmaps/notflagged.ico")
522 else:
523 bitmap_check = opj("bitmaps/aquachecked.ico")
524 bitmap_uncheck = opj("bitmaps/aquanotchecked.ico")
525 bitmap_flag = opj("bitmaps/aquaflagged.ico")
526 bitmap_unflag = opj("bitmaps/aquanotflagged.ico")
527
528 bitmap_check = wx.Bitmap(bitmap_check, wx.BITMAP_TYPE_ICO)
529 bitmap_uncheck = wx.Bitmap(bitmap_uncheck, wx.BITMAP_TYPE_ICO)
530 bitmap_flag = wx.Bitmap(bitmap_flag, wx.BITMAP_TYPE_ICO)
531 bitmap_unflag = wx.Bitmap(bitmap_unflag, wx.BITMAP_TYPE_ICO)
532
533 self.bitmap_uncheck.SetBitmap(bitmap_uncheck)
534 self.bitmap_check.SetBitmap(bitmap_check)
535 self.bitmap_unflag.SetBitmap(bitmap_unflag)
536 self.bitmap_flag.SetBitmap(bitmap_flag)
537
538 self.bitmap_check.Refresh()
539 self.bitmap_uncheck.Refresh()
540 self.bitmap_flag.Refresh()
541 self.bitmap_unflag.Refresh()
542
543 event.Skip()
544
545
546 def OnOk(self, event):
547
548 selection = self.listicons.GetSelection()
549 self.parent.SetCheckRadio(selection)
550 self.Destroy()
551 event.Skip()
552
553
554 def OnCancel(self, event):
555
556 self.Destroy()
557 event.Skip()
558
559
560#---------------------------------------------------------------------------
561# Just A Dialog To Select Tree Items Icons
562#---------------------------------------------------------------------------
563class TreeIcons(wx.Dialog):
564
565 def __init__(self, parent=None, id=-1, title="", pos=wx.DefaultPosition,
566 size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE, oldpen=None,
567 bitmaps=None):
568
569 wx.Dialog.__init__(self, parent, id, title, pos, size, style)
570
571 self.bitmaps = [None, None, None, None]
572 empty = wx.EmptyBitmap(16, 16)
573 self.parent = parent
574
575 self.bitmaps[0] = wx.StaticBitmap(self, -1, empty)
576 self.combonormal = wx.ComboBox(self, -1, choices=ArtIDs, style=wx.CB_DROPDOWN|wx.CB_READONLY)
577 self.bitmaps[1] = wx.StaticBitmap(self, -1, empty)
578 self.comboselected = wx.ComboBox(self, -1, choices=ArtIDs, style=wx.CB_DROPDOWN|wx.CB_READONLY)
579 self.bitmaps[2] = wx.StaticBitmap(self, -1, empty)
580 self.comboexpanded = wx.ComboBox(self, -1, choices=ArtIDs, style=wx.CB_DROPDOWN|wx.CB_READONLY)
581 self.bitmaps[3] = wx.StaticBitmap(self, -1, empty)
582 self.comboselectedexpanded = wx.ComboBox(self, -1, choices=ArtIDs, style=wx.CB_DROPDOWN|wx.CB_READONLY)
583 self.okbutton = wx.Button(self, wx.ID_OK)
584 self.cancelbutton = wx.Button(self, wx.ID_CANCEL)
585
586 self.combonormal.SetSelection(bitmaps[0] >= 0 and bitmaps[0]+1 or 0)
587 self.comboselected.SetSelection(bitmaps[1] >= 0 and bitmaps[1]+1 or 0)
588 self.comboexpanded.SetSelection(bitmaps[2] >= 0 and bitmaps[2]+1 or 0)
589 self.comboselectedexpanded.SetSelection(bitmaps[3] >= 0 and bitmaps[3]+1 or 0)
590
591 self.GetBitmaps(bitmaps)
592
593 self.__set_properties()
594 self.__do_layout()
595
596 self.Bind(wx.EVT_COMBOBOX, self.OnComboNormal, self.combonormal)
597 self.Bind(wx.EVT_COMBOBOX, self.OnComboSelected, self.comboselected)
598 self.Bind(wx.EVT_COMBOBOX, self.OnComboExpanded, self.comboexpanded)
599 self.Bind(wx.EVT_COMBOBOX, self.OnComboSelectedExpanded, self.comboselectedexpanded)
600 self.Bind(wx.EVT_BUTTON, self.OnOk, self.okbutton)
601 self.Bind(wx.EVT_BUTTON, self.OnCancel, self.cancelbutton)
602
603
604 def __set_properties(self):
605
606 self.SetTitle("Item Icon Selector")
607 self.okbutton.SetDefault()
608
609
610 def __do_layout(self):
611
612 mainsizer = wx.BoxSizer(wx.VERTICAL)
613 sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
614 gridsizer = wx.FlexGridSizer(4, 3, 5, 5)
615 label_1 = wx.StaticText(self, -1, "Please Choose The Icons For This Item (All Are Optional):")
616 label_1.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
617 mainsizer.Add(label_1, 0, wx.ALL|wx.ADJUST_MINSIZE, 10)
618 label_2 = wx.StaticText(self, -1, "TreeIcon_Normal:")
619 gridsizer.Add(label_2, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
620 gridsizer.Add(self.bitmaps[0], 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
621 gridsizer.Add(self.combonormal, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
622 label_3 = wx.StaticText(self, -1, "TreeIcon_Selected:")
623 gridsizer.Add(label_3, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
624 gridsizer.Add(self.bitmaps[1], 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
625 gridsizer.Add(self.comboselected, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
626 label_4 = wx.StaticText(self, -1, "TreeIcon_Expanded:")
627 gridsizer.Add(label_4, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
628 gridsizer.Add(self.bitmaps[2], 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
629 gridsizer.Add(self.comboexpanded, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
630 label_5 = wx.StaticText(self, -1, "TreeIcon_SelectedExpanded:")
631 gridsizer.Add(label_5, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
632 gridsizer.Add(self.bitmaps[3], 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
633 gridsizer.Add(self.comboselectedexpanded, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
634 gridsizer.AddGrowableCol(0)
635 gridsizer.AddGrowableCol(1)
636 gridsizer.AddGrowableCol(2)
637 mainsizer.Add(gridsizer, 0, wx.ALL|wx.EXPAND, 5)
638 sizer_2.Add(self.okbutton, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 20)
639 sizer_2.Add((20, 20), 1, wx.ADJUST_MINSIZE, 0)
640 sizer_2.Add(self.cancelbutton, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 20)
641 mainsizer.Add(sizer_2, 1, wx.EXPAND, 0)
642 self.SetAutoLayout(True)
643 self.SetSizer(mainsizer)
644 mainsizer.Fit(self)
645 mainsizer.SetSizeHints(self)
646 self.Layout()
647 self.Centre()
648
649
650 def OnComboNormal(self, event):
651
652 input = event.GetSelection()
653 self.GetBitmap(input, 0)
654 event.Skip()
655
656
657 def OnComboSelected(self, event):
658
659 input = event.GetSelection()
660 self.GetBitmap(input, 1)
661 event.Skip()
662
663
664 def OnComboExpanded(self, event):
665
666 input = event.GetSelection()
667 self.GetBitmap(input, 2)
668 event.Skip()
669
670
671 def OnComboSelectedExpanded(self, event):
672
673 input = event.GetSelection()
674 self.GetBitmap(input, 3)
675 event.Skip()
676
677
678 def OnOk(self, event):
679
680 bitmaps = [-1, -1, -1, -1]
681 normal = self.combonormal.GetSelection()
682 selected = self.comboselected.GetSelection()
683 expanded = self.comboexpanded.GetSelection()
684 selexp = self.comboselectedexpanded.GetSelection()
685
686 bitmaps = [(normal > 0 and normal or -1), (selected > 0 and selected or -1),
687 (expanded > 0 and expanded or -1), (selexp > 0 and selexp or -1)]
688
689 newbitmaps = []
690
691 for bmp in bitmaps:
692 if bmp > 0:
693 newbitmaps.append(bmp-1)
694 else:
695 newbitmaps.append(bmp)
696
697 self.parent.SetNewIcons(newbitmaps)
698
699 self.Destroy()
700 event.Skip()
701
702
703 def OnCancel(self, event):
704
705 self.Destroy()
706 event.Skip()
707
708
709 def GetBitmap(self, input, which):
710
711 if input == 0:
712 bmp = wx.EmptyBitmap(16,16)
713 self.ClearBmp(bmp)
714 elif input > 36:
715 bmp = images.getSmilesBitmap()
716 else:
717 bmp = wx.ArtProvider_GetBitmap(eval(ArtIDs[input]), wx.ART_OTHER, (16,16))
718 if not bmp.Ok():
719 bmp = wx.EmptyBitmap(16,16)
720 self.ClearBmp(bmp)
721
722 self.bitmaps[which].SetBitmap(bmp)
723 self.bitmaps[which].Refresh()
724
725
726 def GetBitmaps(self, bitmaps):
727
728 output = []
729
730 for count, input in enumerate(bitmaps):
731 if input < 0:
732 bmp = wx.EmptyBitmap(16,16)
733 self.ClearBmp(bmp)
734 elif input > 35:
735 bmp = images.getSmilesBitmap()
736 else:
737 bmp = wx.ArtProvider_GetBitmap(eval(ArtIDs[input+1]), wx.ART_OTHER, (16,16))
738 if not bmp.Ok():
739 bmp = wx.EmptyBitmap(16,16)
740 self.ClearBmp(bmp)
741
742 self.bitmaps[count].SetBitmap(bmp)
743
744
745 def ClearBmp(self, bmp):
746
747 dc = wx.MemoryDC()
748 dc.SelectObject(bmp)
749 dc.SetBackground(wx.Brush("white"))
750 dc.Clear()
751
752
753#---------------------------------------------------------------------------
754# CustomTreeCtrl Demo Implementation
755#---------------------------------------------------------------------------
756class CustomTreeCtrlDemo(wx.Panel):
757
758 def __init__(self, parent, log):
759 wx.Panel.__init__(self, parent)
760
761 self.log = log
762 self.oldicons = 0
763
764 splitter = wx.SplitterWindow(self, -1, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D)
765
766 # Create the CustomTreeCtrl, using a derived class defined below
cbfc9df6
RD
767 self.tree = CustomTreeCtrl(splitter, -1, log=self.log,
768 style= wx.SUNKEN_BORDER| CT.TR_HAS_BUTTONS | CT.TR_HAS_VARIABLE_ROW_HEIGHT)
c8f129d0
RD
769
770 self.leftpanel = wx.ScrolledWindow(splitter, -1, style=wx.SUNKEN_BORDER)
771 self.leftpanel.SetScrollRate(20,20)
772 width = self.PopulateLeftPanel(self.tree.styles, self.tree.events)
773
774 # add the windows to the splitter and split it.
775 splitter.SplitVertically(self.leftpanel, self.tree, 300)
776 splitter.SetMinimumPaneSize(width+5)
777
778 sizer = wx.BoxSizer()
779 sizer.Add(splitter, 1, wx.EXPAND)
780 self.SetSizer(sizer)
781
782
783 def PopulateLeftPanel(self, styles, events):
784 pnl = wx.Panel(self.leftpanel)
785 mainsizer = wx.BoxSizer(wx.VERTICAL)
786 recreatetree = wx.Button(pnl, -1, "Recreate CustomTreeCtrl")
787 mainsizer.Add(recreatetree, 0, wx.ALL|wx.ALIGN_CENTER, 10)
788 recreatetree.Bind(wx.EVT_BUTTON, self.OnRecreateTree)
789
790 staticboxstyles = wx.StaticBox(pnl, -1, "CustomTreeCtrl Styles")
791 stylesizer = wx.StaticBoxSizer(staticboxstyles, wx.VERTICAL)
792 staticboxevents = wx.StaticBox(pnl, -1, "CustomTreeCtrl Events")
793 eventssizer = wx.StaticBoxSizer(staticboxevents, wx.VERTICAL)
794 staticboxcolours = wx.StaticBox(pnl, -1, "CustomTreeCtrl Images/Colours")
795 colourssizer = wx.StaticBoxSizer(staticboxcolours, wx.VERTICAL)
796 staticboxthemes = wx.StaticBox(pnl, -1, "CustomTreeCtrl Themes/Gradients")
797 themessizer = wx.StaticBoxSizer(staticboxthemes, wx.VERTICAL)
798
799 self.treestyles = []
800 self.treeevents = []
801
802 for count, style in enumerate(styles):
803
804 if count == 0:
805 tags = wx.ALL
806 else:
807 tags = wx.LEFT|wx.RIGHT|wx.BOTTOM
808
809 if style != "TR_DEFAULT_STYLE":
810 check = wx.CheckBox(pnl, -1, style)
811 stylesizer.Add(check, 0, tags, 3)
812
813 if style in ["TR_HAS_BUTTONS", "TR_HAS_VARIABLE_ROW_HEIGHT"]:
814 check.SetValue(1)
815
816 if style == "TR_HAS_VARIABLE_ROW_HEIGHT":
817 check.Enable(False)
818
819 check.Bind(wx.EVT_CHECKBOX, self.OnCheckStyle)
820 self.treestyles.append(check)
821
822
823 for count, event in enumerate(events):
824
825 if count == 0:
826 tags = wx.ALL
827 else:
828 tags = wx.LEFT|wx.RIGHT|wx.BOTTOM
829
830 if count not in [6, 17, 22, 23]:
831 check = wx.CheckBox(pnl, -1, event)
832 eventssizer.Add(check, 0, tags, 3)
833
834 if event in ["EVT_TREE_ITEM_EXPANDED", "EVT_TREE_ITEM_COLLAPSED",
835 "EVT_TREE_SEL_CHANGED", "EVT_TREE_SEL_CHANGING"]:
836
837 check.SetValue(1)
838
839 check.Bind(wx.EVT_CHECKBOX, self.OnCheckEvent)
840 self.treeevents.append(check)
841
842 sizer1 = wx.BoxSizer(wx.HORIZONTAL)
843 label = wx.StaticText(pnl, -1, "Connection Pen")
844 font = label.GetFont()
845 font.SetWeight(wx.FONTWEIGHT_BOLD)
846 label.SetFont(font)
847 buttonconnection = wx.Button(pnl, -1, "Choose...")
848 buttonconnection.Bind(wx.EVT_BUTTON, self.OnButtonConnection)
849 sizer1.Add(label, 0, wx.ALL|wx.ALIGN_CENTER, 5)
850 sizer1.Add((1,0), 1, wx.EXPAND)
851 sizer1.Add(buttonconnection, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_RIGHT, 5)
852
853 sizer2 = wx.BoxSizer(wx.HORIZONTAL)
854 label = wx.StaticText(pnl, -1, "Border Pen")
855 font = label.GetFont()
856 font.SetWeight(wx.FONTWEIGHT_BOLD)
857 label.SetFont(font)
858 buttonborder = wx.Button(pnl, -1, "Choose...")
859 buttonborder.Bind(wx.EVT_BUTTON, self.OnButtonBorder)
860 sizer2.Add(label, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER, 5)
861 sizer2.Add((1,0), 1, wx.EXPAND)
862 sizer2.Add(buttonborder, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_RIGHT, 5)
863
864 sizer3 = wx.BoxSizer(wx.HORIZONTAL)
865 label = wx.StaticText(pnl, -1, "Tree Buttons")
866 font = label.GetFont()
867 font.SetWeight(wx.FONTWEIGHT_BOLD)
868 label.SetFont(font)
869 buttontree = wx.Button(pnl, -1, "Choose...")
870 buttontree.Bind(wx.EVT_BUTTON, self.OnButtonTree)
871 sizer3.Add(label, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER, 5)
872 sizer3.Add((1,0), 1, wx.EXPAND)
873 sizer3.Add(buttontree, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_RIGHT, 5)
874
875 sizer4 = wx.BoxSizer(wx.HORIZONTAL)
876 label = wx.StaticText(pnl, -1, "Check/Radio Buttons")
877 font = label.GetFont()
878 font.SetWeight(wx.FONTWEIGHT_BOLD)
879 label.SetFont(font)
880 buttoncr = wx.Button(pnl, -1, "Choose...")
881 buttoncr.Bind(wx.EVT_BUTTON, self.OnButtonCheckRadio)
882 sizer4.Add(label, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER, 5)
883 sizer4.Add((1,0), 1, wx.EXPAND)
884 sizer4.Add(buttoncr, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_RIGHT, 5)
885
886 sizer5 = wx.BoxSizer(wx.HORIZONTAL)
887 radioimage = wx.RadioButton(pnl, -1, "Image Background", style=wx.RB_GROUP)
888 radioimage.Bind(wx.EVT_RADIOBUTTON, self.OnBackgroundImage)
889 self.imagebutton = wx.Button(pnl, -1, "Choose...")
890 self.imagebutton.Bind(wx.EVT_BUTTON, self.OnChooseImage)
891 sizer5.Add(radioimage, 0, wx.ALL|wx.ALIGN_CENTER, 5)
892 sizer5.Add((1,0), 1, wx.EXPAND)
893 sizer5.Add(self.imagebutton, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_RIGHT, 5)
894
895 sizer6 = wx.BoxSizer(wx.HORIZONTAL)
896 radiobackground = wx.RadioButton(pnl, -1, "Background Colour")
897 radiobackground.Bind(wx.EVT_RADIOBUTTON, self.OnBackgroundColour)
898 self.backbutton = csel.ColourSelect(pnl, -1, "Choose...", wx.WHITE)
899 self.backbutton.Bind(csel.EVT_COLOURSELECT, self.OnChooseBackground)
900 sizer6.Add(radiobackground, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER, 5)
901 sizer6.Add((1,0), 1, wx.EXPAND)
902 sizer6.Add(self.backbutton, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER, 5)
903
904 colourssizer.Add(sizer1, 0, wx.EXPAND)
905 colourssizer.Add(sizer2, 0, wx.EXPAND)
906 colourssizer.Add(sizer3, 0, wx.EXPAND)
907 colourssizer.Add(sizer4, 0, wx.EXPAND)
908 colourssizer.Add(sizer5, 0, wx.EXPAND)
909 colourssizer.Add(sizer6, 0, wx.EXPAND)
910
911 sizera = wx.BoxSizer(wx.HORIZONTAL)
912 self.checknormal = wx.CheckBox(pnl, -1, "Standard Colours")
913 self.focus = csel.ColourSelect(pnl, -1, "Focus",
914 self.tree.GetHilightFocusColour())
915 self.unfocus = csel.ColourSelect(pnl, -1, "Non-Focus",
916 self.tree.GetHilightNonFocusColour())
917 self.checknormal.Bind(wx.EVT_CHECKBOX, self.OnCheckNormal)
918 self.focus.Bind(csel.EVT_COLOURSELECT, self.OnFocusColour)
919 self.unfocus.Bind(csel.EVT_COLOURSELECT, self.OnNonFocusColour)
920 sizera1 = wx.BoxSizer(wx.VERTICAL)
921 sizera1.Add(self.focus, 0, wx.BOTTOM, 2)
922 sizera1.Add(self.unfocus, 0)
923 sizera.Add(self.checknormal, 0, wx.ALL, 3)
924 sizera.Add((1, 0), 1, wx.EXPAND)
925 sizera.Add(sizera1, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, 3)
926
927 sizerb = wx.BoxSizer(wx.VERTICAL)
928 self.checkgradient = wx.CheckBox(pnl, -1, "Gradient Theme")
929 self.checkgradient.Bind(wx.EVT_CHECKBOX, self.OnCheckGradient)
930 sizerb1 = wx.BoxSizer(wx.HORIZONTAL)
931 sizerb1.Add((10, 0))
932 self.radiohorizontal = wx.RadioButton(pnl, -1, "Horizontal", style=wx.RB_GROUP)
933 self.radiohorizontal.Bind(wx.EVT_RADIOBUTTON, self.OnHorizontal)
934 sizerb1.Add(self.radiohorizontal, 0, wx.TOP|wx.BOTTOM, 3)
935 sizerb2 = wx.BoxSizer(wx.HORIZONTAL)
936 sizerb2.Add((10, 0))
937 self.radiovertical = wx.RadioButton(pnl, -1, "Vertical")
938 self.radiovertical.Bind(wx.EVT_RADIOBUTTON, self.OnVertical)
939 sizerb2.Add(self.radiovertical, 0, wx.BOTTOM, 3)
940 sizerb3 = wx.BoxSizer(wx.HORIZONTAL)
941 self.firstcolour = csel.ColourSelect(pnl, -1, "First Colour",
942 self.tree.GetFirstGradientColour())
943 self.secondcolour = csel.ColourSelect(pnl, -1, "Second Colour",
944 self.tree.GetSecondGradientColour())
945 self.firstcolour.Bind(csel.EVT_COLOURSELECT, self.OnFirstColour)
946 self.secondcolour.Bind(csel.EVT_COLOURSELECT, self.OnSecondColour)
947 sizerb3.Add(self.firstcolour, 0, wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 3)
948 sizerb3.Add(self.secondcolour, 0, wx.LEFT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 3)
949 sizerb.Add(self.checkgradient, 0, wx.ALL, 3)
950 sizerb.Add(sizerb1, 0)
951 sizerb.Add(sizerb2, 0)
952 sizerb.Add(sizerb3, 0, wx.ALIGN_CENTER)
953
954 self.checkvista = wx.CheckBox(pnl, -1, "Windows Vista Theme")
955 self.checkvista.Bind(wx.EVT_CHECKBOX, self.OnVista)
956
957 themessizer.Add(sizera, 0, wx.EXPAND)
958 themessizer.Add(sizerb, 0, wx.EXPAND)
959 themessizer.Add((0, 5))
960 themessizer.Add(self.checkvista, 0, wx.EXPAND|wx.ALL, 3)
961
962 mainsizer.Add(stylesizer, 0, wx.EXPAND|wx.ALL, 5)
963 mainsizer.Add(colourssizer, 0, wx.EXPAND|wx.ALL, 5)
964 mainsizer.Add(themessizer, 0, wx.EXPAND|wx.ALL, 5)
965 mainsizer.Add(eventssizer, 0, wx.EXPAND|wx.ALL, 5)
966
967 pnl.SetSizer(mainsizer)
968 pnl.Fit()
969
970 swsizer = wx.BoxSizer(wx.VERTICAL)
971 swsizer.Add(pnl, 0, wx.EXPAND)
972 self.leftpanel.SetSizer(swsizer)
973 swsizer.Layout()
974
975 radiobackground.SetValue(1)
976 self.checknormal.SetValue(1)
977 self.radiohorizontal.Enable(False)
978 self.radiovertical.Enable(False)
979 self.firstcolour.Enable(False)
980 self.secondcolour.Enable(False)
981 self.imagebutton.Enable(False)
982
983 return mainsizer.CalcMin().width + wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X)
984
985
986 def OnRecreateTree(self, event):
987
988 splitter = self.tree.GetParent()
989 newtree = CustomTreeCtrl(splitter, -1, log=self.log)
990 splitter.ReplaceWindow(self.tree, newtree)
991 self.tree.Destroy()
992 self.tree = newtree
993 # Todo: The settings in the leftpanel should be reset too
994
995
996 def OnCheckStyle(self, event):
997
998 self.tree.ChangeStyle(self.treestyles)
999 event.Skip()
1000
1001
1002 def OnCheckEvent(self, event):
1003
1004 obj = event.GetEventObject()
1005 self.tree.BindEvents(obj)
1006
1007 event.Skip()
1008
1009
1010 def OnButtonConnection(self, event):
1011
1012 pen = self.tree.GetConnectionPen()
1013 dlg = PenDialog(self, -1, oldpen=pen, pentype=0)
1014
1015 dlg.ShowModal()
1016
1017 event.Skip()
1018
1019
1020 def SetConnectionPen(self, pen):
1021
1022 self.tree.SetConnectionPen(pen)
1023
1024
1025 def OnButtonBorder(self, event):
1026
1027 pen = self.tree.GetBorderPen()
1028 dlg = PenDialog(self, -1, oldpen=pen, pentype=1)
1029
1030 dlg.ShowModal()
1031 event.Skip()
1032
1033
1034 def SetBorderPen(self, pen):
1035
1036 self.tree.SetBorderPen(pen)
1037
1038
1039 def OnButtonTree(self, event):
1040
1041 dlg = TreeButtonsDialog(self, -1, oldicons=self.oldicons)
1042 dlg.ShowModal()
1043
1044 event.Skip()
1045
1046
1047 def OnButtonCheckRadio(self, event):
1048
1049 dlg = CheckDialog(self, -1)
1050 dlg.ShowModal()
1051
1052 event.Skip()
1053
1054
1055 def SetTreeButtons(self, selection):
1056
1057 bitmap_plus = opj("bitmaps/plus" + str(selection+1) + ".ico")
1058 bitmap_minus = opj("bitmaps/minus" + str(selection+1) + ".ico")
1059
1060 bitmap = wx.Bitmap(bitmap_plus, wx.BITMAP_TYPE_ICO)
1061 width = bitmap.GetWidth()
1062
1063 il = wx.ImageList(width, width)
1064
1065 il.Add(wx.Bitmap(bitmap_plus, wx.BITMAP_TYPE_ICO))
1066 il.Add(wx.Bitmap(bitmap_plus, wx.BITMAP_TYPE_ICO))
1067 il.Add(wx.Bitmap(bitmap_minus, wx.BITMAP_TYPE_ICO))
1068 il.Add(wx.Bitmap(bitmap_minus, wx.BITMAP_TYPE_ICO))
1069
1070 self.il = il
1071 self.tree.SetButtonsImageList(il)
1072
1073
1074 def SetCheckRadio(self, selection):
1075
1076 if selection == 0:
1077 self.tree.SetImageListCheck(13, 13)
1078 else:
1079 bitmap_check = opj("bitmaps/aquachecked.ico")
1080 bitmap_uncheck = opj("bitmaps/aquanotchecked.ico")
1081 bitmap_flag = opj("bitmaps/aquaflagged.ico")
1082 bitmap_unflag = opj("bitmaps/aquanotflagged.ico")
1083
1084 il = wx.ImageList(16, 16)
1085
1086 il.Add(wx.Bitmap(bitmap_check, wx.BITMAP_TYPE_ICO))
1087 il.Add(wx.Bitmap(bitmap_uncheck, wx.BITMAP_TYPE_ICO))
1088 il.Add(wx.Bitmap(bitmap_flag, wx.BITMAP_TYPE_ICO))
1089 il.Add(wx.Bitmap(bitmap_unflag, wx.BITMAP_TYPE_ICO))
1090 self.tree.SetImageListCheck(16, 16, il)
1091
1092
1093 def OnBackgroundImage(self, event):
1094
1095 if hasattr(self, "backgroundimage"):
1096 self.tree.SetBackgroundImage(self.backgroundimage)
1097
1098 self.backbutton.Enable(False)
1099 self.imagebutton.Enable(True)
1100
1101 event.Skip()
1102
1103
1104 def OnChooseImage(self, event):
1105
1106 wildcard = "JPEG Files (*.jpg)|*.jpg|" \
1107 "Bitmap Files (*.bmp)|*.bmp|" \
1108 "PNG Files (*.png)|*.png|" \
1109 "Icon Files (*.ico)|*.ico|" \
1110 "GIF Files (*.gif)|*.gif|" \
1111 "All files (*.*)|*.*"
1112
1113 dlg = wx.FileDialog(self, "Choose An Image File", ".", "", wildcard, wx.OPEN)
1114
1115 if dlg.ShowModal() == wx.ID_OK:
1116 path = dlg.GetPath()
1117 else:
1118 dlg.Destroy()
1119 return
1120
1121 dlg.Destroy()
1122 bitmap = wx.Bitmap(path, wx.BITMAP_TYPE_ANY)
1123 self.tree.SetBackgroundImage(bitmap)
1124 self.backgroundimage = bitmap
1125
1126 event.Skip()
1127
1128
1129 def OnBackgroundColour(self, event):
1130
1131 self.imagebutton.Enable(False)
1132 self.backbutton.Enable(True)
1133 self.tree.SetBackgroundImage(None)
1134
1135 event.Skip()
1136
1137
1138 def OnChooseBackground(self, event):
1139
1140 col1 = event.GetValue()
1141 self.tree.SetBackgroundColour(col1)
1142 event.Skip()
1143
1144
1145 def OnCheckNormal(self, event):
1146
1147 self.radiohorizontal.Enable(False)
1148 self.radiovertical.Enable(False)
1149 self.firstcolour.Enable(False)
1150 self.secondcolour.Enable(False)
1151 self.focus.Enable(True)
1152 self.unfocus.Enable(True)
1153 self.checkgradient.SetValue(0)
1154 self.checkvista.SetValue(0)
1155 self.tree.EnableSelectionGradient(False)
1156 self.tree.EnableSelectionVista(False)
1157 event.Skip()
1158
1159
1160 def OnFocusColour(self, event):
1161
1162 col1 = event.GetValue()
1163 self.tree.SetHilightFocusColour(col1)
1164 event.Skip()
1165
1166
1167 def OnNonFocusColour(self, event):
1168
1169 col1 = event.GetValue()
1170 self.tree.SetHilightNonFocusColour(col1)
1171 event.Skip()
1172
1173
1174 def OnCheckGradient(self, event):
1175
1176 self.radiohorizontal.Enable(True)
1177 self.radiovertical.Enable(True)
1178 self.firstcolour.Enable(True)
1179 self.secondcolour.Enable(True)
1180 self.checknormal.SetValue(0)
1181 self.checkvista.SetValue(0)
1182 self.focus.Enable(False)
1183 self.unfocus.Enable(False)
1184 self.tree.SetGradientStyle(self.radiovertical.GetValue())
1185 self.tree.EnableSelectionVista(False)
1186 self.tree.EnableSelectionGradient(True)
1187
1188 event.Skip()
1189
1190
1191 def OnHorizontal(self, event):
1192
1193 self.tree.SetGradientStyle(self.radiovertical.GetValue())
1194 event.Skip()
1195
1196
1197 def OnVertical(self, event):
1198
1199 self.tree.SetGradientStyle(self.radiovertical.GetValue())
1200 event.Skip()
1201
1202
1203 def OnFirstColour(self, event):
1204
1205 col1 = event.GetValue()
1206 self.tree.SetFirstGradientColour(wx.Colour(col1[0], col1[1], col1[2]))
1207 event.Skip()
1208
1209
1210 def OnSecondColour(self, event):
1211
1212 col1 = event.GetValue()
1213 self.tree.SetSecondGradientColour(wx.Colour(col1[0], col1[1], col1[2]))
1214 event.Skip()
1215
1216
1217 def OnVista(self, event):
1218
1219 self.radiohorizontal.Enable(False)
1220 self.radiovertical.Enable(False)
1221 self.firstcolour.Enable(False)
1222 self.secondcolour.Enable(False)
1223 self.checknormal.SetValue(0)
1224 self.checkgradient.SetValue(0)
1225 self.focus.Enable(False)
1226 self.unfocus.Enable(False)
1227 self.tree.EnableSelectionGradient(False)
1228 self.tree.EnableSelectionVista(True)
1229
1230 event.Skip()
1231
1232
1233
1234
1235
1236#---------------------------------------------------------------------------
1237# CustomTreeCtrl Demo Implementation
1238#---------------------------------------------------------------------------
1239class CustomTreeCtrl(CT.CustomTreeCtrl):
1240
1241 def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
1242 size=wx.DefaultSize,
cbfc9df6 1243 style=wx.SUNKEN_BORDER | CT.TR_HAS_BUTTONS | CT.TR_HAS_VARIABLE_ROW_HEIGHT,
c8f129d0
RD
1244 log=None):
1245
cbfc9df6 1246 CT.CustomTreeCtrl.__init__(self, parent, id, pos, size, style)
c8f129d0
RD
1247
1248 alldata = dir(CT)
1249
1250 treestyles = []
1251 events = []
1252 for data in alldata:
1253 if data.startswith("TR_"):
1254 treestyles.append(data)
1255 elif data.startswith("EVT_"):
1256 events.append(data)
1257
1258 self.events = events
1259 self.styles = treestyles
1260 self.item = None
1261
1262 il = wx.ImageList(16, 16)
1263
1264 for items in ArtIDs[1:-1]:
1265 bmp = wx.ArtProvider_GetBitmap(eval(items), wx.ART_TOOLBAR, (16, 16))
1266 il.Add(bmp)
1267
1268 smileidx = il.Add(images.getSmilesBitmap())
1269 numicons = il.GetImageCount()
1270
1271 self.AssignImageList(il)
1272 self.count = 0
1273 self.log = log
1274
1275 # NOTE: For some reason tree items have to have a data object in
1276 # order to be sorted. Since our compare just uses the labels
1277 # we don't need any real data, so we'll just use None below for
1278 # the item data.
1279
1280 self.root = self.AddRoot("The Root Item")
1281
1282 if not(self.GetTreeStyle() & CT.TR_HIDE_ROOT):
1283 self.SetPyData(self.root, None)
1284 self.SetItemImage(self.root, 24, CT.TreeItemIcon_Normal)
1285 self.SetItemImage(self.root, 13, CT.TreeItemIcon_Expanded)
1286
1287 textctrl = wx.TextCtrl(self, -1, "I Am A Simple\nMultiline wx.TexCtrl", style=wx.TE_MULTILINE)
1288 self.gauge = wx.Gauge(self, -1, 50, style=wx.GA_HORIZONTAL|wx.GA_SMOOTH)
1289 self.gauge.SetValue(0)
1290 combobox = wx.ComboBox(self, -1, choices=["That", "Was", "A", "Nice", "Holyday!"], style=wx.CB_READONLY|wx.CB_DROPDOWN)
1291
1292 textctrl.Bind(wx.EVT_CHAR, self.OnTextCtrl)
1293 combobox.Bind(wx.EVT_COMBOBOX, self.OnComboBox)
1294
1295 for x in range(15):
1296 if x == 1:
1297 child = self.AppendItem(self.root, "Item %d" % x + "\nHello World\nHappy wxPython-ing!")
1298 self.SetItemBold(child, True)
1299 else:
1300 child = self.AppendItem(self.root, "Item %d" % x)
1301 self.SetPyData(child, None)
1302 self.SetItemImage(child, 24, CT.TreeItemIcon_Normal)
1303 self.SetItemImage(child, 13, CT.TreeItemIcon_Expanded)
1304
1305 for y in range(5):
1306 if y == 0 and x == 1:
1307 last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)), ct_type=2, wnd=self.gauge)
1308 elif y == 1 and x == 2:
1309 last = self.AppendItem(child, "Item %d-%s" % (x, chr(ord("a")+y)), ct_type=1, wnd=textctrl)
1310 elif 2 < y < 4:
1311 last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
1312 elif y == 4 and x == 1:
1313 last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)), wnd=combobox)
1314 else:
1315 last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)), ct_type=2)
1316
1317 self.SetPyData(last, None)
1318 self.SetItemImage(last, 24, CT.TreeItemIcon_Normal)
1319 self.SetItemImage(last, 13, CT.TreeItemIcon_Expanded)
1320
1321 for z in range(5):
1322 if z > 2:
1323 item = self.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z), ct_type=1)
1324 elif 0 < z <= 2:
1325 item = self.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z), ct_type=2)
1326 elif z == 0:
1327 item = self.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z))
1328 self.SetItemHyperText(item, True)
1329 self.SetPyData(item, None)
1330 self.SetItemImage(item, 28, CT.TreeItemIcon_Normal)
1331 self.SetItemImage(item, numicons-1, CT.TreeItemIcon_Selected)
1332
1333 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
1334 self.Bind(wx.EVT_IDLE, self.OnIdle)
1335
c8f129d0
RD
1336 self.eventdict = {'EVT_TREE_BEGIN_DRAG': self.OnBeginDrag, 'EVT_TREE_BEGIN_LABEL_EDIT': self.OnBeginEdit,
1337 'EVT_TREE_BEGIN_RDRAG': self.OnBeginRDrag, 'EVT_TREE_DELETE_ITEM': self.OnDeleteItem,
1338 'EVT_TREE_END_DRAG': self.OnEndDrag, 'EVT_TREE_END_LABEL_EDIT': self.OnEndEdit,
1339 'EVT_TREE_ITEM_ACTIVATED': self.OnActivate, 'EVT_TREE_ITEM_CHECKED': self.OnItemCheck,
1340 'EVT_TREE_ITEM_CHECKING': self.OnItemChecking, 'EVT_TREE_ITEM_COLLAPSED': self.OnItemCollapsed,
1341 'EVT_TREE_ITEM_COLLAPSING': self.OnItemCollapsing, 'EVT_TREE_ITEM_EXPANDED': self.OnItemExpanded,
1342 'EVT_TREE_ITEM_EXPANDING': self.OnItemExpanding, 'EVT_TREE_ITEM_GETTOOLTIP': self.OnToolTip,
1343 'EVT_TREE_ITEM_MENU': self.OnItemMenu, 'EVT_TREE_ITEM_RIGHT_CLICK': self.OnRightDown,
1344 'EVT_TREE_KEY_DOWN': self.OnKey, 'EVT_TREE_SEL_CHANGED': self.OnSelChanged,
1345 'EVT_TREE_SEL_CHANGING': self.OnSelChanging, "EVT_TREE_ITEM_HYPERLINK": self.OnHyperLink}
1346
1347 mainframe = wx.GetTopLevelParent(self)
1348
1349 if not hasattr(mainframe, "leftpanel"):
1350 self.Bind(CT.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded)
1351 self.Bind(CT.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed)
1352 self.Bind(CT.EVT_TREE_SEL_CHANGED, self.OnSelChanged)
1353 self.Bind(CT.EVT_TREE_SEL_CHANGING, self.OnSelChanging)
1354 self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
1355 self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
1356 else:
1357 for combos in mainframe.treeevents:
1358 self.BindEvents(combos)
1359
1360 if hasattr(mainframe, "leftpanel"):
1361 self.ChangeStyle(mainframe.treestyles)
1362
1363 if not(self.GetTreeStyle() & CT.TR_HIDE_ROOT):
1364 self.SelectItem(self.root)
1365 self.Expand(self.root)
1366
1367
1368 def BindEvents(self, choice, recreate=False):
1369
1370 value = choice.GetValue()
1371 text = choice.GetLabel()
1372
1373 evt = "CT." + text
1374 binder = self.eventdict[text]
1375
1376 if value == 1:
1377 if evt == "CT.EVT_TREE_BEGIN_RDRAG":
1378 self.Bind(wx.EVT_RIGHT_DOWN, None)
1379 self.Bind(wx.EVT_RIGHT_UP, None)
1380 self.Bind(eval(evt), binder)
1381 else:
1382 self.Bind(eval(evt), None)
1383 if evt == "CT.EVT_TREE_BEGIN_RDRAG":
1384 self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
1385 self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
1386
1387
1388 def ChangeStyle(self, combos):
1389
1390 style = 0
1391 for combo in combos:
1392 if combo.GetValue() == 1:
1393 style = style | eval("CT." + combo.GetLabel())
1394
1395 if self.GetTreeStyle() != style:
1396 self.SetTreeStyle(style)
1397
1398
1399 def OnCompareItems(self, item1, item2):
1400
1401 t1 = self.GetItemText(item1)
1402 t2 = self.GetItemText(item2)
1403
1404 self.log.write('compare: ' + t1 + ' <> ' + t2 + "\n")
1405
1406 if t1 < t2:
1407 return -1
1408 if t1 == t2:
1409 return 0
1410
1411 return 1
1412
1413
1414 def OnIdle(self, event):
1415
1416 if self.gauge:
1417 try:
1418 if self.gauge.IsEnabled() and self.gauge.IsShown():
1419 self.count = self.count + 1
1420
1421 if self.count >= 50:
1422 self.count = 0
1423
1424 self.gauge.SetValue(self.count)
1425
1426 except:
1427 self.gauge = None
1428
1429 event.Skip()
1430
1431
1432 def OnRightDown(self, event):
1433
1434 pt = event.GetPosition()
1435 item, flags = self.HitTest(pt)
1436
1437 if item:
1438 self.item = item
1439 self.log.write("OnRightClick: %s, %s, %s" % (self.GetItemText(item), type(item), item.__class__) + "\n")
1440 self.SelectItem(item)
1441
1442
1443 def OnRightUp(self, event):
1444
1445 item = self.item
1446
1447 if not item:
1448 event.Skip()
1449 return
1450
1451 if not self.IsEnabled(item):
1452 event.Skip()
1453 return
1454
1455 # Item Text Appearance
1456 ishtml = self.IsItemHyperText(item)
1457 back = self.GetItemBackgroundColour(item)
1458 fore = self.GetItemTextColour(item)
1459 isbold = self.IsBold(item)
1460 font = self.GetItemFont(item)
1461
1462 # Icons On Item
1463 normal = self.GetItemImage(item, CT.TreeItemIcon_Normal)
1464 selected = self.GetItemImage(item, CT.TreeItemIcon_Selected)
1465 expanded = self.GetItemImage(item, CT.TreeItemIcon_Expanded)
1466 selexp = self.GetItemImage(item, CT.TreeItemIcon_SelectedExpanded)
1467
1468 # Enabling/Disabling Windows Associated To An Item
1469 haswin = self.GetItemWindow(item)
1470
1471 # Enabling/Disabling Items
1472 enabled = self.IsEnabled(item)
1473
1474 # Generic Item's Info
1475 children = self.GetChildrenCount(item)
1476 itemtype = self.GetItemType(item)
1477 text = self.GetItemText(item)
1478 pydata = self.GetPyData(item)
1479
1480 self.current = item
1481 self.itemdict = {"ishtml": ishtml, "back": back, "fore": fore, "isbold": isbold,
1482 "font": font, "normal": normal, "selected": selected, "expanded": expanded,
1483 "selexp": selexp, "haswin": haswin, "children": children,
1484 "itemtype": itemtype, "text": text, "pydata": pydata, "enabled": enabled}
1485
1486 menu = wx.Menu()
1487
1488 item1 = menu.Append(wx.ID_ANY, "Change Item Background Colour")
1489 item2 = menu.Append(wx.ID_ANY, "Modify Item Text Colour")
1490 menu.AppendSeparator()
1491 if isbold:
1492 strs = "Make Item Text Not Bold"
1493 else:
1494 strs = "Make Item Text Bold"
1495 item3 = menu.Append(wx.ID_ANY, strs)
1496 item4 = menu.Append(wx.ID_ANY, "Change Item Font")
1497 menu.AppendSeparator()
1498 if ishtml:
1499 strs = "Set Item As Non-Hyperlink"
1500 else:
1501 strs = "Set Item As Hyperlink"
1502 item5 = menu.Append(wx.ID_ANY, strs)
1503 menu.AppendSeparator()
1504 if haswin:
1505 enabled = self.GetItemWindowEnabled(item)
1506 if enabled:
1507 strs = "Disable Associated Widget"
1508 else:
1509 strs = "Enable Associated Widget"
1510 else:
1511 strs = "Enable Associated Widget"
1512 item6 = menu.Append(wx.ID_ANY, strs)
1513
1514 if not haswin:
1515 item6.Enable(False)
1516
1517 item7 = menu.Append(wx.ID_ANY, "Disable Item")
1518
1519 menu.AppendSeparator()
1520 item8 = menu.Append(wx.ID_ANY, "Change Item Icons")
1521 menu.AppendSeparator()
1522 item9 = menu.Append(wx.ID_ANY, "Get Other Information For This Item")
1523 menu.AppendSeparator()
1524
1525 item10 = menu.Append(wx.ID_ANY, "Delete Item")
1526 if item == self.GetRootItem():
1527 item10.Enable(False)
1528 item11 = menu.Append(wx.ID_ANY, "Prepend An Item")
1529 item12 = menu.Append(wx.ID_ANY, "Append An Item")
1530
1531 self.Bind(wx.EVT_MENU, self.OnItemBackground, item1)
1532 self.Bind(wx.EVT_MENU, self.OnItemForeground, item2)
1533 self.Bind(wx.EVT_MENU, self.OnItemBold, item3)
1534 self.Bind(wx.EVT_MENU, self.OnItemFont, item4)
1535 self.Bind(wx.EVT_MENU, self.OnItemHyperText, item5)
1536 self.Bind(wx.EVT_MENU, self.OnEnableWindow, item6)
1537 self.Bind(wx.EVT_MENU, self.OnDisableItem, item7)
1538 self.Bind(wx.EVT_MENU, self.OnItemIcons, item8)
1539 self.Bind(wx.EVT_MENU, self.OnItemInfo, item9)
1540 self.Bind(wx.EVT_MENU, self.OnItemDelete, item10)
1541 self.Bind(wx.EVT_MENU, self.OnItemPrepend, item11)
1542 self.Bind(wx.EVT_MENU, self.OnItemAppend, item12)
1543
1544 self.PopupMenu(menu)
1545 menu.Destroy()
c8f129d0
RD
1546
1547
1548 def OnItemBackground(self, event):
1549
1550 colourdata = wx.ColourData()
1551 colourdata.SetColour(self.itemdict["back"])
1552 dlg = wx.ColourDialog(self, colourdata)
1553
1554 dlg.GetColourData().SetChooseFull(True)
1555
1556 if dlg.ShowModal() == wx.ID_OK:
1557 data = dlg.GetColourData()
1558 col1 = data.GetColour().Get()
1559 self.SetItemBackgroundColour(self.current, col1)
1560 dlg.Destroy()
c8f129d0
RD
1561
1562
1563 def OnItemForeground(self, event):
1564
1565 colourdata = wx.ColourData()
1566 colourdata.SetColour(self.itemdict["fore"])
1567 dlg = wx.ColourDialog(self, colourdata)
1568
1569 dlg.GetColourData().SetChooseFull(True)
1570
1571 if dlg.ShowModal() == wx.ID_OK:
1572 data = dlg.GetColourData()
1573 col1 = data.GetColour().Get()
1574 self.SetItemTextColour(self.current, col1)
1575 dlg.Destroy()
c8f129d0
RD
1576
1577
1578 def OnItemBold(self, event):
1579
1580 self.SetItemBold(self.current, not self.itemdict["isbold"])
c8f129d0
RD
1581
1582
1583 def OnItemFont(self, event):
1584
1585 data = wx.FontData()
1586 font = self.itemdict["font"]
1587
1588 if font is None:
1589 font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
1590
1591 data.SetInitialFont(font)
1592
1593 dlg = wx.FontDialog(self, data)
1594
1595 if dlg.ShowModal() == wx.ID_OK:
1596 data = dlg.GetFontData()
1597 font = data.GetChosenFont()
1598 self.SetItemFont(self.current, font)
1599
1600 dlg.Destroy()
c8f129d0
RD
1601
1602
1603 def OnItemHyperText(self, event):
1604
1605 self.SetItemHyperText(self.current, not self.itemdict["ishtml"])
c8f129d0
RD
1606
1607
1608 def OnEnableWindow(self, event):
1609
1610 enable = self.GetItemWindowEnabled(self.current)
1611 self.SetItemWindowEnabled(self.current, not enable)
1612
c8f129d0
RD
1613
1614 def OnDisableItem(self, event):
1615
1616 self.EnableItem(self.current, False)
c8f129d0
RD
1617
1618
1619 def OnItemIcons(self, event):
1620
1621 bitmaps = [self.itemdict["normal"], self.itemdict["selected"],
1622 self.itemdict["expanded"], self.itemdict["selexp"]]
1623
1624 wx.BeginBusyCursor()
1625 dlg = TreeIcons(self, -1, bitmaps=bitmaps)
1626 wx.EndBusyCursor()
1627 dlg.ShowModal()
c8f129d0
RD
1628
1629
1630 def SetNewIcons(self, bitmaps):
1631
1632 self.SetItemImage(self.current, bitmaps[0], CT.TreeItemIcon_Normal)
1633 self.SetItemImage(self.current, bitmaps[1], CT.TreeItemIcon_Selected)
1634 self.SetItemImage(self.current, bitmaps[2], CT.TreeItemIcon_Expanded)
1635 self.SetItemImage(self.current, bitmaps[3], CT.TreeItemIcon_SelectedExpanded)
1636
1637
1638 def OnItemInfo(self, event):
1639
1640 itemtext = self.itemdict["text"]
1641 numchildren = str(self.itemdict["children"])
1642 itemtype = self.itemdict["itemtype"]
1643 pydata = repr(type(self.itemdict["pydata"]))
1644
1645 if itemtype == 0:
1646 itemtype = "Normal"
1647 elif itemtype == 1:
1648 itemtype = "CheckBox"
1649 else:
1650 itemtype = "RadioButton"
1651
1652 strs = "Information On Selected Item:\n\n" + "Text: " + itemtext + "\n" \
1653 "Number Of Children: " + numchildren + "\n" \
1654 "Item Type: " + itemtype + "\n" \
1655 "Item Data Type: " + pydata + "\n"
1656
1657 dlg = wx.MessageDialog(self, strs, "CustomTreeCtrlDemo Info", wx.OK | wx.ICON_INFORMATION)
1658 dlg.ShowModal()
1659 dlg.Destroy()
1660
c8f129d0
RD
1661
1662
1663 def OnItemDelete(self, event):
1664
1665 strs = "Are You Sure You Want To Delete Item " + self.GetItemText(self.current) + "?"
1666 dlg = wx.MessageDialog(None, strs, 'Deleting Item', wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_QUESTION)
1667
1668 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
1669 dlg.Destroy()
1670 return
1671
1672 dlg.Destroy()
1673
1674 self.DeleteChildren(self.current)
1675 self.Delete(self.current)
1676 self.current = None
1677
c8f129d0
RD
1678
1679
1680 def OnItemPrepend(self, event):
1681
1682 dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')
1683
1684 if dlg.ShowModal() == wx.ID_OK:
1685 newname = dlg.GetValue()
1686 newitem = self.PrependItem(self.current, newname)
1687 self.EnsureVisible(newitem)
1688
1689 dlg.Destroy()
c8f129d0
RD
1690
1691
1692 def OnItemAppend(self, event):
1693
1694 dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')
1695
1696 if dlg.ShowModal() == wx.ID_OK:
1697 newname = dlg.GetValue()
1698 newitem = self.AppendItem(self.current, newname)
1699 self.EnsureVisible(newitem)
1700
1701 dlg.Destroy()
c8f129d0
RD
1702
1703
1704 def OnBeginEdit(self, event):
1705
1706 self.log.write("OnBeginEdit" + "\n")
1707 # show how to prevent edit...
1708 item = event.GetItem()
1709 if item and self.GetItemText(item) == "The Root Item":
1710 wx.Bell()
1711 self.log.write("You can't edit this one..." + "\n")
1712
1713 # Lets just see what's visible of its children
1714 cookie = 0
1715 root = event.GetItem()
1716 (child, cookie) = self.GetFirstChild(root)
1717
1718 while child:
1719 self.log.write("Child [%s] visible = %d" % (self.GetItemText(child), self.IsVisible(child)) + "\n")
1720 (child, cookie) = self.GetNextChild(root, cookie)
1721
1722 event.Veto()
1723
1724
1725 def OnEndEdit(self, event):
1726
1727 self.log.write("OnEndEdit: %s %s" %(event.IsEditCancelled(), event.GetLabel()))
1728 # show how to reject edit, we'll not allow any digits
1729 for x in event.GetLabel():
1730 if x in string.digits:
1731 self.log.write(", You can't enter digits..." + "\n")
1732 event.Veto()
1733 return
1734
1735 self.log.write("\n")
1736
1737
1738 def OnLeftDClick(self, event):
1739
1740 pt = event.GetPosition()
1741 item, flags = self.HitTest(pt)
1742 if item and (flags & CT.TREE_HITTEST_ONITEMLABEL):
1743 if self.GetTreeStyle() & CT.TR_EDIT_LABELS:
1744 self.log.write("OnLeftDClick: %s (manually starting label edit)"% self.GetItemText(item) + "\n")
1745 self.EditLabel(item)
1746 else:
1747 self.log.write("OnLeftDClick: Cannot Start Manual Editing, Missing Style TR_EDIT_LABELS\n")
1748
1749 event.Skip()
1750
1751
1752 def OnItemExpanded(self, event):
1753
1754 item = event.GetItem()
1755 if item:
1756 self.log.write("OnItemExpanded: %s" % self.GetItemText(item) + "\n")
1757
1758
1759 def OnItemExpanding(self, event):
1760
1761 item = event.GetItem()
1762 if item:
1763 self.log.write("OnItemExpanding: %s" % self.GetItemText(item) + "\n")
1764
1765 event.Skip()
1766
1767
1768 def OnItemCollapsed(self, event):
1769
1770 item = event.GetItem()
1771 if item:
1772 self.log.write("OnItemCollapsed: %s" % self.GetItemText(item) + "\n")
1773
1774
1775 def OnItemCollapsing(self, event):
1776
1777 item = event.GetItem()
1778 if item:
1779 self.log.write("OnItemCollapsing: %s" % self.GetItemText(item) + "\n")
1780
1781 event.Skip()
1782
1783
1784 def OnSelChanged(self, event):
1785
1786 self.item = event.GetItem()
1787 if self.item:
1788 self.log.write("OnSelChanged: %s" % self.GetItemText(self.item))
1789 if wx.Platform == '__WXMSW__':
1790 self.log.write(", BoundingRect: %s" % self.GetBoundingRect(self.item, True) + "\n")
1791 else:
1792 self.log.write("\n")
1793
1794 event.Skip()
1795
1796
1797 def OnSelChanging(self, event):
1798
1799 item = event.GetItem()
1800 olditem = event.GetOldItem()
1801
1802 if item:
1803 if not olditem:
1804 olditemtext = "None"
1805 else:
1806 olditemtext = self.GetItemText(olditem)
1807 self.log.write("OnSelChanging: From %s" % olditemtext + " To %s" % self.GetItemText(item) + "\n")
1808
1809 event.Skip()
1810
1811
1812 def OnBeginDrag(self, event):
1813
1814 self.item = event.GetItem()
1815 if self.item:
1816 self.log.write("Beginning Drag..." + "\n")
1817
1818 event.Allow()
c8f129d0
RD
1819
1820
1821 def OnBeginRDrag(self, event):
1822
1823 self.item = event.GetItem()
1824 if self.item:
1825 self.log.write("Beginning Right Drag..." + "\n")
1826
1827 event.Allow()
c8f129d0
RD
1828
1829
1830 def OnEndDrag(self, event):
1831
1832 self.item = event.GetItem()
1833 if self.item:
1834 self.log.write("Ending Drag!" + "\n")
1835
1836 event.Skip()
1837
1838
1839 def OnDeleteItem(self, event):
1840
1841 item = event.GetItem()
1842
1843 if not item:
1844 return
1845
1846 self.log.write("Deleting Item: %s" % self.GetItemText(item) + "\n")
1847 event.Skip()
1848
1849
1850 def OnItemCheck(self, event):
1851
1852 item = event.GetItem()
1853 self.log.write("Item " + self.GetItemText(item) + " Has Been Checked!\n")
1854 event.Skip()
1855
1856
1857 def OnItemChecking(self, event):
1858
1859 item = event.GetItem()
1860 self.log.write("Item " + self.GetItemText(item) + " Is Being Checked...\n")
1861 event.Skip()
1862
1863
1864 def OnToolTip(self, event):
1865
1866 item = event.GetItem()
1867 if item:
1868 event.SetToolTip(wx.ToolTip(self.GetItemText(item)))
1869
1870
1871 def OnItemMenu(self, event):
1872
1873 item = event.GetItem()
1874 if item:
1875 self.log.write("OnItemMenu: %s" % self.GetItemText(item) + "\n")
1876
1877 event.Skip()
1878
1879
1880 def OnKey(self, event):
1881
1882 keycode = event.GetKeyCode()
1883 keyname = keyMap.get(keycode, None)
1884
1885 if keycode == wx.WXK_BACK:
1886 self.log.write("OnKeyDown: HAHAHAHA! I Vetoed Your Backspace! HAHAHAHA\n")
1887 return
1888
1889 if keyname is None:
1890 if "unicode" in wx.PlatformInfo:
1891 keycode = event.GetUnicodeKey()
1892 if keycode <= 127:
1893 keycode = event.GetKeyCode()
1894 keyname = "\"" + unichr(event.GetUnicodeKey()) + "\""
1895 if keycode < 27:
1896 keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
1897
1898 elif keycode < 256:
1899 if keycode == 0:
1900 keyname = "NUL"
1901 elif keycode < 27:
1902 keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
1903 else:
1904 keyname = "\"%s\"" % chr(keycode)
1905 else:
1906 keyname = "unknown (%s)" % keycode
1907
1908 self.log.write("OnKeyDown: You Pressed '" + keyname + "'\n")
1909
1910 event.Skip()
1911
1912
1913 def OnActivate(self, event):
1914
1915 if self.item:
1916 self.log.write("OnActivate: %s" % self.GetItemText(self.item) + "\n")
1917
1918 event.Skip()
1919
1920
1921 def OnHyperLink(self, event):
1922
1923 item = event.GetItem()
1924 if item:
1925 self.log.write("OnHyperLink: %s" % self.GetItemText(self.item) + "\n")
1926
1927
1928 def OnTextCtrl(self, event):
1929
1930 char = chr(event.GetKeyCode())
1931 self.log.write("EDITING THE TEXTCTRL: You Wrote '" + char + \
1932 "' (KeyCode = " + str(event.GetKeyCode()) + ")\n")
1933 event.Skip()
1934
1935
1936 def OnComboBox(self, event):
1937
1938 selection = event.GetEventObject().GetValue()
1939 self.log.write("CHOICE FROM COMBOBOX: You Chose '" + selection + "'\n")
1940 event.Skip()
1941
1942
1943
1944#----------------------------------------------------------------------
1945
1946def runTest(frame, nb, log):
1947 win = CustomTreeCtrlDemo(nb, log)
1948 return win
1949
1950#----------------------------------------------------------------------
1951
1952
1953
1954overview = CT.__doc__
1955
1956
1957if __name__ == '__main__':
1958 import sys,os
1959 import run
1960 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1961