[e2f1023] | 1 | |
---|
| 2 | import numpy |
---|
| 3 | import string |
---|
[d89f09b] | 4 | import wx |
---|
[f22e626] | 5 | import sys |
---|
[1b1bbf9] | 6 | #from wx.lib.flatnotebook import FlatNotebook as nb |
---|
| 7 | from wx.aui import AuiNotebook as nb |
---|
[a93f525] | 8 | |
---|
[340c2b3] | 9 | from sans.guiframe.panel_base import PanelBase |
---|
[3cd5806] | 10 | from sans.guiframe.events import PanelOnFocusEvent |
---|
[6bbeacd4] | 11 | from sans.guiframe.events import StatusEvent |
---|
[66ff250] | 12 | |
---|
[cfc0913] | 13 | import basepage |
---|
[6bbeacd4] | 14 | import models |
---|
[330573d] | 15 | _BOX_WIDTH = 80 |
---|
| 16 | |
---|
| 17 | |
---|
[1b1bbf9] | 18 | class FitPanel(nb, PanelBase): |
---|
[925a30e] | 19 | |
---|
[d89f09b] | 20 | """ |
---|
[5062bbf] | 21 | FitPanel class contains fields allowing to fit models and data |
---|
| 22 | |
---|
| 23 | :note: For Fit to be performed the user should check at least one parameter |
---|
[d89f09b] | 24 | on fit Panel window. |
---|
| 25 | |
---|
| 26 | """ |
---|
| 27 | ## Internal name for the AUI manager |
---|
| 28 | window_name = "Fit panel" |
---|
| 29 | ## Title to appear on top of the window |
---|
| 30 | window_caption = "Fit Panel " |
---|
[2139c3f] | 31 | CENTER_PANE = True |
---|
[7437880] | 32 | |
---|
[6bbeacd4] | 33 | def __init__(self, parent, manager=None, *args, **kwargs): |
---|
[5062bbf] | 34 | """ |
---|
| 35 | """ |
---|
[1b1bbf9] | 36 | nb.__init__(self, parent, -1, |
---|
[3244cbe1] | 37 | style= wx.aui.AUI_NB_WINDOWLIST_BUTTON| |
---|
| 38 | wx.aui.AUI_NB_DEFAULT_STYLE| |
---|
| 39 | wx.CLIP_CHILDREN) |
---|
[3cd5806] | 40 | PanelBase.__init__(self, parent) |
---|
[1b1bbf9] | 41 | #self.SetWindowStyleFlag(style=nb.FNB_FANCY_TABS) |
---|
[6bbeacd4] | 42 | self._manager = manager |
---|
[340c2b3] | 43 | self.parent = parent |
---|
| 44 | self.event_owner = None |
---|
[d89f09b] | 45 | #dictionary of miodel {model class name, model class} |
---|
[6bbeacd4] | 46 | self.menu_mng = models.ModelManager() |
---|
[b2d9826] | 47 | self.model_list_box = self.menu_mng.get_model_list() |
---|
[1b1bbf9] | 48 | #pageClosedEvent = nb.EVT_FLATNOTEBOOK_PAGE_CLOSING |
---|
[f22e626] | 49 | self.pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE |
---|
[1b1bbf9] | 50 | |
---|
[f22e626] | 51 | self.Bind(self.pageClosedEvent, self.on_close_page) |
---|
[6bbeacd4] | 52 | ## save the title of the last page tab added |
---|
[2f189dc] | 53 | self.fit_page_name = {} |
---|
[cfc0913] | 54 | ## list of existing fit page |
---|
[2f189dc] | 55 | self.opened_pages = {} |
---|
| 56 | #page of simultaneous fit |
---|
[ffa69b6] | 57 | self.sim_page = None |
---|
[66ff250] | 58 | self.fit_engine_type = "scipy" |
---|
[cfc0913] | 59 | ## get the state of a page |
---|
| 60 | self.Bind(basepage.EVT_PAGE_INFO, self._onGetstate) |
---|
[330573d] | 61 | self.Bind(basepage.EVT_PREVIOUS_STATE, self._onUndo) |
---|
[fe496eeb] | 62 | self.Bind(basepage.EVT_NEXT_STATE, self._onRedo) |
---|
[90a7bbd] | 63 | self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.on_page_changing) |
---|
[f22e626] | 64 | self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSED, self.on_closed) |
---|
[1b1bbf9] | 65 | |
---|
[f22e626] | 66 | def on_closed(self, event): |
---|
| 67 | """ |
---|
| 68 | """ |
---|
[394ffa7] | 69 | if self.GetPageCount() == 0: |
---|
| 70 | self.add_empty_page() |
---|
| 71 | self.enable_close_button() |
---|
[f22e626] | 72 | |
---|
[4e78f56] | 73 | def save_project(self, doc=None): |
---|
| 74 | """ |
---|
| 75 | return an xml node containing state of the panel |
---|
| 76 | that guiframe can write to file |
---|
| 77 | """ |
---|
| 78 | for uid, page in self.opened_pages.iteritems(): |
---|
| 79 | data = page.get_data() |
---|
| 80 | # state must be cloned |
---|
| 81 | state = page.get_state().clone() |
---|
| 82 | if data is not None: |
---|
| 83 | new_doc = self._manager.state_reader.write_toXML(data, state) |
---|
| 84 | if doc != None and hasattr(doc, "firstChild"): |
---|
| 85 | child = new_doc.firstChild.firstChild |
---|
| 86 | doc.firstChild.appendChild(child) |
---|
| 87 | else: |
---|
| 88 | doc = new_doc |
---|
| 89 | return doc |
---|
[6bbeacd4] | 90 | |
---|
[66ff250] | 91 | def _on_engine_change(self, name='scipy'): |
---|
| 92 | """ |
---|
| 93 | """ |
---|
| 94 | for panel in self.opened_pages.values(): |
---|
| 95 | self.set_engine_helper(panel=panel, name=name) |
---|
| 96 | |
---|
| 97 | def set_engine_helper(self, panel, name='scipy'): |
---|
| 98 | """ |
---|
| 99 | """ |
---|
| 100 | self.fit_engine_type = name |
---|
| 101 | if panel != self.sim_page: |
---|
| 102 | panel._on_engine_change(name=self.fit_engine_type) |
---|
| 103 | |
---|
[b2d9826] | 104 | def update_model_list(self): |
---|
| 105 | """ |
---|
| 106 | """ |
---|
[9466f2d6] | 107 | temp = self.menu_mng.update() |
---|
| 108 | if len(temp): |
---|
| 109 | self.model_list_box = temp |
---|
| 110 | return temp |
---|
[b2d9826] | 111 | |
---|
| 112 | |
---|
[66ff250] | 113 | def get_page_by_id(self, uid): |
---|
[6bbeacd4] | 114 | """ |
---|
| 115 | """ |
---|
[66ff250] | 116 | if uid not in self.opened_pages: |
---|
| 117 | msg = "Fitpanel cannot find ID: %s in self.opened_pages" % str(uid) |
---|
[6bbeacd4] | 118 | raise ValueError, msg |
---|
| 119 | else: |
---|
[66ff250] | 120 | return self.opened_pages[uid] |
---|
[31b0c47] | 121 | |
---|
[90a7bbd] | 122 | def on_page_changing(self, event): |
---|
[6bbeacd4] | 123 | """ |
---|
[f22e626] | 124 | calls the function when the current event handler has exited. avoiding |
---|
| 125 | to call panel on focus on a panel that is currently deleted |
---|
| 126 | """ |
---|
| 127 | wx.CallAfter(self.helper_on_page_change) |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | def helper_on_page_change(self): |
---|
| 131 | """ |
---|
[6bbeacd4] | 132 | """ |
---|
[90a7bbd] | 133 | pos = self.GetSelection() |
---|
| 134 | if pos != -1: |
---|
| 135 | selected_page = self.GetPage(pos) |
---|
| 136 | wx.PostEvent(self.parent, PanelOnFocusEvent(panel=selected_page)) |
---|
[e4c9030] | 137 | self.enable_close_button() |
---|
[f22e626] | 138 | |
---|
[3cd5806] | 139 | def on_set_focus(self, event): |
---|
| 140 | """ |
---|
| 141 | """ |
---|
| 142 | pos = self.GetSelection() |
---|
[90a7bbd] | 143 | if pos != -1: |
---|
| 144 | selected_page = self.GetPage(pos) |
---|
| 145 | wx.PostEvent(self.parent, PanelOnFocusEvent(panel=selected_page)) |
---|
[3cd5806] | 146 | |
---|
[c8deee5] | 147 | def get_data(self): |
---|
| 148 | """ |
---|
| 149 | get the data in the current page |
---|
| 150 | """ |
---|
| 151 | pos = self.GetSelection() |
---|
[90a7bbd] | 152 | if pos != -1: |
---|
| 153 | selected_page = self.GetPage(pos) |
---|
| 154 | return selected_page.get_data() |
---|
[c8deee5] | 155 | |
---|
[e88ebfd] | 156 | def set_model_state(state): |
---|
| 157 | """ |
---|
| 158 | receive a state to reset the model in the current page |
---|
| 159 | """ |
---|
| 160 | pos = self.GetSelection() |
---|
| 161 | if pos != -1: |
---|
| 162 | selected_page = self.GetPage(pos) |
---|
| 163 | selected_page.set_model_state(state) |
---|
| 164 | |
---|
[c8deee5] | 165 | def get_state(self): |
---|
| 166 | """ |
---|
| 167 | return the state of the current selected page |
---|
| 168 | """ |
---|
| 169 | pos = self.GetSelection() |
---|
[90a7bbd] | 170 | if pos != -1: |
---|
| 171 | selected_page = self.GetPage(pos) |
---|
| 172 | return selected_page.get_state() |
---|
[c8deee5] | 173 | |
---|
[f22e626] | 174 | |
---|
[6bbeacd4] | 175 | |
---|
[ac2dc0e] | 176 | def close_all(self): |
---|
| 177 | """ |
---|
[8897d66] | 178 | remove all pages, used when a svs file is opened |
---|
| 179 | """ |
---|
[90a7bbd] | 180 | |
---|
[8897d66] | 181 | #get number of pages |
---|
| 182 | nop = self.GetPageCount() |
---|
| 183 | #use while-loop, for-loop will not do the job well. |
---|
| 184 | while (nop>0): |
---|
| 185 | #delete the first page until no page exists |
---|
| 186 | page = self.GetPage(0) |
---|
[90a7bbd] | 187 | if self._manager.parent.panel_on_focus == page: |
---|
| 188 | self._manager.parent.panel_on_focus = None |
---|
[8897d66] | 189 | self._close_helper(selected_page=page) |
---|
| 190 | self.DeletePage(0) |
---|
| 191 | nop = nop - 1 |
---|
[90a7bbd] | 192 | |
---|
[ac2dc0e] | 193 | ## save the title of the last page tab added |
---|
| 194 | self.fit_page_name = {} |
---|
| 195 | ## list of existing fit page |
---|
| 196 | self.opened_pages = {} |
---|
| 197 | |
---|
[31b0c47] | 198 | def set_state(self, state): |
---|
| 199 | """ |
---|
[5062bbf] | 200 | Restore state of the panel |
---|
[31b0c47] | 201 | """ |
---|
| 202 | page_is_opened = False |
---|
| 203 | if state is not None: |
---|
[66ff250] | 204 | for uid, panel in self.opened_pages.iteritems(): |
---|
[31b0c47] | 205 | #Don't return any panel is the exact same page is created |
---|
[4bee68d] | 206 | if uid == panel.uid and panel.data == state.data: |
---|
[31b0c47] | 207 | # the page is still opened |
---|
| 208 | panel.reset_page(state=state) |
---|
[645f9b6] | 209 | panel.save_current_state() |
---|
[31b0c47] | 210 | page_is_opened = True |
---|
| 211 | if not page_is_opened: |
---|
[9f391af] | 212 | panel = self._manager.add_fit_page(data=state.data) |
---|
[31b0c47] | 213 | # add data associated to the page created |
---|
| 214 | if panel is not None: |
---|
[4bee68d] | 215 | self._manager.store_data(uid=panel.uid, |
---|
| 216 | data=state.data, |
---|
| 217 | caption=panel.window_caption) |
---|
[31b0c47] | 218 | panel.reset_page(state=state) |
---|
[645f9b6] | 219 | panel.save_current_state() |
---|
[31b0c47] | 220 | |
---|
[90a7bbd] | 221 | def clear_panel(self): |
---|
[9b18735] | 222 | """ |
---|
| 223 | Clear and close all panels, used by guimanager |
---|
| 224 | """ |
---|
[90a7bbd] | 225 | |
---|
| 226 | #close all panels only when svs file opened |
---|
| 227 | self.close_all() |
---|
| 228 | self._manager.mypanels = [] |
---|
| 229 | |
---|
[9b18735] | 230 | |
---|
[ac2dc0e] | 231 | def on_close_page(self, event=None): |
---|
[51d47b5] | 232 | """ |
---|
[5062bbf] | 233 | close page and remove all references to the closed page |
---|
[51d47b5] | 234 | """ |
---|
[d361b462] | 235 | nbr_page = self.GetPageCount() |
---|
[51d47b5] | 236 | selected_page = self.GetPage(self.GetSelection()) |
---|
[f22e626] | 237 | if nbr_page == 1: |
---|
| 238 | if selected_page.get_data() == None: |
---|
| 239 | if event is not None: |
---|
| 240 | event.Veto() |
---|
| 241 | return |
---|
[2f189dc] | 242 | self._close_helper(selected_page=selected_page) |
---|
[9853ad0] | 243 | |
---|
[2f189dc] | 244 | def close_page_with_data(self, deleted_data): |
---|
| 245 | """ |
---|
[5062bbf] | 246 | close a fit page when its data is completely remove from the graph |
---|
[2f189dc] | 247 | """ |
---|
[784e2fa] | 248 | if deleted_data is None: |
---|
| 249 | return |
---|
[2f189dc] | 250 | for index in range(self.GetPageCount()): |
---|
| 251 | selected_page = self.GetPage(index) |
---|
| 252 | if hasattr(selected_page,"get_data"): |
---|
| 253 | data = selected_page.get_data() |
---|
[ac2dc0e] | 254 | |
---|
[784e2fa] | 255 | if data is None: |
---|
| 256 | #the fitpanel exists and only the initial fit page is open |
---|
| 257 | #with no selected data |
---|
| 258 | return |
---|
[f22e626] | 259 | if data.id == deleted_data.id: |
---|
[2f189dc] | 260 | self._close_helper(selected_page) |
---|
| 261 | self.DeletePage(index) |
---|
| 262 | break |
---|
[d89f09b] | 263 | |
---|
| 264 | def set_manager(self, manager): |
---|
| 265 | """ |
---|
[5062bbf] | 266 | set panel manager |
---|
| 267 | |
---|
| 268 | :param manager: instance of plugin fitting |
---|
| 269 | |
---|
[d89f09b] | 270 | """ |
---|
[c8deee5] | 271 | self._manager = manager |
---|
[3cd5806] | 272 | for pos in range(self.GetPageCount()): |
---|
| 273 | page = self.GetPage(pos) |
---|
| 274 | if page is not None: |
---|
| 275 | page.set_manager(self._manager) |
---|
[a93f525] | 276 | |
---|
[ffa69b6] | 277 | def set_model_list(self, dict): |
---|
[c77d859] | 278 | """ |
---|
[5062bbf] | 279 | copy a dictionary of model into its own dictionary |
---|
| 280 | |
---|
| 281 | :param dict: dictionnary made of model name as key and model class |
---|
[c77d859] | 282 | as value |
---|
| 283 | """ |
---|
| 284 | self.model_list_box = dict |
---|
[51d47b5] | 285 | |
---|
[c77d859] | 286 | def get_current_page(self): |
---|
| 287 | """ |
---|
[5062bbf] | 288 | :return: the current page selected |
---|
| 289 | |
---|
[c77d859] | 290 | """ |
---|
[6bbeacd4] | 291 | return self.GetPage(self.GetSelection()) |
---|
[c77d859] | 292 | |
---|
[51d47b5] | 293 | def add_sim_page(self): |
---|
[925a30e] | 294 | """ |
---|
[5062bbf] | 295 | Add the simultaneous fit page |
---|
[925a30e] | 296 | """ |
---|
[51d47b5] | 297 | from simfitpage import SimultaneousFitPage |
---|
[c8deee5] | 298 | page_finder= self._manager.get_page_finder() |
---|
[b28717b] | 299 | self.sim_page = SimultaneousFitPage(self,page_finder=page_finder, id=-1) |
---|
[66ff250] | 300 | self.sim_page.uid = wx.NewId() |
---|
[6bbeacd4] | 301 | self.AddPage(self.sim_page,"Simultaneous Fit", True) |
---|
[c8deee5] | 302 | self.sim_page.set_manager(self._manager) |
---|
[f22e626] | 303 | self.enable_close_button() |
---|
[51d47b5] | 304 | return self.sim_page |
---|
[d89f09b] | 305 | |
---|
[6bbeacd4] | 306 | |
---|
[2f189dc] | 307 | def add_empty_page(self): |
---|
[9853ad0] | 308 | """ |
---|
[5062bbf] | 309 | add an empty page |
---|
[9853ad0] | 310 | """ |
---|
[2f189dc] | 311 | from fitpage import FitPage |
---|
[6bbeacd4] | 312 | panel = FitPage(parent=self) |
---|
[66ff250] | 313 | panel.uid = wx.NewId() |
---|
[6bbeacd4] | 314 | panel.populate_box(dict=self.model_list_box) |
---|
[c8deee5] | 315 | panel.set_manager(self._manager) |
---|
[7b3bbbe] | 316 | index = self.GetPageCount() |
---|
| 317 | #caption = str(panel.window_name) + " " + str(self._manager.index_model) |
---|
| 318 | caption = str(panel.window_name) + " " + str(index) |
---|
[ae4ade7] | 319 | self.AddPage(panel, caption, select=True) |
---|
[66ff250] | 320 | self.opened_pages[panel.uid] = panel |
---|
| 321 | self.set_engine_helper(panel=panel) |
---|
[f22e626] | 322 | self.enable_close_button() |
---|
[2f189dc] | 323 | return panel |
---|
| 324 | |
---|
[f22e626] | 325 | def enable_close_button(self): |
---|
| 326 | """ |
---|
| 327 | display the close button on tab for more than 1 tabs else remove the |
---|
| 328 | close button |
---|
| 329 | """ |
---|
| 330 | if self.GetPageCount() <= 1: |
---|
| 331 | style = self.GetWindowStyleFlag() |
---|
| 332 | if style & wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB == wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB: |
---|
| 333 | style = style & ~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB |
---|
| 334 | self.SetWindowStyle(style) |
---|
| 335 | else: |
---|
| 336 | style = self.GetWindowStyleFlag() |
---|
| 337 | if style & wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB != wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB: |
---|
| 338 | style |= wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB |
---|
| 339 | self.SetWindowStyle(style) |
---|
| 340 | |
---|
[8ee56a9] | 341 | def delete_data(self, data): |
---|
| 342 | """ |
---|
| 343 | Delete the given data |
---|
| 344 | """ |
---|
[f22e626] | 345 | if data.__class__.__name__ != "list": |
---|
| 346 | raise ValueError, "Fitpanel delete_data expect list of id" |
---|
| 347 | else: |
---|
| 348 | n = self.GetPageCount() |
---|
| 349 | for page in self.opened_pages.values(): |
---|
| 350 | pos = self.GetPageIndex(page) |
---|
| 351 | temp_data = page.get_data() |
---|
| 352 | #stop the fitting before deleting the page |
---|
| 353 | page.is_fitting() |
---|
| 354 | if temp_data is not None and temp_data.id in data: |
---|
| 355 | self.SetSelection(pos) |
---|
| 356 | self.on_close_page(event=None) |
---|
| 357 | temp = self.GetSelection() |
---|
| 358 | self.DeletePage(temp) |
---|
| 359 | if self.GetPageCount()== 0: |
---|
[e4c9030] | 360 | self._manager.on_add_new_page(event=None) |
---|
[f22e626] | 361 | |
---|
[6bbeacd4] | 362 | def set_data(self, data): |
---|
[2f189dc] | 363 | """ |
---|
[5062bbf] | 364 | Add a fitting page on the notebook contained by fitpanel |
---|
| 365 | |
---|
| 366 | :param data: data to fit |
---|
| 367 | |
---|
| 368 | :return panel : page just added for further used. is used by fitting module |
---|
| 369 | |
---|
[2f189dc] | 370 | """ |
---|
| 371 | if data is None: |
---|
| 372 | return None |
---|
[6bbeacd4] | 373 | for page in self.opened_pages.values(): |
---|
| 374 | #check if the selected data existing in the fitpanel |
---|
| 375 | pos = self.GetPageIndex(page) |
---|
| 376 | if page.get_data() is None: |
---|
[a5701e6] | 377 | enable2D = page.get_view_mode() |
---|
| 378 | if (data.__class__.__name__ == "Data2D" and enable2D)\ |
---|
| 379 | or (data.__class__.__name__ == "Data1D" and not enable2D): |
---|
| 380 | page.set_data(data) |
---|
| 381 | self.SetPageText(pos, str(data.name)) |
---|
| 382 | self.SetSelection(pos) |
---|
| 383 | return page |
---|
[ae4ade7] | 384 | |
---|
[6bbeacd4] | 385 | elif page.get_data().id == data.id: |
---|
| 386 | msg = "Data already existing in the fitting panel" |
---|
| 387 | wx.PostEvent(self._manager.parent, |
---|
| 388 | StatusEvent(status=msg, info='warning')) |
---|
| 389 | self.SetSelection(pos) |
---|
| 390 | return page |
---|
[9b18735] | 391 | |
---|
[6bbeacd4] | 392 | page = self.add_empty_page() |
---|
[9f391af] | 393 | pos = self.GetPageIndex(page) |
---|
[6bbeacd4] | 394 | page.set_data(data) |
---|
| 395 | self.SetPageText(pos, str(data.name)) |
---|
[66ff250] | 396 | self.opened_pages[page.uid] = page |
---|
[ae4ade7] | 397 | |
---|
[6bbeacd4] | 398 | return page |
---|
| 399 | |
---|
| 400 | def _onGetstate(self, event): |
---|
[cfc0913] | 401 | """ |
---|
[5062bbf] | 402 | copy the state of a page |
---|
[cfc0913] | 403 | """ |
---|
[6bbeacd4] | 404 | page = event.page |
---|
[66ff250] | 405 | if page.uid in self.fit_page_name: |
---|
| 406 | self.fit_page_name[page.uid].appendItem(page.createMemento()) |
---|
[cfc0913] | 407 | |
---|
[4e78f56] | 408 | def _onUndo(self, event): |
---|
[330573d] | 409 | """ |
---|
[5062bbf] | 410 | return the previous state of a given page is available |
---|
[330573d] | 411 | """ |
---|
| 412 | page = event.page |
---|
[66ff250] | 413 | if page.uid in self.fit_page_name: |
---|
| 414 | if self.fit_page_name[page.uid].getCurrentPosition()==0: |
---|
[330573d] | 415 | state = None |
---|
| 416 | else: |
---|
[66ff250] | 417 | state = self.fit_page_name[page.uid].getPreviousItem() |
---|
[fe496eeb] | 418 | page._redo.Enable(True) |
---|
[330573d] | 419 | page.reset_page(state) |
---|
[fe496eeb] | 420 | |
---|
[2f189dc] | 421 | def _onRedo(self, event): |
---|
[fe496eeb] | 422 | """ |
---|
[5062bbf] | 423 | return the next state available |
---|
[fe496eeb] | 424 | """ |
---|
| 425 | page = event.page |
---|
[66ff250] | 426 | if page.uid in self.fit_page_name: |
---|
| 427 | length= len(self.fit_page_name[page.uid]) |
---|
| 428 | if self.fit_page_name[page.uid].getCurrentPosition()== length -1: |
---|
[fe496eeb] | 429 | state = None |
---|
| 430 | page._redo.Enable(False) |
---|
[3b9e023] | 431 | page._redo.Enable(True) |
---|
[fe496eeb] | 432 | else: |
---|
[66ff250] | 433 | state =self.fit_page_name[page.uid].getNextItem() |
---|
[fe496eeb] | 434 | page.reset_page(state) |
---|
[2f189dc] | 435 | |
---|
| 436 | def _close_helper(self, selected_page): |
---|
[3f1af74] | 437 | """ |
---|
[5062bbf] | 438 | Delete the given page from the notebook |
---|
[3f1af74] | 439 | """ |
---|
[2f189dc] | 440 | #remove hint page |
---|
[1b1bbf9] | 441 | #if selected_page == self.hint_page: |
---|
| 442 | # return |
---|
[2f189dc] | 443 | ## removing sim_page |
---|
| 444 | if selected_page == self.sim_page : |
---|
[c8deee5] | 445 | self._manager.sim_page=None |
---|
[2f189dc] | 446 | return |
---|
[b787e68c] | 447 | |
---|
[2f189dc] | 448 | ## closing other pages |
---|
| 449 | state = selected_page.createMemento() |
---|
| 450 | page_name = selected_page.window_name |
---|
[c8deee5] | 451 | page_finder = self._manager.get_page_finder() |
---|
[2f189dc] | 452 | fitproblem = None |
---|
| 453 | ## removing fit page |
---|
[c6036f5] | 454 | data = selected_page.get_data() |
---|
| 455 | #Don' t remove plot for 2D |
---|
| 456 | flag = True |
---|
| 457 | if data.__class__.__name__ == 'Data2D': |
---|
| 458 | flag = False |
---|
[2f189dc] | 459 | if selected_page in page_finder: |
---|
| 460 | #Delete the name of the page into the list of open page |
---|
[66ff250] | 461 | for uid, list in self.opened_pages.iteritems(): |
---|
[2f189dc] | 462 | #Don't return any panel is the exact same page is created |
---|
[6bbeacd4] | 463 | |
---|
[66ff250] | 464 | if flag and selected_page.uid == uid: |
---|
| 465 | self._manager.remove_plot(uid, theory=False) |
---|
[2f189dc] | 466 | break |
---|
| 467 | del page_finder[selected_page] |
---|
| 468 | ##remove the check box link to the model name of this page (selected_page) |
---|
| 469 | try: |
---|
| 470 | self.sim_page.draw_page() |
---|
| 471 | except: |
---|
| 472 | ## that page is already deleted no need to remove check box on |
---|
| 473 | ##non existing page |
---|
| 474 | pass |
---|
| 475 | |
---|
| 476 | #Delete the name of the page into the list of open page |
---|
[66ff250] | 477 | for uid, list in self.opened_pages.iteritems(): |
---|
[2f189dc] | 478 | #Don't return any panel is the exact same page is created |
---|
[66ff250] | 479 | if selected_page.uid == uid: |
---|
| 480 | del self.opened_pages[selected_page.uid] |
---|
[2f189dc] | 481 | break |
---|
[f22e626] | 482 | |
---|
[b787e68c] | 483 | |
---|