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