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