]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/CustomTreeCtrl.py
removed code inside USE_SIZABLE_CALENDAR, we should allow making the main calendar...
[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
767 self.tree = CustomTreeCtrl(splitter, -1, log=self.log, style=wx.SUNKEN_BORDER)
768
769 self.leftpanel = wx.ScrolledWindow(splitter, -1, style=wx.SUNKEN_BORDER)
770 self.leftpanel.SetScrollRate(20,20)
771 width = self.PopulateLeftPanel(self.tree.styles, self.tree.events)
772
773 # add the windows to the splitter and split it.
774 splitter.SplitVertically(self.leftpanel, self.tree, 300)
775 splitter.SetMinimumPaneSize(width+5)
776
777 sizer = wx.BoxSizer()
778 sizer.Add(splitter, 1, wx.EXPAND)
779 self.SetSizer(sizer)
780
781
782 def PopulateLeftPanel(self, styles, events):
783 pnl = wx.Panel(self.leftpanel)
784 mainsizer = wx.BoxSizer(wx.VERTICAL)
785 recreatetree = wx.Button(pnl, -1, "Recreate CustomTreeCtrl")
786 mainsizer.Add(recreatetree, 0, wx.ALL|wx.ALIGN_CENTER, 10)
787 recreatetree.Bind(wx.EVT_BUTTON, self.OnRecreateTree)
788
789 staticboxstyles = wx.StaticBox(pnl, -1, "CustomTreeCtrl Styles")
790 stylesizer = wx.StaticBoxSizer(staticboxstyles, wx.VERTICAL)
791 staticboxevents = wx.StaticBox(pnl, -1, "CustomTreeCtrl Events")
792 eventssizer = wx.StaticBoxSizer(staticboxevents, wx.VERTICAL)
793 staticboxcolours = wx.StaticBox(pnl, -1, "CustomTreeCtrl Images/Colours")
794 colourssizer = wx.StaticBoxSizer(staticboxcolours, wx.VERTICAL)
795 staticboxthemes = wx.StaticBox(pnl, -1, "CustomTreeCtrl Themes/Gradients")
796 themessizer = wx.StaticBoxSizer(staticboxthemes, wx.VERTICAL)
797
798 self.treestyles = []
799 self.treeevents = []
800
801 for count, style in enumerate(styles):
802
803 if count == 0:
804 tags = wx.ALL
805 else:
806 tags = wx.LEFT|wx.RIGHT|wx.BOTTOM
807
808 if style != "TR_DEFAULT_STYLE":
809 check = wx.CheckBox(pnl, -1, style)
810 stylesizer.Add(check, 0, tags, 3)
811
812 if style in ["TR_HAS_BUTTONS", "TR_HAS_VARIABLE_ROW_HEIGHT"]:
813 check.SetValue(1)
814
815 if style == "TR_HAS_VARIABLE_ROW_HEIGHT":
816 check.Enable(False)
817
818 check.Bind(wx.EVT_CHECKBOX, self.OnCheckStyle)
819 self.treestyles.append(check)
820
821
822 for count, event in enumerate(events):
823
824 if count == 0:
825 tags = wx.ALL
826 else:
827 tags = wx.LEFT|wx.RIGHT|wx.BOTTOM
828
829 if count not in [6, 17, 22, 23]:
830 check = wx.CheckBox(pnl, -1, event)
831 eventssizer.Add(check, 0, tags, 3)
832
833 if event in ["EVT_TREE_ITEM_EXPANDED", "EVT_TREE_ITEM_COLLAPSED",
834 "EVT_TREE_SEL_CHANGED", "EVT_TREE_SEL_CHANGING"]:
835
836 check.SetValue(1)
837
838 check.Bind(wx.EVT_CHECKBOX, self.OnCheckEvent)
839 self.treeevents.append(check)
840
841 sizer1 = wx.BoxSizer(wx.HORIZONTAL)
842 label = wx.StaticText(pnl, -1, "Connection Pen")
843 font = label.GetFont()
844 font.SetWeight(wx.FONTWEIGHT_BOLD)
845 label.SetFont(font)
846 buttonconnection = wx.Button(pnl, -1, "Choose...")
847 buttonconnection.Bind(wx.EVT_BUTTON, self.OnButtonConnection)
848 sizer1.Add(label, 0, wx.ALL|wx.ALIGN_CENTER, 5)
849 sizer1.Add((1,0), 1, wx.EXPAND)
850 sizer1.Add(buttonconnection, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_RIGHT, 5)
851
852 sizer2 = wx.BoxSizer(wx.HORIZONTAL)
853 label = wx.StaticText(pnl, -1, "Border Pen")
854 font = label.GetFont()
855 font.SetWeight(wx.FONTWEIGHT_BOLD)
856 label.SetFont(font)
857 buttonborder = wx.Button(pnl, -1, "Choose...")
858 buttonborder.Bind(wx.EVT_BUTTON, self.OnButtonBorder)
859 sizer2.Add(label, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER, 5)
860 sizer2.Add((1,0), 1, wx.EXPAND)
861 sizer2.Add(buttonborder, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_RIGHT, 5)
862
863 sizer3 = wx.BoxSizer(wx.HORIZONTAL)
864 label = wx.StaticText(pnl, -1, "Tree Buttons")
865 font = label.GetFont()
866 font.SetWeight(wx.FONTWEIGHT_BOLD)
867 label.SetFont(font)
868 buttontree = wx.Button(pnl, -1, "Choose...")
869 buttontree.Bind(wx.EVT_BUTTON, self.OnButtonTree)
870 sizer3.Add(label, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER, 5)
871 sizer3.Add((1,0), 1, wx.EXPAND)
872 sizer3.Add(buttontree, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_RIGHT, 5)
873
874 sizer4 = wx.BoxSizer(wx.HORIZONTAL)
875 label = wx.StaticText(pnl, -1, "Check/Radio Buttons")
876 font = label.GetFont()
877 font.SetWeight(wx.FONTWEIGHT_BOLD)
878 label.SetFont(font)
879 buttoncr = wx.Button(pnl, -1, "Choose...")
880 buttoncr.Bind(wx.EVT_BUTTON, self.OnButtonCheckRadio)
881 sizer4.Add(label, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER, 5)
882 sizer4.Add((1,0), 1, wx.EXPAND)
883 sizer4.Add(buttoncr, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_RIGHT, 5)
884
885 sizer5 = wx.BoxSizer(wx.HORIZONTAL)
886 radioimage = wx.RadioButton(pnl, -1, "Image Background", style=wx.RB_GROUP)
887 radioimage.Bind(wx.EVT_RADIOBUTTON, self.OnBackgroundImage)
888 self.imagebutton = wx.Button(pnl, -1, "Choose...")
889 self.imagebutton.Bind(wx.EVT_BUTTON, self.OnChooseImage)
890 sizer5.Add(radioimage, 0, wx.ALL|wx.ALIGN_CENTER, 5)
891 sizer5.Add((1,0), 1, wx.EXPAND)
892 sizer5.Add(self.imagebutton, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_RIGHT, 5)
893
894 sizer6 = wx.BoxSizer(wx.HORIZONTAL)
895 radiobackground = wx.RadioButton(pnl, -1, "Background Colour")
896 radiobackground.Bind(wx.EVT_RADIOBUTTON, self.OnBackgroundColour)
897 self.backbutton = csel.ColourSelect(pnl, -1, "Choose...", wx.WHITE)
898 self.backbutton.Bind(csel.EVT_COLOURSELECT, self.OnChooseBackground)
899 sizer6.Add(radiobackground, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER, 5)
900 sizer6.Add((1,0), 1, wx.EXPAND)
901 sizer6.Add(self.backbutton, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER, 5)
902
903 colourssizer.Add(sizer1, 0, wx.EXPAND)
904 colourssizer.Add(sizer2, 0, wx.EXPAND)
905 colourssizer.Add(sizer3, 0, wx.EXPAND)
906 colourssizer.Add(sizer4, 0, wx.EXPAND)
907 colourssizer.Add(sizer5, 0, wx.EXPAND)
908 colourssizer.Add(sizer6, 0, wx.EXPAND)
909
910 sizera = wx.BoxSizer(wx.HORIZONTAL)
911 self.checknormal = wx.CheckBox(pnl, -1, "Standard Colours")
912 self.focus = csel.ColourSelect(pnl, -1, "Focus",
913 self.tree.GetHilightFocusColour())
914 self.unfocus = csel.ColourSelect(pnl, -1, "Non-Focus",
915 self.tree.GetHilightNonFocusColour())
916 self.checknormal.Bind(wx.EVT_CHECKBOX, self.OnCheckNormal)
917 self.focus.Bind(csel.EVT_COLOURSELECT, self.OnFocusColour)
918 self.unfocus.Bind(csel.EVT_COLOURSELECT, self.OnNonFocusColour)
919 sizera1 = wx.BoxSizer(wx.VERTICAL)
920 sizera1.Add(self.focus, 0, wx.BOTTOM, 2)
921 sizera1.Add(self.unfocus, 0)
922 sizera.Add(self.checknormal, 0, wx.ALL, 3)
923 sizera.Add((1, 0), 1, wx.EXPAND)
924 sizera.Add(sizera1, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, 3)
925
926 sizerb = wx.BoxSizer(wx.VERTICAL)
927 self.checkgradient = wx.CheckBox(pnl, -1, "Gradient Theme")
928 self.checkgradient.Bind(wx.EVT_CHECKBOX, self.OnCheckGradient)
929 sizerb1 = wx.BoxSizer(wx.HORIZONTAL)
930 sizerb1.Add((10, 0))
931 self.radiohorizontal = wx.RadioButton(pnl, -1, "Horizontal", style=wx.RB_GROUP)
932 self.radiohorizontal.Bind(wx.EVT_RADIOBUTTON, self.OnHorizontal)
933 sizerb1.Add(self.radiohorizontal, 0, wx.TOP|wx.BOTTOM, 3)
934 sizerb2 = wx.BoxSizer(wx.HORIZONTAL)
935 sizerb2.Add((10, 0))
936 self.radiovertical = wx.RadioButton(pnl, -1, "Vertical")
937 self.radiovertical.Bind(wx.EVT_RADIOBUTTON, self.OnVertical)
938 sizerb2.Add(self.radiovertical, 0, wx.BOTTOM, 3)
939 sizerb3 = wx.BoxSizer(wx.HORIZONTAL)
940 self.firstcolour = csel.ColourSelect(pnl, -1, "First Colour",
941 self.tree.GetFirstGradientColour())
942 self.secondcolour = csel.ColourSelect(pnl, -1, "Second Colour",
943 self.tree.GetSecondGradientColour())
944 self.firstcolour.Bind(csel.EVT_COLOURSELECT, self.OnFirstColour)
945 self.secondcolour.Bind(csel.EVT_COLOURSELECT, self.OnSecondColour)
946 sizerb3.Add(self.firstcolour, 0, wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 3)
947 sizerb3.Add(self.secondcolour, 0, wx.LEFT|wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 3)
948 sizerb.Add(self.checkgradient, 0, wx.ALL, 3)
949 sizerb.Add(sizerb1, 0)
950 sizerb.Add(sizerb2, 0)
951 sizerb.Add(sizerb3, 0, wx.ALIGN_CENTER)
952
953 self.checkvista = wx.CheckBox(pnl, -1, "Windows Vista Theme")
954 self.checkvista.Bind(wx.EVT_CHECKBOX, self.OnVista)
955
956 themessizer.Add(sizera, 0, wx.EXPAND)
957 themessizer.Add(sizerb, 0, wx.EXPAND)
958 themessizer.Add((0, 5))
959 themessizer.Add(self.checkvista, 0, wx.EXPAND|wx.ALL, 3)
960
961 mainsizer.Add(stylesizer, 0, wx.EXPAND|wx.ALL, 5)
962 mainsizer.Add(colourssizer, 0, wx.EXPAND|wx.ALL, 5)
963 mainsizer.Add(themessizer, 0, wx.EXPAND|wx.ALL, 5)
964 mainsizer.Add(eventssizer, 0, wx.EXPAND|wx.ALL, 5)
965
966 pnl.SetSizer(mainsizer)
967 pnl.Fit()
968
969 swsizer = wx.BoxSizer(wx.VERTICAL)
970 swsizer.Add(pnl, 0, wx.EXPAND)
971 self.leftpanel.SetSizer(swsizer)
972 swsizer.Layout()
973
974 radiobackground.SetValue(1)
975 self.checknormal.SetValue(1)
976 self.radiohorizontal.Enable(False)
977 self.radiovertical.Enable(False)
978 self.firstcolour.Enable(False)
979 self.secondcolour.Enable(False)
980 self.imagebutton.Enable(False)
981
982 return mainsizer.CalcMin().width + wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X)
983
984
985 def OnRecreateTree(self, event):
986
987 splitter = self.tree.GetParent()
988 newtree = CustomTreeCtrl(splitter, -1, log=self.log)
989 splitter.ReplaceWindow(self.tree, newtree)
990 self.tree.Destroy()
991 self.tree = newtree
992 # Todo: The settings in the leftpanel should be reset too
993
994
995 def OnCheckStyle(self, event):
996
997 self.tree.ChangeStyle(self.treestyles)
998 event.Skip()
999
1000
1001 def OnCheckEvent(self, event):
1002
1003 obj = event.GetEventObject()
1004 self.tree.BindEvents(obj)
1005
1006 event.Skip()
1007
1008
1009 def OnButtonConnection(self, event):
1010
1011 pen = self.tree.GetConnectionPen()
1012 dlg = PenDialog(self, -1, oldpen=pen, pentype=0)
1013
1014 dlg.ShowModal()
1015
1016 event.Skip()
1017
1018
1019 def SetConnectionPen(self, pen):
1020
1021 self.tree.SetConnectionPen(pen)
1022
1023
1024 def OnButtonBorder(self, event):
1025
1026 pen = self.tree.GetBorderPen()
1027 dlg = PenDialog(self, -1, oldpen=pen, pentype=1)
1028
1029 dlg.ShowModal()
1030 event.Skip()
1031
1032
1033 def SetBorderPen(self, pen):
1034
1035 self.tree.SetBorderPen(pen)
1036
1037
1038 def OnButtonTree(self, event):
1039
1040 dlg = TreeButtonsDialog(self, -1, oldicons=self.oldicons)
1041 dlg.ShowModal()
1042
1043 event.Skip()
1044
1045
1046 def OnButtonCheckRadio(self, event):
1047
1048 dlg = CheckDialog(self, -1)
1049 dlg.ShowModal()
1050
1051 event.Skip()
1052
1053
1054 def SetTreeButtons(self, selection):
1055
1056 bitmap_plus = opj("bitmaps/plus" + str(selection+1) + ".ico")
1057 bitmap_minus = opj("bitmaps/minus" + str(selection+1) + ".ico")
1058
1059 bitmap = wx.Bitmap(bitmap_plus, wx.BITMAP_TYPE_ICO)
1060 width = bitmap.GetWidth()
1061
1062 il = wx.ImageList(width, width)
1063
1064 il.Add(wx.Bitmap(bitmap_plus, wx.BITMAP_TYPE_ICO))
1065 il.Add(wx.Bitmap(bitmap_plus, wx.BITMAP_TYPE_ICO))
1066 il.Add(wx.Bitmap(bitmap_minus, wx.BITMAP_TYPE_ICO))
1067 il.Add(wx.Bitmap(bitmap_minus, wx.BITMAP_TYPE_ICO))
1068
1069 self.il = il
1070 self.tree.SetButtonsImageList(il)
1071
1072
1073 def SetCheckRadio(self, selection):
1074
1075 if selection == 0:
1076 self.tree.SetImageListCheck(13, 13)
1077 else:
1078 bitmap_check = opj("bitmaps/aquachecked.ico")
1079 bitmap_uncheck = opj("bitmaps/aquanotchecked.ico")
1080 bitmap_flag = opj("bitmaps/aquaflagged.ico")
1081 bitmap_unflag = opj("bitmaps/aquanotflagged.ico")
1082
1083 il = wx.ImageList(16, 16)
1084
1085 il.Add(wx.Bitmap(bitmap_check, wx.BITMAP_TYPE_ICO))
1086 il.Add(wx.Bitmap(bitmap_uncheck, wx.BITMAP_TYPE_ICO))
1087 il.Add(wx.Bitmap(bitmap_flag, wx.BITMAP_TYPE_ICO))
1088 il.Add(wx.Bitmap(bitmap_unflag, wx.BITMAP_TYPE_ICO))
1089 self.tree.SetImageListCheck(16, 16, il)
1090
1091
1092 def OnBackgroundImage(self, event):
1093
1094 if hasattr(self, "backgroundimage"):
1095 self.tree.SetBackgroundImage(self.backgroundimage)
1096
1097 self.backbutton.Enable(False)
1098 self.imagebutton.Enable(True)
1099
1100 event.Skip()
1101
1102
1103 def OnChooseImage(self, event):
1104
1105 wildcard = "JPEG Files (*.jpg)|*.jpg|" \
1106 "Bitmap Files (*.bmp)|*.bmp|" \
1107 "PNG Files (*.png)|*.png|" \
1108 "Icon Files (*.ico)|*.ico|" \
1109 "GIF Files (*.gif)|*.gif|" \
1110 "All files (*.*)|*.*"
1111
1112 dlg = wx.FileDialog(self, "Choose An Image File", ".", "", wildcard, wx.OPEN)
1113
1114 if dlg.ShowModal() == wx.ID_OK:
1115 path = dlg.GetPath()
1116 else:
1117 dlg.Destroy()
1118 return
1119
1120 dlg.Destroy()
1121 bitmap = wx.Bitmap(path, wx.BITMAP_TYPE_ANY)
1122 self.tree.SetBackgroundImage(bitmap)
1123 self.backgroundimage = bitmap
1124
1125 event.Skip()
1126
1127
1128 def OnBackgroundColour(self, event):
1129
1130 self.imagebutton.Enable(False)
1131 self.backbutton.Enable(True)
1132 self.tree.SetBackgroundImage(None)
1133
1134 event.Skip()
1135
1136
1137 def OnChooseBackground(self, event):
1138
1139 col1 = event.GetValue()
1140 self.tree.SetBackgroundColour(col1)
1141 event.Skip()
1142
1143
1144 def OnCheckNormal(self, event):
1145
1146 self.radiohorizontal.Enable(False)
1147 self.radiovertical.Enable(False)
1148 self.firstcolour.Enable(False)
1149 self.secondcolour.Enable(False)
1150 self.focus.Enable(True)
1151 self.unfocus.Enable(True)
1152 self.checkgradient.SetValue(0)
1153 self.checkvista.SetValue(0)
1154 self.tree.EnableSelectionGradient(False)
1155 self.tree.EnableSelectionVista(False)
1156 event.Skip()
1157
1158
1159 def OnFocusColour(self, event):
1160
1161 col1 = event.GetValue()
1162 self.tree.SetHilightFocusColour(col1)
1163 event.Skip()
1164
1165
1166 def OnNonFocusColour(self, event):
1167
1168 col1 = event.GetValue()
1169 self.tree.SetHilightNonFocusColour(col1)
1170 event.Skip()
1171
1172
1173 def OnCheckGradient(self, event):
1174
1175 self.radiohorizontal.Enable(True)
1176 self.radiovertical.Enable(True)
1177 self.firstcolour.Enable(True)
1178 self.secondcolour.Enable(True)
1179 self.checknormal.SetValue(0)
1180 self.checkvista.SetValue(0)
1181 self.focus.Enable(False)
1182 self.unfocus.Enable(False)
1183 self.tree.SetGradientStyle(self.radiovertical.GetValue())
1184 self.tree.EnableSelectionVista(False)
1185 self.tree.EnableSelectionGradient(True)
1186
1187 event.Skip()
1188
1189
1190 def OnHorizontal(self, event):
1191
1192 self.tree.SetGradientStyle(self.radiovertical.GetValue())
1193 event.Skip()
1194
1195
1196 def OnVertical(self, event):
1197
1198 self.tree.SetGradientStyle(self.radiovertical.GetValue())
1199 event.Skip()
1200
1201
1202 def OnFirstColour(self, event):
1203
1204 col1 = event.GetValue()
1205 self.tree.SetFirstGradientColour(wx.Colour(col1[0], col1[1], col1[2]))
1206 event.Skip()
1207
1208
1209 def OnSecondColour(self, event):
1210
1211 col1 = event.GetValue()
1212 self.tree.SetSecondGradientColour(wx.Colour(col1[0], col1[1], col1[2]))
1213 event.Skip()
1214
1215
1216 def OnVista(self, event):
1217
1218 self.radiohorizontal.Enable(False)
1219 self.radiovertical.Enable(False)
1220 self.firstcolour.Enable(False)
1221 self.secondcolour.Enable(False)
1222 self.checknormal.SetValue(0)
1223 self.checkgradient.SetValue(0)
1224 self.focus.Enable(False)
1225 self.unfocus.Enable(False)
1226 self.tree.EnableSelectionGradient(False)
1227 self.tree.EnableSelectionVista(True)
1228
1229 event.Skip()
1230
1231
1232
1233
1234
1235#---------------------------------------------------------------------------
1236# CustomTreeCtrl Demo Implementation
1237#---------------------------------------------------------------------------
1238class CustomTreeCtrl(CT.CustomTreeCtrl):
1239
1240 def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
1241 size=wx.DefaultSize,
1242 style=wx.SUNKEN_BORDER,
1243 ctstyle=CT.TR_HAS_BUTTONS | CT.TR_HAS_VARIABLE_ROW_HEIGHT,
1244 log=None):
1245
1246 CT.CustomTreeCtrl.__init__(self, parent, id, pos, size, style, ctstyle)
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()
1819 event.Skip()
1820
1821
1822 def OnBeginRDrag(self, event):
1823
1824 self.item = event.GetItem()
1825 if self.item:
1826 self.log.write("Beginning Right Drag..." + "\n")
1827
1828 event.Allow()
1829 event.Skip()
1830
1831
1832 def OnEndDrag(self, event):
1833
1834 self.item = event.GetItem()
1835 if self.item:
1836 self.log.write("Ending Drag!" + "\n")
1837
1838 event.Skip()
1839
1840
1841 def OnDeleteItem(self, event):
1842
1843 item = event.GetItem()
1844
1845 if not item:
1846 return
1847
1848 self.log.write("Deleting Item: %s" % self.GetItemText(item) + "\n")
1849 event.Skip()
1850
1851
1852 def OnItemCheck(self, event):
1853
1854 item = event.GetItem()
1855 self.log.write("Item " + self.GetItemText(item) + " Has Been Checked!\n")
1856 event.Skip()
1857
1858
1859 def OnItemChecking(self, event):
1860
1861 item = event.GetItem()
1862 self.log.write("Item " + self.GetItemText(item) + " Is Being Checked...\n")
1863 event.Skip()
1864
1865
1866 def OnToolTip(self, event):
1867
1868 item = event.GetItem()
1869 if item:
1870 event.SetToolTip(wx.ToolTip(self.GetItemText(item)))
1871
1872
1873 def OnItemMenu(self, event):
1874
1875 item = event.GetItem()
1876 if item:
1877 self.log.write("OnItemMenu: %s" % self.GetItemText(item) + "\n")
1878
1879 event.Skip()
1880
1881
1882 def OnKey(self, event):
1883
1884 keycode = event.GetKeyCode()
1885 keyname = keyMap.get(keycode, None)
1886
1887 if keycode == wx.WXK_BACK:
1888 self.log.write("OnKeyDown: HAHAHAHA! I Vetoed Your Backspace! HAHAHAHA\n")
1889 return
1890
1891 if keyname is None:
1892 if "unicode" in wx.PlatformInfo:
1893 keycode = event.GetUnicodeKey()
1894 if keycode <= 127:
1895 keycode = event.GetKeyCode()
1896 keyname = "\"" + unichr(event.GetUnicodeKey()) + "\""
1897 if keycode < 27:
1898 keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
1899
1900 elif keycode < 256:
1901 if keycode == 0:
1902 keyname = "NUL"
1903 elif keycode < 27:
1904 keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
1905 else:
1906 keyname = "\"%s\"" % chr(keycode)
1907 else:
1908 keyname = "unknown (%s)" % keycode
1909
1910 self.log.write("OnKeyDown: You Pressed '" + keyname + "'\n")
1911
1912 event.Skip()
1913
1914
1915 def OnActivate(self, event):
1916
1917 if self.item:
1918 self.log.write("OnActivate: %s" % self.GetItemText(self.item) + "\n")
1919
1920 event.Skip()
1921
1922
1923 def OnHyperLink(self, event):
1924
1925 item = event.GetItem()
1926 if item:
1927 self.log.write("OnHyperLink: %s" % self.GetItemText(self.item) + "\n")
1928
1929
1930 def OnTextCtrl(self, event):
1931
1932 char = chr(event.GetKeyCode())
1933 self.log.write("EDITING THE TEXTCTRL: You Wrote '" + char + \
1934 "' (KeyCode = " + str(event.GetKeyCode()) + ")\n")
1935 event.Skip()
1936
1937
1938 def OnComboBox(self, event):
1939
1940 selection = event.GetEventObject().GetValue()
1941 self.log.write("CHOICE FROM COMBOBOX: You Chose '" + selection + "'\n")
1942 event.Skip()
1943
1944
1945
1946#----------------------------------------------------------------------
1947
1948def runTest(frame, nb, log):
1949 win = CustomTreeCtrlDemo(nb, log)
1950 return win
1951
1952#----------------------------------------------------------------------
1953
1954
1955
1956overview = CT.__doc__
1957
1958
1959if __name__ == '__main__':
1960 import sys,os
1961 import run
1962 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1963