4 import wx
.lib
.colourselect
as csel
6 import wx
.lib
.customtreectrl
as CT
11 #---------------------------------------------------------------------------
14 penstyle
= ["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"]
19 "wx.ART_ADD_BOOKMARK",
20 "wx.ART_DEL_BOOKMARK",
21 "wx.ART_HELP_SIDE_PANEL",
22 "wx.ART_HELP_SETTINGS",
30 "wx.ART_GO_TO_PARENT",
46 "wx.ART_EXECUTABLE_FILE",
54 "wx.ART_MISSING_IMAGE",
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",
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"
166 #---------------------------------------------------------------------------
167 # Just A Dialog To Select Pen Styles
168 #---------------------------------------------------------------------------
169 class PenDialog(wx
.Dialog
):
171 def __init__(self
, parent
=None, id=-1, title
="", pos
=wx
.DefaultPosition
,
172 size
=wx
.DefaultSize
, style
=wx
.DEFAULT_DIALOG_STYLE
, oldpen
=None,
175 wx
.Dialog
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
177 self
.colourbutton
= csel
.ColourSelect(self
)
178 self
.spinwidth
= wx
.SpinCtrl(self
, -1, "1", min=1, max=3, style
=wx
.SP_ARROW_KEYS
)
180 self
.combostyle
= wx
.ComboBox(self
, -1, choices
=penstyle
, style
=wx
.CB_DROPDOWN|wx
.CB_READONLY
)
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
)
185 self
.okbutton
= wx
.Button(self
, wx
.ID_OK
)
186 self
.cancelbutton
= wx
.Button(self
, wx
.ID_CANCEL
)
190 self
.pentype
= pentype
192 self
.__set
_properties
()
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
)
200 def __set_properties(self
):
202 self
.SetTitle("Pen Dialog Selector")
203 self
.colourbutton
.SetMinSize((25, 25))
204 self
.colourbutton
.SetColour(self
.oldpen
.GetColour())
206 style
= self
.oldpen
.GetStyle()
207 for count
, st
in enumerate(penstyle
):
208 if eval(st
) == style
:
209 self
.combostyle
.SetSelection(count
)
211 self
.combodash
.Enable(True)
213 self
.combodash
.Enable(False)
216 if self
.combodash
.IsEnabled():
217 dashes
= repr(self
.oldpen
.GetDashes())
218 self
.combodash
.SetValue(dashes
)
220 self
.spinwidth
.SetValue(self
.oldpen
.GetWidth())
221 self
.okbutton
.SetDefault()
223 if self
.pentype
== 1:
224 self
.spinwidth
.Enable(False)
227 def __do_layout(self
):
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
)
262 mainsizer
.SetSizeHints(self
)
269 def OnStyle(self
, event
):
271 choice
= event
.GetEventObject().GetValue()
272 self
.combodash
.Enable(choice
==5)
276 def OnOk(self
, event
):
278 colour
= self
.colourbutton
.GetColour()
279 style
= eval(self
.combostyle
.GetValue())
280 width
= int(self
.spinwidth
.GetValue())
283 if self
.combostyle
.GetSelection() == 5:
284 dashes
= eval(self
.combodash
.GetValue())
286 pen
= wx
.Pen(colour
, width
, style
)
289 pen
.SetDashes(dashes
)
291 pen
.SetCap(wx
.CAP_BUTT
)
293 if self
.pentype
== 0:
294 self
.parent
.SetConnectionPen(pen
)
296 self
.parent
.SetBorderPen(pen
)
302 def OnCancel(self
, event
):
308 #---------------------------------------------------------------------------
309 # Just A Dialog To Select Tree Buttons Icons
310 #---------------------------------------------------------------------------
311 class TreeButtonsDialog(wx
.Dialog
):
313 def __init__(self
, parent
=None, id=-1, title
="", pos
=wx
.DefaultPosition
,
314 size
=wx
.DefaultSize
, style
=wx
.DEFAULT_DIALOG_STYLE
, oldicons
=None):
316 wx
.Dialog
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
318 self
.listicons
= wx
.ListBox(self
, -1, choices
=["Set 1", "Set 2", "Set 3", "Set 4", "Set 5"], style
=wx
.LB_SINGLE
)
320 bitmap_plus
= opj("bitmaps/plus" + str(oldicons
+1) + ".ico")
321 bitmap_minus
= opj("bitmaps/minus" + str(oldicons
+1) + ".ico")
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()
330 self
.bitmap_plus
= wx
.StaticBitmap(self
, -1, bitmap_plus
)
331 self
.bitmap_minus
= wx
.StaticBitmap(self
, -1, bitmap_minus
)
333 self
.okbutton
= wx
.Button(self
, wx
.ID_OK
)
334 self
.cancelbutton
= wx
.Button(self
, wx
.ID_CANCEL
)
338 self
.__set
_properties
()
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
)
346 def __set_properties(self
):
348 self
.SetTitle("Tree Buttons Selector")
349 self
.listicons
.SetSelection(0)
350 self
.okbutton
.SetDefault()
353 def __do_layout(self
):
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
)
384 mainsizer
.SetSizeHints(self
)
388 def OnListBox(self
, event
):
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")
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()
401 self
.bitmap_plus
.SetBitmap(bitmap_plus
)
402 self
.bitmap_minus
.SetBitmap(bitmap_minus
)
404 self
.bitmap_plus
.Refresh()
405 self
.bitmap_minus
.Refresh()
409 def OnOk(self
, event
):
411 selection
= self
.listicons
.GetSelection()
412 self
.parent
.SetTreeButtons(selection
)
417 def OnCancel(self
, event
):
423 #---------------------------------------------------------------------------
424 # Just A Dialog To Select Tree Check/Radio Item Icons
425 #---------------------------------------------------------------------------
426 class CheckDialog(wx
.Dialog
):
428 def __init__(self
, parent
=None, id=-1, title
="", pos
=wx
.DefaultPosition
,
429 size
=wx
.DefaultSize
, style
=wx
.DEFAULT_DIALOG_STYLE
):
431 wx
.Dialog
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
433 self
.listicons
= wx
.ListBox(self
, -1, choices
=["Set 1", "Set 2"], style
=wx
.LB_SINGLE
)
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
)
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
)
445 self
.okbutton
= wx
.Button(self
, wx
.ID_OK
)
446 self
.cancelbutton
= wx
.Button(self
, wx
.ID_CANCEL
)
450 self
.__set
_properties
()
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
)
458 def __set_properties(self
):
460 self
.SetTitle("Check/Radio Icon Selector")
461 self
.listicons
.SetSelection(0)
462 self
.okbutton
.SetDefault()
465 def __do_layout(self
):
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)
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
)
509 mainsizer
.SetSizeHints(self
)
513 def OnListBox(self
, event
):
515 selection
= self
.listicons
.GetSelection()
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")
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")
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
)
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
)
538 self
.bitmap_check
.Refresh()
539 self
.bitmap_uncheck
.Refresh()
540 self
.bitmap_flag
.Refresh()
541 self
.bitmap_unflag
.Refresh()
546 def OnOk(self
, event
):
548 selection
= self
.listicons
.GetSelection()
549 self
.parent
.SetCheckRadio(selection
)
554 def OnCancel(self
, event
):
560 #---------------------------------------------------------------------------
561 # Just A Dialog To Select Tree Items Icons
562 #---------------------------------------------------------------------------
563 class TreeIcons(wx
.Dialog
):
565 def __init__(self
, parent
=None, id=-1, title
="", pos
=wx
.DefaultPosition
,
566 size
=wx
.DefaultSize
, style
=wx
.DEFAULT_DIALOG_STYLE
, oldpen
=None,
569 wx
.Dialog
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
571 self
.bitmaps
= [None, None, None, None]
572 empty
= wx
.EmptyBitmap(16, 16)
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
)
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)
591 self
.GetBitmaps(bitmaps
)
593 self
.__set
_properties
()
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
)
604 def __set_properties(self
):
606 self
.SetTitle("Item Icon Selector")
607 self
.okbutton
.SetDefault()
610 def __do_layout(self
):
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
)
645 mainsizer
.SetSizeHints(self
)
650 def OnComboNormal(self
, event
):
652 input = event
.GetSelection()
653 self
.GetBitmap(input, 0)
657 def OnComboSelected(self
, event
):
659 input = event
.GetSelection()
660 self
.GetBitmap(input, 1)
664 def OnComboExpanded(self
, event
):
666 input = event
.GetSelection()
667 self
.GetBitmap(input, 2)
671 def OnComboSelectedExpanded(self
, event
):
673 input = event
.GetSelection()
674 self
.GetBitmap(input, 3)
678 def OnOk(self
, event
):
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()
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)]
693 newbitmaps
.append(bmp
-1)
695 newbitmaps
.append(bmp
)
697 self
.parent
.SetNewIcons(newbitmaps
)
703 def OnCancel(self
, event
):
709 def GetBitmap(self
, input, which
):
712 bmp
= wx
.EmptyBitmap(16,16)
715 bmp
= images
.getSmilesBitmap()
717 bmp
= wx
.ArtProvider_GetBitmap(eval(ArtIDs
[input]), wx
.ART_OTHER
, (16,16))
719 bmp
= wx
.EmptyBitmap(16,16)
722 self
.bitmaps
[which
].SetBitmap(bmp
)
723 self
.bitmaps
[which
].Refresh()
726 def GetBitmaps(self
, bitmaps
):
730 for count
, input in enumerate(bitmaps
):
732 bmp
= wx
.EmptyBitmap(16,16)
735 bmp
= images
.getSmilesBitmap()
737 bmp
= wx
.ArtProvider_GetBitmap(eval(ArtIDs
[input+1]), wx
.ART_OTHER
, (16,16))
739 bmp
= wx
.EmptyBitmap(16,16)
742 self
.bitmaps
[count
].SetBitmap(bmp
)
745 def ClearBmp(self
, bmp
):
749 dc
.SetBackground(wx
.Brush("white"))
753 #---------------------------------------------------------------------------
754 # CustomTreeCtrl Demo Implementation
755 #---------------------------------------------------------------------------
756 class CustomTreeCtrlDemo(wx
.Panel
):
758 def __init__(self
, parent
, log
):
759 wx
.Panel
.__init
__(self
, parent
)
764 splitter
= wx
.SplitterWindow(self
, -1, style
=wx
.CLIP_CHILDREN | wx
.SP_LIVE_UPDATE | wx
.SP_3D
)
766 # Create the CustomTreeCtrl, using a derived class defined below
767 self
.tree
= CustomTreeCtrl(splitter
, -1, log
=self
.log
,
768 style
= wx
.SUNKEN_BORDER| CT
.TR_HAS_BUTTONS | CT
.TR_HAS_VARIABLE_ROW_HEIGHT
)
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
)
774 # add the windows to the splitter and split it.
775 splitter
.SplitVertically(self
.leftpanel
, self
.tree
, 300)
776 splitter
.SetMinimumPaneSize(width
+5)
778 sizer
= wx
.BoxSizer()
779 sizer
.Add(splitter
, 1, wx
.EXPAND
)
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
)
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
)
802 for count
, style
in enumerate(styles
):
807 tags
= wx
.LEFT|wx
.RIGHT|wx
.BOTTOM
809 if style
!= "TR_DEFAULT_STYLE":
810 check
= wx
.CheckBox(pnl
, -1, style
)
811 stylesizer
.Add(check
, 0, tags
, 3)
813 if style
in ["TR_HAS_BUTTONS", "TR_HAS_VARIABLE_ROW_HEIGHT"]:
816 if style
== "TR_HAS_VARIABLE_ROW_HEIGHT":
819 check
.Bind(wx
.EVT_CHECKBOX
, self
.OnCheckStyle
)
820 self
.treestyles
.append(check
)
823 for count
, event
in enumerate(events
):
828 tags
= wx
.LEFT|wx
.RIGHT|wx
.BOTTOM
830 if count
not in [6, 17, 22, 23]:
831 check
= wx
.CheckBox(pnl
, -1, event
)
832 eventssizer
.Add(check
, 0, tags
, 3)
834 if event
in ["EVT_TREE_ITEM_EXPANDED", "EVT_TREE_ITEM_COLLAPSED",
835 "EVT_TREE_SEL_CHANGED", "EVT_TREE_SEL_CHANGING"]:
839 check
.Bind(wx
.EVT_CHECKBOX
, self
.OnCheckEvent
)
840 self
.treeevents
.append(check
)
842 sizer1
= wx
.BoxSizer(wx
.HORIZONTAL
)
843 label
= wx
.StaticText(pnl
, -1, "Connection Pen")
844 font
= label
.GetFont()
845 font
.SetWeight(wx
.FONTWEIGHT_BOLD
)
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)
853 sizer2
= wx
.BoxSizer(wx
.HORIZONTAL
)
854 label
= wx
.StaticText(pnl
, -1, "Border Pen")
855 font
= label
.GetFont()
856 font
.SetWeight(wx
.FONTWEIGHT_BOLD
)
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)
864 sizer3
= wx
.BoxSizer(wx
.HORIZONTAL
)
865 label
= wx
.StaticText(pnl
, -1, "Tree Buttons")
866 font
= label
.GetFont()
867 font
.SetWeight(wx
.FONTWEIGHT_BOLD
)
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)
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
)
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)
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)
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)
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
)
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)
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
)
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
)
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
)
954 self
.checkvista
= wx
.CheckBox(pnl
, -1, "Windows Vista Theme")
955 self
.checkvista
.Bind(wx
.EVT_CHECKBOX
, self
.OnVista
)
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)
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)
967 pnl
.SetSizer(mainsizer
)
970 swsizer
= wx
.BoxSizer(wx
.VERTICAL
)
971 swsizer
.Add(pnl
, 0, wx
.EXPAND
)
972 self
.leftpanel
.SetSizer(swsizer
)
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)
983 return mainsizer
.CalcMin().width
+ wx
.SystemSettings
.GetMetric(wx
.SYS_VSCROLL_X
)
986 def OnRecreateTree(self
, event
):
988 splitter
= self
.tree
.GetParent()
989 newtree
= CustomTreeCtrl(splitter
, -1, log
=self
.log
)
990 splitter
.ReplaceWindow(self
.tree
, newtree
)
993 # Todo: The settings in the leftpanel should be reset too
996 def OnCheckStyle(self
, event
):
998 self
.tree
.ChangeStyle(self
.treestyles
)
1002 def OnCheckEvent(self
, event
):
1004 obj
= event
.GetEventObject()
1005 self
.tree
.BindEvents(obj
)
1010 def OnButtonConnection(self
, event
):
1012 pen
= self
.tree
.GetConnectionPen()
1013 dlg
= PenDialog(self
, -1, oldpen
=pen
, pentype
=0)
1020 def SetConnectionPen(self
, pen
):
1022 self
.tree
.SetConnectionPen(pen
)
1025 def OnButtonBorder(self
, event
):
1027 pen
= self
.tree
.GetBorderPen()
1028 dlg
= PenDialog(self
, -1, oldpen
=pen
, pentype
=1)
1034 def SetBorderPen(self
, pen
):
1036 self
.tree
.SetBorderPen(pen
)
1039 def OnButtonTree(self
, event
):
1041 dlg
= TreeButtonsDialog(self
, -1, oldicons
=self
.oldicons
)
1047 def OnButtonCheckRadio(self
, event
):
1049 dlg
= CheckDialog(self
, -1)
1055 def SetTreeButtons(self
, selection
):
1057 bitmap_plus
= opj("bitmaps/plus" + str(selection
+1) + ".ico")
1058 bitmap_minus
= opj("bitmaps/minus" + str(selection
+1) + ".ico")
1060 bitmap
= wx
.Bitmap(bitmap_plus
, wx
.BITMAP_TYPE_ICO
)
1061 width
= bitmap
.GetWidth()
1063 il
= wx
.ImageList(width
, width
)
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
))
1071 self
.tree
.SetButtonsImageList(il
)
1074 def SetCheckRadio(self
, selection
):
1077 self
.tree
.SetImageListCheck(13, 13)
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")
1084 il
= wx
.ImageList(16, 16)
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
)
1093 def OnBackgroundImage(self
, event
):
1095 if hasattr(self
, "backgroundimage"):
1096 self
.tree
.SetBackgroundImage(self
.backgroundimage
)
1098 self
.backbutton
.Enable(False)
1099 self
.imagebutton
.Enable(True)
1104 def OnChooseImage(self
, event
):
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 (*.*)|*.*"
1113 dlg
= wx
.FileDialog(self
, "Choose An Image File", ".", "", wildcard
, wx
.OPEN
)
1115 if dlg
.ShowModal() == wx
.ID_OK
:
1116 path
= dlg
.GetPath()
1122 bitmap
= wx
.Bitmap(path
, wx
.BITMAP_TYPE_ANY
)
1123 self
.tree
.SetBackgroundImage(bitmap
)
1124 self
.backgroundimage
= bitmap
1129 def OnBackgroundColour(self
, event
):
1131 self
.imagebutton
.Enable(False)
1132 self
.backbutton
.Enable(True)
1133 self
.tree
.SetBackgroundImage(None)
1138 def OnChooseBackground(self
, event
):
1140 col1
= event
.GetValue()
1141 self
.tree
.SetBackgroundColour(col1
)
1145 def OnCheckNormal(self
, event
):
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)
1160 def OnFocusColour(self
, event
):
1162 col1
= event
.GetValue()
1163 self
.tree
.SetHilightFocusColour(col1
)
1167 def OnNonFocusColour(self
, event
):
1169 col1
= event
.GetValue()
1170 self
.tree
.SetHilightNonFocusColour(col1
)
1174 def OnCheckGradient(self
, event
):
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)
1191 def OnHorizontal(self
, event
):
1193 self
.tree
.SetGradientStyle(self
.radiovertical
.GetValue())
1197 def OnVertical(self
, event
):
1199 self
.tree
.SetGradientStyle(self
.radiovertical
.GetValue())
1203 def OnFirstColour(self
, event
):
1205 col1
= event
.GetValue()
1206 self
.tree
.SetFirstGradientColour(wx
.Colour(col1
[0], col1
[1], col1
[2]))
1210 def OnSecondColour(self
, event
):
1212 col1
= event
.GetValue()
1213 self
.tree
.SetSecondGradientColour(wx
.Colour(col1
[0], col1
[1], col1
[2]))
1217 def OnVista(self
, event
):
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)
1236 #---------------------------------------------------------------------------
1237 # CustomTreeCtrl Demo Implementation
1238 #---------------------------------------------------------------------------
1239 class CustomTreeCtrl(CT
.CustomTreeCtrl
):
1241 def __init__(self
, parent
, id=wx
.ID_ANY
, pos
=wx
.DefaultPosition
,
1242 size
=wx
.DefaultSize
,
1243 style
=wx
.SUNKEN_BORDER | CT
.TR_HAS_BUTTONS | CT
.TR_HAS_VARIABLE_ROW_HEIGHT
,
1246 CT
.CustomTreeCtrl
.__init
__(self
, parent
, id, pos
, size
, style
)
1252 for data
in alldata
:
1253 if data
.startswith("TR_"):
1254 treestyles
.append(data
)
1255 elif data
.startswith("EVT_"):
1258 self
.events
= events
1259 self
.styles
= treestyles
1262 il
= wx
.ImageList(16, 16)
1264 for items
in ArtIDs
[1:-1]:
1265 bmp
= wx
.ArtProvider_GetBitmap(eval(items
), wx
.ART_TOOLBAR
, (16, 16))
1268 smileidx
= il
.Add(images
.getSmilesBitmap())
1269 numicons
= il
.GetImageCount()
1271 self
.AssignImageList(il
)
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
1280 self
.root
= self
.AddRoot("The Root Item")
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
)
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
)
1292 textctrl
.Bind(wx
.EVT_CHAR
, self
.OnTextCtrl
)
1293 combobox
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboBox
)
1297 child
= self
.AppendItem(self
.root
, "Item %d" % x
+ "\nHello World\nHappy wxPython-ing!")
1298 self
.SetItemBold(child
, True)
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
)
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
)
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
)
1315 last
= self
.AppendItem(child
, "item %d-%s" % (x
, chr(ord("a")+y
)), ct_type
=2)
1317 self
.SetPyData(last
, None)
1318 self
.SetItemImage(last
, 24, CT
.TreeItemIcon_Normal
)
1319 self
.SetItemImage(last
, 13, CT
.TreeItemIcon_Expanded
)
1323 item
= self
.AppendItem(last
, "item %d-%s-%d" % (x
, chr(ord("a")+y
), z
), ct_type
=1)
1325 item
= self
.AppendItem(last
, "item %d-%s-%d" % (x
, chr(ord("a")+y
), z
), ct_type
=2)
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
)
1333 self
.Bind(wx
.EVT_LEFT_DCLICK
, self
.OnLeftDClick
)
1334 self
.Bind(wx
.EVT_IDLE
, self
.OnIdle
)
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
}
1347 mainframe
= wx
.GetTopLevelParent(self
)
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
)
1357 for combos
in mainframe
.treeevents
:
1358 self
.BindEvents(combos
)
1360 if hasattr(mainframe
, "leftpanel"):
1361 self
.ChangeStyle(mainframe
.treestyles
)
1363 if not(self
.GetTreeStyle() & CT
.TR_HIDE_ROOT
):
1364 self
.SelectItem(self
.root
)
1365 self
.Expand(self
.root
)
1368 def BindEvents(self
, choice
, recreate
=False):
1370 value
= choice
.GetValue()
1371 text
= choice
.GetLabel()
1374 binder
= self
.eventdict
[text
]
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
)
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
)
1388 def ChangeStyle(self
, combos
):
1391 for combo
in combos
:
1392 if combo
.GetValue() == 1:
1393 style
= style |
eval("CT." + combo
.GetLabel())
1395 if self
.GetTreeStyle() != style
:
1396 self
.SetTreeStyle(style
)
1399 def OnCompareItems(self
, item1
, item2
):
1401 t1
= self
.GetItemText(item1
)
1402 t2
= self
.GetItemText(item2
)
1404 self
.log
.write('compare: ' + t1
+ ' <> ' + t2
+ "\n")
1414 def OnIdle(self
, event
):
1418 if self
.gauge
.IsEnabled() and self
.gauge
.IsShown():
1419 self
.count
= self
.count
+ 1
1421 if self
.count
>= 50:
1424 self
.gauge
.SetValue(self
.count
)
1432 def OnRightDown(self
, event
):
1434 pt
= event
.GetPosition()
1435 item
, flags
= self
.HitTest(pt
)
1439 self
.log
.write("OnRightClick: %s, %s, %s" % (self
.GetItemText(item
), type(item
), item
.__class
__) + "\n")
1440 self
.SelectItem(item
)
1443 def OnRightUp(self
, event
):
1451 if not self
.IsEnabled(item
):
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
)
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
)
1468 # Enabling/Disabling Windows Associated To An Item
1469 haswin
= self
.GetItemWindow(item
)
1471 # Enabling/Disabling Items
1472 enabled
= self
.IsEnabled(item
)
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
)
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
}
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()
1492 strs
= "Make Item Text Not Bold"
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()
1499 strs
= "Set Item As Non-Hyperlink"
1501 strs
= "Set Item As Hyperlink"
1502 item5
= menu
.Append(wx
.ID_ANY
, strs
)
1503 menu
.AppendSeparator()
1505 enabled
= self
.GetItemWindowEnabled(item
)
1507 strs
= "Disable Associated Widget"
1509 strs
= "Enable Associated Widget"
1511 strs
= "Enable Associated Widget"
1512 item6
= menu
.Append(wx
.ID_ANY
, strs
)
1517 item7
= menu
.Append(wx
.ID_ANY
, "Disable Item")
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()
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")
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
)
1544 self
.PopupMenu(menu
)
1548 def OnItemBackground(self
, event
):
1550 colourdata
= wx
.ColourData()
1551 colourdata
.SetColour(self
.itemdict
["back"])
1552 dlg
= wx
.ColourDialog(self
, colourdata
)
1554 dlg
.GetColourData().SetChooseFull(True)
1556 if dlg
.ShowModal() == wx
.ID_OK
:
1557 data
= dlg
.GetColourData()
1558 col1
= data
.GetColour().Get()
1559 self
.SetItemBackgroundColour(self
.current
, col1
)
1563 def OnItemForeground(self
, event
):
1565 colourdata
= wx
.ColourData()
1566 colourdata
.SetColour(self
.itemdict
["fore"])
1567 dlg
= wx
.ColourDialog(self
, colourdata
)
1569 dlg
.GetColourData().SetChooseFull(True)
1571 if dlg
.ShowModal() == wx
.ID_OK
:
1572 data
= dlg
.GetColourData()
1573 col1
= data
.GetColour().Get()
1574 self
.SetItemTextColour(self
.current
, col1
)
1578 def OnItemBold(self
, event
):
1580 self
.SetItemBold(self
.current
, not self
.itemdict
["isbold"])
1583 def OnItemFont(self
, event
):
1585 data
= wx
.FontData()
1586 font
= self
.itemdict
["font"]
1589 font
= wx
.SystemSettings_GetFont(wx
.SYS_DEFAULT_GUI_FONT
)
1591 data
.SetInitialFont(font
)
1593 dlg
= wx
.FontDialog(self
, data
)
1595 if dlg
.ShowModal() == wx
.ID_OK
:
1596 data
= dlg
.GetFontData()
1597 font
= data
.GetChosenFont()
1598 self
.SetItemFont(self
.current
, font
)
1603 def OnItemHyperText(self
, event
):
1605 self
.SetItemHyperText(self
.current
, not self
.itemdict
["ishtml"])
1608 def OnEnableWindow(self
, event
):
1610 enable
= self
.GetItemWindowEnabled(self
.current
)
1611 self
.SetItemWindowEnabled(self
.current
, not enable
)
1614 def OnDisableItem(self
, event
):
1616 self
.EnableItem(self
.current
, False)
1619 def OnItemIcons(self
, event
):
1621 bitmaps
= [self
.itemdict
["normal"], self
.itemdict
["selected"],
1622 self
.itemdict
["expanded"], self
.itemdict
["selexp"]]
1624 wx
.BeginBusyCursor()
1625 dlg
= TreeIcons(self
, -1, bitmaps
=bitmaps
)
1630 def SetNewIcons(self
, bitmaps
):
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
)
1638 def OnItemInfo(self
, event
):
1640 itemtext
= self
.itemdict
["text"]
1641 numchildren
= str(self
.itemdict
["children"])
1642 itemtype
= self
.itemdict
["itemtype"]
1643 pydata
= repr(type(self
.itemdict
["pydata"]))
1648 itemtype
= "CheckBox"
1650 itemtype
= "RadioButton"
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"
1657 dlg
= wx
.MessageDialog(self
, strs
, "CustomTreeCtrlDemo Info", wx
.OK | wx
.ICON_INFORMATION
)
1663 def OnItemDelete(self
, event
):
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
)
1668 if dlg
.ShowModal() in [wx
.ID_NO
, wx
.ID_CANCEL
]:
1674 self
.DeleteChildren(self
.current
)
1675 self
.Delete(self
.current
)
1680 def OnItemPrepend(self
, event
):
1682 dlg
= wx
.TextEntryDialog(self
, "Please Enter The New Item Name", 'Item Naming', 'Python')
1684 if dlg
.ShowModal() == wx
.ID_OK
:
1685 newname
= dlg
.GetValue()
1686 newitem
= self
.PrependItem(self
.current
, newname
)
1687 self
.EnsureVisible(newitem
)
1692 def OnItemAppend(self
, event
):
1694 dlg
= wx
.TextEntryDialog(self
, "Please Enter The New Item Name", 'Item Naming', 'Python')
1696 if dlg
.ShowModal() == wx
.ID_OK
:
1697 newname
= dlg
.GetValue()
1698 newitem
= self
.AppendItem(self
.current
, newname
)
1699 self
.EnsureVisible(newitem
)
1704 def OnBeginEdit(self
, event
):
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":
1711 self
.log
.write("You can't edit this one..." + "\n")
1713 # Lets just see what's visible of its children
1715 root
= event
.GetItem()
1716 (child
, cookie
) = self
.GetFirstChild(root
)
1719 self
.log
.write("Child [%s] visible = %d" % (self
.GetItemText(child
), self
.IsVisible(child
)) + "\n")
1720 (child
, cookie
) = self
.GetNextChild(root
, cookie
)
1725 def OnEndEdit(self
, event
):
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")
1735 self
.log
.write("\n")
1738 def OnLeftDClick(self
, event
):
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
)
1747 self
.log
.write("OnLeftDClick: Cannot Start Manual Editing, Missing Style TR_EDIT_LABELS\n")
1752 def OnItemExpanded(self
, event
):
1754 item
= event
.GetItem()
1756 self
.log
.write("OnItemExpanded: %s" % self
.GetItemText(item
) + "\n")
1759 def OnItemExpanding(self
, event
):
1761 item
= event
.GetItem()
1763 self
.log
.write("OnItemExpanding: %s" % self
.GetItemText(item
) + "\n")
1768 def OnItemCollapsed(self
, event
):
1770 item
= event
.GetItem()
1772 self
.log
.write("OnItemCollapsed: %s" % self
.GetItemText(item
) + "\n")
1775 def OnItemCollapsing(self
, event
):
1777 item
= event
.GetItem()
1779 self
.log
.write("OnItemCollapsing: %s" % self
.GetItemText(item
) + "\n")
1784 def OnSelChanged(self
, event
):
1786 self
.item
= event
.GetItem()
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")
1792 self
.log
.write("\n")
1797 def OnSelChanging(self
, event
):
1799 item
= event
.GetItem()
1800 olditem
= event
.GetOldItem()
1804 olditemtext
= "None"
1806 olditemtext
= self
.GetItemText(olditem
)
1807 self
.log
.write("OnSelChanging: From %s" % olditemtext
+ " To %s" % self
.GetItemText(item
) + "\n")
1812 def OnBeginDrag(self
, event
):
1814 self
.item
= event
.GetItem()
1816 self
.log
.write("Beginning Drag..." + "\n")
1821 def OnBeginRDrag(self
, event
):
1823 self
.item
= event
.GetItem()
1825 self
.log
.write("Beginning Right Drag..." + "\n")
1830 def OnEndDrag(self
, event
):
1832 self
.item
= event
.GetItem()
1834 self
.log
.write("Ending Drag!" + "\n")
1839 def OnDeleteItem(self
, event
):
1841 item
= event
.GetItem()
1846 self
.log
.write("Deleting Item: %s" % self
.GetItemText(item
) + "\n")
1850 def OnItemCheck(self
, event
):
1852 item
= event
.GetItem()
1853 self
.log
.write("Item " + self
.GetItemText(item
) + " Has Been Checked!\n")
1857 def OnItemChecking(self
, event
):
1859 item
= event
.GetItem()
1860 self
.log
.write("Item " + self
.GetItemText(item
) + " Is Being Checked...\n")
1864 def OnToolTip(self
, event
):
1866 item
= event
.GetItem()
1868 event
.SetToolTip(wx
.ToolTip(self
.GetItemText(item
)))
1871 def OnItemMenu(self
, event
):
1873 item
= event
.GetItem()
1875 self
.log
.write("OnItemMenu: %s" % self
.GetItemText(item
) + "\n")
1880 def OnKey(self
, event
):
1882 keycode
= event
.GetKeyCode()
1883 keyname
= keyMap
.get(keycode
, None)
1885 if keycode
== wx
.WXK_BACK
:
1886 self
.log
.write("OnKeyDown: HAHAHAHA! I Vetoed Your Backspace! HAHAHAHA\n")
1890 if "unicode" in wx
.PlatformInfo
:
1891 keycode
= event
.GetUnicodeKey()
1893 keycode
= event
.GetKeyCode()
1894 keyname
= "\"" + unichr(event
.GetUnicodeKey()) + "\""
1896 keyname
= "Ctrl-%s" % chr(ord('A') + keycode
-1)
1902 keyname
= "Ctrl-%s" % chr(ord('A') + keycode
-1)
1904 keyname
= "\"%s\"" % chr(keycode
)
1906 keyname
= "unknown (%s)" % keycode
1908 self
.log
.write("OnKeyDown: You Pressed '" + keyname
+ "'\n")
1913 def OnActivate(self
, event
):
1916 self
.log
.write("OnActivate: %s" % self
.GetItemText(self
.item
) + "\n")
1921 def OnHyperLink(self
, event
):
1923 item
= event
.GetItem()
1925 self
.log
.write("OnHyperLink: %s" % self
.GetItemText(self
.item
) + "\n")
1928 def OnTextCtrl(self
, event
):
1930 char
= chr(event
.GetKeyCode())
1931 self
.log
.write("EDITING THE TEXTCTRL: You Wrote '" + char
+ \
1932 "' (KeyCode = " + str(event
.GetKeyCode()) + ")\n")
1936 def OnComboBox(self
, event
):
1938 selection
= event
.GetEventObject().GetValue()
1939 self
.log
.write("CHOICE FROM COMBOBOX: You Chose '" + selection
+ "'\n")
1944 #----------------------------------------------------------------------
1946 def runTest(frame
, nb
, log
):
1947 win
= CustomTreeCtrlDemo(nb
, log
)
1950 #----------------------------------------------------------------------
1954 overview
= CT
.__doc
__
1957 if __name__
== '__main__':
1960 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])