]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/tools/XRCed/tree.py
0a4d4d0638509fc0d790d0dfbd8d371c950c60cf
[wxWidgets.git] / wxPython / wx / tools / XRCed / tree.py
1 # Name: tree.py
2 # Purpose: XRC editor, XML_tree class
3 # Author: Roman Rolinsky <rolinsky@mema.ucl.ac.be>
4 # Created: 02.12.2002
5 # RCS-ID: $Id$
6
7 from xxx import * # xxx imports globals and params
8 import types
9 import traceback
10
11 # Constant to define standart window name
12 STD_NAME = '_XRCED_T_W'
13
14 # Icons
15 import images
16
17 class MemoryFile:
18 def __init__(self, name):
19 self.name = name
20 self.buffer = ''
21 def write(self, data):
22 if g.currentEncoding:
23 encoding = g.currentEncoding
24 else:
25 encoding = wxGetDefaultPyEncoding()
26 try:
27 self.buffer += data.encode(encoding)
28 except UnicodeEncodeError:
29 self.buffer += data.encode(encoding, 'xmlcharrefreplace')
30
31 def close(self):
32 wxMemoryFSHandler_AddFile(self.name, self.buffer)
33
34 ################################################################################
35
36 # Redefine writing to include encoding
37 class MyDocument(minidom.Document):
38 def __init__(self):
39 minidom.Document.__init__(self)
40 self.encoding = ''
41 def writexml(self, writer, indent="", addindent="", newl="", encoding=""):
42 if encoding: encdstr = 'encoding="%s"' % encoding
43 else: encdstr = ''
44 writer.write('<?xml version="1.0" %s?>\n' % encdstr)
45 for node in self.childNodes:
46 node.writexml(writer, indent, addindent, newl)
47
48 ################################################################################
49
50 # Ids for menu commands
51 class ID_NEW:
52 PANEL = wxNewId()
53 DIALOG = wxNewId()
54 FRAME = wxNewId()
55 TOOL_BAR = wxNewId()
56 TOOL = wxNewId()
57 MENU_BAR = wxNewId()
58 MENU = wxNewId()
59
60 STATIC_TEXT = wxNewId()
61 TEXT_CTRL = wxNewId()
62
63 BUTTON = wxNewId()
64 BITMAP_BUTTON = wxNewId()
65 RADIO_BUTTON = wxNewId()
66 SPIN_BUTTON = wxNewId()
67 TOGGLE_BUTTON = wxNewId()
68
69 STATIC_BOX = wxNewId()
70 CHECK_BOX = wxNewId()
71 RADIO_BOX = wxNewId()
72 COMBO_BOX = wxNewId()
73 LIST_BOX = wxNewId()
74
75 STATIC_LINE = wxNewId()
76 STATIC_BITMAP = wxNewId()
77 CHOICE = wxNewId()
78 SLIDER = wxNewId()
79 GAUGE = wxNewId()
80 SCROLL_BAR = wxNewId()
81 TREE_CTRL = wxNewId()
82 LIST_CTRL = wxNewId()
83 CHECK_LIST = wxNewId()
84 NOTEBOOK = wxNewId()
85 SPLITTER_WINDOW = wxNewId()
86 SCROLLED_WINDOW = wxNewId()
87 HTML_WINDOW = wxNewId()
88 CALENDAR_CTRL = wxNewId()
89 GENERIC_DIR_CTRL = wxNewId()
90 SPIN_CTRL = wxNewId()
91 UNKNOWN = wxNewId()
92 WIZARD = wxNewId()
93 WIZARD_PAGE = wxNewId()
94 WIZARD_PAGE_SIMPLE = wxNewId()
95 STATUS_BAR = wxNewId()
96
97 BOX_SIZER = wxNewId()
98 STATIC_BOX_SIZER = wxNewId()
99 GRID_SIZER = wxNewId()
100 FLEX_GRID_SIZER = wxNewId()
101 GRID_BAG_SIZER = wxNewId()
102 STD_DIALOG_BUTTON_SIZER = wxNewId()
103 SPACER = wxNewId()
104
105 TOOL_BAR = wxNewId()
106 TOOL = wxNewId()
107 MENU = wxNewId()
108 MENU_ITEM = wxNewId()
109 SEPARATOR = wxNewId()
110
111 OK_BUTTON = wxNewId()
112 YES_BUTTON = wxNewId()
113 SAVE_BUTTON = wxNewId()
114 APPLY_BUTTON = wxNewId()
115 NO_BUTTON = wxNewId()
116 CANCEL_BUTTON = wxNewId()
117 HELP_BUTTON = wxNewId()
118 CONTEXT_HELP_BUTTON = wxNewId()
119
120 LAST = wxNewId()
121
122
123
124 class PullDownMenu:
125 ID_EXPAND = wxNewId()
126 ID_COLLAPSE = wxNewId()
127 ID_PASTE_SIBLING = wxNewId()
128 ID_TOOL_PASTE = wxNewId()
129 ID_SUBCLASS = wxNewId()
130
131 def __init__(self, parent):
132 self.ID_DELETE = parent.ID_DELETE
133 EVT_MENU_RANGE(parent, ID_NEW.PANEL, ID_NEW.LAST, parent.OnCreate)
134 EVT_MENU_RANGE(parent, 1000 + ID_NEW.PANEL, 1000 + ID_NEW.LAST, parent.OnReplace)
135 EVT_MENU(parent, self.ID_COLLAPSE, parent.OnCollapse)
136 EVT_MENU(parent, self.ID_EXPAND, parent.OnExpand)
137 EVT_MENU(parent, self.ID_PASTE_SIBLING, parent.OnPaste)
138 EVT_MENU(parent, self.ID_SUBCLASS, parent.OnSubclass)
139 # We connect to tree, but process in frame
140 EVT_MENU_HIGHLIGHT_ALL(g.tree, parent.OnPullDownHighlight)
141
142 # Mapping from IDs to element names
143 self.createMap = {
144 ID_NEW.PANEL: 'wxPanel',
145 ID_NEW.DIALOG: 'wxDialog',
146 ID_NEW.FRAME: 'wxFrame',
147 ID_NEW.WIZARD: 'wxWizard',
148 ID_NEW.WIZARD_PAGE: 'wxWizardPage',
149 ID_NEW.WIZARD_PAGE_SIMPLE: 'wxWizardPageSimple',
150 ID_NEW.TOOL_BAR: 'wxToolBar',
151 ID_NEW.TOOL: 'tool',
152 ID_NEW.MENU_BAR: 'wxMenuBar',
153 ID_NEW.MENU: 'wxMenu',
154 ID_NEW.MENU_ITEM: 'wxMenuItem',
155 ID_NEW.SEPARATOR: 'separator',
156
157 ID_NEW.STATIC_TEXT: 'wxStaticText',
158 ID_NEW.TEXT_CTRL: 'wxTextCtrl',
159
160 ID_NEW.BUTTON: 'wxButton',
161 ID_NEW.BITMAP_BUTTON: 'wxBitmapButton',
162 ID_NEW.RADIO_BUTTON: 'wxRadioButton',
163 ID_NEW.SPIN_BUTTON: 'wxSpinButton',
164 ID_NEW.TOGGLE_BUTTON: 'wxToggleButton',
165
166 ID_NEW.STATIC_BOX: 'wxStaticBox',
167 ID_NEW.CHECK_BOX: 'wxCheckBox',
168 ID_NEW.RADIO_BOX: 'wxRadioBox',
169 ID_NEW.COMBO_BOX: 'wxComboBox',
170 ID_NEW.LIST_BOX: 'wxListBox',
171
172 ID_NEW.STATIC_LINE: 'wxStaticLine',
173 ID_NEW.STATIC_BITMAP: 'wxStaticBitmap',
174 ID_NEW.CHOICE: 'wxChoice',
175 ID_NEW.SLIDER: 'wxSlider',
176 ID_NEW.GAUGE: 'wxGauge',
177 ID_NEW.SCROLL_BAR: 'wxScrollBar',
178 ID_NEW.TREE_CTRL: 'wxTreeCtrl',
179 ID_NEW.LIST_CTRL: 'wxListCtrl',
180 ID_NEW.CHECK_LIST: 'wxCheckListBox',
181 ID_NEW.NOTEBOOK: 'wxNotebook',
182 ID_NEW.SPLITTER_WINDOW: 'wxSplitterWindow',
183 ID_NEW.SCROLLED_WINDOW: 'wxScrolledWindow',
184 ID_NEW.HTML_WINDOW: 'wxHtmlWindow',
185 ID_NEW.CALENDAR_CTRL: 'wxCalendarCtrl',
186 ID_NEW.GENERIC_DIR_CTRL: 'wxGenericDirCtrl',
187 ID_NEW.SPIN_CTRL: 'wxSpinCtrl',
188
189 ID_NEW.BOX_SIZER: 'wxBoxSizer',
190 ID_NEW.STATIC_BOX_SIZER: 'wxStaticBoxSizer',
191 ID_NEW.GRID_SIZER: 'wxGridSizer',
192 ID_NEW.FLEX_GRID_SIZER: 'wxFlexGridSizer',
193 ID_NEW.GRID_BAG_SIZER: 'wxGridBagSizer',
194 ID_NEW.STD_DIALOG_BUTTON_SIZER: 'wxStdDialogButtonSizer',
195 ID_NEW.SPACER: 'spacer',
196 ID_NEW.UNKNOWN: 'unknown',
197
198 ID_NEW.OK_BUTTON: 'wxButton',
199 ID_NEW.YES_BUTTON: 'wxButton',
200 ID_NEW.SAVE_BUTTON: 'wxButton',
201 ID_NEW.APPLY_BUTTON: 'wxButton',
202 ID_NEW.NO_BUTTON: 'wxButton',
203 ID_NEW.CANCEL_BUTTON: 'wxButton',
204 ID_NEW.HELP_BUTTON: 'wxButton',
205 ID_NEW.CONTEXT_HELP_BUTTON: 'wxButton',
206 }
207 self.topLevel = [
208 (ID_NEW.PANEL, 'Panel', 'Create panel'),
209 (ID_NEW.DIALOG, 'Dialog', 'Create dialog'),
210 (ID_NEW.FRAME, 'Frame', 'Create frame'),
211 (ID_NEW.WIZARD, 'Wizard', 'Create wizard'),
212 None,
213 (ID_NEW.TOOL_BAR, 'ToolBar', 'Create toolbar'),
214 (ID_NEW.MENU_BAR, 'MenuBar', 'Create menubar'),
215 (ID_NEW.MENU, 'Menu', 'Create menu')
216 ]
217 self.containers = [
218 (ID_NEW.PANEL, 'Panel', 'Create panel'),
219 (ID_NEW.NOTEBOOK, 'Notebook', 'Create notebook control'),
220 (ID_NEW.SPLITTER_WINDOW, 'SplitterWindow', 'Create splitter window'),
221 (ID_NEW.TOOL_BAR, 'ToolBar', 'Create toolbar'),
222 # (ID_NEW.WIZARD_PAGE, 'WizardPage', 'Create wizard page'),
223 (ID_NEW.WIZARD_PAGE_SIMPLE, 'WizardPageSimple', 'Create simple wizard page'),
224 ]
225 self.sizers = [
226 (ID_NEW.BOX_SIZER, 'BoxSizer', 'Create box sizer'),
227 (ID_NEW.STATIC_BOX_SIZER, 'StaticBoxSizer',
228 'Create static box sizer'),
229 (ID_NEW.GRID_SIZER, 'GridSizer', 'Create grid sizer'),
230 (ID_NEW.FLEX_GRID_SIZER, 'FlexGridSizer',
231 'Create flexgrid sizer'),
232 (ID_NEW.GRID_BAG_SIZER, 'GridBagSizer',
233 'Create gridbag sizer'),
234 # (ID_NEW.STD_DIALOG_BUTTON_SIZER, 'StdDialogButtonSizer',
235 # 'Create standard button sizer'),
236 (ID_NEW.SPACER, 'Spacer', 'Create spacer'),
237 ]
238 self.controls = [
239 ['control', 'Various controls',
240 (ID_NEW.STATIC_TEXT, 'Label', 'Create label'),
241 (ID_NEW.STATIC_BITMAP, 'Bitmap', 'Create bitmap'),
242 (ID_NEW.STATIC_LINE, 'Line', 'Create line'),
243 (ID_NEW.TEXT_CTRL, 'TextBox', 'Create text box'),
244 (ID_NEW.CHOICE, 'Choice', 'Create choice'),
245 (ID_NEW.SLIDER, 'Slider', 'Create slider'),
246 (ID_NEW.GAUGE, 'Gauge', 'Create gauge'),
247 (ID_NEW.SPIN_CTRL, 'SpinCtrl', 'Create spin'),
248 (ID_NEW.SCROLL_BAR, 'ScrollBar', 'Create scroll bar'),
249 (ID_NEW.TREE_CTRL, 'TreeCtrl', 'Create tree'),
250 (ID_NEW.LIST_CTRL, 'ListCtrl', 'Create list'),
251 (ID_NEW.CHECK_LIST, 'CheckList', 'Create check list'),
252 (ID_NEW.SCROLLED_WINDOW, 'ScrolledWindow', 'Create scrolled window'),
253 (ID_NEW.HTML_WINDOW, 'HtmlWindow', 'Create HTML window'),
254 (ID_NEW.CALENDAR_CTRL, 'CalendarCtrl', 'Create calendar control'),
255 (ID_NEW.GENERIC_DIR_CTRL, 'GenericDirCtrl', 'Create generic dir control'),
256 (ID_NEW.UNKNOWN, 'Unknown', 'Create custom control placeholder'),
257 ],
258 ['button', 'Buttons',
259 (ID_NEW.BUTTON, 'Button', 'Create button'),
260 (ID_NEW.BITMAP_BUTTON, 'BitmapButton', 'Create bitmap button'),
261 (ID_NEW.RADIO_BUTTON, 'RadioButton', 'Create radio button'),
262 (ID_NEW.SPIN_BUTTON, 'SpinButton', 'Create spin button'),
263 (ID_NEW.TOGGLE_BUTTON, 'ToggleButton', 'Create toggle button'),
264 ],
265 ['box', 'Boxes',
266 (ID_NEW.STATIC_BOX, 'StaticBox', 'Create static box'),
267 (ID_NEW.CHECK_BOX, 'CheckBox', 'Create check box'),
268 (ID_NEW.RADIO_BOX, 'RadioBox', 'Create radio box'),
269 (ID_NEW.COMBO_BOX, 'ComboBox', 'Create combo box'),
270 (ID_NEW.LIST_BOX, 'ListBox', 'Create list box'),
271 ],
272 ['container', 'Containers',
273 (ID_NEW.PANEL, 'Panel', 'Create panel'),
274 (ID_NEW.NOTEBOOK, 'Notebook', 'Create notebook control'),
275 (ID_NEW.SPLITTER_WINDOW, 'SplitterWindow', 'Create splitter window'),
276 (ID_NEW.TOOL_BAR, 'ToolBar', 'Create toolbar'),
277 # (ID_NEW.WIZARD_PAGE, 'Wizard Page', 'Create wizard page'),
278 (ID_NEW.WIZARD_PAGE_SIMPLE, 'WizardPageSimple', 'Create simple wizard page'),
279 ],
280 ['sizer', 'Sizers',
281 (ID_NEW.BOX_SIZER, 'BoxSizer', 'Create box sizer'),
282 (ID_NEW.STATIC_BOX_SIZER, 'StaticBoxSizer',
283 'Create static box sizer'),
284 (ID_NEW.GRID_SIZER, 'GridSizer', 'Create grid sizer'),
285 (ID_NEW.FLEX_GRID_SIZER, 'FlexGridSizer',
286 'Create flexgrid sizer'),
287 (ID_NEW.GRID_BAG_SIZER, 'GridBagSizer',
288 'Create gridbag sizer'),
289 (ID_NEW.SPACER, 'Spacer', 'Create spacer'),
290 (ID_NEW.STD_DIALOG_BUTTON_SIZER, 'StdDialogButtonSizer',
291 'Create standard button sizer'),
292 ]
293 ]
294 self.menuControls = [
295 (ID_NEW.MENU, 'Menu', 'Create menu'),
296 (ID_NEW.MENU_ITEM, 'MenuItem', 'Create menu item'),
297 (ID_NEW.SEPARATOR, 'Separator', 'Create separator'),
298 ]
299 self.toolBarControls = [
300 (ID_NEW.TOOL, 'Tool', 'Create tool'),
301 (ID_NEW.SEPARATOR, 'Separator', 'Create separator'),
302 ['control', 'Various controls',
303 (ID_NEW.STATIC_TEXT, 'Label', 'Create label'),
304 (ID_NEW.STATIC_BITMAP, 'Bitmap', 'Create bitmap'),
305 (ID_NEW.STATIC_LINE, 'Line', 'Create line'),
306 (ID_NEW.TEXT_CTRL, 'TextBox', 'Create text box'),
307 (ID_NEW.CHOICE, 'Choice', 'Create choice'),
308 (ID_NEW.SLIDER, 'Slider', 'Create slider'),
309 (ID_NEW.GAUGE, 'Gauge', 'Create gauge'),
310 (ID_NEW.SCROLL_BAR, 'ScrollBar', 'Create scroll bar'),
311 (ID_NEW.LIST_CTRL, 'ListCtrl', 'Create list control'),
312 (ID_NEW.CHECK_LIST, 'CheckList', 'Create check list'),
313 ],
314 ['button', 'Buttons',
315 (ID_NEW.BUTTON, 'Button', 'Create button'),
316 (ID_NEW.BITMAP_BUTTON, 'BitmapButton', 'Create bitmap button'),
317 (ID_NEW.RADIO_BUTTON, 'RadioButton', 'Create radio button'),
318 (ID_NEW.SPIN_BUTTON, 'SpinButton', 'Create spin button'),
319 ],
320 ['box', 'Boxes',
321 (ID_NEW.STATIC_BOX, 'StaticBox', 'Create static box'),
322 (ID_NEW.CHECK_BOX, 'CheckBox', 'Create check box'),
323 (ID_NEW.RADIO_BOX, 'RadioBox', 'Create radio box'),
324 (ID_NEW.COMBO_BOX, 'ComboBox', 'Create combo box'),
325 (ID_NEW.LIST_BOX, 'ListBox', 'Create list box'),
326 ],
327 ]
328 self.stdButtons = [
329 (ID_NEW.OK_BUTTON, 'OK Button', 'Create standard button'),
330 (ID_NEW.YES_BUTTON, 'YES Button', 'Create standard button'),
331 (ID_NEW.SAVE_BUTTON, 'SAVE Button', 'Create standard button'),
332 (ID_NEW.APPLY_BUTTON, 'APPLY Button', 'Create standard button'),
333 (ID_NEW.NO_BUTTON, 'NO Button', 'Create standard button'),
334 (ID_NEW.CANCEL_BUTTON, 'CANCEL Button', 'Create standard button'),
335 (ID_NEW.HELP_BUTTON, 'HELP Button', 'Create standard button'),
336 (ID_NEW.CONTEXT_HELP_BUTTON, 'CONTEXT HELP Button', 'Create standard button'),
337 ]
338 self.stdButtonIDs = {
339 ID_NEW.OK_BUTTON: ('wxID_OK', '&Ok'),
340 ID_NEW.YES_BUTTON: ('wxID_YES', '&Yes'),
341 ID_NEW.SAVE_BUTTON: ('wxID_SAVE', '&Save'),
342 ID_NEW.APPLY_BUTTON: ('wxID_APPLY', '&Apply'),
343 ID_NEW.NO_BUTTON: ('wxID_NO', '&No'),
344 ID_NEW.CANCEL_BUTTON: ('wxID_CANCEL', '&Cancel'),
345 ID_NEW.HELP_BUTTON: ('wxID_HELP', '&Help'),
346 ID_NEW.CONTEXT_HELP_BUTTON: ('wxID_CONTEXT_HELP', '&Help'),
347 }
348
349
350
351 ################################################################################
352
353 # Set menu to list items.
354 # Each menu command is a tuple (id, label, help)
355 # submenus are lists [id, label, help, submenu]
356 # and separators are any other type. Shift is for making
357 # alternative sets of IDs. (+1000).
358 def SetMenu(m, list, shift=False):
359 for l in list:
360 if type(l) == types.TupleType:
361 # Shift ID
362 if shift: l = (1000 + l[0],) + l[1:]
363 apply(m.Append, l)
364 elif type(l) == types.ListType:
365 subMenu = wxMenu()
366 SetMenu(subMenu, l[2:])
367 m.AppendMenu(wxNewId(), l[0], subMenu, l[1])
368 else: # separator
369 m.AppendSeparator()
370
371 ################################################################################
372
373 class HighLightBox:
374 def __init__(self, pos, size):
375 if size.width == -1: size.width = 0
376 if size.height == -1: size.height = 0
377 w = g.testWin.panel
378 l1 = wxWindow(w, -1, pos, wxSize(size.width, 2))
379 l1.SetBackgroundColour(wxRED)
380 l2 = wxWindow(w, -1, pos, wxSize(2, size.height))
381 l2.SetBackgroundColour(wxRED)
382 l3 = wxWindow(w, -1, wxPoint(pos.x + size.width - 2, pos.y), wxSize(2, size.height))
383 l3.SetBackgroundColour(wxRED)
384 l4 = wxWindow(w, -1, wxPoint(pos.x, pos.y + size.height - 2), wxSize(size.width, 2))
385 l4.SetBackgroundColour(wxRED)
386 self.lines = [l1, l2, l3, l4]
387 # Move highlight to a new position
388 def Replace(self, pos, size):
389 if size.width == -1: size.width = 0
390 if size.height == -1: size.height = 0
391 self.lines[0].SetDimensions(pos.x, pos.y, size.width, 2)
392 self.lines[1].SetDimensions(pos.x, pos.y, 2, size.height)
393 self.lines[2].SetDimensions(pos.x + size.width - 2, pos.y, 2, size.height)
394 self.lines[3].SetDimensions(pos.x, pos.y + size.height - 2, size.width, 2)
395 # Remove it
396 def Remove(self):
397 map(wxWindow.Destroy, self.lines)
398 g.testWin.highLight = None
399 def Refresh(self):
400 map(wxWindow.Refresh, self.lines)
401
402 ################################################################################
403
404 class XML_Tree(wxTreeCtrl):
405 def __init__(self, parent, id):
406 wxTreeCtrl.__init__(self, parent, id, style = wxTR_HAS_BUTTONS)
407 self.SetBackgroundColour(wxColour(224, 248, 224))
408 # Register events
409 EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
410 # One works on Linux, another on Windows
411 if wxPlatform == '__WXGTK__':
412 EVT_TREE_ITEM_ACTIVATED(self, self.GetId(), self.OnItemActivated)
413 else:
414 EVT_LEFT_DCLICK(self, self.OnDClick)
415 EVT_RIGHT_DOWN(self, self.OnRightDown)
416 EVT_TREE_ITEM_EXPANDED(self, self.GetId(), self.OnItemExpandedCollapsed)
417 EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemExpandedCollapsed)
418
419 self.selection = None
420 self.needUpdate = False
421 self.pendingHighLight = None
422 self.ctrl = self.shift = False
423 self.dom = None
424 # Create image list
425 il = wxImageList(16, 16, True)
426 self.rootImage = il.Add(images.getTreeRootImage().Scale(16,16).ConvertToBitmap())
427 xxxObject.image = il.Add(images.getTreeDefaultImage().Scale(16,16).ConvertToBitmap())
428 xxxPanel.image = il.Add(images.getTreePanelImage().Scale(16,16).ConvertToBitmap())
429 xxxDialog.image = il.Add(images.getTreeDialogImage().Scale(16,16).ConvertToBitmap())
430 xxxFrame.image = il.Add(images.getTreeFrameImage().Scale(16,16).ConvertToBitmap())
431 xxxMenuBar.image = il.Add(images.getTreeMenuBarImage().Scale(16,16).ConvertToBitmap())
432 xxxMenu.image = il.Add(images.getTreeMenuImage().Scale(16,16).ConvertToBitmap())
433 xxxMenuItem.image = il.Add(images.getTreeMenuItemImage().Scale(16,16).ConvertToBitmap())
434 xxxToolBar.image = il.Add(images.getTreeToolBarImage().Scale(16,16).ConvertToBitmap())
435 xxxTool.image = il.Add(images.getTreeToolImage().Scale(16,16).ConvertToBitmap())
436 xxxSeparator.image = il.Add(images.getTreeSeparatorImage().Scale(16,16).ConvertToBitmap())
437 xxxSizer.imageH = il.Add(images.getTreeSizerHImage().Scale(16,16).ConvertToBitmap())
438 xxxSizer.imageV = il.Add(images.getTreeSizerVImage().Scale(16,16).ConvertToBitmap())
439 xxxStaticBoxSizer.imageH = il.Add(images.getTreeStaticBoxSizerHImage().Scale(16,16).ConvertToBitmap())
440 xxxStaticBoxSizer.imageV = il.Add(images.getTreeStaticBoxSizerVImage().Scale(16,16).ConvertToBitmap())
441 xxxGridSizer.image = il.Add(images.getTreeSizerGridImage().Scale(16,16).ConvertToBitmap())
442 xxxFlexGridSizer.image = il.Add(images.getTreeSizerFlexGridImage().Scale(16,16).ConvertToBitmap())
443 self.il = il
444 self.SetImageList(il)
445
446 def RegisterKeyEvents(self):
447 EVT_KEY_DOWN(self, g.tools.OnKeyDown)
448 EVT_KEY_UP(self, g.tools.OnKeyUp)
449 EVT_ENTER_WINDOW(self, g.tools.OnMouse)
450 EVT_LEAVE_WINDOW(self, g.tools.OnMouse)
451
452 def Unselect(self):
453 self.selection = None
454 wxTreeCtrl.Unselect(self)
455 g.tools.UpdateUI()
456
457 def ExpandAll(self, item):
458 if self.ItemHasChildren(item):
459 self.Expand(item)
460 i, cookie = self.GetFirstChild(item)
461 children = []
462 while i.IsOk():
463 children.append(i)
464 i, cookie = self.GetNextChild(item, cookie)
465 for i in children:
466 self.ExpandAll(i)
467 def CollapseAll(self, item):
468 if self.ItemHasChildren(item):
469 i, cookie = self.GetFirstChild(item)
470 children = []
471 while i.IsOk():
472 children.append(i)
473 i, cookie = self.GetNextChild(item, cookie)
474 for i in children:
475 self.CollapseAll(i)
476 self.Collapse(item)
477
478 # Clear tree
479 def Clear(self):
480 self.DeleteAllItems()
481 # Add minimal structure
482 if self.dom: self.dom.unlink()
483 self.dom = MyDocument()
484 self.dummyNode = self.dom.createComment('dummy node')
485 # Create main node
486 self.mainNode = self.dom.createElement('resource')
487 self.dom.appendChild(self.mainNode)
488 self.rootObj = xxxMainNode(self.dom)
489 self.root = self.AddRoot('XML tree', self.rootImage,
490 data=wxTreeItemData(self.rootObj))
491 self.SetItemHasChildren(self.root)
492 self.Unselect()
493 self.Expand(self.root)
494
495 # Clear old data and set new
496 def SetData(self, dom):
497 self.DeleteAllItems()
498 # Add minimal structure
499 if self.dom: self.dom.unlink()
500 self.dom = dom
501 self.dummyNode = self.dom.createComment('dummy node')
502 # Find 'resource' child, add it's children
503 self.mainNode = dom.documentElement
504 self.rootObj = xxxMainNode(self.dom)
505 self.root = self.AddRoot('XML tree', self.rootImage,
506 data=wxTreeItemData(self.rootObj))
507 self.SetItemHasChildren(self.root)
508 nodes = self.mainNode.childNodes[:]
509 for node in nodes:
510 if IsObject(node):
511 self.AddNode(self.root, None, node)
512 else:
513 self.mainNode.removeChild(node)
514 node.unlink()
515 self.Expand(self.root)
516 self.Unselect()
517
518 # Add tree item for given parent item if node is DOM element node with
519 # 'object' tag. xxxParent is parent xxx object
520 def AddNode(self, itemParent, xxxParent, node):
521 # Set item data to current node
522 try:
523 xxx = MakeXXXFromDOM(xxxParent, node)
524 except:
525 print 'ERROR: MakeXXXFromDom(%s, %s)' % (xxxParent, node)
526 raise
527 treeObj = xxx.treeObject()
528 # Append tree item
529 item = self.AppendItem(itemParent, treeObj.treeName(),
530 image=treeObj.treeImage(),
531 data=wxTreeItemData(xxx))
532 # Try to find children objects
533 if treeObj.hasChildren:
534 nodes = treeObj.element.childNodes[:]
535 for n in nodes:
536 if IsObject(n):
537 self.AddNode(item, treeObj, n)
538 elif n.nodeType != minidom.Node.ELEMENT_NODE:
539 treeObj.element.removeChild(n)
540 n.unlink()
541
542 # Insert new item at specific position
543 def InsertNode(self, itemParent, parent, elem, nextItem):
544 # Insert in XML tree and wxWin
545 xxx = MakeXXXFromDOM(parent, elem)
546 # If nextItem is None, we append to parent, otherwise insert before it
547 if nextItem.IsOk():
548 node = self.GetPyData(nextItem).element
549 parent.element.insertBefore(elem, node)
550 # Inserting before is difficult, se we insert after or first child
551 index = self.ItemIndex(nextItem)
552 newItem = self.InsertItemBefore(itemParent, index,
553 xxx.treeName(), image=xxx.treeImage())
554 self.SetPyData(newItem, xxx)
555 else:
556 parent.element.appendChild(elem)
557 newItem = self.AppendItem(itemParent, xxx.treeName(), image=xxx.treeImage(),
558 data=wxTreeItemData(xxx))
559 # Add children items
560 if xxx.hasChildren:
561 treeObj = xxx.treeObject()
562 for n in treeObj.element.childNodes:
563 if IsObject(n):
564 self.AddNode(newItem, treeObj, n)
565 return newItem
566
567 # Remove leaf of tree, return it's data object
568 def RemoveLeaf(self, leaf):
569 xxx = self.GetPyData(leaf)
570 node = xxx.element
571 parent = node.parentNode
572 parent.removeChild(node)
573 self.Delete(leaf)
574 # Reset selection object
575 self.selection = None
576 return node
577 # Find position relative to the top-level window
578 def FindNodePos(self, item, obj=None):
579 # Root at (0,0)
580 if item == g.testWin.item: return wxPoint(0, 0)
581 itemParent = self.GetItemParent(item)
582 # Select NB page
583 if not obj: obj = self.FindNodeObject(item)
584 if self.GetPyData(itemParent).treeObject().__class__ == xxxNotebook:
585 notebook = self.FindNodeObject(itemParent)
586 # Find position
587 for i in range(notebook.GetPageCount()):
588 if notebook.GetPage(i) == obj:
589 if notebook.GetSelection() != i:
590 notebook.SetSelection(i)
591 # Remove highlight - otherwise highlight window won't be visible
592 if g.testWin.highLight:
593 g.testWin.highLight.Remove()
594 break
595 # Find first ancestor which is a wxWindow (not a sizer)
596 winParent = itemParent
597 while self.GetPyData(winParent).isSizer:
598 winParent = self.GetItemParent(winParent)
599 # Notebook children are layed out in a little strange way
600 if self.GetPyData(itemParent).treeObject().__class__ == xxxNotebook:
601 parentPos = wxPoint(0,0)
602 else:
603 parentPos = self.FindNodePos(winParent)
604 # Position (-1,-1) is really (0,0)
605 pos = obj.GetPosition()
606 if pos == (-1,-1): pos = (0,0)
607 return parentPos + pos
608
609 # Find window (or sizer) corresponding to a tree item.
610 def FindNodeObject(self, item):
611 testWin = g.testWin
612 # If top-level, return testWin (or panel its panel)
613 if item == testWin.item: return testWin.panel
614 itemParent = self.GetItemParent(item)
615 xxx = self.GetPyData(item).treeObject()
616 parentWin = self.FindNodeObject(itemParent)
617 # Top-level sizer? return window's sizer
618 if xxx.isSizer and isinstance(parentWin, wxWindow):
619 return parentWin.GetSizer()
620 elif isinstance(xxx.parent, xxxToolBar):
621 # How to get tool from toolbar?
622 return parentWin.GetChildren()[0]
623 elif isinstance(xxx.parent, xxxStdDialogButtonSizer):
624 # This sizer returns non-existing children
625 for ch in parentWin.GetChildren():
626 if ch.GetWindow() and ch.GetWindow().GetName() == xxx.name:
627 return ch.GetWindow()
628 return None
629 # Otherwise get parent's object and it's child
630 child = parentWin.GetChildren()[self.ItemIndex(item)]
631 # Return window or sizer for sizer items
632 if child.GetClassName() == 'wxSizerItem':
633 if child.IsWindow(): child = child.GetWindow()
634 elif child.IsSizer():
635 child = child.GetSizer()
636 # Test for notebook sizers
637 if isinstance(child, wxNotebookSizer):
638 child = child.GetNotebook()
639 return child
640
641 def OnSelChanged(self, evt):
642 self.ChangeSelection(evt.GetItem())
643
644 def ChangeSelection(self, item):
645 # Apply changes
646 # !!! problem with wxGTK - GetOldItem is Ok if nothing selected
647 #oldItem = evt.GetOldItem()
648 status = ''
649 oldItem = self.selection
650 if oldItem:
651 xxx = self.GetPyData(oldItem)
652 # If some data was modified, apply changes
653 if g.panel.IsModified():
654 self.Apply(xxx, oldItem)
655 #if conf.autoRefresh:
656 if g.testWin:
657 if g.testWin.highLight:
658 g.testWin.highLight.Remove()
659 self.needUpdate = True
660 status = 'Changes were applied'
661 g.frame.SetStatusText(status)
662 # Generate view
663 self.selection = item
664 if not self.selection.IsOk():
665 self.selection = None
666 return
667 xxx = self.GetPyData(self.selection)
668 # Update panel
669 g.panel.SetData(xxx)
670 # Update tools
671 g.tools.UpdateUI()
672 # Highlighting is done in OnIdle
673 self.pendingHighLight = self.selection
674
675 # Check if item is in testWin subtree
676 def IsHighlatable(self, item):
677 if item == g.testWin.item: return False
678 while item != self.root:
679 item = self.GetItemParent(item)
680 if item == g.testWin.item: return True
681 return False
682
683 # Highlight selected item
684 def HighLight(self, item):
685 self.pendingHighLight = None
686 # Can highlight only with some top-level windows
687 if not g.testWin or self.GetPyData(g.testWin.item).treeObject().__class__ \
688 not in [xxxDialog, xxxPanel, xxxFrame]:
689 return
690 # If a control from another window is selected, remove highlight
691 if not self.IsHighlatable(item):
692 if g.testWin.highLight: g.testWin.highLight.Remove()
693 return
694 # Get window/sizer object
695 obj = self.FindNodeObject(item)
696 if not obj: return
697 pos = self.FindNodePos(item, obj)
698 size = obj.GetSize()
699 # Highlight
700 # Negative positions are not working quite well
701 if g.testWin.highLight:
702 g.testWin.highLight.Replace(pos, size)
703 else:
704 g.testWin.highLight = HighLightBox(pos, size)
705 g.testWin.highLight.Refresh()
706 g.testWin.highLight.item = item
707
708 def ShowTestWindow(self, item):
709 xxx = self.GetPyData(item)
710 if g.panel.IsModified():
711 self.Apply(xxx, item) # apply changes
712 treeObj = xxx.treeObject()
713 if treeObj.className not in ['wxFrame', 'wxPanel', 'wxDialog',
714 'wxMenuBar', 'wxToolBar', 'wxWizard',
715 'wxWizardPageSimple']:
716 wxLogMessage('No view for this element (yet)')
717 return
718 # Show item in bold
719 if g.testWin: # Reset old
720 self.SetItemBold(g.testWin.item, False)
721 self.CreateTestWin(item)
722 # Maybe an error occurred, so we need to test
723 if g.testWin: self.SetItemBold(g.testWin.item)
724
725 # Double-click on Linux
726 def OnItemActivated(self, evt):
727 if evt.GetItem() != self.root:
728 self.ShowTestWindow(evt.GetItem())
729
730 # Double-click on Windows
731 def OnDClick(self, evt):
732 item, flags = self.HitTest(evt.GetPosition())
733 if flags in [wxTREE_HITTEST_ONITEMBUTTON, wxTREE_HITTEST_ONITEMLABEL]:
734 if item != self.root: self.ShowTestWindow(item)
735 else:
736 evt.Skip()
737
738 def OnItemExpandedCollapsed(self, evt):
739 # Update tool palette
740 g.tools.UpdateUI()
741 evt.Skip()
742
743 # (re)create test window
744 def CreateTestWin(self, item):
745 testWin = g.testWin
746 # Create a window with this resource
747 xxx = self.GetPyData(item).treeObject()
748
749 # If frame
750 # if xxx.__class__ == xxxFrame:
751 # Frame can't have many children,
752 # but it's first child possibly can...
753 # child = self.GetFirstChild(item)[0]
754 # if child.IsOk() and self.GetPyData(child).__class__ == xxxPanel:
755 # # Clean-up before recursive call or error
756 # wxMemoryFSHandler_RemoveFile('xxx.xrc')
757 # wxEndBusyCursor()
758 # self.CreateTestWin(child)
759 # return
760
761 wxBeginBusyCursor()
762 wxYield()
763 # Close old window, remember where it was
764 highLight = None
765 if testWin:
766 pos = testWin.GetPosition()
767 if item == testWin.item:
768 # Remember highlight if same top-level window
769 if testWin.highLight:
770 highLight = testWin.highLight.item
771 if xxx.className == 'wxPanel':
772 if testWin.highLight:
773 testWin.pendingHighLight = highLight
774 testWin.highLight.Remove()
775 testWin.panel.Destroy()
776 testWin.panel = None
777 else:
778 testWin.Destroy()
779 testWin = g.testWin = None
780 else:
781 testWin.Destroy()
782 testWin = g.testWin = None
783 else:
784 pos = g.testWinPos
785 # Save in memory FS
786 memFile = MemoryFile('xxx.xrc')
787 # Create partial XML file - faster for big files
788
789 dom = MyDocument()
790 mainNode = dom.createElement('resource')
791 dom.appendChild(mainNode)
792
793 # Remove temporarily from old parent
794 elem = xxx.element
795 # Change window id to _XRCED_T_W. This gives some name for
796 # unnamed windows, and for named gives the possibility to
797 # write sawfish scripts.
798 if not xxx.name:
799 name = 'noname'
800 else:
801 name = xxx.name
802 elem.setAttribute('name', STD_NAME)
803 # Replace wizard page class temporarily
804 if xxx.__class__ in [xxxWizardPage, xxxWizardPageSimple]:
805 oldCl = elem.getAttribute('class')
806 elem.setAttribute('class', 'wxPanel')
807 parent = elem.parentNode
808 next = elem.nextSibling
809 parent.replaceChild(self.dummyNode, elem)
810 # Append to new DOM, write it
811 mainNode.appendChild(elem)
812 dom.writexml(memFile, encoding=self.rootObj.params['encoding'].value())
813 # Put back in place
814 mainNode.removeChild(elem)
815 dom.unlink()
816 parent.replaceChild(elem, self.dummyNode)
817 # Remove temporary name or restore changed
818 if not xxx.name:
819 elem.removeAttribute('name')
820 else:
821 elem.setAttribute('name', xxx.name)
822 if xxx.__class__ in [xxxWizardPage, xxxWizardPageSimple]:
823 elem.setAttribute('class', oldCl)
824 memFile.close() # write to wxMemoryFS
825 xmlFlags = wxXRC_NO_SUBCLASSING
826 # Use translations if encoding is not specified
827 if not g.currentEncoding:
828 xmlFlags != wxXRC_USE_LOCALE
829 res = wxXmlResource('', xmlFlags)
830 res.Load('memory:xxx.xrc')
831 try:
832 if xxx.__class__ == xxxFrame:
833 # Frame can't have many children,
834 # but it's first child possibly can...
835 # child = self.GetFirstChild(item)[0]
836 # if child.IsOk() and self.GetPyData(child).__class__ == xxxPanel:
837 # # Clean-up before recursive call or error
838 # wxMemoryFSHandler_RemoveFile('xxx.xrc')
839 # wxEndBusyCursor()
840 # self.CreateTestWin(child)
841 # return
842 # This currently works under GTK, but not under MSW
843 testWin = g.testWin = wxPreFrame()
844 res.LoadOnFrame(testWin, g.frame, STD_NAME)
845 # Create status bar
846 testWin.panel = testWin
847 testWin.CreateStatusBar()
848 testWin.SetClientSize(testWin.GetBestSize())
849 testWin.SetPosition(pos)
850 testWin.Show(True)
851 elif xxx.__class__ == xxxPanel:
852 # Create new frame
853 if not testWin:
854 testWin = g.testWin = wxFrame(g.frame, -1, 'Panel: ' + name,
855 pos=pos, name=STD_NAME)
856 testWin.panel = res.LoadPanel(testWin, STD_NAME)
857 testWin.SetClientSize(testWin.GetBestSize())
858 testWin.Show(True)
859 elif xxx.__class__ == xxxDialog:
860 testWin = g.testWin = res.LoadDialog(None, STD_NAME)
861 testWin.panel = testWin
862 testWin.Layout()
863 testWin.SetPosition(pos)
864 testWin.Show(True)
865 # Dialog's default code does not produce EVT_CLOSE
866 EVT_BUTTON(testWin, wxID_OK, self.OnCloseTestWin)
867 EVT_BUTTON(testWin, wxID_CANCEL, self.OnCloseTestWin)
868 elif xxx.__class__ == xxxWizard:
869 wiz = wxPreWizard()
870 res.LoadOnObject(wiz, None, STD_NAME, 'wxWizard')
871 # Find first page (don't know better way)
872 firstPage = None
873 for w in wiz.GetChildren():
874 if isinstance(w, wxWizardPage):
875 firstPage = w
876 break
877 if not firstPage:
878 wxLogError('Wizard is empty')
879 else:
880 # Wizard should be modal
881 self.SetItemBold(item)
882 wiz.RunWizard(w)
883 self.SetItemBold(item, False)
884 wiz.Destroy()
885 elif xxx.__class__ in [xxxWizardPage, xxxWizardPageSimple]:
886 # Create new frame
887 if not testWin:
888 testWin = g.testWin = wxFrame(g.frame, -1, 'Wizard page: ' + name,
889 pos=pos, name=STD_NAME)
890 testWin.panel = wxPrePanel()
891 res.LoadOnObject(testWin.panel, testWin, STD_NAME, 'wxPanel')
892 testWin.SetClientSize(testWin.GetBestSize())
893 testWin.Show(True)
894 elif xxx.__class__ == xxxMenuBar:
895 testWin = g.testWin = wxFrame(g.frame, -1, 'MenuBar: ' + name,
896 pos=pos, name=STD_NAME)
897 testWin.panel = None
898 # Set status bar to display help
899 testWin.CreateStatusBar()
900 testWin.menuBar = res.LoadMenuBar(STD_NAME)
901 testWin.SetMenuBar(testWin.menuBar)
902 testWin.Show(True)
903 elif xxx.__class__ == xxxToolBar:
904 testWin = g.testWin = wxFrame(g.frame, -1, 'ToolBar: ' + name,
905 pos=pos, name=STD_NAME)
906 testWin.panel = None
907 # Set status bar to display help
908 testWin.CreateStatusBar()
909 testWin.toolBar = res.LoadToolBar(testWin, STD_NAME)
910 testWin.SetToolBar(testWin.toolBar)
911 testWin.Show(True)
912 if testWin:
913 testWin.item = item
914 EVT_CLOSE(testWin, self.OnCloseTestWin)
915 testWin.highLight = None
916 if highLight and not self.pendingHighLight:
917 self.HighLight(highLight)
918 except:
919 if g.testWin:
920 self.SetItemBold(item, False)
921 g.testWinPos = g.testWin.GetPosition()
922 g.testWin.Destroy()
923 g.testWin = None
924 inf = sys.exc_info()
925 wxLogError(traceback.format_exception(inf[0], inf[1], None)[-1])
926 wxLogError('Error loading resource')
927 wxMemoryFSHandler_RemoveFile('xxx.xrc')
928 wxEndBusyCursor()
929
930 def CloseTestWindow(self):
931 if not g.testWin: return
932 self.SetItemBold(g.testWin.item, False)
933 g.frame.tb.ToggleTool(g.frame.ID_TOOL_LOCATE, False)
934 g.testWinPos = g.testWin.GetPosition()
935 g.testWin.Destroy()
936 g.testWin = None
937
938 def OnCloseTestWin(self, evt):
939 self.CloseTestWindow()
940
941 # Return item index in parent
942 def ItemIndex(self, item):
943 n = 0 # index of sibling
944 prev = self.GetPrevSibling(item)
945 while prev.IsOk():
946 prev = self.GetPrevSibling(prev)
947 n += 1
948 return n
949
950 # Full tree index of an item - list of positions
951 def ItemFullIndex(self, item):
952 if not item.IsOk(): return None
953 l = []
954 while item != self.root:
955 l.insert(0, self.ItemIndex(item))
956 item = self.GetItemParent(item)
957 return l
958 # Get item position from full index
959 def ItemAtFullIndex(self, index):
960 if index is None: return wxTreeItemId()
961 item = self.root
962 for i in index:
963 item = self.GetFirstChild(item)[0]
964 for k in range(i): item = self.GetNextSibling(item)
965 return item
966
967 # True if next item should be inserted after current (vs. appended to it)
968 def NeedInsert(self, item):
969 xxx = self.GetPyData(item)
970 if item == self.root: return False # root item
971 if xxx.hasChildren and not self.GetChildrenCount(item, False):
972 return False
973 return not (self.IsExpanded(item) and self.GetChildrenCount(item, False))
974
975 # Pull-down
976 def OnRightDown(self, evt):
977 pullDownMenu = g.pullDownMenu
978 # select this item
979 pt = evt.GetPosition();
980 item, flags = self.HitTest(pt)
981 if item.Ok() and flags & wxTREE_HITTEST_ONITEM:
982 self.SelectItem(item)
983
984 # Setup menu
985 menu = wxMenu()
986
987 item = self.selection
988 if not item:
989 menu.Append(g.pullDownMenu.ID_EXPAND, 'Expand', 'Expand tree')
990 menu.Append(g.pullDownMenu.ID_COLLAPSE, 'Collapse', 'Collapse tree')
991 else:
992 # self.ctrl = evt.ControlDown() # save Ctrl state
993 # self.shift = evt.ShiftDown() # and Shift too
994 m = wxMenu() # create menu
995 if self.ctrl:
996 needInsert = True
997 else:
998 needInsert = self.NeedInsert(item)
999 if item == self.root or needInsert and self.GetItemParent(item) == self.root:
1000 SetMenu(m, pullDownMenu.topLevel)
1001 else:
1002 xxx = self.GetPyData(item).treeObject()
1003 # Check parent for possible child nodes if inserting sibling
1004 if needInsert: xxx = xxx.parent
1005 if xxx.__class__ == xxxMenuBar:
1006 m.Append(ID_NEW.MENU, 'Menu', 'Create menu')
1007 elif xxx.__class__ in [xxxToolBar, xxxTool] or \
1008 xxx.__class__ == xxxSeparator and xxx.parent.__class__ == xxxToolBar:
1009 SetMenu(m, pullDownMenu.toolBarControls)
1010 elif xxx.__class__ in [xxxMenu, xxxMenuItem]:
1011 SetMenu(m, pullDownMenu.menuControls)
1012 elif xxx.__class__ == xxxStdDialogButtonSizer:
1013 SetMenu(m, pullDownMenu.stdButtons)
1014 else:
1015 SetMenu(m, pullDownMenu.controls)
1016 if xxx.__class__ == xxxNotebook:
1017 m.Enable(m.FindItem('sizer'), False)
1018 elif not (xxx.isSizer or xxx.parent and xxx.parent.isSizer):
1019 m.Enable(ID_NEW.SPACER, False)
1020 # Select correct label for create menu
1021 if not needInsert:
1022 if self.shift:
1023 menu.AppendMenu(wxNewId(), 'Insert Child', m,
1024 'Create child object as the first child')
1025 else:
1026 menu.AppendMenu(wxNewId(), 'Append Child', m,
1027 'Create child object as the last child')
1028 else:
1029 if self.shift:
1030 menu.AppendMenu(wxNewId(), 'Create Sibling', m,
1031 'Create sibling before selected object')
1032 else:
1033 menu.AppendMenu(wxNewId(), 'Create Sibling', m,
1034 'Create sibling after selected object')
1035 # Build replace menu
1036 if item != self.root:
1037 xxx = self.GetPyData(item).treeObject()
1038 m = wxMenu() # create replace menu
1039 if xxx.__class__ == xxxMenuBar:
1040 m.Append(1000 + ID_NEW.MENU, 'Menu', 'Create menu')
1041 elif xxx.__class__ in [xxxMenu, xxxMenuItem]:
1042 SetMenu(m, pullDownMenu.menuControls, shift=True)
1043 elif xxx.__class__ == xxxToolBar and \
1044 self.GetItemParent(item) == self.root:
1045 SetMenu(m, [], shift=True)
1046 elif xxx.__class__ in [xxxFrame, xxxDialog, xxxPanel]:
1047 SetMenu(m, [
1048 (ID_NEW.PANEL, 'Panel', 'Create panel'),
1049 (ID_NEW.DIALOG, 'Dialog', 'Create dialog'),
1050 (ID_NEW.FRAME, 'Frame', 'Create frame')], shift=True)
1051 elif xxx.isSizer:
1052 SetMenu(m, pullDownMenu.sizers, shift=True)
1053 else:
1054 SetMenu(m, pullDownMenu.controls, shift=True)
1055 id = wxNewId()
1056 menu.AppendMenu(id, 'Replace With', m)
1057 if not m.GetMenuItemCount(): menu.Enable(id, False)
1058 menu.Append(pullDownMenu.ID_SUBCLASS, 'Subclass...',
1059 'Set subclass property')
1060 menu.AppendSeparator()
1061 # Not using standart IDs because we don't want to show shortcuts
1062 menu.Append(wxID_CUT, 'Cut', 'Cut to the clipboard')
1063 menu.Append(wxID_COPY, 'Copy', 'Copy to the clipboard')
1064 if self.ctrl and item != self.root:
1065 menu.Append(pullDownMenu.ID_PASTE_SIBLING, 'Paste Sibling',
1066 'Paste from the clipboard as a sibling')
1067 else:
1068 menu.Append(wxID_PASTE, 'Paste', 'Paste from the clipboard')
1069 menu.Append(pullDownMenu.ID_DELETE,
1070 'Delete', 'Delete object')
1071 if self.ItemHasChildren(item):
1072 menu.AppendSeparator()
1073 menu.Append(pullDownMenu.ID_EXPAND, 'Expand', 'Expand subtree')
1074 menu.Append(pullDownMenu.ID_COLLAPSE, 'Collapse', 'Collapse subtree')
1075 self.PopupMenu(menu, evt.GetPosition())
1076 menu.Destroy()
1077
1078 # Apply changes
1079 def Apply(self, xxx, item):
1080 g.panel.Apply()
1081 # Update tree view
1082 xxx = xxx.treeObject()
1083 if xxx.hasName and self.GetItemText(item) != xxx.name:
1084 self.SetItemText(item, xxx.treeName())
1085 # Item width may have changed
1086 # !!! Tric to update tree width (wxGTK, ??)
1087 self.SetIndent(self.GetIndent())
1088 # Change tree icon for sizers
1089 if isinstance(xxx, xxxBoxSizer):
1090 self.SetItemImage(item, xxx.treeImage())
1091 # Set global modified state
1092 g.frame.modified = True
1093