2 # Purpose: XRC editor, XML_tree class
3 # Author: Roman Rolinsky <rolinsky@mema.ucl.ac.be>
7 from xxx
import * # xxx imports globals and params
11 # Constant to define standart window name
12 STD_NAME
= '_XRCED_T_W'
18 def __init__(self
, name
):
21 def write(self
, data
):
23 encoding
= g
.currentEncoding
25 encoding
= wx
.GetDefaultPyEncoding()
27 self
.buffer += data
.encode(encoding
)
28 except UnicodeEncodeError:
29 self
.buffer += data
.encode(encoding
, 'xmlcharrefreplace')
32 wx
.MemoryFSHandler
.AddFile(self
.name
, self
.buffer)
34 ################################################################################
36 # Redefine writing to include encoding
37 class MyDocument(minidom
.Document
):
39 minidom
.Document
.__init
__(self
)
41 def writexml(self
, writer
, indent
="", addindent
="", newl
="", encoding
=""):
42 if encoding
: encdstr
= 'encoding="%s"' % encoding
44 writer
.write('<?xml version="1.0" %s?>\n' % encdstr
)
45 for node
in self
.childNodes
:
46 node
.writexml(writer
, indent
, addindent
, newl
)
48 ################################################################################
50 # Ids for menu commands
59 STATUS_BAR
= wx
.NewId()
61 STATIC_TEXT
= wx
.NewId()
62 TEXT_CTRL
= wx
.NewId()
65 BITMAP_BUTTON
= wx
.NewId()
66 RADIO_BUTTON
= wx
.NewId()
67 SPIN_BUTTON
= wx
.NewId()
68 TOGGLE_BUTTON
= wx
.NewId()
70 STATIC_BOX
= wx
.NewId()
71 CHECK_BOX
= wx
.NewId()
72 RADIO_BOX
= wx
.NewId()
73 COMBO_BOX
= wx
.NewId()
76 STATIC_LINE
= wx
.NewId()
77 STATIC_BITMAP
= wx
.NewId()
81 SCROLL_BAR
= wx
.NewId()
82 TREE_CTRL
= wx
.NewId()
83 LIST_CTRL
= wx
.NewId()
84 CHECK_LIST
= wx
.NewId()
86 CHOICEBOOK
= wx
.NewId()
88 SPLITTER_WINDOW
= wx
.NewId()
90 SCROLLED_WINDOW
= wx
.NewId()
91 HTML_WINDOW
= wx
.NewId()
92 CALENDAR_CTRL
= wx
.NewId()
93 DATE_CTRL
= wx
.NewId()
94 FILE_PICKER_CTRL
= wx
.NewId()
95 GENERIC_DIR_CTRL
= wx
.NewId()
96 SPIN_CTRL
= wx
.NewId()
99 WIZARD_PAGE
= wx
.NewId()
100 WIZARD_PAGE_SIMPLE
= wx
.NewId()
103 STATUS_BAR
= wx
.NewId()
105 BOX_SIZER
= wx
.NewId()
106 STATIC_BOX_SIZER
= wx
.NewId()
107 GRID_SIZER
= wx
.NewId()
108 FLEX_GRID_SIZER
= wx
.NewId()
109 GRID_BAG_SIZER
= wx
.NewId()
110 STD_DIALOG_BUTTON_SIZER
= wx
.NewId()
113 TOOL_BAR
= wx
.NewId()
116 MENU_ITEM
= wx
.NewId()
117 SEPARATOR
= wx
.NewId()
119 OK_BUTTON
= wx
.NewId()
120 YES_BUTTON
= wx
.NewId()
121 SAVE_BUTTON
= wx
.NewId()
122 APPLY_BUTTON
= wx
.NewId()
123 NO_BUTTON
= wx
.NewId()
124 CANCEL_BUTTON
= wx
.NewId()
125 HELP_BUTTON
= wx
.NewId()
126 CONTEXT_HELP_BUTTON
= wx
.NewId()
136 ID_EXPAND
= wx
.NewId()
137 ID_COLLAPSE
= wx
.NewId()
138 ID_PASTE_SIBLING
= wx
.NewId()
139 ID_TOOL_PASTE
= wx
.NewId()
140 ID_SUBCLASS
= wx
.NewId()
142 def __init__(self
, parent
):
143 self
.ID_DELETE
= parent
.ID_DELETE
144 wx
.EVT_MENU_RANGE(parent
, ID_NEW
.PANEL
, ID_NEW
.LAST
, parent
.OnCreate
)
145 wx
.EVT_MENU_RANGE(parent
, 1000 + ID_NEW
.PANEL
, 1000 + ID_NEW
.LAST
, parent
.OnReplace
)
146 wx
.EVT_MENU(parent
, self
.ID_COLLAPSE
, parent
.OnCollapse
)
147 wx
.EVT_MENU(parent
, self
.ID_EXPAND
, parent
.OnExpand
)
148 wx
.EVT_MENU(parent
, self
.ID_PASTE_SIBLING
, parent
.OnPaste
)
149 wx
.EVT_MENU(parent
, self
.ID_SUBCLASS
, parent
.OnSubclass
)
150 # We connect to tree, but process in frame
151 wx
.EVT_MENU_HIGHLIGHT_ALL(g
.tree
, parent
.OnPullDownHighlight
)
153 # Mapping from IDs to element names
155 ID_NEW
.PANEL
: 'wxPanel',
156 ID_NEW
.DIALOG
: 'wxDialog',
157 ID_NEW
.FRAME
: 'wxFrame',
158 ID_NEW
.WIZARD
: 'wxWizard',
159 ID_NEW
.WIZARD_PAGE
: 'wxWizardPage',
160 ID_NEW
.WIZARD_PAGE_SIMPLE
: 'wxWizardPageSimple',
161 ID_NEW
.TOOL_BAR
: 'wxToolBar',
163 ID_NEW
.STATUS_BAR
: 'wxStatusBar',
164 ID_NEW
.MENU_BAR
: 'wxMenuBar',
165 ID_NEW
.MENU
: 'wxMenu',
166 ID_NEW
.MENU_ITEM
: 'wxMenuItem',
167 ID_NEW
.BITMAP
: 'wxBitmap',
168 ID_NEW
.ICON
: 'wxIcon',
169 ID_NEW
.SEPARATOR
: 'separator',
171 ID_NEW
.STATIC_TEXT
: 'wxStaticText',
172 ID_NEW
.TEXT_CTRL
: 'wxTextCtrl',
174 ID_NEW
.BUTTON
: 'wxButton',
175 ID_NEW
.BITMAP_BUTTON
: 'wxBitmapButton',
176 ID_NEW
.RADIO_BUTTON
: 'wxRadioButton',
177 ID_NEW
.SPIN_BUTTON
: 'wxSpinButton',
178 ID_NEW
.TOGGLE_BUTTON
: 'wxToggleButton',
180 ID_NEW
.STATIC_BOX
: 'wxStaticBox',
181 ID_NEW
.CHECK_BOX
: 'wxCheckBox',
182 ID_NEW
.RADIO_BOX
: 'wxRadioBox',
183 ID_NEW
.COMBO_BOX
: 'wxComboBox',
184 ID_NEW
.LIST_BOX
: 'wxListBox',
185 ID_NEW
.CHECK_LIST
: 'wxCheckListBox',
187 ID_NEW
.STATIC_LINE
: 'wxStaticLine',
188 ID_NEW
.STATIC_BITMAP
: 'wxStaticBitmap',
189 ID_NEW
.CHOICE
: 'wxChoice',
190 ID_NEW
.SLIDER
: 'wxSlider',
191 ID_NEW
.GAUGE
: 'wxGauge',
192 ID_NEW
.SCROLL_BAR
: 'wxScrollBar',
193 ID_NEW
.TREE_CTRL
: 'wxTreeCtrl',
194 ID_NEW
.LIST_CTRL
: 'wxListCtrl',
195 ID_NEW
.NOTEBOOK
: 'wxNotebook',
196 ID_NEW
.CHOICEBOOK
: 'wxChoicebook',
197 ID_NEW
.LISTBOOK
: 'wxListbook',
198 ID_NEW
.SPLITTER_WINDOW
: 'wxSplitterWindow',
199 ID_NEW
.GRID
: 'wxGrid',
200 ID_NEW
.SCROLLED_WINDOW
: 'wxScrolledWindow',
201 ID_NEW
.HTML_WINDOW
: 'wxHtmlWindow',
202 ID_NEW
.CALENDAR_CTRL
: 'wxCalendarCtrl',
203 ID_NEW
.DATE_CTRL
: 'wxDatePickerCtrl',
204 ID_NEW
.FILE_PICKER_CTRL
: 'wxFilePickerCtrl',
205 ID_NEW
.GENERIC_DIR_CTRL
: 'wxGenericDirCtrl',
206 ID_NEW
.SPIN_CTRL
: 'wxSpinCtrl',
208 ID_NEW
.BOX_SIZER
: 'wxBoxSizer',
209 ID_NEW
.STATIC_BOX_SIZER
: 'wxStaticBoxSizer',
210 ID_NEW
.GRID_SIZER
: 'wxGridSizer',
211 ID_NEW
.FLEX_GRID_SIZER
: 'wxFlexGridSizer',
212 ID_NEW
.GRID_BAG_SIZER
: 'wxGridBagSizer',
213 ID_NEW
.STD_DIALOG_BUTTON_SIZER
: 'wxStdDialogButtonSizer',
214 ID_NEW
.SPACER
: 'spacer',
215 ID_NEW
.UNKNOWN
: 'unknown',
217 ID_NEW
.OK_BUTTON
: 'wxButton',
218 ID_NEW
.YES_BUTTON
: 'wxButton',
219 ID_NEW
.SAVE_BUTTON
: 'wxButton',
220 ID_NEW
.APPLY_BUTTON
: 'wxButton',
221 ID_NEW
.NO_BUTTON
: 'wxButton',
222 ID_NEW
.CANCEL_BUTTON
: 'wxButton',
223 ID_NEW
.HELP_BUTTON
: 'wxButton',
224 ID_NEW
.CONTEXT_HELP_BUTTON
: 'wxButton',
227 (ID_NEW
.PANEL
, 'Panel', 'Create panel'),
228 (ID_NEW
.DIALOG
, 'Dialog', 'Create dialog'),
229 (ID_NEW
.FRAME
, 'Frame', 'Create frame'),
230 (ID_NEW
.WIZARD
, 'Wizard', 'Create wizard'),
232 (ID_NEW
.TOOL_BAR
, 'ToolBar', 'Create toolbar'),
233 (ID_NEW
.MENU_BAR
, 'MenuBar', 'Create menubar'),
234 (ID_NEW
.MENU
, 'Menu', 'Create menu'),
236 (ID_NEW
.BITMAP
, 'Bitmap', 'Create bitmap'),
237 (ID_NEW
.ICON
, 'Icon', 'Create icon'),
240 (ID_NEW
.PANEL
, 'Panel', 'Create panel'),
241 (ID_NEW
.NOTEBOOK
, 'Notebook', 'Create notebook control'),
242 (ID_NEW
.CHOICEBOOK
, 'Choicebook', 'Create choicebook control'),
243 (ID_NEW
.LISTBOOK
, 'Listbook', 'Create listbook control'),
244 (ID_NEW
.SPLITTER_WINDOW
, 'SplitterWindow', 'Create splitter window'),
245 (ID_NEW
.TOOL_BAR
, 'ToolBar', 'Create toolbar'),
246 (ID_NEW
.STATUS_BAR
, 'StatusBar', 'Create status bar'),
247 # (ID_NEW.WIZARD_PAGE, 'WizardPage', 'Create wizard page'),
248 (ID_NEW
.WIZARD_PAGE_SIMPLE
, 'WizardPageSimple', 'Create simple wizard page'),
251 (ID_NEW
.BOX_SIZER
, 'BoxSizer', 'Create box sizer'),
252 (ID_NEW
.STATIC_BOX_SIZER
, 'StaticBoxSizer',
253 'Create static box sizer'),
254 (ID_NEW
.GRID_SIZER
, 'GridSizer', 'Create grid sizer'),
255 (ID_NEW
.FLEX_GRID_SIZER
, 'FlexGridSizer',
256 'Create flexgrid sizer'),
257 (ID_NEW
.GRID_BAG_SIZER
, 'GridBagSizer',
258 'Create gridbag sizer'),
259 # (ID_NEW.STD_DIALOG_BUTTON_SIZER, 'StdDialogButtonSizer',
260 # 'Create standard button sizer'),
261 (ID_NEW
.SPACER
, 'Spacer', 'Create spacer'),
264 ['control', 'Various controls',
265 (ID_NEW
.STATIC_TEXT
, 'Label', 'Create label'),
266 (ID_NEW
.STATIC_BITMAP
, 'Bitmap', 'Create bitmap'),
267 (ID_NEW
.STATIC_LINE
, 'Line', 'Create line'),
268 (ID_NEW
.TEXT_CTRL
, 'TextBox', 'Create text box'),
269 (ID_NEW
.CHOICE
, 'Choice', 'Create choice'),
270 (ID_NEW
.SLIDER
, 'Slider', 'Create slider'),
271 (ID_NEW
.GAUGE
, 'Gauge', 'Create gauge'),
272 (ID_NEW
.SPIN_CTRL
, 'SpinCtrl', 'Create spin'),
273 (ID_NEW
.SCROLL_BAR
, 'ScrollBar', 'Create scroll bar'),
274 (ID_NEW
.TREE_CTRL
, 'TreeCtrl', 'Create tree'),
275 (ID_NEW
.LIST_CTRL
, 'ListCtrl', 'Create list'),
276 # (ID_NEW.GRID, 'Grid', 'Create grid'),
277 (ID_NEW
.SCROLLED_WINDOW
, 'ScrolledWindow', 'Create scrolled window'),
278 (ID_NEW
.HTML_WINDOW
, 'HtmlWindow', 'Create HTML window'),
279 (ID_NEW
.CALENDAR_CTRL
, 'CalendarCtrl', 'Create calendar control'),
280 (ID_NEW
.DATE_CTRL
, 'DatePickerCtrl', 'Create date picker control'),
281 # (ID_NEW.FILE_PICKER_CTRL, 'FilePickerCtrl', 'Create file picker control'),
282 (ID_NEW
.GENERIC_DIR_CTRL
, 'GenericDirCtrl', 'Create generic dir control'),
283 (ID_NEW
.UNKNOWN
, 'Unknown', 'Create custom control placeholder'),
285 ['button', 'Buttons',
286 (ID_NEW
.BUTTON
, 'Button', 'Create button'),
287 (ID_NEW
.BITMAP_BUTTON
, 'BitmapButton', 'Create bitmap button'),
288 (ID_NEW
.RADIO_BUTTON
, 'RadioButton', 'Create radio button'),
289 (ID_NEW
.SPIN_BUTTON
, 'SpinButton', 'Create spin button'),
290 (ID_NEW
.TOGGLE_BUTTON
, 'ToggleButton', 'Create toggle button'),
293 (ID_NEW
.STATIC_BOX
, 'StaticBox', 'Create static box'),
294 (ID_NEW
.CHECK_BOX
, 'CheckBox', 'Create check box'),
295 (ID_NEW
.RADIO_BOX
, 'RadioBox', 'Create radio box'),
296 (ID_NEW
.COMBO_BOX
, 'ComboBox', 'Create combo box'),
297 (ID_NEW
.LIST_BOX
, 'ListBox', 'Create list box'),
298 (ID_NEW
.CHECK_LIST
, 'CheckListBox', 'Create checklist box'),
300 ['container', 'Containers',
301 (ID_NEW
.PANEL
, 'Panel', 'Create panel'),
302 (ID_NEW
.NOTEBOOK
, 'Notebook', 'Create notebook control'),
303 (ID_NEW
.CHOICEBOOK
, 'Choicebook', 'Create choicebook control'),
304 (ID_NEW
.LISTBOOK
, 'Listbook', 'Create listbook control'),
305 (ID_NEW
.SPLITTER_WINDOW
, 'SplitterWindow', 'Create splitter window'),
306 (ID_NEW
.TOOL_BAR
, 'ToolBar', 'Create toolbar'),
307 (ID_NEW
.STATUS_BAR
, 'StatusBar', 'Create status bar'),
308 (ID_NEW
.MENU_BAR
, 'MenuBar', 'Create menubar'),
309 # (ID_NEW.WIZARD_PAGE, 'Wizard Page', 'Create wizard page'),
310 (ID_NEW
.WIZARD_PAGE_SIMPLE
, 'WizardPageSimple', 'Create simple wizard page'),
313 (ID_NEW
.BOX_SIZER
, 'BoxSizer', 'Create box sizer'),
314 (ID_NEW
.STATIC_BOX_SIZER
, 'StaticBoxSizer',
315 'Create static box sizer'),
316 (ID_NEW
.GRID_SIZER
, 'GridSizer', 'Create grid sizer'),
317 (ID_NEW
.FLEX_GRID_SIZER
, 'FlexGridSizer',
318 'Create flexgrid sizer'),
319 (ID_NEW
.GRID_BAG_SIZER
, 'GridBagSizer',
320 'Create gridbag sizer'),
321 (ID_NEW
.SPACER
, 'Spacer', 'Create spacer'),
322 (ID_NEW
.STD_DIALOG_BUTTON_SIZER
, 'StdDialogButtonSizer',
323 'Create standard button sizer'),
326 self
.menuControls
= [
327 (ID_NEW
.MENU
, 'Menu', 'Create menu'),
328 (ID_NEW
.MENU_ITEM
, 'MenuItem', 'Create menu item'),
329 (ID_NEW
.SEPARATOR
, 'Separator', 'Create separator'),
331 self
.toolBarControls
= [
332 (ID_NEW
.TOOL
, 'Tool', 'Create tool'),
333 (ID_NEW
.SEPARATOR
, 'Separator', 'Create separator'),
334 ['control', 'Various controls',
335 (ID_NEW
.STATIC_TEXT
, 'Label', 'Create label'),
336 (ID_NEW
.STATIC_BITMAP
, 'Bitmap', 'Create bitmap'),
337 (ID_NEW
.STATIC_LINE
, 'Line', 'Create line'),
338 (ID_NEW
.TEXT_CTRL
, 'TextBox', 'Create text box'),
339 (ID_NEW
.CHOICE
, 'Choice', 'Create choice'),
340 (ID_NEW
.SLIDER
, 'Slider', 'Create slider'),
341 (ID_NEW
.GAUGE
, 'Gauge', 'Create gauge'),
342 (ID_NEW
.SCROLL_BAR
, 'ScrollBar', 'Create scroll bar'),
343 (ID_NEW
.LIST_CTRL
, 'ListCtrl', 'Create list control'),
345 ['button', 'Buttons',
346 (ID_NEW
.BUTTON
, 'Button', 'Create button'),
347 (ID_NEW
.BITMAP_BUTTON
, 'BitmapButton', 'Create bitmap button'),
348 (ID_NEW
.RADIO_BUTTON
, 'RadioButton', 'Create radio button'),
349 (ID_NEW
.SPIN_BUTTON
, 'SpinButton', 'Create spin button'),
352 (ID_NEW
.STATIC_BOX
, 'StaticBox', 'Create static box'),
353 (ID_NEW
.CHECK_BOX
, 'CheckBox', 'Create check box'),
354 (ID_NEW
.RADIO_BOX
, 'RadioBox', 'Create radio box'),
355 (ID_NEW
.COMBO_BOX
, 'ComboBox', 'Create combo box'),
356 (ID_NEW
.LIST_BOX
, 'ListBox', 'Create list box'),
357 (ID_NEW
.CHECK_LIST
, 'CheckListBox', 'Create checklist box'),
361 (ID_NEW
.OK_BUTTON
, 'OK Button', 'Create standard button'),
362 (ID_NEW
.YES_BUTTON
, 'YES Button', 'Create standard button'),
363 (ID_NEW
.SAVE_BUTTON
, 'SAVE Button', 'Create standard button'),
364 (ID_NEW
.APPLY_BUTTON
, 'APPLY Button', 'Create standard button'),
365 (ID_NEW
.NO_BUTTON
, 'NO Button', 'Create standard button'),
366 (ID_NEW
.CANCEL_BUTTON
, 'CANCEL Button', 'Create standard button'),
367 (ID_NEW
.HELP_BUTTON
, 'HELP Button', 'Create standard button'),
368 (ID_NEW
.CONTEXT_HELP_BUTTON
, 'CONTEXT HELP Button', 'Create standard button'),
370 self
.stdButtonIDs
= {
371 ID_NEW
.OK_BUTTON
: ('wxID_OK', '&Ok'),
372 ID_NEW
.YES_BUTTON
: ('wxID_YES', '&Yes'),
373 ID_NEW
.SAVE_BUTTON
: ('wxID_SAVE', '&Save'),
374 ID_NEW
.APPLY_BUTTON
: ('wxID_APPLY', '&Apply'),
375 ID_NEW
.NO_BUTTON
: ('wxID_NO', '&No'),
376 ID_NEW
.CANCEL_BUTTON
: ('wxID_CANCEL', '&Cancel'),
377 ID_NEW
.HELP_BUTTON
: ('wxID_HELP', '&Help'),
378 ID_NEW
.CONTEXT_HELP_BUTTON
: ('wxID_CONTEXT_HELP', '&Help'),
383 ################################################################################
385 # Set menu to list items.
386 # Each menu command is a tuple (id, label, help)
387 # submenus are lists [id, label, help, submenu]
388 # and separators are any other type. Shift is for making
389 # alternative sets of IDs. (+1000).
390 def SetMenu(m
, list, shift
=False):
392 if type(l
) == types
.TupleType
:
394 if shift
: l
= (1000 + l
[0],) + l
[1:]
396 elif type(l
) == types
.ListType
:
398 SetMenu(subMenu
, l
[2:], shift
)
399 m
.AppendMenu(wx
.NewId(), l
[0], subMenu
, l
[1])
403 ################################################################################
406 def __init__(self
, pos
, size
):
407 if size
.width
== -1: size
.width
= 0
408 if size
.height
== -1: size
.height
= 0
410 l1
= wx
.Window(w
, -1, pos
, wx
.Size(size
.width
, 2))
411 l1
.SetBackgroundColour(wx
.RED
)
412 l2
= wx
.Window(w
, -1, pos
, wx
.Size(2, size
.height
))
413 l2
.SetBackgroundColour(wx
.RED
)
414 l3
= wx
.Window(w
, -1, wx
.Point(pos
.x
+ size
.width
- 2, pos
.y
), wx
.Size(2, size
.height
))
415 l3
.SetBackgroundColour(wx
.RED
)
416 l4
= wx
.Window(w
, -1, wx
.Point(pos
.x
, pos
.y
+ size
.height
- 2), wx
.Size(size
.width
, 2))
417 l4
.SetBackgroundColour(wx
.RED
)
418 self
.lines
= [l1
, l2
, l3
, l4
]
419 # Move highlight to a new position
420 def Replace(self
, pos
, size
):
421 if size
.width
== -1: size
.width
= 0
422 if size
.height
== -1: size
.height
= 0
423 self
.lines
[0].SetDimensions(pos
.x
, pos
.y
, size
.width
, 2)
424 self
.lines
[1].SetDimensions(pos
.x
, pos
.y
, 2, size
.height
)
425 self
.lines
[2].SetDimensions(pos
.x
+ size
.width
- 2, pos
.y
, 2, size
.height
)
426 self
.lines
[3].SetDimensions(pos
.x
, pos
.y
+ size
.height
- 2, size
.width
, 2)
429 map(wx
.Window
.Destroy
, self
.lines
)
430 g
.testWin
.highLight
= None
432 map(wx
.Window
.Refresh
, self
.lines
)
434 ################################################################################
436 class XML_Tree(wx
.TreeCtrl
):
437 def __init__(self
, parent
, id):
438 wx
.TreeCtrl
.__init
__(self
, parent
, id, style
= wx
.TR_HAS_BUTTONS | wx
.TR_MULTIPLE
)
439 self
.SetBackgroundColour(wx
.Colour(224, 248, 224))
440 self
.fontComment
= wx
.Font(g
.sysFont().GetPointSize(), wx
.DEFAULT
,
441 wx
.FONTSTYLE_ITALIC
, wx
.NORMAL
)
443 wx
.EVT_TREE_SEL_CHANGED(self
, self
.GetId(), self
.OnSelChanged
)
444 # One works on Linux, another on Windows
445 if wx
.Platform
== '__WXGTK__':
446 wx
.EVT_TREE_ITEM_ACTIVATED(self
, self
.GetId(), self
.OnItemActivated
)
448 wx
.EVT_LEFT_DCLICK(self
, self
.OnDClick
)
449 wx
.EVT_RIGHT_DOWN(self
, self
.OnRightDown
)
450 wx
.EVT_TREE_ITEM_EXPANDED(self
, self
.GetId(), self
.OnItemExpandedCollapsed
)
451 wx
.EVT_TREE_ITEM_COLLAPSED(self
, self
.GetId(), self
.OnItemExpandedCollapsed
)
453 self
.selection
= None
454 self
.selectionChanging
= False
455 self
.needUpdate
= False
456 self
.pendingHighLight
= None
457 self
.ctrl
= self
.shift
= False
460 il
= wx
.ImageList(16, 16, True)
461 self
.rootImage
= il
.Add(images
.getTreeRootImage().Scale(16,16).ConvertToBitmap())
462 xxxComment
.image
= il
.Add(images
.getTreeCommentImage().Scale(16,16).ConvertToBitmap())
463 xxxObject
.image
= il
.Add(images
.getTreeDefaultImage().Scale(16,16).ConvertToBitmap())
464 xxxPanel
.image
= il
.Add(images
.getTreePanelImage().Scale(16,16).ConvertToBitmap())
465 xxxDialog
.image
= il
.Add(images
.getTreeDialogImage().Scale(16,16).ConvertToBitmap())
466 xxxFrame
.image
= il
.Add(images
.getTreeFrameImage().Scale(16,16).ConvertToBitmap())
467 xxxMenuBar
.image
= il
.Add(images
.getTreeMenuBarImage().Scale(16,16).ConvertToBitmap())
468 xxxMenu
.image
= il
.Add(images
.getTreeMenuImage().Scale(16,16).ConvertToBitmap())
469 xxxMenuItem
.image
= il
.Add(images
.getTreeMenuItemImage().Scale(16,16).ConvertToBitmap())
470 xxxToolBar
.image
= il
.Add(images
.getTreeToolBarImage().Scale(16,16).ConvertToBitmap())
471 xxxTool
.image
= il
.Add(images
.getTreeToolImage().Scale(16,16).ConvertToBitmap())
472 xxxSeparator
.image
= il
.Add(images
.getTreeSeparatorImage().Scale(16,16).ConvertToBitmap())
473 xxxSizer
.imageH
= il
.Add(images
.getTreeSizerHImage().Scale(16,16).ConvertToBitmap())
474 xxxSizer
.imageV
= il
.Add(images
.getTreeSizerVImage().Scale(16,16).ConvertToBitmap())
475 xxxStaticBoxSizer
.imageH
= il
.Add(images
.getTreeStaticBoxSizerHImage().Scale(16,16).ConvertToBitmap())
476 xxxStaticBoxSizer
.imageV
= il
.Add(images
.getTreeStaticBoxSizerVImage().Scale(16,16).ConvertToBitmap())
477 xxxGridSizer
.image
= il
.Add(images
.getTreeSizerGridImage().Scale(16,16).ConvertToBitmap())
478 xxxFlexGridSizer
.image
= il
.Add(images
.getTreeSizerFlexGridImage().Scale(16,16).ConvertToBitmap())
480 self
.SetImageList(il
)
482 def RegisterKeyEvents(self
):
483 wx
.EVT_KEY_DOWN(self
, g
.tools
.OnKeyDown
)
484 wx
.EVT_KEY_UP(self
, g
.tools
.OnKeyUp
)
485 wx
.EVT_ENTER_WINDOW(self
, g
.tools
.OnMouse
)
486 wx
.EVT_LEAVE_WINDOW(self
, g
.tools
.OnMouse
)
488 def ExpandAll(self
, item
):
489 if self
.ItemHasChildren(item
):
491 i
, cookie
= self
.GetFirstChild(item
)
495 i
, cookie
= self
.GetNextChild(item
, cookie
)
498 def CollapseAll(self
, item
):
499 if self
.ItemHasChildren(item
):
500 i
, cookie
= self
.GetFirstChild(item
)
504 i
, cookie
= self
.GetNextChild(item
, cookie
)
511 self
.selection
= None
513 self
.DeleteAllItems()
514 # Add minimal structure
515 if self
.dom
: self
.dom
.unlink()
516 self
.dom
= MyDocument()
517 self
.dummyNode
= self
.dom
.createComment('dummy node')
519 self
.mainNode
= self
.dom
.createElement('resource')
520 self
.dom
.appendChild(self
.mainNode
)
521 self
.rootObj
= xxxMainNode(self
.dom
)
522 self
.root
= self
.AddRoot('XML tree', self
.rootImage
,
523 data
=wx
.TreeItemData(self
.rootObj
))
524 self
.SetItemHasChildren(self
.root
)
525 self
.testElem
= self
.dom
.createElement('dummy')
526 self
.mainNode
.appendChild(self
.testElem
)
527 self
.Expand(self
.root
)
529 # Clear old data and set new
530 def SetData(self
, dom
):
531 self
.selection
= None
533 self
.DeleteAllItems()
534 # Add minimal structure
535 if self
.dom
: self
.dom
.unlink()
537 self
.dummyNode
= self
.dom
.createComment('dummy node')
538 # Find 'resource' child, add it's children
539 self
.mainNode
= dom
.documentElement
540 self
.rootObj
= xxxMainNode(self
.dom
)
541 self
.root
= self
.AddRoot('XML tree', self
.rootImage
,
542 data
=wx
.TreeItemData(self
.rootObj
))
543 self
.SetItemHasChildren(self
.root
)
544 nodes
= self
.mainNode
.childNodes
[:]
547 self
.AddNode(self
.root
, None, node
)
549 self
.mainNode
.removeChild(node
)
551 if self
.mainNode
.firstChild
:
552 self
.testElem
= self
.dom
.createElement('dummy')
553 self
.mainNode
.insertBefore(self
.testElem
, self
.mainNode
.firstChild
)
555 self
.testElem
= self
.dom
.createElement('dummy')
556 self
.mainNode
.appendChild(self
.testElem
)
557 self
.Expand(self
.root
)
559 # Add tree item for given parent item if node is DOM element node with
560 # object/object_ref tag. xxxParent is parent xxx object
561 def AddNode(self
, itemParent
, xxxParent
, node
):
562 # Set item data to current node
564 xxx
= MakeXXXFromDOM(xxxParent
, node
)
566 print 'ERROR: MakeXXXFromDom(%s, %s)' % (xxxParent
, node
)
568 treeObj
= xxx
.treeObject()
570 item
= self
.AppendItem(itemParent
, treeObj
.treeName(),
571 image
=treeObj
.treeImage(),
572 data
=wx
.TreeItemData(xxx
))
573 # Different color for comments and references
574 if xxx
.className
== 'comment':
575 self
.SetItemTextColour(item
, 'Blue')
576 self
.SetItemFont(item
, self
.fontComment
)
578 self
.SetItemTextColour(item
, 'DarkGreen')
579 elif treeObj
.hasStyle
and treeObj
.params
.get('hidden', False):
580 self
.SetItemTextColour(item
, 'Grey')
581 # Try to find children objects
582 if treeObj
.hasChildren
:
583 nodes
= treeObj
.node
.childNodes
[:]
586 self
.AddNode(item
, treeObj
, n
)
587 elif n
.nodeType
!= minidom
.Node
.ELEMENT_NODE
:
588 treeObj
.node
.removeChild(n
)
591 # Insert new item at specific position
592 def InsertNode(self
, itemParent
, parent
, elem
, nextItem
):
593 # Insert in XML tree and wxWin
594 xxx
= MakeXXXFromDOM(parent
, elem
)
595 # If nextItem is None, we append to parent, otherwise insert before it
597 node
= self
.GetPyData(nextItem
).node
598 parent
.node
.insertBefore(elem
, node
)
599 # Inserting before is difficult, se we insert after or first child
600 index
= self
.ItemIndex(nextItem
)
601 newItem
= self
.InsertItemBefore(itemParent
, index
,
602 xxx
.treeName(), image
=xxx
.treeImage())
603 self
.SetPyData(newItem
, xxx
)
605 parent
.node
.appendChild(elem
)
606 newItem
= self
.AppendItem(itemParent
, xxx
.treeName(), image
=xxx
.treeImage(),
607 data
=wx
.TreeItemData(xxx
))
608 treeObj
= xxx
.treeObject()
609 # Different color for references and comments
610 if xxx
.className
== 'comment':
611 self
.SetItemTextColour(newItem
, 'Blue')
613 self
.SetItemTextColour(newItem
, 'DarkGreen')
614 elif treeObj
.hasStyle
and treeObj
.params
.get('hidden', False):
615 self
.SetItemTextColour(newItem
, 'Grey')
618 treeObj
= xxx
.treeObject()
619 for n
in treeObj
.node
.childNodes
:
621 self
.AddNode(newItem
, treeObj
, n
)
624 # Remove leaf of tree, return it's data object
625 def RemoveLeaf(self
, leaf
):
626 xxx
= self
.GetPyData(leaf
)
628 parent
= node
.parentNode
629 parent
.removeChild(node
)
631 # Reset selection object
632 self
.selection
= None
635 # Find position relative to the top-level window
636 def FindNodePos(self
, item
, obj
=None):
638 if item
== g
.testWin
.item
: return wx
.Point(0, 0)
639 itemParent
= self
.GetItemParent(item
)
641 if not obj
: obj
= self
.FindNodeObject(item
)
642 if self
.GetPyData(itemParent
).treeObject().__class
__ in \
643 [xxxNotebook
, xxxChoicebook
, xxxListbook
]:
644 book
= self
.FindNodeObject(itemParent
)
646 for i
in range(book
.GetPageCount()):
647 if book
.GetPage(i
) == obj
:
648 if book
.GetSelection() != i
:
650 # Remove highlight - otherwise highlight window won't be visible
651 if g
.testWin
.highLight
:
652 g
.testWin
.highLight
.Remove()
654 # For sizers and notebooks we must select the first window-like parent
655 winParent
= itemParent
656 while self
.GetPyData(winParent
).isSizer
:
657 winParent
= self
.GetItemParent(winParent
)
658 # Notebook children are layed out in a little strange way
659 # wxGTK places NB panels relative to the NB parent
660 if wx
.Platform
== '__WXGTK__':
661 if self
.GetPyData(itemParent
).treeObject().__class
__ == xxxNotebook
:
662 winParent
= self
.GetItemParent(winParent
)
663 parentPos
= self
.FindNodePos(winParent
)
664 pos
= obj
.GetPosition()
665 # Position (-1,-1) is really (0,0)
666 if pos
== (-1,-1): pos
= (0,0)
667 return parentPos
+ pos
669 # Find window (or sizer) corresponding to a tree item.
670 def FindNodeObject(self
, item
):
672 # If top-level, return testWin (or panel its panel)
673 if item
== testWin
.item
: return testWin
.panel
674 itemParent
= self
.GetItemParent(item
)
675 xxx
= self
.GetPyData(item
).treeObject()
676 parentWin
= self
.FindNodeObject(itemParent
)
677 # Top-level sizer? return window's sizer
678 if xxx
.isSizer
and isinstance(parentWin
, wx
.Window
):
679 return parentWin
.GetSizer()
680 elif xxx
.__class
__ in [xxxMenu
, xxxMenuItem
, xxxSeparator
]: return None
681 elif xxx
.__class
__ in [xxxToolBar
, xxxMenuBar
]:
682 # If it's the main toolbar or menubar, we can't really select it
683 if xxx
.parent
.__class
__ == xxxFrame
: return None
684 elif isinstance(xxx
.parent
, xxxToolBar
):
685 # Select complete toolbar
687 elif isinstance(xxx
.parent
, xxxStdDialogButtonSizer
):
688 # This sizer returns non-existing children
689 for ch
in parentWin
.GetChildren():
690 if ch
.GetWindow() and ch
.GetWindow().GetName() == xxx
.name
:
691 return ch
.GetWindow()
693 elif xxx
.parent
.__class
__ in [xxxChoicebook
, xxxListbook
]:
694 # First window is controld
695 return parentWin
.GetChildren()[self
.ItemIndex(item
)+1]
696 # Otherwise get parent's object and it's child
697 child
= parentWin
.GetChildren()[self
.WindowIndex(item
)]
698 # Return window or sizer for sizer items
699 if child
.GetClassName() == 'wxSizerItem':
700 if child
.IsWindow(): child
= child
.GetWindow()
701 elif child
.IsSizer():
702 child
= child
.GetSizer()
705 def OnSelChanged(self
, evt
):
706 if self
.selectionChanging
: return
707 self
.selectionChanging
= True
709 self
.SelectItem(evt
.GetItem())
710 self
.selectionChanging
= False
712 def ChangeSelection(self
, item
):
714 # !!! problem with wxGTK - GetOldItem is Ok if nothing selected
715 #oldItem = evt.GetOldItem()
717 oldItem
= self
.selection
718 # use GetItemParent as a way to determine if the itemId is still valid
719 if oldItem
and self
.GetItemParent(oldItem
):
720 xxx
= self
.GetPyData(oldItem
)
721 # If some data was modified, apply changes
722 if g
.panel
.IsModified():
723 self
.Apply(xxx
, oldItem
)
725 if g
.testWin
.highLight
:
726 g
.testWin
.highLight
.Remove()
727 self
.needUpdate
= True
728 status
= 'Changes were applied'
729 g
.frame
.SetStatusText(status
)
731 self
.selection
= item
732 if not self
.selection
.IsOk():
733 self
.selection
= None
735 xxx
= self
.GetPyData(self
.selection
)
740 # Highlighting is done in OnIdle
741 self
.pendingHighLight
= self
.selection
743 # Check if item is in testWin subtree
744 def IsHighlatable(self
, item
):
745 if item
== g
.testWin
.item
: return False
746 while item
!= self
.root
:
747 item
= self
.GetItemParent(item
)
748 if item
== g
.testWin
.item
:
752 # Highlight selected item
753 def HighLight(self
, item
):
754 self
.pendingHighLight
= None
755 # Can highlight only with some top-level windows
756 if not g
.testWin
or self
.GetPyData(g
.testWin
.item
).treeObject().__class
__ \
757 not in [xxxDialog
, xxxPanel
, xxxFrame
]:
759 # If a control from another window is selected, remove highlight
760 if not self
.IsHighlatable(item
):
761 if g
.testWin
.highLight
: g
.testWin
.highLight
.Remove()
763 # Get window/sizer object
764 obj
= self
.FindNodeObject(item
)
765 xxx
= self
.GetPyData(item
).treeObject()
766 # Remove existing HL if item not found or is hidden
767 if not obj
or xxx
.hasStyle
and xxx
.params
.get('hidden', False):
768 if g
.testWin
.highLight
: g
.testWin
.highLight
.Remove()
770 pos
= self
.FindNodePos(item
, obj
)
773 # Negative positions are not working quite well
774 if g
.testWin
.highLight
:
775 g
.testWin
.highLight
.Replace(pos
, size
)
777 g
.testWin
.highLight
= HighLightBox(pos
, size
)
778 g
.testWin
.highLight
.Refresh()
779 g
.testWin
.highLight
.item
= item
781 def ShowTestWindow(self
, item
):
782 xxx
= self
.GetPyData(item
)
783 if g
.panel
.IsModified():
784 self
.Apply(xxx
, item
) # apply changes
785 availableViews
= ['wxFrame', 'wxPanel', 'wxDialog',
786 'wxMenuBar', 'wxToolBar', 'wxWizard',
787 'wxWizardPageSimple']
789 # Walk up the tree until we find an item that has a view
790 while item
and self
.GetPyData(item
).treeObject().className
not in availableViews
:
791 item
= self
.GetItemParent(item
)
792 if not item
or not item
.IsOk():
793 wx
.LogMessage('No view for this element (yet)')
796 if g
.testWin
: # Reset old
798 self
.SetItemBold(g
.testWin
.item
, False)
801 self
.CreateTestWin(item
)
804 # Maybe an error occurred, so we need to test
806 self
.SetItemBold(g
.testWin
.item
)
807 # Select original item
808 self
.ChangeSelection(originalItem
)
810 # Double-click on Linux
811 def OnItemActivated(self
, evt
):
812 if evt
.GetItem() != self
.root
:
813 self
.ShowTestWindow(evt
.GetItem())
815 # Double-click on Windows
816 def OnDClick(self
, evt
):
817 item
, flags
= self
.HitTest(evt
.GetPosition())
818 if flags
in [wx
.TREE_HITTEST_ONITEMBUTTON
, wx
.TREE_HITTEST_ONITEMLABEL
]:
819 if item
!= self
.root
: self
.ShowTestWindow(item
)
823 def OnItemExpandedCollapsed(self
, evt
):
824 # Update tool palette
828 # (re)create test window
829 def CreateTestWin(self
, item
):
831 # Create a window with this resource
832 xxx
= self
.GetPyData(item
).treeObject()
835 # if xxx.__class__ == xxxFrame:
836 # Frame can't have many children,
837 # but it's first child possibly can...
838 # child = self.GetFirstChild(item)[0]
839 # if child.IsOk() and self.GetPyData(child).__class__ == xxxPanel:
840 # # Clean-up before recursive call or error
841 # wx.MemoryFSHandler.RemoveFile('xxx.xrc')
843 # self.CreateTestWin(child)
846 # Close old window, remember where it was
849 pos
= testWin
.GetPosition()
850 if item
== testWin
.item
:
851 # Remember highlight if same top-level window
852 if testWin
.highLight
:
853 highLight
= testWin
.highLight
.item
854 if xxx
.className
== 'wxPanel':
855 if testWin
.highLight
:
856 testWin
.pendingHighLight
= highLight
857 testWin
.highLight
.Remove()
858 testWin
.panel
.Destroy()
862 testWin
= g
.testWin
= None
865 testWin
= g
.testWin
= None
869 memFile
= MemoryFile('xxx.xrc')
870 # Create memory XML file
871 elem
= xxx
.node
.cloneNode(True)
876 elem
.setAttribute('name', STD_NAME
)
877 oldTestNode
= self
.testElem
879 self
.mainNode
.replaceChild(elem
, oldTestNode
)
881 # Replace wizard page class temporarily
882 if xxx
.__class
__ in [xxxWizardPage
, xxxWizardPageSimple
]:
883 oldCl
= elem
.getAttribute('class')
884 elem
.setAttribute('class', 'wxPanel')
885 parent
= elem
.parentNode
886 encd
= self
.rootObj
.params
['encoding'].value()
887 if not encd
: encd
= None
889 self
.dom
.writexml(memFile
, encoding
=encd
)
892 wx
.LogError(traceback
.format_exception(inf
[0], inf
[1], None)[-1])
893 wx
.LogError('Error writing temporary file')
894 memFile
.close() # write to wxMemoryFS
895 xmlFlags
= xrc
.XRC_NO_SUBCLASSING
896 # Use translations if encoding is not specified
897 if not g
.currentEncoding
:
898 xmlFlags
!= xrc
.XRC_USE_LOCALE
899 res
= xrc
.XmlResource('', xmlFlags
)
900 res
.Load('memory:xxx.xrc')
902 if xxx
.__class
__ == xxxFrame
:
903 # Frame can't have many children,
904 # but it's first child possibly can...
905 # child = self.GetFirstChild(item)[0]
906 # if child.IsOk() and self.GetPyData(child).__class__ == xxxPanel:
907 # # Clean-up before recursive call or error
908 # wx.MemoryFSHandler.RemoveFile('xxx.xrc')
910 # self.CreateTestWin(child)
912 # This currently works under GTK, but not under MSW
913 testWin
= g
.testWin
= wx
.PreFrame()
914 res
.LoadOnFrame(testWin
, g
.frame
, STD_NAME
)
916 testWin
.panel
= testWin
917 #testWin.CreateStatusBar()
918 testWin
.SetClientSize(testWin
.GetBestSize())
919 testWin
.SetPosition(pos
)
921 elif xxx
.__class
__ == xxxPanel
:
924 testWin
= g
.testWin
= wx
.Frame(g
.frame
, -1, 'Panel: ' + name
,
925 pos
=pos
, name
=STD_NAME
)
926 testWin
.panel
= res
.LoadPanel(testWin
, STD_NAME
)
927 testWin
.SetClientSize(testWin
.GetBestSize())
929 elif xxx
.__class
__ == xxxDialog
:
930 testWin
= g
.testWin
= res
.LoadDialog(g
.frame
, STD_NAME
)
931 testWin
.panel
= testWin
933 testWin
.SetPosition(pos
)
935 # Dialog's default code does not produce wx.EVT_CLOSE
936 wx
.EVT_BUTTON(testWin
, wx
.ID_OK
, self
.OnCloseTestWin
)
937 wx
.EVT_BUTTON(testWin
, wx
.ID_CANCEL
, self
.OnCloseTestWin
)
938 elif xxx
.__class
__ == xxxWizard
:
939 wiz
= wx
.wizard
.PreWizard()
940 res
.LoadOnObject(wiz
, g
.frame
, STD_NAME
, 'wxWizard')
941 # Find first page (don't know better way)
943 for w
in wiz
.GetChildren():
944 if isinstance(w
, wx
.wizard
.WizardPage
):
948 wx
.LogError('Wizard is empty')
950 # Wizard should be modal
951 self
.SetItemBold(item
)
953 self
.SetItemBold(item
, False)
955 elif xxx
.__class
__ in [xxxWizardPage
, xxxWizardPageSimple
]:
958 testWin
= g
.testWin
= wx
.Frame(g
.frame
, -1, 'Wizard page: ' + name
,
959 pos
=pos
, name
=STD_NAME
)
960 testWin
.panel
= wx
.PrePanel()
961 res
.LoadOnObject(testWin
.panel
, testWin
, STD_NAME
, 'wxPanel')
962 testWin
.SetClientSize(testWin
.GetBestSize())
964 elif xxx
.__class
__ == xxxMenuBar
:
965 testWin
= g
.testWin
= wx
.Frame(g
.frame
, -1, 'MenuBar: ' + name
,
966 pos
=pos
, name
=STD_NAME
)
968 # Set status bar to display help
969 testWin
.CreateStatusBar()
970 testWin
.menuBar
= res
.LoadMenuBar(STD_NAME
)
971 testWin
.SetMenuBar(testWin
.menuBar
)
973 elif xxx
.__class
__ == xxxToolBar
:
974 testWin
= g
.testWin
= wx
.Frame(g
.frame
, -1, 'ToolBar: ' + name
,
975 pos
=pos
, name
=STD_NAME
)
977 # Set status bar to display help
978 testWin
.CreateStatusBar()
979 testWin
.toolBar
= res
.LoadToolBar(testWin
, STD_NAME
)
980 testWin
.SetToolBar(testWin
.toolBar
)
982 # Catch some events, set highlight
985 wx
.EVT_CLOSE(testWin
, self
.OnCloseTestWin
)
986 wx
.EVT_SIZE(testWin
, self
.OnSizeTestWin
)
987 testWin
.highLight
= None
988 if highLight
and not self
.pendingHighLight
:
989 self
.HighLight(highLight
)
992 self
.SetItemBold(item
, False)
993 g
.testWinPos
= g
.testWin
.GetPosition()
997 wx
.LogError(traceback
.format_exception(inf
[0], inf
[1], None)[-1])
998 wx
.LogError('Error loading resource')
999 wx
.MemoryFSHandler
.RemoveFile('xxx.xrc')
1001 def CloseTestWindow(self
):
1002 if not g
.testWin
: return
1003 self
.SetItemBold(g
.testWin
.item
, False)
1004 g
.frame
.tb
.ToggleTool(g
.frame
.ID_TOOL_LOCATE
, False)
1005 g
.testWinPos
= g
.testWin
.GetPosition()
1009 def OnCloseTestWin(self
, evt
):
1010 self
.CloseTestWindow()
1012 def OnSizeTestWin(self
, evt
):
1013 if g
.testWin
.highLight
:
1014 self
.HighLight(g
.testWin
.highLight
.item
)
1017 # Return index in parent, for real window children
1018 def WindowIndex(self
, item
):
1019 n
= 0 # index of sibling
1020 prev
= self
.GetPrevSibling(item
)
1022 # MenuBar is not a child
1023 if not isinstance(self
.GetPyData(prev
), xxxMenuBar
):
1025 prev
= self
.GetPrevSibling(prev
)
1028 # Return item index in parent
1029 def ItemIndex(self
, item
):
1030 n
= 0 # index of sibling
1031 prev
= self
.GetPrevSibling(item
)
1033 prev
= self
.GetPrevSibling(prev
)
1037 # Full tree index of an item - list of positions
1038 def ItemFullIndex(self
, item
):
1039 if not item
.IsOk(): return None
1041 while item
!= self
.root
:
1042 l
.insert(0, self
.ItemIndex(item
))
1043 item
= self
.GetItemParent(item
)
1045 # Get item position from full index
1046 def ItemAtFullIndex(self
, index
):
1047 if index
is None: return wx
.TreeItemId()
1050 item
= self
.GetFirstChild(item
)[0]
1051 for k
in range(i
): item
= self
.GetNextSibling(item
)
1054 # True if next item should be inserted after current (vs. appended to it)
1055 def NeedInsert(self
, item
):
1056 xxx
= self
.GetPyData(item
)
1057 if item
== self
.root
: return False # root item
1058 if xxx
.hasChildren
and not self
.GetChildrenCount(item
, False):
1060 return not (self
.IsExpanded(item
) and self
.GetChildrenCount(item
, False))
1062 # Override to use like single-selection tree
1063 def GetSelection(self
):
1064 return self
.selection
1065 def SelectItem(self
, item
):
1067 self
.ChangeSelection(item
)
1068 wx
.TreeCtrl
.SelectItem(self
, item
)
1071 def OnRightDown(self
, evt
):
1072 pullDownMenu
= g
.pullDownMenu
1074 pt
= evt
.GetPosition();
1075 item
, flags
= self
.HitTest(pt
)
1076 if item
.Ok() and flags
& wx
.TREE_HITTEST_ONITEM
:
1077 self
.SelectItem(item
)
1082 item
= self
.selection
1084 menu
.Append(g
.pullDownMenu
.ID_EXPAND
, 'Expand', 'Expand tree')
1085 menu
.Append(g
.pullDownMenu
.ID_COLLAPSE
, 'Collapse', 'Collapse tree')
1087 # self.ctrl = evt.ControlDown() # save Ctrl state
1088 # self.shift = evt.ShiftDown() # and Shift too
1089 m
= wx
.Menu() # create menu
1093 needInsert
= self
.NeedInsert(item
)
1094 if item
== self
.root
or needInsert
and self
.GetItemParent(item
) == self
.root
:
1095 SetMenu(m
, pullDownMenu
.topLevel
)
1097 m
.Append(ID_NEW
.REF
, 'reference...', 'Create object_ref node')
1098 m
.Append(ID_NEW
.COMMENT
, 'comment', 'Create comment node')
1100 xxx
= self
.GetPyData(item
).treeObject()
1101 # Check parent for possible child nodes if inserting sibling
1102 if needInsert
: xxx
= xxx
.parent
1103 if xxx
.__class
__ == xxxMenuBar
:
1104 m
.Append(ID_NEW
.MENU
, 'Menu', 'Create menu')
1105 elif xxx
.__class
__ in [xxxToolBar
, xxxTool
] or \
1106 xxx
.__class
__ == xxxSeparator
and xxx
.parent
.__class
__ == xxxToolBar
:
1107 SetMenu(m
, pullDownMenu
.toolBarControls
)
1108 elif xxx
.__class
__ in [xxxMenu
, xxxMenuItem
]:
1109 SetMenu(m
, pullDownMenu
.menuControls
)
1110 elif xxx
.__class
__ == xxxStdDialogButtonSizer
:
1111 SetMenu(m
, pullDownMenu
.stdButtons
)
1113 SetMenu(m
, pullDownMenu
.controls
)
1114 if xxx
.__class
__ in [xxxNotebook
, xxxChoicebook
, xxxListbook
]:
1115 m
.Enable(m
.FindItem('sizer'), False)
1116 elif not (xxx
.isSizer
or xxx
.parent
and xxx
.parent
.isSizer
):
1117 m
.Enable(ID_NEW
.SPACER
, False)
1118 if xxx
.__class
__ is not xxxFrame
:
1119 m
.Enable(ID_NEW
.MENU_BAR
, False)
1121 m
.Append(ID_NEW
.REF
, 'reference...', 'Create object_ref node')
1122 m
.Append(ID_NEW
.COMMENT
, 'comment', 'Create comment node')
1123 # Select correct label for create menu
1126 menu
.AppendMenu(wx
.NewId(), 'Insert Child', m
,
1127 'Create child object as the first child')
1129 menu
.AppendMenu(wx
.NewId(), 'Append Child', m
,
1130 'Create child object as the last child')
1133 menu
.AppendMenu(wx
.NewId(), 'Create Sibling', m
,
1134 'Create sibling before selected object')
1136 menu
.AppendMenu(wx
.NewId(), 'Create Sibling', m
,
1137 'Create sibling after selected object')
1138 # Build replace menu
1139 if item
!= self
.root
:
1140 xxx
= self
.GetPyData(item
).treeObject()
1141 m
= wx
.Menu() # create replace menu
1142 if xxx
.__class
__ == xxxMenuBar
:
1143 m
.Append(1000 + ID_NEW
.MENU
, 'Menu', 'Create menu')
1144 elif xxx
.__class
__ in [xxxMenu
, xxxMenuItem
]:
1145 SetMenu(m
, pullDownMenu
.menuControls
, shift
=True)
1146 elif xxx
.__class
__ == xxxToolBar
and \
1147 self
.GetItemParent(item
) == self
.root
:
1148 SetMenu(m
, [], shift
=True)
1149 elif xxx
.__class
__ in [xxxFrame
, xxxDialog
, xxxPanel
]:
1151 (ID_NEW
.PANEL
, 'Panel', 'Create panel'),
1152 (ID_NEW
.DIALOG
, 'Dialog', 'Create dialog'),
1153 (ID_NEW
.FRAME
, 'Frame', 'Create frame')], shift
=True)
1154 elif xxx
.isSizer
and self
.ItemHasChildren(item
):
1155 SetMenu(m
, pullDownMenu
.sizers
, shift
=True)
1157 SetMenu(m
, pullDownMenu
.controls
, shift
=True)
1160 menu
.AppendMenu(id, 'Replace With', m
)
1161 if not m
.GetMenuItemCount(): menu
.Enable(id, False)
1162 menu
.Append(pullDownMenu
.ID_SUBCLASS
, 'Subclass...',
1163 'Set "subclass" property')
1164 menu
.AppendSeparator()
1165 # Not using standart IDs because we don't want to show shortcuts
1166 menu
.Append(wx
.ID_CUT
, 'Cut', 'Cut to the clipboard')
1167 menu
.Append(wx
.ID_COPY
, 'Copy', 'Copy to the clipboard')
1168 if self
.ctrl
and item
!= self
.root
:
1169 menu
.Append(pullDownMenu
.ID_PASTE_SIBLING
, 'Paste Sibling',
1170 'Paste from the clipboard as a sibling')
1172 menu
.Append(wx
.ID_PASTE
, 'Paste', 'Paste from the clipboard')
1173 menu
.Append(pullDownMenu
.ID_DELETE
,
1174 'Delete', 'Delete object')
1175 if self
.ItemHasChildren(item
):
1176 menu
.AppendSeparator()
1177 menu
.Append(pullDownMenu
.ID_EXPAND
, 'Expand', 'Expand subtree')
1178 menu
.Append(pullDownMenu
.ID_COLLAPSE
, 'Collapse', 'Collapse subtree')
1179 self
.PopupMenu(menu
, evt
.GetPosition())
1182 # Redefine to force the update of font dimentions on wxGTK
1183 if wx
.Platform
== '__WXGTK__':
1184 def SetItemBold(self
, item
, state
=True):
1185 wx
.TreeCtrl
.SetItemBold(self
, item
, state
)
1186 self
.SetIndent(self
.GetIndent())
1189 def Apply(self
, xxx
, item
):
1192 xxx
= xxx
.treeObject()
1193 if xxx
.hasName
and self
.GetItemText(item
) != xxx
.name
:
1194 self
.SetItemText(item
, xxx
.treeName())
1195 # Item width may have changed
1196 # !!! Tric to update tree width (wxGTK, ??)
1197 self
.SetIndent(self
.GetIndent())
1198 elif xxx
.className
== 'comment':
1199 self
.SetItemText(item
, xxx
.treeName())
1200 # Change tree icon for sizers
1201 if isinstance(xxx
, xxxBoxSizer
):
1202 self
.SetItemImage(item
, xxx
.treeImage())
1203 # Set global modified state
1204 g
.frame
.SetModified()