]>
Commit | Line | Data |
---|---|---|
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 | 7 | from xxx import * # xxx imports globals and params |
fdc1a8be | 8 | import types |
a4c013b2 | 9 | import traceback |
d14a1e28 RD |
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): | |
9a69d0aa | 22 | if g.currentEncoding: |
4eb5bfc6 | 23 | encoding = g.currentEncoding |
9a69d0aa | 24 | else: |
29a41103 | 25 | encoding = wx.GetDefaultPyEncoding() |
4eb5bfc6 RD |
26 | try: |
27 | self.buffer += data.encode(encoding) | |
28 | except UnicodeEncodeError: | |
29 | self.buffer += data.encode(encoding, 'xmlcharrefreplace') | |
30 | ||
d14a1e28 | 31 | def close(self): |
29a41103 | 32 | wx.MemoryFSHandler.AddFile(self.name, self.buffer) |
d14a1e28 RD |
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: | |
29a41103 RD |
52 | PANEL = wx.NewId() |
53 | DIALOG = wx.NewId() | |
54 | FRAME = wx.NewId() | |
55 | TOOL_BAR = wx.NewId() | |
56 | TOOL = wx.NewId() | |
57 | MENU_BAR = wx.NewId() | |
58 | MENU = wx.NewId() | |
59 | STATUS_BAR = wx.NewId() | |
d14a1e28 | 60 | |
29a41103 RD |
61 | STATIC_TEXT = wx.NewId() |
62 | TEXT_CTRL = wx.NewId() | |
d14a1e28 | 63 | |
29a41103 RD |
64 | BUTTON = wx.NewId() |
65 | BITMAP_BUTTON = wx.NewId() | |
66 | RADIO_BUTTON = wx.NewId() | |
67 | SPIN_BUTTON = wx.NewId() | |
68 | TOGGLE_BUTTON = wx.NewId() | |
d14a1e28 | 69 | |
29a41103 RD |
70 | STATIC_BOX = wx.NewId() |
71 | CHECK_BOX = wx.NewId() | |
72 | RADIO_BOX = wx.NewId() | |
73 | COMBO_BOX = wx.NewId() | |
74 | LIST_BOX = wx.NewId() | |
d14a1e28 | 75 | |
29a41103 RD |
76 | STATIC_LINE = wx.NewId() |
77 | STATIC_BITMAP = wx.NewId() | |
78 | CHOICE = wx.NewId() | |
79 | SLIDER = wx.NewId() | |
80 | GAUGE = wx.NewId() | |
81 | SCROLL_BAR = wx.NewId() | |
82 | TREE_CTRL = wx.NewId() | |
83 | LIST_CTRL = wx.NewId() | |
84 | CHECK_LIST = wx.NewId() | |
85 | NOTEBOOK = wx.NewId() | |
86 | CHOICEBOOK = wx.NewId() | |
87 | LISTBOOK = wx.NewId() | |
88 | SPLITTER_WINDOW = wx.NewId() | |
b372319f | 89 | GRID = wx.NewId() |
29a41103 RD |
90 | SCROLLED_WINDOW = wx.NewId() |
91 | HTML_WINDOW = wx.NewId() | |
92 | CALENDAR_CTRL = wx.NewId() | |
93 | DATE_CTRL = wx.NewId() | |
b372319f | 94 | FILE_PICKER_CTRL = wx.NewId() |
29a41103 RD |
95 | GENERIC_DIR_CTRL = wx.NewId() |
96 | SPIN_CTRL = wx.NewId() | |
97 | UNKNOWN = wx.NewId() | |
98 | WIZARD = wx.NewId() | |
99 | WIZARD_PAGE = wx.NewId() | |
100 | WIZARD_PAGE_SIMPLE = wx.NewId() | |
101 | BITMAP = wx.NewId() | |
102 | ICON = wx.NewId() | |
103 | STATUS_BAR = wx.NewId() | |
d14a1e28 | 104 | |
29a41103 RD |
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() | |
111 | SPACER = wx.NewId() | |
64bce500 | 112 | |
29a41103 RD |
113 | TOOL_BAR = wx.NewId() |
114 | TOOL = wx.NewId() | |
115 | MENU = wx.NewId() | |
116 | MENU_ITEM = wx.NewId() | |
117 | SEPARATOR = wx.NewId() | |
64b9ac75 | 118 | |
29a41103 RD |
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() | |
64b9ac75 | 127 | |
29a41103 | 128 | REF = wx.NewId() |
b372319f | 129 | COMMENT = wx.NewId() |
03319b65 | 130 | |
c0d5ae74 RR |
131 | CUSTOM = wx.NewId() |
132 | for i in range(99): wx.NewId() # reserve IDs for custom controls | |
133 | ||
29a41103 | 134 | LAST = wx.NewId() |
d14a1e28 | 135 | |
64b9ac75 RR |
136 | |
137 | ||
d14a1e28 | 138 | class PullDownMenu: |
29a41103 RD |
139 | ID_EXPAND = wx.NewId() |
140 | ID_COLLAPSE = wx.NewId() | |
141 | ID_PASTE_SIBLING = wx.NewId() | |
142 | ID_TOOL_PASTE = wx.NewId() | |
143 | ID_SUBCLASS = wx.NewId() | |
d14a1e28 RD |
144 | |
145 | def __init__(self, parent): | |
146 | self.ID_DELETE = parent.ID_DELETE | |
29a41103 RD |
147 | wx.EVT_MENU_RANGE(parent, ID_NEW.PANEL, ID_NEW.LAST, parent.OnCreate) |
148 | wx.EVT_MENU_RANGE(parent, 1000 + ID_NEW.PANEL, 1000 + ID_NEW.LAST, parent.OnReplace) | |
149 | wx.EVT_MENU(parent, self.ID_COLLAPSE, parent.OnCollapse) | |
150 | wx.EVT_MENU(parent, self.ID_EXPAND, parent.OnExpand) | |
151 | wx.EVT_MENU(parent, self.ID_PASTE_SIBLING, parent.OnPaste) | |
152 | wx.EVT_MENU(parent, self.ID_SUBCLASS, parent.OnSubclass) | |
d14a1e28 | 153 | # We connect to tree, but process in frame |
29a41103 | 154 | wx.EVT_MENU_HIGHLIGHT_ALL(g.tree, parent.OnPullDownHighlight) |
d14a1e28 RD |
155 | |
156 | # Mapping from IDs to element names | |
157 | self.createMap = { | |
158 | ID_NEW.PANEL: 'wxPanel', | |
159 | ID_NEW.DIALOG: 'wxDialog', | |
160 | ID_NEW.FRAME: 'wxFrame', | |
64bce500 RR |
161 | ID_NEW.WIZARD: 'wxWizard', |
162 | ID_NEW.WIZARD_PAGE: 'wxWizardPage', | |
163 | ID_NEW.WIZARD_PAGE_SIMPLE: 'wxWizardPageSimple', | |
d14a1e28 RD |
164 | ID_NEW.TOOL_BAR: 'wxToolBar', |
165 | ID_NEW.TOOL: 'tool', | |
306b6fe9 | 166 | ID_NEW.STATUS_BAR: 'wxStatusBar', |
d14a1e28 RD |
167 | ID_NEW.MENU_BAR: 'wxMenuBar', |
168 | ID_NEW.MENU: 'wxMenu', | |
169 | ID_NEW.MENU_ITEM: 'wxMenuItem', | |
306b6fe9 RR |
170 | ID_NEW.BITMAP: 'wxBitmap', |
171 | ID_NEW.ICON: 'wxIcon', | |
d14a1e28 RD |
172 | ID_NEW.SEPARATOR: 'separator', |
173 | ||
174 | ID_NEW.STATIC_TEXT: 'wxStaticText', | |
175 | ID_NEW.TEXT_CTRL: 'wxTextCtrl', | |
176 | ||
177 | ID_NEW.BUTTON: 'wxButton', | |
178 | ID_NEW.BITMAP_BUTTON: 'wxBitmapButton', | |
179 | ID_NEW.RADIO_BUTTON: 'wxRadioButton', | |
180 | ID_NEW.SPIN_BUTTON: 'wxSpinButton', | |
3d49f2fb | 181 | ID_NEW.TOGGLE_BUTTON: 'wxToggleButton', |
d14a1e28 RD |
182 | |
183 | ID_NEW.STATIC_BOX: 'wxStaticBox', | |
184 | ID_NEW.CHECK_BOX: 'wxCheckBox', | |
185 | ID_NEW.RADIO_BOX: 'wxRadioBox', | |
186 | ID_NEW.COMBO_BOX: 'wxComboBox', | |
187 | ID_NEW.LIST_BOX: 'wxListBox', | |
306b6fe9 | 188 | ID_NEW.CHECK_LIST: 'wxCheckListBox', |
d14a1e28 RD |
189 | |
190 | ID_NEW.STATIC_LINE: 'wxStaticLine', | |
191 | ID_NEW.STATIC_BITMAP: 'wxStaticBitmap', | |
192 | ID_NEW.CHOICE: 'wxChoice', | |
193 | ID_NEW.SLIDER: 'wxSlider', | |
194 | ID_NEW.GAUGE: 'wxGauge', | |
195 | ID_NEW.SCROLL_BAR: 'wxScrollBar', | |
196 | ID_NEW.TREE_CTRL: 'wxTreeCtrl', | |
197 | ID_NEW.LIST_CTRL: 'wxListCtrl', | |
d14a1e28 | 198 | ID_NEW.NOTEBOOK: 'wxNotebook', |
306b6fe9 RR |
199 | ID_NEW.CHOICEBOOK: 'wxChoicebook', |
200 | ID_NEW.LISTBOOK: 'wxListbook', | |
68ae5821 | 201 | ID_NEW.SPLITTER_WINDOW: 'wxSplitterWindow', |
b372319f | 202 | ID_NEW.GRID: 'wxGrid', |
d14a1e28 RD |
203 | ID_NEW.SCROLLED_WINDOW: 'wxScrolledWindow', |
204 | ID_NEW.HTML_WINDOW: 'wxHtmlWindow', | |
205 | ID_NEW.CALENDAR_CTRL: 'wxCalendarCtrl', | |
306b6fe9 | 206 | ID_NEW.DATE_CTRL: 'wxDatePickerCtrl', |
b372319f | 207 | ID_NEW.FILE_PICKER_CTRL: 'wxFilePickerCtrl', |
d14a1e28 RD |
208 | ID_NEW.GENERIC_DIR_CTRL: 'wxGenericDirCtrl', |
209 | ID_NEW.SPIN_CTRL: 'wxSpinCtrl', | |
210 | ||
211 | ID_NEW.BOX_SIZER: 'wxBoxSizer', | |
212 | ID_NEW.STATIC_BOX_SIZER: 'wxStaticBoxSizer', | |
213 | ID_NEW.GRID_SIZER: 'wxGridSizer', | |
214 | ID_NEW.FLEX_GRID_SIZER: 'wxFlexGridSizer', | |
a4c013b2 | 215 | ID_NEW.GRID_BAG_SIZER: 'wxGridBagSizer', |
64bce500 | 216 | ID_NEW.STD_DIALOG_BUTTON_SIZER: 'wxStdDialogButtonSizer', |
d14a1e28 RD |
217 | ID_NEW.SPACER: 'spacer', |
218 | ID_NEW.UNKNOWN: 'unknown', | |
64b9ac75 RR |
219 | |
220 | ID_NEW.OK_BUTTON: 'wxButton', | |
221 | ID_NEW.YES_BUTTON: 'wxButton', | |
222 | ID_NEW.SAVE_BUTTON: 'wxButton', | |
223 | ID_NEW.APPLY_BUTTON: 'wxButton', | |
224 | ID_NEW.NO_BUTTON: 'wxButton', | |
225 | ID_NEW.CANCEL_BUTTON: 'wxButton', | |
226 | ID_NEW.HELP_BUTTON: 'wxButton', | |
227 | ID_NEW.CONTEXT_HELP_BUTTON: 'wxButton', | |
d14a1e28 RD |
228 | } |
229 | self.topLevel = [ | |
230 | (ID_NEW.PANEL, 'Panel', 'Create panel'), | |
231 | (ID_NEW.DIALOG, 'Dialog', 'Create dialog'), | |
232 | (ID_NEW.FRAME, 'Frame', 'Create frame'), | |
64bce500 | 233 | (ID_NEW.WIZARD, 'Wizard', 'Create wizard'), |
d14a1e28 RD |
234 | None, |
235 | (ID_NEW.TOOL_BAR, 'ToolBar', 'Create toolbar'), | |
236 | (ID_NEW.MENU_BAR, 'MenuBar', 'Create menubar'), | |
306b6fe9 RR |
237 | (ID_NEW.MENU, 'Menu', 'Create menu'), |
238 | None, | |
239 | (ID_NEW.BITMAP, 'Bitmap', 'Create bitmap'), | |
240 | (ID_NEW.ICON, 'Icon', 'Create icon'), | |
d14a1e28 RD |
241 | ] |
242 | self.containers = [ | |
243 | (ID_NEW.PANEL, 'Panel', 'Create panel'), | |
244 | (ID_NEW.NOTEBOOK, 'Notebook', 'Create notebook control'), | |
306b6fe9 RR |
245 | (ID_NEW.CHOICEBOOK, 'Choicebook', 'Create choicebook control'), |
246 | (ID_NEW.LISTBOOK, 'Listbook', 'Create listbook control'), | |
68ae5821 | 247 | (ID_NEW.SPLITTER_WINDOW, 'SplitterWindow', 'Create splitter window'), |
d14a1e28 | 248 | (ID_NEW.TOOL_BAR, 'ToolBar', 'Create toolbar'), |
306b6fe9 | 249 | (ID_NEW.STATUS_BAR, 'StatusBar', 'Create status bar'), |
64bce500 RR |
250 | # (ID_NEW.WIZARD_PAGE, 'WizardPage', 'Create wizard page'), |
251 | (ID_NEW.WIZARD_PAGE_SIMPLE, 'WizardPageSimple', 'Create simple wizard page'), | |
d14a1e28 RD |
252 | ] |
253 | self.sizers = [ | |
254 | (ID_NEW.BOX_SIZER, 'BoxSizer', 'Create box sizer'), | |
255 | (ID_NEW.STATIC_BOX_SIZER, 'StaticBoxSizer', | |
256 | 'Create static box sizer'), | |
257 | (ID_NEW.GRID_SIZER, 'GridSizer', 'Create grid sizer'), | |
258 | (ID_NEW.FLEX_GRID_SIZER, 'FlexGridSizer', | |
259 | 'Create flexgrid sizer'), | |
a4c013b2 RR |
260 | (ID_NEW.GRID_BAG_SIZER, 'GridBagSizer', |
261 | 'Create gridbag sizer'), | |
64bce500 RR |
262 | # (ID_NEW.STD_DIALOG_BUTTON_SIZER, 'StdDialogButtonSizer', |
263 | # 'Create standard button sizer'), | |
d14a1e28 RD |
264 | (ID_NEW.SPACER, 'Spacer', 'Create spacer'), |
265 | ] | |
266 | self.controls = [ | |
267 | ['control', 'Various controls', | |
268 | (ID_NEW.STATIC_TEXT, 'Label', 'Create label'), | |
269 | (ID_NEW.STATIC_BITMAP, 'Bitmap', 'Create bitmap'), | |
270 | (ID_NEW.STATIC_LINE, 'Line', 'Create line'), | |
271 | (ID_NEW.TEXT_CTRL, 'TextBox', 'Create text box'), | |
272 | (ID_NEW.CHOICE, 'Choice', 'Create choice'), | |
273 | (ID_NEW.SLIDER, 'Slider', 'Create slider'), | |
274 | (ID_NEW.GAUGE, 'Gauge', 'Create gauge'), | |
275 | (ID_NEW.SPIN_CTRL, 'SpinCtrl', 'Create spin'), | |
276 | (ID_NEW.SCROLL_BAR, 'ScrollBar', 'Create scroll bar'), | |
277 | (ID_NEW.TREE_CTRL, 'TreeCtrl', 'Create tree'), | |
278 | (ID_NEW.LIST_CTRL, 'ListCtrl', 'Create list'), | |
b372319f | 279 | # (ID_NEW.GRID, 'Grid', 'Create grid'), |
d14a1e28 RD |
280 | (ID_NEW.SCROLLED_WINDOW, 'ScrolledWindow', 'Create scrolled window'), |
281 | (ID_NEW.HTML_WINDOW, 'HtmlWindow', 'Create HTML window'), | |
282 | (ID_NEW.CALENDAR_CTRL, 'CalendarCtrl', 'Create calendar control'), | |
306b6fe9 | 283 | (ID_NEW.DATE_CTRL, 'DatePickerCtrl', 'Create date picker control'), |
b372319f | 284 | # (ID_NEW.FILE_PICKER_CTRL, 'FilePickerCtrl', 'Create file picker control'), |
d14a1e28 RD |
285 | (ID_NEW.GENERIC_DIR_CTRL, 'GenericDirCtrl', 'Create generic dir control'), |
286 | (ID_NEW.UNKNOWN, 'Unknown', 'Create custom control placeholder'), | |
287 | ], | |
288 | ['button', 'Buttons', | |
289 | (ID_NEW.BUTTON, 'Button', 'Create button'), | |
290 | (ID_NEW.BITMAP_BUTTON, 'BitmapButton', 'Create bitmap button'), | |
291 | (ID_NEW.RADIO_BUTTON, 'RadioButton', 'Create radio button'), | |
292 | (ID_NEW.SPIN_BUTTON, 'SpinButton', 'Create spin button'), | |
3d49f2fb | 293 | (ID_NEW.TOGGLE_BUTTON, 'ToggleButton', 'Create toggle button'), |
d14a1e28 RD |
294 | ], |
295 | ['box', 'Boxes', | |
296 | (ID_NEW.STATIC_BOX, 'StaticBox', 'Create static box'), | |
297 | (ID_NEW.CHECK_BOX, 'CheckBox', 'Create check box'), | |
298 | (ID_NEW.RADIO_BOX, 'RadioBox', 'Create radio box'), | |
299 | (ID_NEW.COMBO_BOX, 'ComboBox', 'Create combo box'), | |
300 | (ID_NEW.LIST_BOX, 'ListBox', 'Create list box'), | |
306b6fe9 | 301 | (ID_NEW.CHECK_LIST, 'CheckListBox', 'Create checklist box'), |
d14a1e28 RD |
302 | ], |
303 | ['container', 'Containers', | |
304 | (ID_NEW.PANEL, 'Panel', 'Create panel'), | |
305 | (ID_NEW.NOTEBOOK, 'Notebook', 'Create notebook control'), | |
306b6fe9 RR |
306 | (ID_NEW.CHOICEBOOK, 'Choicebook', 'Create choicebook control'), |
307 | (ID_NEW.LISTBOOK, 'Listbook', 'Create listbook control'), | |
68ae5821 | 308 | (ID_NEW.SPLITTER_WINDOW, 'SplitterWindow', 'Create splitter window'), |
d14a1e28 | 309 | (ID_NEW.TOOL_BAR, 'ToolBar', 'Create toolbar'), |
306b6fe9 | 310 | (ID_NEW.STATUS_BAR, 'StatusBar', 'Create status bar'), |
f65bb0f8 | 311 | (ID_NEW.MENU_BAR, 'MenuBar', 'Create menubar'), |
64bce500 RR |
312 | # (ID_NEW.WIZARD_PAGE, 'Wizard Page', 'Create wizard page'), |
313 | (ID_NEW.WIZARD_PAGE_SIMPLE, 'WizardPageSimple', 'Create simple wizard page'), | |
d14a1e28 RD |
314 | ], |
315 | ['sizer', 'Sizers', | |
316 | (ID_NEW.BOX_SIZER, 'BoxSizer', 'Create box sizer'), | |
317 | (ID_NEW.STATIC_BOX_SIZER, 'StaticBoxSizer', | |
318 | 'Create static box sizer'), | |
319 | (ID_NEW.GRID_SIZER, 'GridSizer', 'Create grid sizer'), | |
320 | (ID_NEW.FLEX_GRID_SIZER, 'FlexGridSizer', | |
321 | 'Create flexgrid sizer'), | |
a4c013b2 RR |
322 | (ID_NEW.GRID_BAG_SIZER, 'GridBagSizer', |
323 | 'Create gridbag sizer'), | |
d14a1e28 | 324 | (ID_NEW.SPACER, 'Spacer', 'Create spacer'), |
64bce500 RR |
325 | (ID_NEW.STD_DIALOG_BUTTON_SIZER, 'StdDialogButtonSizer', |
326 | 'Create standard button sizer'), | |
d14a1e28 RD |
327 | ] |
328 | ] | |
329 | self.menuControls = [ | |
330 | (ID_NEW.MENU, 'Menu', 'Create menu'), | |
331 | (ID_NEW.MENU_ITEM, 'MenuItem', 'Create menu item'), | |
332 | (ID_NEW.SEPARATOR, 'Separator', 'Create separator'), | |
333 | ] | |
334 | self.toolBarControls = [ | |
335 | (ID_NEW.TOOL, 'Tool', 'Create tool'), | |
336 | (ID_NEW.SEPARATOR, 'Separator', 'Create separator'), | |
337 | ['control', 'Various controls', | |
338 | (ID_NEW.STATIC_TEXT, 'Label', 'Create label'), | |
339 | (ID_NEW.STATIC_BITMAP, 'Bitmap', 'Create bitmap'), | |
340 | (ID_NEW.STATIC_LINE, 'Line', 'Create line'), | |
341 | (ID_NEW.TEXT_CTRL, 'TextBox', 'Create text box'), | |
342 | (ID_NEW.CHOICE, 'Choice', 'Create choice'), | |
343 | (ID_NEW.SLIDER, 'Slider', 'Create slider'), | |
344 | (ID_NEW.GAUGE, 'Gauge', 'Create gauge'), | |
345 | (ID_NEW.SCROLL_BAR, 'ScrollBar', 'Create scroll bar'), | |
346 | (ID_NEW.LIST_CTRL, 'ListCtrl', 'Create list control'), | |
d14a1e28 RD |
347 | ], |
348 | ['button', 'Buttons', | |
349 | (ID_NEW.BUTTON, 'Button', 'Create button'), | |
350 | (ID_NEW.BITMAP_BUTTON, 'BitmapButton', 'Create bitmap button'), | |
351 | (ID_NEW.RADIO_BUTTON, 'RadioButton', 'Create radio button'), | |
352 | (ID_NEW.SPIN_BUTTON, 'SpinButton', 'Create spin button'), | |
353 | ], | |
354 | ['box', 'Boxes', | |
355 | (ID_NEW.STATIC_BOX, 'StaticBox', 'Create static box'), | |
356 | (ID_NEW.CHECK_BOX, 'CheckBox', 'Create check box'), | |
357 | (ID_NEW.RADIO_BOX, 'RadioBox', 'Create radio box'), | |
358 | (ID_NEW.COMBO_BOX, 'ComboBox', 'Create combo box'), | |
359 | (ID_NEW.LIST_BOX, 'ListBox', 'Create list box'), | |
306b6fe9 | 360 | (ID_NEW.CHECK_LIST, 'CheckListBox', 'Create checklist box'), |
d14a1e28 RD |
361 | ], |
362 | ] | |
64b9ac75 RR |
363 | self.stdButtons = [ |
364 | (ID_NEW.OK_BUTTON, 'OK Button', 'Create standard button'), | |
365 | (ID_NEW.YES_BUTTON, 'YES Button', 'Create standard button'), | |
366 | (ID_NEW.SAVE_BUTTON, 'SAVE Button', 'Create standard button'), | |
367 | (ID_NEW.APPLY_BUTTON, 'APPLY Button', 'Create standard button'), | |
368 | (ID_NEW.NO_BUTTON, 'NO Button', 'Create standard button'), | |
369 | (ID_NEW.CANCEL_BUTTON, 'CANCEL Button', 'Create standard button'), | |
370 | (ID_NEW.HELP_BUTTON, 'HELP Button', 'Create standard button'), | |
371 | (ID_NEW.CONTEXT_HELP_BUTTON, 'CONTEXT HELP Button', 'Create standard button'), | |
372 | ] | |
373 | self.stdButtonIDs = { | |
374 | ID_NEW.OK_BUTTON: ('wxID_OK', '&Ok'), | |
375 | ID_NEW.YES_BUTTON: ('wxID_YES', '&Yes'), | |
376 | ID_NEW.SAVE_BUTTON: ('wxID_SAVE', '&Save'), | |
377 | ID_NEW.APPLY_BUTTON: ('wxID_APPLY', '&Apply'), | |
378 | ID_NEW.NO_BUTTON: ('wxID_NO', '&No'), | |
379 | ID_NEW.CANCEL_BUTTON: ('wxID_CANCEL', '&Cancel'), | |
380 | ID_NEW.HELP_BUTTON: ('wxID_HELP', '&Help'), | |
381 | ID_NEW.CONTEXT_HELP_BUTTON: ('wxID_CONTEXT_HELP', '&Help'), | |
382 | } | |
8c64c153 | 383 | self.custom = ['custom', 'User-defined controls'] |
c0d5ae74 RR |
384 | self.customMap = {} |
385 | ||
386 | def addCustom(self, klass): | |
8c64c153 RR |
387 | n = len(self.custom)-2 |
388 | self.custom.append((ID_NEW.CUSTOM + n, klass)) | |
c0d5ae74 | 389 | self.customMap[ID_NEW.CUSTOM + n] = klass |
64b9ac75 | 390 | |
d14a1e28 RD |
391 | |
392 | ################################################################################ | |
393 | ||
394 | # Set menu to list items. | |
395 | # Each menu command is a tuple (id, label, help) | |
396 | # submenus are lists [id, label, help, submenu] | |
64b9ac75 RR |
397 | # and separators are any other type. Shift is for making |
398 | # alternative sets of IDs. (+1000). | |
399 | def SetMenu(m, list, shift=False): | |
d14a1e28 RD |
400 | for l in list: |
401 | if type(l) == types.TupleType: | |
402 | # Shift ID | |
64b9ac75 | 403 | if shift: l = (1000 + l[0],) + l[1:] |
d14a1e28 RD |
404 | apply(m.Append, l) |
405 | elif type(l) == types.ListType: | |
29a41103 | 406 | subMenu = wx.Menu() |
0725108f | 407 | SetMenu(subMenu, l[2:], shift) |
29a41103 | 408 | m.AppendMenu(wx.NewId(), l[0], subMenu, l[1]) |
d14a1e28 RD |
409 | else: # separator |
410 | m.AppendSeparator() | |
411 | ||
412 | ################################################################################ | |
413 | ||
414 | class HighLightBox: | |
415 | def __init__(self, pos, size): | |
416 | if size.width == -1: size.width = 0 | |
417 | if size.height == -1: size.height = 0 | |
418 | w = g.testWin.panel | |
29a41103 RD |
419 | l1 = wx.Window(w, -1, pos, wx.Size(size.width, 2)) |
420 | l1.SetBackgroundColour(wx.RED) | |
421 | l2 = wx.Window(w, -1, pos, wx.Size(2, size.height)) | |
422 | l2.SetBackgroundColour(wx.RED) | |
423 | l3 = wx.Window(w, -1, wx.Point(pos.x + size.width - 2, pos.y), wx.Size(2, size.height)) | |
424 | l3.SetBackgroundColour(wx.RED) | |
425 | l4 = wx.Window(w, -1, wx.Point(pos.x, pos.y + size.height - 2), wx.Size(size.width, 2)) | |
426 | l4.SetBackgroundColour(wx.RED) | |
d14a1e28 | 427 | self.lines = [l1, l2, l3, l4] |
8c64c153 | 428 | self.size = size |
d14a1e28 RD |
429 | # Move highlight to a new position |
430 | def Replace(self, pos, size): | |
431 | if size.width == -1: size.width = 0 | |
432 | if size.height == -1: size.height = 0 | |
433 | self.lines[0].SetDimensions(pos.x, pos.y, size.width, 2) | |
434 | self.lines[1].SetDimensions(pos.x, pos.y, 2, size.height) | |
435 | self.lines[2].SetDimensions(pos.x + size.width - 2, pos.y, 2, size.height) | |
436 | self.lines[3].SetDimensions(pos.x, pos.y + size.height - 2, size.width, 2) | |
8c64c153 | 437 | self.size = size |
d14a1e28 RD |
438 | # Remove it |
439 | def Remove(self): | |
29a41103 | 440 | map(wx.Window.Destroy, self.lines) |
d14a1e28 | 441 | g.testWin.highLight = None |
9a69d0aa | 442 | def Refresh(self): |
29a41103 | 443 | map(wx.Window.Refresh, self.lines) |
d14a1e28 RD |
444 | |
445 | ################################################################################ | |
446 | ||
29a41103 | 447 | class XML_Tree(wx.TreeCtrl): |
d14a1e28 | 448 | def __init__(self, parent, id): |
fe295b0d RR |
449 | wx.TreeCtrl.__init__(self, parent, id, |
450 | style = wx.TR_HAS_BUTTONS | wx.TR_MULTIPLE | wx.TR_EDIT_LABELS) | |
29a41103 | 451 | self.SetBackgroundColour(wx.Colour(224, 248, 224)) |
fe295b0d RR |
452 | self.fontComment = wx.FFont(self.GetFont().GetPointSize(), |
453 | self.GetFont().GetFamily(), | |
454 | wx.FONTFLAG_ITALIC) | |
d14a1e28 | 455 | # Register events |
29a41103 | 456 | wx.EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged) |
d14a1e28 | 457 | # One works on Linux, another on Windows |
29a41103 RD |
458 | if wx.Platform == '__WXGTK__': |
459 | wx.EVT_TREE_ITEM_ACTIVATED(self, self.GetId(), self.OnItemActivated) | |
d14a1e28 | 460 | else: |
29a41103 RD |
461 | wx.EVT_LEFT_DCLICK(self, self.OnDClick) |
462 | wx.EVT_RIGHT_DOWN(self, self.OnRightDown) | |
463 | wx.EVT_TREE_ITEM_EXPANDED(self, self.GetId(), self.OnItemExpandedCollapsed) | |
464 | wx.EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemExpandedCollapsed) | |
fe295b0d RR |
465 | self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnBeginLabelEdit) |
466 | self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnEndLabelEdit) | |
d14a1e28 RD |
467 | |
468 | self.selection = None | |
2458faeb | 469 | self.selectionChanging = False |
d14a1e28 RD |
470 | self.needUpdate = False |
471 | self.pendingHighLight = None | |
472 | self.ctrl = self.shift = False | |
473 | self.dom = None | |
474 | # Create image list | |
29a41103 | 475 | il = wx.ImageList(16, 16, True) |
d14a1e28 | 476 | self.rootImage = il.Add(images.getTreeRootImage().Scale(16,16).ConvertToBitmap()) |
b372319f | 477 | xxxComment.image = il.Add(images.getTreeCommentImage().Scale(16,16).ConvertToBitmap()) |
d14a1e28 RD |
478 | xxxObject.image = il.Add(images.getTreeDefaultImage().Scale(16,16).ConvertToBitmap()) |
479 | xxxPanel.image = il.Add(images.getTreePanelImage().Scale(16,16).ConvertToBitmap()) | |
480 | xxxDialog.image = il.Add(images.getTreeDialogImage().Scale(16,16).ConvertToBitmap()) | |
481 | xxxFrame.image = il.Add(images.getTreeFrameImage().Scale(16,16).ConvertToBitmap()) | |
482 | xxxMenuBar.image = il.Add(images.getTreeMenuBarImage().Scale(16,16).ConvertToBitmap()) | |
483 | xxxMenu.image = il.Add(images.getTreeMenuImage().Scale(16,16).ConvertToBitmap()) | |
484 | xxxMenuItem.image = il.Add(images.getTreeMenuItemImage().Scale(16,16).ConvertToBitmap()) | |
485 | xxxToolBar.image = il.Add(images.getTreeToolBarImage().Scale(16,16).ConvertToBitmap()) | |
486 | xxxTool.image = il.Add(images.getTreeToolImage().Scale(16,16).ConvertToBitmap()) | |
487 | xxxSeparator.image = il.Add(images.getTreeSeparatorImage().Scale(16,16).ConvertToBitmap()) | |
488 | xxxSizer.imageH = il.Add(images.getTreeSizerHImage().Scale(16,16).ConvertToBitmap()) | |
489 | xxxSizer.imageV = il.Add(images.getTreeSizerVImage().Scale(16,16).ConvertToBitmap()) | |
490 | xxxStaticBoxSizer.imageH = il.Add(images.getTreeStaticBoxSizerHImage().Scale(16,16).ConvertToBitmap()) | |
491 | xxxStaticBoxSizer.imageV = il.Add(images.getTreeStaticBoxSizerVImage().Scale(16,16).ConvertToBitmap()) | |
492 | xxxGridSizer.image = il.Add(images.getTreeSizerGridImage().Scale(16,16).ConvertToBitmap()) | |
493 | xxxFlexGridSizer.image = il.Add(images.getTreeSizerFlexGridImage().Scale(16,16).ConvertToBitmap()) | |
494 | self.il = il | |
495 | self.SetImageList(il) | |
496 | ||
497 | def RegisterKeyEvents(self): | |
29a41103 RD |
498 | wx.EVT_KEY_DOWN(self, g.tools.OnKeyDown) |
499 | wx.EVT_KEY_UP(self, g.tools.OnKeyUp) | |
500 | wx.EVT_ENTER_WINDOW(self, g.tools.OnMouse) | |
501 | wx.EVT_LEAVE_WINDOW(self, g.tools.OnMouse) | |
d14a1e28 | 502 | |
d14a1e28 RD |
503 | def ExpandAll(self, item): |
504 | if self.ItemHasChildren(item): | |
505 | self.Expand(item) | |
fdc1a8be | 506 | i, cookie = self.GetFirstChild(item) |
d14a1e28 RD |
507 | children = [] |
508 | while i.IsOk(): | |
509 | children.append(i) | |
510 | i, cookie = self.GetNextChild(item, cookie) | |
511 | for i in children: | |
512 | self.ExpandAll(i) | |
513 | def CollapseAll(self, item): | |
514 | if self.ItemHasChildren(item): | |
fdc1a8be | 515 | i, cookie = self.GetFirstChild(item) |
d14a1e28 RD |
516 | children = [] |
517 | while i.IsOk(): | |
518 | children.append(i) | |
519 | i, cookie = self.GetNextChild(item, cookie) | |
520 | for i in children: | |
521 | self.CollapseAll(i) | |
522 | self.Collapse(item) | |
523 | ||
524 | # Clear tree | |
525 | def Clear(self): | |
0725108f RR |
526 | self.selection = None |
527 | self.UnselectAll() | |
d14a1e28 RD |
528 | self.DeleteAllItems() |
529 | # Add minimal structure | |
530 | if self.dom: self.dom.unlink() | |
531 | self.dom = MyDocument() | |
532 | self.dummyNode = self.dom.createComment('dummy node') | |
533 | # Create main node | |
534 | self.mainNode = self.dom.createElement('resource') | |
535 | self.dom.appendChild(self.mainNode) | |
536 | self.rootObj = xxxMainNode(self.dom) | |
537 | self.root = self.AddRoot('XML tree', self.rootImage, | |
29a41103 | 538 | data=wx.TreeItemData(self.rootObj)) |
d14a1e28 | 539 | self.SetItemHasChildren(self.root) |
34b29ae7 RR |
540 | self.testElem = self.dom.createElement('dummy') |
541 | self.mainNode.appendChild(self.testElem) | |
fdc1a8be | 542 | self.Expand(self.root) |
d14a1e28 RD |
543 | |
544 | # Clear old data and set new | |
545 | def SetData(self, dom): | |
0725108f RR |
546 | self.selection = None |
547 | self.UnselectAll() | |
d14a1e28 RD |
548 | self.DeleteAllItems() |
549 | # Add minimal structure | |
550 | if self.dom: self.dom.unlink() | |
551 | self.dom = dom | |
552 | self.dummyNode = self.dom.createComment('dummy node') | |
553 | # Find 'resource' child, add it's children | |
554 | self.mainNode = dom.documentElement | |
555 | self.rootObj = xxxMainNode(self.dom) | |
556 | self.root = self.AddRoot('XML tree', self.rootImage, | |
29a41103 | 557 | data=wx.TreeItemData(self.rootObj)) |
d14a1e28 RD |
558 | self.SetItemHasChildren(self.root) |
559 | nodes = self.mainNode.childNodes[:] | |
560 | for node in nodes: | |
561 | if IsObject(node): | |
562 | self.AddNode(self.root, None, node) | |
563 | else: | |
564 | self.mainNode.removeChild(node) | |
565 | node.unlink() | |
34b29ae7 RR |
566 | if self.mainNode.firstChild: |
567 | self.testElem = self.dom.createElement('dummy') | |
568 | self.mainNode.insertBefore(self.testElem, self.mainNode.firstChild) | |
569 | else: | |
570 | self.testElem = self.dom.createElement('dummy') | |
571 | self.mainNode.appendChild(self.testElem) | |
d14a1e28 | 572 | self.Expand(self.root) |
d14a1e28 RD |
573 | |
574 | # Add tree item for given parent item if node is DOM element node with | |
03319b65 | 575 | # object/object_ref tag. xxxParent is parent xxx object |
d14a1e28 RD |
576 | def AddNode(self, itemParent, xxxParent, node): |
577 | # Set item data to current node | |
578 | try: | |
579 | xxx = MakeXXXFromDOM(xxxParent, node) | |
580 | except: | |
581 | print 'ERROR: MakeXXXFromDom(%s, %s)' % (xxxParent, node) | |
582 | raise | |
583 | treeObj = xxx.treeObject() | |
584 | # Append tree item | |
585 | item = self.AppendItem(itemParent, treeObj.treeName(), | |
586 | image=treeObj.treeImage(), | |
29a41103 | 587 | data=wx.TreeItemData(xxx)) |
b372319f RR |
588 | # Different color for comments and references |
589 | if xxx.className == 'comment': | |
590 | self.SetItemTextColour(item, 'Blue') | |
591 | self.SetItemFont(item, self.fontComment) | |
592 | elif treeObj.ref: | |
03319b65 | 593 | self.SetItemTextColour(item, 'DarkGreen') |
75aa1946 RR |
594 | elif treeObj.hasStyle and treeObj.params.get('hidden', False): |
595 | self.SetItemTextColour(item, 'Grey') | |
d14a1e28 RD |
596 | # Try to find children objects |
597 | if treeObj.hasChildren: | |
b372319f | 598 | nodes = treeObj.node.childNodes[:] |
d14a1e28 RD |
599 | for n in nodes: |
600 | if IsObject(n): | |
601 | self.AddNode(item, treeObj, n) | |
602 | elif n.nodeType != minidom.Node.ELEMENT_NODE: | |
b372319f | 603 | treeObj.node.removeChild(n) |
d14a1e28 RD |
604 | n.unlink() |
605 | ||
606 | # Insert new item at specific position | |
607 | def InsertNode(self, itemParent, parent, elem, nextItem): | |
608 | # Insert in XML tree and wxWin | |
609 | xxx = MakeXXXFromDOM(parent, elem) | |
610 | # If nextItem is None, we append to parent, otherwise insert before it | |
611 | if nextItem.IsOk(): | |
b372319f RR |
612 | node = self.GetPyData(nextItem).node |
613 | parent.node.insertBefore(elem, node) | |
d14a1e28 RD |
614 | # Inserting before is difficult, se we insert after or first child |
615 | index = self.ItemIndex(nextItem) | |
616 | newItem = self.InsertItemBefore(itemParent, index, | |
617 | xxx.treeName(), image=xxx.treeImage()) | |
618 | self.SetPyData(newItem, xxx) | |
619 | else: | |
b372319f | 620 | parent.node.appendChild(elem) |
d14a1e28 | 621 | newItem = self.AppendItem(itemParent, xxx.treeName(), image=xxx.treeImage(), |
29a41103 | 622 | data=wx.TreeItemData(xxx)) |
b372319f RR |
623 | treeObj = xxx.treeObject() |
624 | # Different color for references and comments | |
625 | if xxx.className == 'comment': | |
626 | self.SetItemTextColour(newItem, 'Blue') | |
fe295b0d | 627 | self.SetItemFont(newItem, self.fontComment) |
b372319f RR |
628 | elif treeObj.ref: |
629 | self.SetItemTextColour(newItem, 'DarkGreen') | |
630 | elif treeObj.hasStyle and treeObj.params.get('hidden', False): | |
631 | self.SetItemTextColour(newItem, 'Grey') | |
d14a1e28 RD |
632 | # Add children items |
633 | if xxx.hasChildren: | |
634 | treeObj = xxx.treeObject() | |
b372319f | 635 | for n in treeObj.node.childNodes: |
d14a1e28 RD |
636 | if IsObject(n): |
637 | self.AddNode(newItem, treeObj, n) | |
638 | return newItem | |
639 | ||
640 | # Remove leaf of tree, return it's data object | |
641 | def RemoveLeaf(self, leaf): | |
642 | xxx = self.GetPyData(leaf) | |
b372319f | 643 | node = xxx.node |
d14a1e28 RD |
644 | parent = node.parentNode |
645 | parent.removeChild(node) | |
646 | self.Delete(leaf) | |
647 | # Reset selection object | |
648 | self.selection = None | |
649 | return node | |
538a0c0d | 650 | |
d14a1e28 | 651 | # Find position relative to the top-level window |
64b9ac75 | 652 | def FindNodePos(self, item, obj=None): |
d14a1e28 | 653 | # Root at (0,0) |
29a41103 | 654 | if item == g.testWin.item: return wx.Point(0, 0) |
d14a1e28 | 655 | itemParent = self.GetItemParent(item) |
306b6fe9 | 656 | # Select book page |
64b9ac75 | 657 | if not obj: obj = self.FindNodeObject(item) |
306b6fe9 RR |
658 | if self.GetPyData(itemParent).treeObject().__class__ in \ |
659 | [xxxNotebook, xxxChoicebook, xxxListbook]: | |
660 | book = self.FindNodeObject(itemParent) | |
d14a1e28 | 661 | # Find position |
306b6fe9 RR |
662 | for i in range(book.GetPageCount()): |
663 | if book.GetPage(i) == obj: | |
664 | if book.GetSelection() != i: | |
665 | book.SetSelection(i) | |
fd919451 RR |
666 | # Remove highlight - otherwise highlight window won't be visible |
667 | if g.testWin.highLight: | |
668 | g.testWin.highLight.Remove() | |
d14a1e28 | 669 | break |
538a0c0d | 670 | # For sizers and notebooks we must select the first window-like parent |
d14a1e28 | 671 | winParent = itemParent |
e2dc45d8 | 672 | while self.GetPyData(winParent).isSizer: |
d14a1e28 | 673 | winParent = self.GetItemParent(winParent) |
e2dc45d8 RR |
674 | # Notebook children are layed out in a little strange way |
675 | # wxGTK places NB panels relative to the NB parent | |
676 | if wx.Platform == '__WXGTK__': | |
677 | if self.GetPyData(itemParent).treeObject().__class__ == xxxNotebook: | |
678 | winParent = self.GetItemParent(winParent) | |
538a0c0d | 679 | parentPos = self.FindNodePos(winParent) |
d14a1e28 | 680 | pos = obj.GetPosition() |
e2dc45d8 | 681 | # Position (-1,-1) is really (0,0) |
d14a1e28 RD |
682 | if pos == (-1,-1): pos = (0,0) |
683 | return parentPos + pos | |
684 | ||
685 | # Find window (or sizer) corresponding to a tree item. | |
686 | def FindNodeObject(self, item): | |
687 | testWin = g.testWin | |
688 | # If top-level, return testWin (or panel its panel) | |
689 | if item == testWin.item: return testWin.panel | |
690 | itemParent = self.GetItemParent(item) | |
691 | xxx = self.GetPyData(item).treeObject() | |
692 | parentWin = self.FindNodeObject(itemParent) | |
693 | # Top-level sizer? return window's sizer | |
29a41103 | 694 | if xxx.isSizer and isinstance(parentWin, wx.Window): |
d14a1e28 | 695 | return parentWin.GetSizer() |
0cbb7d59 | 696 | elif xxx.__class__ in [xxxMenu, xxxMenuItem, xxxSeparator]: return None |
6165053b RR |
697 | elif xxx.__class__ in [xxxToolBar, xxxMenuBar]: |
698 | # If it's the main toolbar or menubar, we can't really select it | |
c0026696 | 699 | if xxx.parent.__class__ == xxxFrame: return None |
837db46d | 700 | elif isinstance(xxx.parent, xxxToolBar): |
c0026696 | 701 | # Select complete toolbar |
03319b65 | 702 | return parentWin |
64b9ac75 RR |
703 | elif isinstance(xxx.parent, xxxStdDialogButtonSizer): |
704 | # This sizer returns non-existing children | |
705 | for ch in parentWin.GetChildren(): | |
706 | if ch.GetWindow() and ch.GetWindow().GetName() == xxx.name: | |
707 | return ch.GetWindow() | |
708 | return None | |
306b6fe9 RR |
709 | elif xxx.parent.__class__ in [xxxChoicebook, xxxListbook]: |
710 | # First window is controld | |
711 | return parentWin.GetChildren()[self.ItemIndex(item)+1] | |
d14a1e28 | 712 | # Otherwise get parent's object and it's child |
0cbb7d59 | 713 | child = parentWin.GetChildren()[self.WindowIndex(item)] |
d14a1e28 RD |
714 | # Return window or sizer for sizer items |
715 | if child.GetClassName() == 'wxSizerItem': | |
716 | if child.IsWindow(): child = child.GetWindow() | |
717 | elif child.IsSizer(): | |
718 | child = child.GetSizer() | |
d14a1e28 RD |
719 | return child |
720 | ||
721 | def OnSelChanged(self, evt): | |
83173c7a | 722 | if self.selectionChanging: return |
2458faeb | 723 | self.selectionChanging = True |
83173c7a RR |
724 | self.UnselectAll() |
725 | self.SelectItem(evt.GetItem()) | |
2458faeb | 726 | self.selectionChanging = False |
fd919451 RR |
727 | |
728 | def ChangeSelection(self, item): | |
d14a1e28 RD |
729 | # Apply changes |
730 | # !!! problem with wxGTK - GetOldItem is Ok if nothing selected | |
731 | #oldItem = evt.GetOldItem() | |
732 | status = '' | |
733 | oldItem = self.selection | |
13542f49 RD |
734 | # use GetItemParent as a way to determine if the itemId is still valid |
735 | if oldItem and self.GetItemParent(oldItem): | |
d14a1e28 RD |
736 | xxx = self.GetPyData(oldItem) |
737 | # If some data was modified, apply changes | |
738 | if g.panel.IsModified(): | |
739 | self.Apply(xxx, oldItem) | |
d14a1e28 RD |
740 | if g.testWin: |
741 | if g.testWin.highLight: | |
742 | g.testWin.highLight.Remove() | |
743 | self.needUpdate = True | |
744 | status = 'Changes were applied' | |
745 | g.frame.SetStatusText(status) | |
746 | # Generate view | |
fd919451 | 747 | self.selection = item |
d14a1e28 RD |
748 | if not self.selection.IsOk(): |
749 | self.selection = None | |
750 | return | |
751 | xxx = self.GetPyData(self.selection) | |
752 | # Update panel | |
753 | g.panel.SetData(xxx) | |
754 | # Update tools | |
755 | g.tools.UpdateUI() | |
d6922577 | 756 | # Highlighting is done in OnIdle |
d14a1e28 RD |
757 | self.pendingHighLight = self.selection |
758 | ||
759 | # Check if item is in testWin subtree | |
760 | def IsHighlatable(self, item): | |
761 | if item == g.testWin.item: return False | |
762 | while item != self.root: | |
763 | item = self.GetItemParent(item) | |
75aa1946 RR |
764 | if item == g.testWin.item: |
765 | return True | |
d14a1e28 RD |
766 | return False |
767 | ||
768 | # Highlight selected item | |
769 | def HighLight(self, item): | |
770 | self.pendingHighLight = None | |
771 | # Can highlight only with some top-level windows | |
772 | if not g.testWin or self.GetPyData(g.testWin.item).treeObject().__class__ \ | |
773 | not in [xxxDialog, xxxPanel, xxxFrame]: | |
774 | return | |
775 | # If a control from another window is selected, remove highlight | |
776 | if not self.IsHighlatable(item): | |
777 | if g.testWin.highLight: g.testWin.highLight.Remove() | |
778 | return | |
779 | # Get window/sizer object | |
64b9ac75 | 780 | obj = self.FindNodeObject(item) |
75aa1946 RR |
781 | xxx = self.GetPyData(item).treeObject() |
782 | # Remove existing HL if item not found or is hidden | |
783 | if not obj or xxx.hasStyle and xxx.params.get('hidden', False): | |
0cbb7d59 RR |
784 | if g.testWin.highLight: g.testWin.highLight.Remove() |
785 | return | |
8c64c153 | 786 | pos = self.FindNodePos(item, obj) |
d14a1e28 RD |
787 | size = obj.GetSize() |
788 | # Highlight | |
d6922577 | 789 | # Negative positions are not working quite well |
8c64c153 RR |
790 | hl = g.testWin.highLight |
791 | # If highlight object has the same size SetDimension does not repaint it | |
792 | # so we must remove the old HL window | |
793 | if hl and hl.size == size: | |
794 | hl.Remove() | |
795 | hl = None | |
796 | if hl: | |
797 | hl.Replace(pos, size) | |
d14a1e28 | 798 | else: |
8c64c153 RR |
799 | g.testWin.highLight = hl = HighLightBox(pos, size) |
800 | hl.Refresh() | |
801 | hl.item = item | |
d14a1e28 RD |
802 | |
803 | def ShowTestWindow(self, item): | |
804 | xxx = self.GetPyData(item) | |
805 | if g.panel.IsModified(): | |
806 | self.Apply(xxx, item) # apply changes | |
306b6fe9 RR |
807 | availableViews = ['wxFrame', 'wxPanel', 'wxDialog', |
808 | 'wxMenuBar', 'wxToolBar', 'wxWizard', | |
809 | 'wxWizardPageSimple'] | |
810 | originalItem = item | |
811 | # Walk up the tree until we find an item that has a view | |
812 | while item and self.GetPyData(item).treeObject().className not in availableViews: | |
813 | item = self.GetItemParent(item) | |
814 | if not item or not item.IsOk(): | |
29a41103 | 815 | wx.LogMessage('No view for this element (yet)') |
d14a1e28 RD |
816 | return |
817 | # Show item in bold | |
818 | if g.testWin: # Reset old | |
e2dc45d8 | 819 | self.UnselectAll() |
d14a1e28 | 820 | self.SetItemBold(g.testWin.item, False) |
306b6fe9 | 821 | try: |
29a41103 | 822 | wx.BeginBusyCursor() |
306b6fe9 RR |
823 | self.CreateTestWin(item) |
824 | finally: | |
29a41103 | 825 | wx.EndBusyCursor() |
d6922577 | 826 | # Maybe an error occurred, so we need to test |
306b6fe9 RR |
827 | if g.testWin: |
828 | self.SetItemBold(g.testWin.item) | |
829 | # Select original item | |
830 | self.ChangeSelection(originalItem) | |
d14a1e28 RD |
831 | |
832 | # Double-click on Linux | |
833 | def OnItemActivated(self, evt): | |
834 | if evt.GetItem() != self.root: | |
835 | self.ShowTestWindow(evt.GetItem()) | |
836 | ||
837 | # Double-click on Windows | |
838 | def OnDClick(self, evt): | |
839 | item, flags = self.HitTest(evt.GetPosition()) | |
29a41103 | 840 | if flags in [wx.TREE_HITTEST_ONITEMBUTTON, wx.TREE_HITTEST_ONITEMLABEL]: |
d14a1e28 RD |
841 | if item != self.root: self.ShowTestWindow(item) |
842 | else: | |
843 | evt.Skip() | |
844 | ||
845 | def OnItemExpandedCollapsed(self, evt): | |
846 | # Update tool palette | |
847 | g.tools.UpdateUI() | |
848 | evt.Skip() | |
849 | ||
850 | # (re)create test window | |
851 | def CreateTestWin(self, item): | |
852 | testWin = g.testWin | |
853 | # Create a window with this resource | |
854 | xxx = self.GetPyData(item).treeObject() | |
d14a1e28 RD |
855 | # Close old window, remember where it was |
856 | highLight = None | |
857 | if testWin: | |
858 | pos = testWin.GetPosition() | |
859 | if item == testWin.item: | |
860 | # Remember highlight if same top-level window | |
861 | if testWin.highLight: | |
862 | highLight = testWin.highLight.item | |
863 | if xxx.className == 'wxPanel': | |
864 | if testWin.highLight: | |
865 | testWin.pendingHighLight = highLight | |
866 | testWin.highLight.Remove() | |
867 | testWin.panel.Destroy() | |
868 | testWin.panel = None | |
869 | else: | |
870 | testWin.Destroy() | |
871 | testWin = g.testWin = None | |
872 | else: | |
873 | testWin.Destroy() | |
874 | testWin = g.testWin = None | |
875 | else: | |
876 | pos = g.testWinPos | |
877 | # Save in memory FS | |
878 | memFile = MemoryFile('xxx.xrc') | |
03319b65 | 879 | # Create memory XML file |
b372319f | 880 | elem = xxx.node.cloneNode(True) |
d14a1e28 RD |
881 | if not xxx.name: |
882 | name = 'noname' | |
883 | else: | |
884 | name = xxx.name | |
885 | elem.setAttribute('name', STD_NAME) | |
34b29ae7 RR |
886 | oldTestNode = self.testElem |
887 | self.testElem = elem | |
888 | self.mainNode.replaceChild(elem, oldTestNode) | |
889 | oldTestNode.unlink() | |
64bce500 RR |
890 | # Replace wizard page class temporarily |
891 | if xxx.__class__ in [xxxWizardPage, xxxWizardPageSimple]: | |
892 | oldCl = elem.getAttribute('class') | |
893 | elem.setAttribute('class', 'wxPanel') | |
d14a1e28 | 894 | parent = elem.parentNode |
03319b65 RR |
895 | encd = self.rootObj.params['encoding'].value() |
896 | if not encd: encd = None | |
34b29ae7 RR |
897 | try: |
898 | self.dom.writexml(memFile, encoding=encd) | |
899 | except: | |
900 | inf = sys.exc_info() | |
29a41103 RD |
901 | wx.LogError(traceback.format_exception(inf[0], inf[1], None)[-1]) |
902 | wx.LogError('Error writing temporary file') | |
d14a1e28 | 903 | memFile.close() # write to wxMemoryFS |
29a41103 | 904 | xmlFlags = xrc.XRC_NO_SUBCLASSING |
d14a1e28 | 905 | # Use translations if encoding is not specified |
9a69d0aa | 906 | if not g.currentEncoding: |
29a41103 RD |
907 | xmlFlags != xrc.XRC_USE_LOCALE |
908 | res = xrc.XmlResource('', xmlFlags) | |
00d15346 RR |
909 | xrc.XmlResource.Set(res) # set as global |
910 | # Register handlers | |
c0d5ae74 | 911 | addHandlers() |
a6166197 | 912 | # Same module list |
d14a1e28 | 913 | res.Load('memory:xxx.xrc') |
a4c013b2 RR |
914 | try: |
915 | if xxx.__class__ == xxxFrame: | |
916 | # Frame can't have many children, | |
917 | # but it's first child possibly can... | |
918 | # child = self.GetFirstChild(item)[0] | |
919 | # if child.IsOk() and self.GetPyData(child).__class__ == xxxPanel: | |
920 | # # Clean-up before recursive call or error | |
29a41103 RD |
921 | # wx.MemoryFSHandler.RemoveFile('xxx.xrc') |
922 | # wx.EndBusyCursor() | |
a4c013b2 RR |
923 | # self.CreateTestWin(child) |
924 | # return | |
925 | # This currently works under GTK, but not under MSW | |
29a41103 | 926 | testWin = g.testWin = wx.PreFrame() |
a4c013b2 RR |
927 | res.LoadOnFrame(testWin, g.frame, STD_NAME) |
928 | # Create status bar | |
929 | testWin.panel = testWin | |
306b6fe9 | 930 | #testWin.CreateStatusBar() |
a4c013b2 | 931 | testWin.SetClientSize(testWin.GetBestSize()) |
a4c013b2 RR |
932 | testWin.SetPosition(pos) |
933 | testWin.Show(True) | |
934 | elif xxx.__class__ == xxxPanel: | |
935 | # Create new frame | |
936 | if not testWin: | |
29a41103 | 937 | testWin = g.testWin = wx.Frame(g.frame, -1, 'Panel: ' + name, |
a4c013b2 RR |
938 | pos=pos, name=STD_NAME) |
939 | testWin.panel = res.LoadPanel(testWin, STD_NAME) | |
940 | testWin.SetClientSize(testWin.GetBestSize()) | |
941 | testWin.Show(True) | |
942 | elif xxx.__class__ == xxxDialog: | |
d84cc8c1 | 943 | testWin = g.testWin = res.LoadDialog(g.frame, STD_NAME) |
a4c013b2 RR |
944 | testWin.panel = testWin |
945 | testWin.Layout() | |
946 | testWin.SetPosition(pos) | |
947 | testWin.Show(True) | |
29a41103 RD |
948 | # Dialog's default code does not produce wx.EVT_CLOSE |
949 | wx.EVT_BUTTON(testWin, wx.ID_OK, self.OnCloseTestWin) | |
950 | wx.EVT_BUTTON(testWin, wx.ID_CANCEL, self.OnCloseTestWin) | |
64bce500 | 951 | elif xxx.__class__ == xxxWizard: |
29a41103 | 952 | wiz = wx.wizard.PreWizard() |
d84cc8c1 | 953 | res.LoadOnObject(wiz, g.frame, STD_NAME, 'wxWizard') |
64bce500 RR |
954 | # Find first page (don't know better way) |
955 | firstPage = None | |
956 | for w in wiz.GetChildren(): | |
29a41103 | 957 | if isinstance(w, wx.wizard.WizardPage): |
64bce500 RR |
958 | firstPage = w |
959 | break | |
960 | if not firstPage: | |
29a41103 | 961 | wx.LogError('Wizard is empty') |
64bce500 RR |
962 | else: |
963 | # Wizard should be modal | |
964 | self.SetItemBold(item) | |
965 | wiz.RunWizard(w) | |
966 | self.SetItemBold(item, False) | |
967 | wiz.Destroy() | |
968 | elif xxx.__class__ in [xxxWizardPage, xxxWizardPageSimple]: | |
969 | # Create new frame | |
970 | if not testWin: | |
29a41103 | 971 | testWin = g.testWin = wx.Frame(g.frame, -1, 'Wizard page: ' + name, |
64bce500 | 972 | pos=pos, name=STD_NAME) |
29a41103 | 973 | testWin.panel = wx.PrePanel() |
64bce500 RR |
974 | res.LoadOnObject(testWin.panel, testWin, STD_NAME, 'wxPanel') |
975 | testWin.SetClientSize(testWin.GetBestSize()) | |
976 | testWin.Show(True) | |
a4c013b2 | 977 | elif xxx.__class__ == xxxMenuBar: |
29a41103 | 978 | testWin = g.testWin = wx.Frame(g.frame, -1, 'MenuBar: ' + name, |
a4c013b2 RR |
979 | pos=pos, name=STD_NAME) |
980 | testWin.panel = None | |
981 | # Set status bar to display help | |
982 | testWin.CreateStatusBar() | |
983 | testWin.menuBar = res.LoadMenuBar(STD_NAME) | |
984 | testWin.SetMenuBar(testWin.menuBar) | |
985 | testWin.Show(True) | |
986 | elif xxx.__class__ == xxxToolBar: | |
29a41103 | 987 | testWin = g.testWin = wx.Frame(g.frame, -1, 'ToolBar: ' + name, |
d14a1e28 | 988 | pos=pos, name=STD_NAME) |
a4c013b2 RR |
989 | testWin.panel = None |
990 | # Set status bar to display help | |
991 | testWin.CreateStatusBar() | |
992 | testWin.toolBar = res.LoadToolBar(testWin, STD_NAME) | |
993 | testWin.SetToolBar(testWin.toolBar) | |
994 | testWin.Show(True) | |
538a0c0d | 995 | # Catch some events, set highlight |
64bce500 RR |
996 | if testWin: |
997 | testWin.item = item | |
29a41103 | 998 | wx.EVT_CLOSE(testWin, self.OnCloseTestWin) |
538a0c0d | 999 | wx.EVT_SIZE(testWin, self.OnSizeTestWin) |
64bce500 RR |
1000 | testWin.highLight = None |
1001 | if highLight and not self.pendingHighLight: | |
1002 | self.HighLight(highLight) | |
a4c013b2 RR |
1003 | except: |
1004 | if g.testWin: | |
1005 | self.SetItemBold(item, False) | |
1006 | g.testWinPos = g.testWin.GetPosition() | |
1007 | g.testWin.Destroy() | |
1008 | g.testWin = None | |
1009 | inf = sys.exc_info() | |
29a41103 RD |
1010 | wx.LogError(traceback.format_exception(inf[0], inf[1], None)[-1]) |
1011 | wx.LogError('Error loading resource') | |
c0d5ae74 RR |
1012 | # Cleanup |
1013 | res.Unload('xxx.xrc') | |
1014 | xrc.XmlResource.Set(None) | |
29a41103 | 1015 | wx.MemoryFSHandler.RemoveFile('xxx.xrc') |
d14a1e28 | 1016 | |
64bce500 RR |
1017 | def CloseTestWindow(self): |
1018 | if not g.testWin: return | |
d14a1e28 | 1019 | self.SetItemBold(g.testWin.item, False) |
016f67ba | 1020 | g.frame.tb.ToggleTool(g.frame.ID_TOOL_LOCATE, False) |
d14a1e28 RD |
1021 | g.testWinPos = g.testWin.GetPosition() |
1022 | g.testWin.Destroy() | |
1023 | g.testWin = None | |
1024 | ||
64bce500 RR |
1025 | def OnCloseTestWin(self, evt): |
1026 | self.CloseTestWindow() | |
1027 | ||
538a0c0d RR |
1028 | def OnSizeTestWin(self, evt): |
1029 | if g.testWin.highLight: | |
1030 | self.HighLight(g.testWin.highLight.item) | |
1031 | evt.Skip() | |
1032 | ||
0cbb7d59 RR |
1033 | # Return index in parent, for real window children |
1034 | def WindowIndex(self, item): | |
1035 | n = 0 # index of sibling | |
1036 | prev = self.GetPrevSibling(item) | |
1037 | while prev.IsOk(): | |
1038 | # MenuBar is not a child | |
1039 | if not isinstance(self.GetPyData(prev), xxxMenuBar): | |
1040 | n += 1 | |
1041 | prev = self.GetPrevSibling(prev) | |
1042 | return n | |
1043 | ||
d14a1e28 RD |
1044 | # Return item index in parent |
1045 | def ItemIndex(self, item): | |
1046 | n = 0 # index of sibling | |
1047 | prev = self.GetPrevSibling(item) | |
1048 | while prev.IsOk(): | |
1049 | prev = self.GetPrevSibling(prev) | |
1050 | n += 1 | |
1051 | return n | |
1052 | ||
1053 | # Full tree index of an item - list of positions | |
1054 | def ItemFullIndex(self, item): | |
1055 | if not item.IsOk(): return None | |
1056 | l = [] | |
1057 | while item != self.root: | |
1058 | l.insert(0, self.ItemIndex(item)) | |
1059 | item = self.GetItemParent(item) | |
1060 | return l | |
1061 | # Get item position from full index | |
1062 | def ItemAtFullIndex(self, index): | |
29a41103 | 1063 | if index is None: return wx.TreeItemId() |
d14a1e28 RD |
1064 | item = self.root |
1065 | for i in index: | |
fdc1a8be | 1066 | item = self.GetFirstChild(item)[0] |
d14a1e28 RD |
1067 | for k in range(i): item = self.GetNextSibling(item) |
1068 | return item | |
1069 | ||
1070 | # True if next item should be inserted after current (vs. appended to it) | |
1071 | def NeedInsert(self, item): | |
1072 | xxx = self.GetPyData(item) | |
1073 | if item == self.root: return False # root item | |
1074 | if xxx.hasChildren and not self.GetChildrenCount(item, False): | |
1075 | return False | |
1076 | return not (self.IsExpanded(item) and self.GetChildrenCount(item, False)) | |
1077 | ||
83173c7a RR |
1078 | # Override to use like single-selection tree |
1079 | def GetSelection(self): | |
a24d7726 | 1080 | return self.selection |
83173c7a RR |
1081 | def SelectItem(self, item): |
1082 | self.UnselectAll() | |
1083 | self.ChangeSelection(item) | |
29a41103 | 1084 | wx.TreeCtrl.SelectItem(self, item) |
83173c7a | 1085 | |
d14a1e28 RD |
1086 | # Pull-down |
1087 | def OnRightDown(self, evt): | |
1088 | pullDownMenu = g.pullDownMenu | |
1089 | # select this item | |
1090 | pt = evt.GetPosition(); | |
1091 | item, flags = self.HitTest(pt) | |
29a41103 | 1092 | if item.Ok() and flags & wx.TREE_HITTEST_ONITEM: |
d14a1e28 RD |
1093 | self.SelectItem(item) |
1094 | ||
1095 | # Setup menu | |
29a41103 | 1096 | menu = wx.Menu() |
d14a1e28 RD |
1097 | |
1098 | item = self.selection | |
1099 | if not item: | |
1100 | menu.Append(g.pullDownMenu.ID_EXPAND, 'Expand', 'Expand tree') | |
1101 | menu.Append(g.pullDownMenu.ID_COLLAPSE, 'Collapse', 'Collapse tree') | |
1102 | else: | |
1103 | # self.ctrl = evt.ControlDown() # save Ctrl state | |
1104 | # self.shift = evt.ShiftDown() # and Shift too | |
29a41103 | 1105 | m = wx.Menu() # create menu |
d14a1e28 RD |
1106 | if self.ctrl: |
1107 | needInsert = True | |
1108 | else: | |
1109 | needInsert = self.NeedInsert(item) | |
1110 | if item == self.root or needInsert and self.GetItemParent(item) == self.root: | |
1111 | SetMenu(m, pullDownMenu.topLevel) | |
03319b65 RR |
1112 | m.AppendSeparator() |
1113 | m.Append(ID_NEW.REF, 'reference...', 'Create object_ref node') | |
b372319f | 1114 | m.Append(ID_NEW.COMMENT, 'comment', 'Create comment node') |
d14a1e28 RD |
1115 | else: |
1116 | xxx = self.GetPyData(item).treeObject() | |
1117 | # Check parent for possible child nodes if inserting sibling | |
1118 | if needInsert: xxx = xxx.parent | |
1119 | if xxx.__class__ == xxxMenuBar: | |
1120 | m.Append(ID_NEW.MENU, 'Menu', 'Create menu') | |
1121 | elif xxx.__class__ in [xxxToolBar, xxxTool] or \ | |
1122 | xxx.__class__ == xxxSeparator and xxx.parent.__class__ == xxxToolBar: | |
1123 | SetMenu(m, pullDownMenu.toolBarControls) | |
1124 | elif xxx.__class__ in [xxxMenu, xxxMenuItem]: | |
1125 | SetMenu(m, pullDownMenu.menuControls) | |
64b9ac75 RR |
1126 | elif xxx.__class__ == xxxStdDialogButtonSizer: |
1127 | SetMenu(m, pullDownMenu.stdButtons) | |
d14a1e28 RD |
1128 | else: |
1129 | SetMenu(m, pullDownMenu.controls) | |
306b6fe9 | 1130 | if xxx.__class__ in [xxxNotebook, xxxChoicebook, xxxListbook]: |
d14a1e28 RD |
1131 | m.Enable(m.FindItem('sizer'), False) |
1132 | elif not (xxx.isSizer or xxx.parent and xxx.parent.isSizer): | |
1133 | m.Enable(ID_NEW.SPACER, False) | |
f65bb0f8 RD |
1134 | if xxx.__class__ is not xxxFrame: |
1135 | m.Enable(ID_NEW.MENU_BAR, False) | |
c0d5ae74 | 1136 | # Add custom controls menu |
8c64c153 RR |
1137 | if len(pullDownMenu.custom) > 2: |
1138 | SetMenu(m, [pullDownMenu.custom]) | |
a6166197 RR |
1139 | m.AppendSeparator() |
1140 | m.Append(ID_NEW.REF, 'reference...', 'Create object_ref node') | |
1141 | m.Append(ID_NEW.COMMENT, 'comment', 'Create comment node') | |
d14a1e28 RD |
1142 | # Select correct label for create menu |
1143 | if not needInsert: | |
1144 | if self.shift: | |
29a41103 | 1145 | menu.AppendMenu(wx.NewId(), 'Insert Child', m, |
d14a1e28 RD |
1146 | 'Create child object as the first child') |
1147 | else: | |
29a41103 | 1148 | menu.AppendMenu(wx.NewId(), 'Append Child', m, |
d14a1e28 RD |
1149 | 'Create child object as the last child') |
1150 | else: | |
1151 | if self.shift: | |
29a41103 | 1152 | menu.AppendMenu(wx.NewId(), 'Create Sibling', m, |
d14a1e28 RD |
1153 | 'Create sibling before selected object') |
1154 | else: | |
29a41103 | 1155 | menu.AppendMenu(wx.NewId(), 'Create Sibling', m, |
d14a1e28 RD |
1156 | 'Create sibling after selected object') |
1157 | # Build replace menu | |
1158 | if item != self.root: | |
1159 | xxx = self.GetPyData(item).treeObject() | |
29a41103 | 1160 | m = wx.Menu() # create replace menu |
d14a1e28 RD |
1161 | if xxx.__class__ == xxxMenuBar: |
1162 | m.Append(1000 + ID_NEW.MENU, 'Menu', 'Create menu') | |
1163 | elif xxx.__class__ in [xxxMenu, xxxMenuItem]: | |
64b9ac75 | 1164 | SetMenu(m, pullDownMenu.menuControls, shift=True) |
d14a1e28 RD |
1165 | elif xxx.__class__ == xxxToolBar and \ |
1166 | self.GetItemParent(item) == self.root: | |
64b9ac75 | 1167 | SetMenu(m, [], shift=True) |
d14a1e28 | 1168 | elif xxx.__class__ in [xxxFrame, xxxDialog, xxxPanel]: |
64b9ac75 | 1169 | SetMenu(m, [ |
d14a1e28 RD |
1170 | (ID_NEW.PANEL, 'Panel', 'Create panel'), |
1171 | (ID_NEW.DIALOG, 'Dialog', 'Create dialog'), | |
64b9ac75 | 1172 | (ID_NEW.FRAME, 'Frame', 'Create frame')], shift=True) |
75aa1946 | 1173 | elif xxx.isSizer and self.ItemHasChildren(item): |
64b9ac75 | 1174 | SetMenu(m, pullDownMenu.sizers, shift=True) |
d14a1e28 | 1175 | else: |
64b9ac75 | 1176 | SetMenu(m, pullDownMenu.controls, shift=True) |
b372319f RR |
1177 | if xxx.isElement: |
1178 | id = wx.NewId() | |
1179 | menu.AppendMenu(id, 'Replace With', m) | |
1180 | if not m.GetMenuItemCount(): menu.Enable(id, False) | |
1181 | menu.Append(pullDownMenu.ID_SUBCLASS, 'Subclass...', | |
1182 | 'Set "subclass" property') | |
d14a1e28 RD |
1183 | menu.AppendSeparator() |
1184 | # Not using standart IDs because we don't want to show shortcuts | |
29a41103 RD |
1185 | menu.Append(wx.ID_CUT, 'Cut', 'Cut to the clipboard') |
1186 | menu.Append(wx.ID_COPY, 'Copy', 'Copy to the clipboard') | |
d14a1e28 RD |
1187 | if self.ctrl and item != self.root: |
1188 | menu.Append(pullDownMenu.ID_PASTE_SIBLING, 'Paste Sibling', | |
1189 | 'Paste from the clipboard as a sibling') | |
1190 | else: | |
29a41103 | 1191 | menu.Append(wx.ID_PASTE, 'Paste', 'Paste from the clipboard') |
d14a1e28 RD |
1192 | menu.Append(pullDownMenu.ID_DELETE, |
1193 | 'Delete', 'Delete object') | |
1194 | if self.ItemHasChildren(item): | |
1195 | menu.AppendSeparator() | |
1196 | menu.Append(pullDownMenu.ID_EXPAND, 'Expand', 'Expand subtree') | |
1197 | menu.Append(pullDownMenu.ID_COLLAPSE, 'Collapse', 'Collapse subtree') | |
1198 | self.PopupMenu(menu, evt.GetPosition()) | |
1199 | menu.Destroy() | |
1200 | ||
c37cba89 RR |
1201 | # Redefine to force the update of font dimentions on wxGTK |
1202 | if wx.Platform == '__WXGTK__': | |
1203 | def SetItemBold(self, item, state=True): | |
1204 | wx.TreeCtrl.SetItemBold(self, item, state) | |
1205 | self.SetIndent(self.GetIndent()) | |
75aa1946 | 1206 | |
d14a1e28 RD |
1207 | # Apply changes |
1208 | def Apply(self, xxx, item): | |
1209 | g.panel.Apply() | |
1210 | # Update tree view | |
1211 | xxx = xxx.treeObject() | |
1212 | if xxx.hasName and self.GetItemText(item) != xxx.name: | |
1213 | self.SetItemText(item, xxx.treeName()) | |
1214 | # Item width may have changed | |
1215 | # !!! Tric to update tree width (wxGTK, ??) | |
1216 | self.SetIndent(self.GetIndent()) | |
b372319f RR |
1217 | elif xxx.className == 'comment': |
1218 | self.SetItemText(item, xxx.treeName()) | |
d14a1e28 RD |
1219 | # Change tree icon for sizers |
1220 | if isinstance(xxx, xxxBoxSizer): | |
1221 | self.SetItemImage(item, xxx.treeImage()) | |
1222 | # Set global modified state | |
03319b65 | 1223 | g.frame.SetModified() |
1fded56b | 1224 | |
fe295b0d RR |
1225 | def OnBeginLabelEdit(self, evt): |
1226 | xxx = self.GetPyData(evt.GetItem()) | |
1227 | if xxx.isElement: | |
1228 | evt.Veto() | |
1229 | else: | |
1230 | evt.Skip() | |
1231 | ||
1232 | def OnEndLabelEdit(self, evt): | |
1233 | xxx = self.GetPyData(evt.GetItem()) | |
1234 | node = xxx.node | |
1235 | if not xxx.isElement: | |
1236 | node.data = evt.GetLabel() | |
1237 | g.panel.SetData(xxx) | |
1238 | evt.Skip() |