1 | """ |
---|
2 | FitPanel class contains fields allowing to fit models and data |
---|
3 | |
---|
4 | :note: For Fit to be performed the user should check at least one parameter |
---|
5 | on fit Panel window. |
---|
6 | |
---|
7 | """ |
---|
8 | import wx |
---|
9 | from wx.aui import AuiNotebook as nb |
---|
10 | |
---|
11 | from sas.guiframe.panel_base import PanelBase |
---|
12 | from sas.guiframe.events import PanelOnFocusEvent |
---|
13 | from sas.guiframe.events import StatusEvent |
---|
14 | from sas.guiframe.dataFitting import check_data_validity |
---|
15 | |
---|
16 | import basepage |
---|
17 | import models |
---|
18 | _BOX_WIDTH = 80 |
---|
19 | |
---|
20 | |
---|
21 | class FitPanel(nb, PanelBase): |
---|
22 | """ |
---|
23 | FitPanel class contains fields allowing to fit models and data |
---|
24 | |
---|
25 | :note: For Fit to be performed the user should check at least one parameter |
---|
26 | on fit Panel window. |
---|
27 | |
---|
28 | """ |
---|
29 | ## Internal name for the AUI manager |
---|
30 | window_name = "Fit panel" |
---|
31 | ## Title to appear on top of the window |
---|
32 | window_caption = "Fit Panel " |
---|
33 | CENTER_PANE = True |
---|
34 | |
---|
35 | def __init__(self, parent, manager=None, *args, **kwargs): |
---|
36 | """ |
---|
37 | """ |
---|
38 | nb.__init__(self, parent, -1, |
---|
39 | style=wx.aui.AUI_NB_WINDOWLIST_BUTTON| |
---|
40 | wx.aui.AUI_NB_DEFAULT_STYLE| |
---|
41 | wx.CLIP_CHILDREN) |
---|
42 | PanelBase.__init__(self, parent) |
---|
43 | #self.SetWindowStyleFlag(style=nb.FNB_FANCY_TABS) |
---|
44 | self._manager = manager |
---|
45 | self.parent = parent |
---|
46 | self.event_owner = None |
---|
47 | #dictionary of miodel {model class name, model class} |
---|
48 | self.menu_mng = models.ModelManager() |
---|
49 | self.model_list_box = self.menu_mng.get_model_list() |
---|
50 | #pageClosedEvent = nb.EVT_FLATNOTEBOOK_PAGE_CLOSING |
---|
51 | self.model_dictionary = self.menu_mng.get_model_dictionary() |
---|
52 | self.pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE |
---|
53 | |
---|
54 | self.Bind(self.pageClosedEvent, self.on_close_page) |
---|
55 | ## save the title of the last page tab added |
---|
56 | self.fit_page_name = {} |
---|
57 | ## list of existing fit page |
---|
58 | self.opened_pages = {} |
---|
59 | #index of fit page |
---|
60 | self.fit_page_index = 0 |
---|
61 | #index of batch page |
---|
62 | self.batch_page_index = 0 |
---|
63 | #page of simultaneous fit |
---|
64 | self.sim_page = None |
---|
65 | self.batch_page = None |
---|
66 | self.fit_engine_type = "bumps" |
---|
67 | ## get the state of a page |
---|
68 | self.Bind(basepage.EVT_PAGE_INFO, self._onGetstate) |
---|
69 | self.Bind(basepage.EVT_PREVIOUS_STATE, self._onUndo) |
---|
70 | self.Bind(basepage.EVT_NEXT_STATE, self._onRedo) |
---|
71 | self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.on_page_changing) |
---|
72 | self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSED, self.on_closed) |
---|
73 | |
---|
74 | def on_closed(self, event): |
---|
75 | """ |
---|
76 | """ |
---|
77 | if self.GetPageCount() == 0: |
---|
78 | self.add_empty_page() |
---|
79 | self.enable_close_button() |
---|
80 | |
---|
81 | def save_project(self, doc=None): |
---|
82 | """ |
---|
83 | return an xml node containing state of the panel |
---|
84 | that guiframe can write to file |
---|
85 | """ |
---|
86 | msg = "" |
---|
87 | for uid, page in self.opened_pages.iteritems(): |
---|
88 | if page.batch_on: |
---|
89 | pos = self.GetPageIndex(page) |
---|
90 | if pos != -1 and page not in [self.sim_page, self.batch_page]: |
---|
91 | msg += "%s .\n" % str(self.GetPageText(pos)) |
---|
92 | else: |
---|
93 | data = page.get_data() |
---|
94 | # state must be cloned |
---|
95 | state = page.get_state().clone() |
---|
96 | if data is not None and page.model is not None: |
---|
97 | new_doc = self._manager.state_reader.write_toXML(data, |
---|
98 | state) |
---|
99 | if doc != None and hasattr(doc, "firstChild"): |
---|
100 | child = new_doc.firstChild.firstChild |
---|
101 | doc.firstChild.appendChild(child) |
---|
102 | else: |
---|
103 | doc = new_doc |
---|
104 | if msg.strip() != "": |
---|
105 | temp = "Save Project is not supported for Batch page.\n" |
---|
106 | temp += "The following pages will not be save:\n" |
---|
107 | message = temp + msg |
---|
108 | wx.PostEvent(self._manager.parent, StatusEvent(status=message, |
---|
109 | info="warning")) |
---|
110 | return doc |
---|
111 | |
---|
112 | def _on_engine_change(self, name='scipy'): |
---|
113 | """ |
---|
114 | """ |
---|
115 | for panel in self.opened_pages.values(): |
---|
116 | self.set_engine_helper(panel=panel, name=name) |
---|
117 | |
---|
118 | def set_engine_helper(self, panel, name='scipy'): |
---|
119 | """ |
---|
120 | """ |
---|
121 | self.fit_engine_type = name |
---|
122 | if panel not in[self.batch_page, self.sim_page]: |
---|
123 | panel._on_engine_change(name=self.fit_engine_type) |
---|
124 | |
---|
125 | def update_model_list(self): |
---|
126 | """ |
---|
127 | """ |
---|
128 | temp = self.menu_mng.update() |
---|
129 | if len(temp): |
---|
130 | self.model_list_box = temp |
---|
131 | return temp |
---|
132 | |
---|
133 | def reset_pmodel_list(self): |
---|
134 | """ |
---|
135 | """ |
---|
136 | temp = self.menu_mng.pulgins_reset() |
---|
137 | if len(temp): |
---|
138 | self.model_list_box = temp |
---|
139 | return temp |
---|
140 | |
---|
141 | def get_page_by_id(self, uid): |
---|
142 | """ |
---|
143 | """ |
---|
144 | if uid not in self.opened_pages: |
---|
145 | msg = "Fitpanel cannot find ID: %s in self.opened_pages" % str(uid) |
---|
146 | raise ValueError, msg |
---|
147 | else: |
---|
148 | return self.opened_pages[uid] |
---|
149 | |
---|
150 | def on_page_changing(self, event): |
---|
151 | """ |
---|
152 | calls the function when the current event handler has exited. avoiding |
---|
153 | to call panel on focus on a panel that is currently deleted |
---|
154 | """ |
---|
155 | wx.CallAfter(self.helper_on_page_change) |
---|
156 | |
---|
157 | def helper_on_page_change(self): |
---|
158 | """ |
---|
159 | """ |
---|
160 | pos = self.GetSelection() |
---|
161 | if pos != -1: |
---|
162 | selected_page = self.GetPage(pos) |
---|
163 | wx.PostEvent(self._manager.parent, |
---|
164 | PanelOnFocusEvent(panel=selected_page)) |
---|
165 | self.enable_close_button() |
---|
166 | |
---|
167 | def on_set_focus(self, event): |
---|
168 | """ |
---|
169 | """ |
---|
170 | pos = self.GetSelection() |
---|
171 | if pos != -1: |
---|
172 | selected_page = self.GetPage(pos) |
---|
173 | wx.PostEvent(self._manager.parent, |
---|
174 | PanelOnFocusEvent(panel=selected_page)) |
---|
175 | |
---|
176 | def get_data(self): |
---|
177 | """ |
---|
178 | get the data in the current page |
---|
179 | """ |
---|
180 | pos = self.GetSelection() |
---|
181 | if pos != -1: |
---|
182 | selected_page = self.GetPage(pos) |
---|
183 | return selected_page.get_data() |
---|
184 | |
---|
185 | def set_model_state(self, state): |
---|
186 | """ |
---|
187 | receive a state to reset the model in the current page |
---|
188 | """ |
---|
189 | pos = self.GetSelection() |
---|
190 | if pos != -1: |
---|
191 | selected_page = self.GetPage(pos) |
---|
192 | selected_page.set_model_state(state) |
---|
193 | |
---|
194 | def get_state(self): |
---|
195 | """ |
---|
196 | return the state of the current selected page |
---|
197 | """ |
---|
198 | pos = self.GetSelection() |
---|
199 | if pos != -1: |
---|
200 | selected_page = self.GetPage(pos) |
---|
201 | return selected_page.get_state() |
---|
202 | |
---|
203 | def close_all(self): |
---|
204 | """ |
---|
205 | remove all pages, used when a svs file is opened |
---|
206 | """ |
---|
207 | |
---|
208 | #get number of pages |
---|
209 | nop = self.GetPageCount() |
---|
210 | #use while-loop, for-loop will not do the job well. |
---|
211 | while (nop > 0): |
---|
212 | #delete the first page until no page exists |
---|
213 | page = self.GetPage(0) |
---|
214 | if self._manager.parent.panel_on_focus == page: |
---|
215 | self._manager.parent.panel_on_focus = None |
---|
216 | self._close_helper(selected_page=page) |
---|
217 | self.DeletePage(0) |
---|
218 | nop = nop - 1 |
---|
219 | |
---|
220 | ## save the title of the last page tab added |
---|
221 | self.fit_page_name = {} |
---|
222 | ## list of existing fit page |
---|
223 | self.opened_pages = {} |
---|
224 | |
---|
225 | def set_state(self, state): |
---|
226 | """ |
---|
227 | Restore state of the panel |
---|
228 | """ |
---|
229 | page_is_opened = False |
---|
230 | if state is not None: |
---|
231 | for uid, panel in self.opened_pages.iteritems(): |
---|
232 | #Don't return any panel is the exact same page is created |
---|
233 | if uid == panel.uid and panel.data == state.data: |
---|
234 | # the page is still opened |
---|
235 | panel.reset_page(state=state) |
---|
236 | panel.save_current_state() |
---|
237 | page_is_opened = True |
---|
238 | if not page_is_opened: |
---|
239 | if state.data.__class__.__name__ != 'list': |
---|
240 | #To support older state file format |
---|
241 | list_data = [state.data] |
---|
242 | else: |
---|
243 | #Todo: need new file format for the list |
---|
244 | list_data = state.data |
---|
245 | panel = self._manager.add_fit_page(data=list_data) |
---|
246 | # add data associated to the page created |
---|
247 | if panel is not None: |
---|
248 | self._manager.store_data(uid=panel.uid, |
---|
249 | data_list=list_data, |
---|
250 | caption=panel.window_caption) |
---|
251 | panel.reset_page(state=state) |
---|
252 | panel.save_current_state() |
---|
253 | |
---|
254 | def clear_panel(self): |
---|
255 | """ |
---|
256 | Clear and close all panels, used by guimanager |
---|
257 | """ |
---|
258 | |
---|
259 | #close all panels only when svs file opened |
---|
260 | self.close_all() |
---|
261 | self._manager.mypanels = [] |
---|
262 | |
---|
263 | def on_close_page(self, event=None): |
---|
264 | """ |
---|
265 | close page and remove all references to the closed page |
---|
266 | """ |
---|
267 | nbr_page = self.GetPageCount() |
---|
268 | selected_page = self.GetPage(self.GetSelection()) |
---|
269 | if nbr_page == 1: |
---|
270 | if selected_page.get_data() == None: |
---|
271 | if event is not None: |
---|
272 | event.Veto() |
---|
273 | return |
---|
274 | self._close_helper(selected_page=selected_page) |
---|
275 | |
---|
276 | def close_page_with_data(self, deleted_data): |
---|
277 | """ |
---|
278 | close a fit page when its data is completely remove from the graph |
---|
279 | """ |
---|
280 | if deleted_data is None: |
---|
281 | return |
---|
282 | for index in range(self.GetPageCount()): |
---|
283 | selected_page = self.GetPage(index) |
---|
284 | if hasattr(selected_page, "get_data"): |
---|
285 | data = selected_page.get_data() |
---|
286 | |
---|
287 | if data is None: |
---|
288 | #the fitpanel exists and only the initial fit page is open |
---|
289 | #with no selected data |
---|
290 | return |
---|
291 | if data.id == deleted_data.id: |
---|
292 | self._close_helper(selected_page) |
---|
293 | self.DeletePage(index) |
---|
294 | break |
---|
295 | |
---|
296 | def set_manager(self, manager): |
---|
297 | """ |
---|
298 | set panel manager |
---|
299 | |
---|
300 | :param manager: instance of plugin fitting |
---|
301 | |
---|
302 | """ |
---|
303 | self._manager = manager |
---|
304 | for pos in range(self.GetPageCount()): |
---|
305 | page = self.GetPage(pos) |
---|
306 | if page is not None: |
---|
307 | page.set_manager(self._manager) |
---|
308 | |
---|
309 | def set_model_list(self, dict): |
---|
310 | """ |
---|
311 | copy a dictionary of model into its own dictionary |
---|
312 | |
---|
313 | :param m_dict: dictionnary made of model name as key and model class |
---|
314 | as value |
---|
315 | """ |
---|
316 | self.model_list_box = dict |
---|
317 | |
---|
318 | def set_model_dict(self, m_dict): |
---|
319 | """ |
---|
320 | copy a dictionary of model name -> model object |
---|
321 | |
---|
322 | :param m_dict: dictionary linking model name -> model object |
---|
323 | """ |
---|
324 | |
---|
325 | def get_current_page(self): |
---|
326 | """ |
---|
327 | :return: the current page selected |
---|
328 | |
---|
329 | """ |
---|
330 | return self.GetPage(self.GetSelection()) |
---|
331 | |
---|
332 | def add_sim_page(self, caption="Const & Simul Fit"): |
---|
333 | """ |
---|
334 | Add the simultaneous fit page |
---|
335 | """ |
---|
336 | from simfitpage import SimultaneousFitPage |
---|
337 | page_finder = self._manager.get_page_finder() |
---|
338 | if caption == "Const & Simul Fit": |
---|
339 | self.sim_page = SimultaneousFitPage(self, page_finder=page_finder, |
---|
340 | id=-1, batch_on=False) |
---|
341 | self.sim_page.window_caption = caption |
---|
342 | self.sim_page.window_name = caption |
---|
343 | self.sim_page.uid = wx.NewId() |
---|
344 | self.AddPage(self.sim_page, caption, True) |
---|
345 | self.sim_page.set_manager(self._manager) |
---|
346 | self.enable_close_button() |
---|
347 | return self.sim_page |
---|
348 | else: |
---|
349 | self.batch_page = SimultaneousFitPage(self, batch_on=True, |
---|
350 | page_finder=page_finder) |
---|
351 | self.batch_page.window_caption = caption |
---|
352 | self.batch_page.window_name = caption |
---|
353 | self.batch_page.uid = wx.NewId() |
---|
354 | self.AddPage(self.batch_page, caption, True) |
---|
355 | self.batch_page.set_manager(self._manager) |
---|
356 | self.enable_close_button() |
---|
357 | return self.batch_page |
---|
358 | |
---|
359 | def add_empty_page(self): |
---|
360 | """ |
---|
361 | add an empty page |
---|
362 | """ |
---|
363 | """ |
---|
364 | if self.batch_on: |
---|
365 | from batchfitpage import BatchFitPage |
---|
366 | panel = BatchFitPage(parent=self) |
---|
367 | #Increment index of batch page |
---|
368 | self.batch_page_index += 1 |
---|
369 | index = self.batch_page_index |
---|
370 | else: |
---|
371 | """ |
---|
372 | from fitpage import FitPage |
---|
373 | panel = FitPage(parent=self) |
---|
374 | if self.batch_on: |
---|
375 | self.batch_page_index += 1 |
---|
376 | caption = "BatchPage" + str(self.batch_page_index) |
---|
377 | panel.set_index_model(self.batch_page_index) |
---|
378 | else: |
---|
379 | #Increment index of fit page |
---|
380 | self.fit_page_index += 1 |
---|
381 | caption = "FitPage" + str(self.fit_page_index) |
---|
382 | panel.set_index_model(self.fit_page_index) |
---|
383 | panel.batch_on = self.batch_on |
---|
384 | panel._set_save_flag(not panel.batch_on) |
---|
385 | panel.set_model_dictionary(self.model_dictionary) |
---|
386 | panel.populate_box(model_dict=self.model_list_box) |
---|
387 | panel.formfactor_combo_init() |
---|
388 | panel.set_manager(self._manager) |
---|
389 | panel.window_caption = caption |
---|
390 | panel.window_name = caption |
---|
391 | self.AddPage(panel, caption, select=True) |
---|
392 | self.opened_pages[panel.uid] = panel |
---|
393 | self.set_engine_helper(panel=panel) |
---|
394 | self._manager.create_fit_problem(panel.uid) |
---|
395 | self._manager.page_finder[panel.uid].add_data(panel.get_data()) |
---|
396 | self.enable_close_button() |
---|
397 | panel.on_set_focus(None) |
---|
398 | return panel |
---|
399 | |
---|
400 | def enable_close_button(self): |
---|
401 | """ |
---|
402 | display the close button on tab for more than 1 tabs else remove the |
---|
403 | close button |
---|
404 | """ |
---|
405 | if self.GetPageCount() <= 1: |
---|
406 | style = self.GetWindowStyleFlag() |
---|
407 | flag = wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB |
---|
408 | if style & wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB == flag: |
---|
409 | style = style & ~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB |
---|
410 | self.SetWindowStyle(style) |
---|
411 | else: |
---|
412 | style = self.GetWindowStyleFlag() |
---|
413 | flag = wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB |
---|
414 | if style & wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB != flag: |
---|
415 | style |= wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB |
---|
416 | self.SetWindowStyle(style) |
---|
417 | |
---|
418 | def delete_data(self, data): |
---|
419 | """ |
---|
420 | Delete the given data |
---|
421 | """ |
---|
422 | if data.__class__.__name__ != "list": |
---|
423 | raise ValueError, "Fitpanel delete_data expect list of id" |
---|
424 | else: |
---|
425 | n = self.GetPageCount() |
---|
426 | for page in self.opened_pages.values(): |
---|
427 | pos = self.GetPageIndex(page) |
---|
428 | temp_data = page.get_data() |
---|
429 | if temp_data is not None and temp_data.id in data: |
---|
430 | self.SetSelection(pos) |
---|
431 | self.on_close_page(event=None) |
---|
432 | temp = self.GetSelection() |
---|
433 | self.DeletePage(temp) |
---|
434 | if self.GetPageCount() == 0: |
---|
435 | self._manager.on_add_new_page(event=None) |
---|
436 | |
---|
437 | def set_data_on_batch_mode(self, data_list): |
---|
438 | """ |
---|
439 | Add all data to a single tab when the application is on Batch mode. |
---|
440 | However all data in the set of data must be either 1D or 2D type. |
---|
441 | This method presents option to select the data type before creating a |
---|
442 | tab. |
---|
443 | """ |
---|
444 | data_1d_list = [] |
---|
445 | data_2d_list = [] |
---|
446 | group_id_1d = wx.NewId() |
---|
447 | # separate data into data1d and data2d list |
---|
448 | for data in data_list: |
---|
449 | if data.__class__.__name__ == "Data1D": |
---|
450 | data.group_id = group_id_1d |
---|
451 | data_1d_list.append(data) |
---|
452 | if data.__class__.__name__ == "Data2D": |
---|
453 | data.group_id = wx.NewId() |
---|
454 | data_2d_list.append(data) |
---|
455 | page = None |
---|
456 | for p in self.opened_pages.values(): |
---|
457 | #check if there is an empty page to fill up |
---|
458 | if not check_data_validity(p.get_data()) and p.batch_on: |
---|
459 | |
---|
460 | #make sure data get placed in 1D empty tab if data is 1D |
---|
461 | #else data get place on 2D tab empty tab |
---|
462 | enable2D = p.get_view_mode() |
---|
463 | if (data.__class__.__name__ == "Data2D" and enable2D)\ |
---|
464 | or (data.__class__.__name__ == "Data1D" and not enable2D): |
---|
465 | page = p |
---|
466 | break |
---|
467 | if data_1d_list and data_2d_list: |
---|
468 | # need to warning the user that this batch is a special case |
---|
469 | from sas import BatchDataDialog |
---|
470 | dlg = BatchDataDialog(self) |
---|
471 | if dlg.ShowModal() == wx.ID_OK: |
---|
472 | data_type = dlg.get_data() |
---|
473 | dlg.Destroy() |
---|
474 | if page is None: |
---|
475 | page = self.add_empty_page() |
---|
476 | if data_type == 1: |
---|
477 | #user has selected only data1D |
---|
478 | page.fill_data_combobox(data_1d_list) |
---|
479 | elif data_type == 2: |
---|
480 | page.fill_data_combobox(data_2d_list) |
---|
481 | else: |
---|
482 | #the batch analysis is canceled |
---|
483 | dlg.Destroy() |
---|
484 | return None |
---|
485 | else: |
---|
486 | if page is None: |
---|
487 | page = self.add_empty_page() |
---|
488 | if data_1d_list and not data_2d_list: |
---|
489 | #only on type of data |
---|
490 | page.fill_data_combobox(data_1d_list) |
---|
491 | elif not data_1d_list and data_2d_list: |
---|
492 | page.fill_data_combobox(data_2d_list) |
---|
493 | |
---|
494 | pos = self.GetPageIndex(page) |
---|
495 | page.batch_on = self.batch_on |
---|
496 | page._set_save_flag(not page.batch_on) |
---|
497 | self.SetSelection(pos) |
---|
498 | self.opened_pages[page.uid] = page |
---|
499 | return page |
---|
500 | |
---|
501 | def set_data(self, data_list): |
---|
502 | """ |
---|
503 | Add a fitting page on the notebook contained by fitpanel |
---|
504 | |
---|
505 | :param data: data to fit |
---|
506 | |
---|
507 | :return panel : page just added for further used. |
---|
508 | is used by fitting module |
---|
509 | |
---|
510 | """ |
---|
511 | if not data_list: |
---|
512 | return None |
---|
513 | if self.batch_on: |
---|
514 | return self.set_data_on_batch_mode(data_list) |
---|
515 | else: |
---|
516 | data = None |
---|
517 | try: |
---|
518 | data = data_list[0] |
---|
519 | except: |
---|
520 | # for 'fitv' files |
---|
521 | data_list = [data] |
---|
522 | data = data_list[0] |
---|
523 | |
---|
524 | if data is None: |
---|
525 | return None |
---|
526 | for page in self.opened_pages.values(): |
---|
527 | #check if the selected data existing in the fitpanel |
---|
528 | pos = self.GetPageIndex(page) |
---|
529 | if not check_data_validity(page.get_data()) and not page.batch_on: |
---|
530 | #make sure data get placed in 1D empty tab if data is 1D |
---|
531 | #else data get place on 2D tab empty tab |
---|
532 | enable2D = page.get_view_mode() |
---|
533 | if (data.__class__.__name__ == "Data2D" and enable2D)\ |
---|
534 | or (data.__class__.__name__ == "Data1D" and not enable2D): |
---|
535 | page.batch_on = self.batch_on |
---|
536 | page._set_save_flag(not page.batch_on) |
---|
537 | page.fill_data_combobox(data_list) |
---|
538 | #caption = "FitPage" + str(self.fit_page_index) |
---|
539 | self.SetPageText(pos, page.window_caption) |
---|
540 | self.SetSelection(pos) |
---|
541 | return page |
---|
542 | #create new page and add data |
---|
543 | page = self.add_empty_page() |
---|
544 | pos = self.GetPageIndex(page) |
---|
545 | page.fill_data_combobox(data_list) |
---|
546 | self.opened_pages[page.uid] = page |
---|
547 | self.SetSelection(pos) |
---|
548 | return page |
---|
549 | |
---|
550 | def _onGetstate(self, event): |
---|
551 | """ |
---|
552 | copy the state of a page |
---|
553 | """ |
---|
554 | page = event.page |
---|
555 | if page.uid in self.fit_page_name: |
---|
556 | self.fit_page_name[page.uid].appendItem(page.createMemento()) |
---|
557 | |
---|
558 | def _onUndo(self, event): |
---|
559 | """ |
---|
560 | return the previous state of a given page is available |
---|
561 | """ |
---|
562 | page = event.page |
---|
563 | if page.uid in self.fit_page_name: |
---|
564 | if self.fit_page_name[page.uid].getCurrentPosition() == 0: |
---|
565 | state = None |
---|
566 | else: |
---|
567 | state = self.fit_page_name[page.uid].getPreviousItem() |
---|
568 | page._redo.Enable(True) |
---|
569 | page.reset_page(state) |
---|
570 | |
---|
571 | def _onRedo(self, event): |
---|
572 | """ |
---|
573 | return the next state available |
---|
574 | """ |
---|
575 | page = event.page |
---|
576 | if page.uid in self.fit_page_name: |
---|
577 | length = len(self.fit_page_name[page.uid]) |
---|
578 | if self.fit_page_name[page.uid].getCurrentPosition() == length - 1: |
---|
579 | state = None |
---|
580 | page._redo.Enable(False) |
---|
581 | page._redo.Enable(True) |
---|
582 | else: |
---|
583 | state = self.fit_page_name[page.uid].getNextItem() |
---|
584 | page.reset_page(state) |
---|
585 | |
---|
586 | def _close_helper(self, selected_page): |
---|
587 | """ |
---|
588 | Delete the given page from the notebook |
---|
589 | """ |
---|
590 | #remove hint page |
---|
591 | #if selected_page == self.hint_page: |
---|
592 | # return |
---|
593 | ## removing sim_page |
---|
594 | if selected_page == self.sim_page: |
---|
595 | self._manager.sim_page = None |
---|
596 | return |
---|
597 | if selected_page == self.batch_page: |
---|
598 | self._manager.batch_page = None |
---|
599 | return |
---|
600 | """ |
---|
601 | # The below is not working when delete #5 and still have #6. |
---|
602 | if selected_page.__class__.__name__ == "FitPage": |
---|
603 | self.fit_page_index -= 1 |
---|
604 | else: |
---|
605 | self.batch_page_index -= 1 |
---|
606 | """ |
---|
607 | ## closing other pages |
---|
608 | state = selected_page.createMemento() |
---|
609 | page_finder = self._manager.get_page_finder() |
---|
610 | ## removing fit page |
---|
611 | data = selected_page.get_data() |
---|
612 | #Don' t remove plot for 2D |
---|
613 | flag = True |
---|
614 | if data.__class__.__name__ == 'Data2D': |
---|
615 | flag = False |
---|
616 | if selected_page in page_finder: |
---|
617 | #Delete the name of the page into the list of open page |
---|
618 | for uid, list in self.opened_pages.iteritems(): |
---|
619 | #Don't return any panel is the exact same page is created |
---|
620 | |
---|
621 | if flag and selected_page.uid == uid: |
---|
622 | self._manager.remove_plot(uid, theory=False) |
---|
623 | break |
---|
624 | del page_finder[selected_page] |
---|
625 | |
---|
626 | #Delete the name of the page into the list of open page |
---|
627 | for uid, list in self.opened_pages.iteritems(): |
---|
628 | #Don't return any panel is the exact same page is created |
---|
629 | if selected_page.uid == uid: |
---|
630 | del self.opened_pages[selected_page.uid] |
---|
631 | break |
---|
632 | ##remove the check box link to the model name of this page (selected_page) |
---|
633 | try: |
---|
634 | self.sim_page.draw_page() |
---|
635 | except: |
---|
636 | ## that page is already deleted no need to remove check box on |
---|
637 | ##non existing page |
---|
638 | pass |
---|
639 | try: |
---|
640 | self.batch_page.draw_page() |
---|
641 | except: |
---|
642 | ## that page is already deleted no need to remove check box on |
---|
643 | ##non existing page |
---|
644 | pass |
---|