Changes in / [60df6c1:ed9f872] in sasview
- Location:
- src/sas/sasgui
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/data_panel.py
r998ca90 re767897 890 890 891 891 892 def on_remove(self, event , msg=""):892 def on_remove(self, event): 893 893 """ 894 894 Get a list of item checked and remove them from the treectrl 895 895 Ask the parent to remove reference to this item 896 896 """ 897 if msg == "": 898 msg = "This operation will delete the data sets checked " 899 msg += "and all the dependents." 897 msg = "This operation will delete the data sets checked " 898 msg += "and all the dependents." 900 899 msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK|wx.CANCEL) 901 900 if msg_box.ShowModal() != wx.ID_OK: 902 return True901 return 903 902 904 903 data_to_remove, theory_to_remove, _ = self.set_data_helper() -
src/sas/sasgui/guiframe/gui_manager.py
re6de6b8 radb0851 1152 1152 self.delete_panel(ID) 1153 1153 break 1154 if self.cpanel_on_focus is not None: 1155 self.cpanel_on_focus.SetFocus() 1154 self.cpanel_on_focus.SetFocus() 1156 1155 1157 1156 … … 1908 1907 if self._default_save_location == None: 1909 1908 self._default_save_location = os.getcwd() 1910 msg = "This operation will set SasView to its freshly opened state " 1911 msg += "before loading the project. Do you wish to continue?" 1912 if not self._data_panel.on_remove(None, msg): 1913 wx.PostEvent(self, StatusEvent(status="Loading Project file...")) 1914 dlg = wx.FileDialog(self, 1909 wx.PostEvent(self, StatusEvent(status="Loading Project file...")) 1910 dlg = wx.FileDialog(self, 1915 1911 "Choose a file", 1916 1912 self._default_save_location, "", 1917 1913 APPLICATION_WLIST) 1918 1919 1914 if dlg.ShowModal() == wx.ID_OK: 1915 path = dlg.GetPath() 1920 1916 if path is not None: 1921 1917 self._default_save_location = os.path.dirname(path) 1922 dlg.Destroy() 1923 # Reset to a base state 1924 self._on_reset_state() 1925 # Load the project file 1926 self.load_state(path=path, is_project=True) 1927 1928 def _on_reset_state(self): 1929 """ 1930 Resets SasView to its freshly opened state. 1931 :return: None 1932 """ 1933 # Reset all plugins to their base state 1934 self._data_panel.set_panel_on_focus() 1935 # Remove all loaded data 1936 self._data_panel.selection_cbox.SetValue('Select all Data') 1937 self._data_panel._on_selection_type(None) 1938 for plugin in self.plugins: 1939 plugin.clear_panel() 1940 # Reset plot number to 0 1941 self.graph_num = 0 1918 dlg.Destroy() 1919 1920 self.load_state(path=path, is_project=True) 1942 1921 1943 1922 def _on_save_application(self, event): … … 2087 2066 except: 2088 2067 logging.info("Failed to connect to www.sasview.org") 2089 self._process_version(version_info, standalone=event == None) 2068 self._process_version(version_info, standalone=event == None) 2069 2070 2071 2072 # 2073 # try: 2074 # req = urllib2.Request(config.__update_URL__) 2075 # res = urllib2.urlopen(req) 2076 # content = res.read().strip() 2077 # logging.info("Connected to www.sasview.org. Latest version: %s" 2078 # % (content)) 2079 # version_info = json.loads(content) 2080 # except: 2081 # logging.info("Failed to connect to www.sasview.org") 2082 # version_info = {"version": "0.0.0"} 2083 # self._process_version(version_info, standalone=event == None) 2090 2084 2091 2085 def _process_version(self, version_info, standalone=True): -
src/sas/sasgui/perspectives/fitting/fitpanel.py
re6de6b8 r05228b0 10 10 11 11 from sas.sasgui.guiframe.panel_base import PanelBase 12 from sas.sasgui.guiframe.events import PanelOnFocusEvent, StatusEvent 12 from sas.sasgui.guiframe.events import PanelOnFocusEvent 13 from sas.sasgui.guiframe.events import StatusEvent 13 14 from sas.sasgui.guiframe.dataFitting import check_data_validity 14 from sas.sasgui.perspectives.fitting.simfitpage import SimultaneousFitPage15 15 16 16 import basepage … … 18 18 _BOX_WIDTH = 80 19 19 20 21 20 class FitPanel(nb, PanelBase): 22 21 """ … … 27 26 28 27 """ 29 # Internal name for the AUI manager28 ## Internal name for the AUI manager 30 29 window_name = "Fit panel" 31 # Title to appear on top of the window30 ## Title to appear on top of the window 32 31 window_caption = "Fit Panel " 33 32 CENTER_PANE = True … … 41 40 wx.CLIP_CHILDREN) 42 41 PanelBase.__init__(self, parent) 43 # 42 #self.SetWindowStyleFlag(style=nb.FNB_FANCY_TABS) 44 43 self._manager = manager 45 44 self.parent = parent 46 45 self.event_owner = None 47 # 46 #dictionary of miodel {model class name, model class} 48 47 self.menu_mng = models.ModelManager() 49 48 self.model_list_box = self.menu_mng.get_model_list() 50 # 49 #pageClosedEvent = nb.EVT_FLATNOTEBOOK_PAGE_CLOSING 51 50 self.model_dictionary = self.menu_mng.get_model_dictionary() 52 51 self.pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE 53 52 54 53 self.Bind(self.pageClosedEvent, self.on_close_page) 55 # save the title of the last page tab added54 ## save the title of the last page tab added 56 55 self.fit_page_name = {} 57 # list of existing fit page56 ## list of existing fit page 58 57 self.opened_pages = {} 59 # 58 #index of fit page 60 59 self.fit_page_index = 0 61 # 60 #index of batch page 62 61 self.batch_page_index = 0 63 # 62 #page of simultaneous fit 64 63 self.sim_page = None 65 64 self.batch_page = None 66 # get the state of a page65 ## get the state of a page 67 66 self.Bind(basepage.EVT_PAGE_INFO, self._onGetstate) 68 67 self.Bind(basepage.EVT_PREVIOUS_STATE, self._onUndo) … … 81 80 """ 82 81 return an xml node containing state of the panel 83 that guiframe can write to file 84 """ 85 # Iterate through all pages and check for batch fitting 86 batch_state = None 87 if self.sim_page is not None: 88 batch_state = self.sim_page.set_state() 89 82 that guiframe can write to file 83 """ 84 msg = "" 90 85 for uid, page in self.opened_pages.iteritems(): 91 data = page.get_data() 92 # state must be cloned 93 state = page.get_state().clone() 94 if data is not None or page.model is not None: 95 new_doc = self._manager.state_reader.write_toXML(data, 96 state, 97 batch_state) 98 if doc is not None and hasattr(doc, "firstChild"): 99 child = new_doc.firstChild.firstChild 100 doc.firstChild.appendChild(child) 101 else: 102 doc = new_doc 103 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 and page.model is not None: 95 new_doc = self._manager.state_reader.write_toXML(data, 96 state) 97 if doc != None and hasattr(doc, "firstChild"): 98 child = new_doc.firstChild.firstChild 99 doc.firstChild.appendChild(child) 100 else: 101 doc = new_doc 102 if msg.strip() != "": 103 temp = "Save Project is not supported for Batch page.\n" 104 temp += "The following pages will not be save:\n" 105 message = temp + msg 106 wx.PostEvent(self._manager.parent, StatusEvent(status=message, 107 info="warning")) 104 108 return doc 105 109 … … 175 179 def get_state(self): 176 180 """ 177 return the state of the current selected page181 return the state of the current selected page 178 182 """ 179 183 pos = self.GetSelection() … … 187 191 """ 188 192 189 # 193 #get number of pages 190 194 nop = self.GetPageCount() 191 # 195 #use while-loop, for-loop will not do the job well. 192 196 while (nop > 0): 193 # 197 #delete the first page until no page exists 194 198 page = self.GetPage(0) 195 199 if self._manager.parent.panel_on_focus == page: … … 197 201 self._close_helper(selected_page=page) 198 202 self.DeletePage(0) 199 nop = self.GetPageCount() 200 # Clear list of names 203 nop = nop - 1 204 205 ## save the title of the last page tab added 201 206 self.fit_page_name = {} 202 # Clear list of opened pages207 ## list of existing fit page 203 208 self.opened_pages = {} 204 self.fit_page_index = 0205 self.batch_page_index = 0206 209 207 210 def set_state(self, state): … … 212 215 if state is not None: 213 216 for uid, panel in self.opened_pages.iteritems(): 214 # 217 #Don't return any panel is the exact same page is created 215 218 if uid == panel.uid and panel.data == state.data: 216 219 # the page is still opened … … 220 223 if not page_is_opened: 221 224 if state.data.__class__.__name__ != 'list': 222 # 225 #To support older state file format 223 226 list_data = [state.data] 224 227 else: 225 # 228 #Todo: need new file format for the list 226 229 list_data = state.data 227 230 panel = self._manager.add_fit_page(data=list_data) … … 238 241 Clear and close all panels, used by guimanager 239 242 """ 240 # close all panels only when svs file opened 243 244 #close all panels only when svs file opened 241 245 self.close_all() 242 246 self._manager.mypanels = [] 243 self.sim_page = None244 self.batch_page = None245 247 246 248 def on_close_page(self, event=None): … … 251 253 selected_page = self.GetPage(self.GetSelection()) 252 254 if nbr_page == 1: 253 if selected_page.get_data() is notNone:255 if selected_page.get_data() == None: 254 256 if event is not None: 255 257 event.Veto() … … 269 271 270 272 if data is None: 271 # 272 # 273 #the fitpanel exists and only the initial fit page is open 274 #with no selected data 273 275 return 274 276 if data.id == deleted_data.id: … … 282 284 283 285 :param manager: instance of plugin fitting 286 284 287 """ 285 288 self._manager = manager … … 330 333 else: 331 334 self.batch_page = SimultaneousFitPage(self, batch_on=True, 332 page_finder=page_finder)335 page_finder=page_finder) 333 336 self.batch_page.window_caption = caption 334 337 self.batch_page.window_name = caption … … 343 346 add an empty page 344 347 """ 348 """ 345 349 if self.batch_on: 346 350 from batchfitpage import BatchFitPage 351 panel = BatchFitPage(parent=self) 352 #Increment index of batch page 353 self.batch_page_index += 1 354 index = self.batch_page_index 355 else: 356 """ 357 from fitpage import FitPage 358 from batchfitpage import BatchFitPage 359 if self.batch_on: 347 360 panel = BatchFitPage(parent=self) 348 361 self.batch_page_index += 1 … … 350 363 panel.set_index_model(self.batch_page_index) 351 364 else: 352 # Increment index of fit page 353 from fitpage import FitPage 365 #Increment index of fit page 354 366 panel = FitPage(parent=self) 355 367 self.fit_page_index += 1 … … 429 441 page = None 430 442 for p in self.opened_pages.values(): 431 # 443 #check if there is an empty page to fill up 432 444 if not check_data_validity(p.get_data()) and p.batch_on: 433 445 434 # 435 # 446 #make sure data get placed in 1D empty tab if data is 1D 447 #else data get place on 2D tab empty tab 436 448 enable2D = p.get_view_mode() 437 449 if (data.__class__.__name__ == "Data2D" and enable2D)\ … … 446 458 data_type = dlg.get_data() 447 459 dlg.Destroy() 448 if page is None:460 if page is None: 449 461 page = self.add_empty_page() 450 462 if data_type == 1: 451 # 463 #user has selected only data1D 452 464 page.fill_data_combobox(data_1d_list) 453 465 elif data_type == 2: 454 466 page.fill_data_combobox(data_2d_list) 455 467 else: 456 # 468 #the batch analysis is canceled 457 469 dlg.Destroy() 458 470 return None … … 491 503 try: 492 504 data = data_list[0] 493 except Exception:505 except: 494 506 # for 'fitv' files 495 507 data_list = [data] … … 499 511 return None 500 512 for page in self.opened_pages.values(): 501 # 513 #check if the selected data existing in the fitpanel 502 514 pos = self.GetPageIndex(page) 503 515 if not check_data_validity(page.get_data()) and not page.batch_on: 504 # 505 # 516 #make sure data get placed in 1D empty tab if data is 1D 517 #else data get place on 2D tab empty tab 506 518 enable2D = page.get_view_mode() 507 519 if (data.__class__.__name__ == "Data2D" and enable2D)\ 508 520 or (data.__class__.__name__ == "Data1D" and not enable2D): 509 521 page.batch_on = self.batch_on 510 522 page._set_save_flag(not page.batch_on) 511 523 page.fill_data_combobox(data_list) 512 # 524 #caption = "FitPage" + str(self.fit_page_index) 513 525 self.SetPageText(pos, page.window_caption) 514 526 self.SetSelection(pos) 515 527 return page 516 # 528 #create new page and add data 517 529 page = self.add_empty_page() 518 530 pos = self.GetPageIndex(page) … … 562 574 Delete the given page from the notebook 563 575 """ 564 # 565 # 576 #remove hint page 577 #if selected_page == self.hint_page: 566 578 # return 567 # removing sim_page579 ## removing sim_page 568 580 if selected_page == self.sim_page: 569 581 self._manager.sim_page = None … … 572 584 self._manager.batch_page = None 573 585 return 574 # closing other pages 586 """ 587 # The below is not working when delete #5 and still have #6. 588 if selected_page.__class__.__name__ == "FitPage": 589 self.fit_page_index -= 1 590 else: 591 self.batch_page_index -= 1 592 """ 593 ## closing other pages 575 594 state = selected_page.createMemento() 576 595 page_finder = self._manager.get_page_finder() 577 # removing fit page596 ## removing fit page 578 597 data = selected_page.get_data() 579 # 598 #Don' t remove plot for 2D 580 599 flag = True 581 600 if data.__class__.__name__ == 'Data2D': 582 601 flag = False 583 602 if selected_page in page_finder: 584 # 603 #Delete the name of the page into the list of open page 585 604 for uid, list in self.opened_pages.iteritems(): 586 # Don't return any panel is the exact same page is created 605 #Don't return any panel is the exact same page is created 606 587 607 if flag and selected_page.uid == uid: 588 608 self._manager.remove_plot(uid, theory=False) … … 590 610 del page_finder[selected_page] 591 611 592 # 612 #Delete the name of the page into the list of open page 593 613 for uid, list in self.opened_pages.iteritems(): 594 # 614 #Don't return any panel is the exact same page is created 595 615 if selected_page.uid == uid: 596 616 del self.opened_pages[selected_page.uid] 597 617 break 598 # remove the check box link to the model name of the selected_page618 ##remove the check box link to the model name of this page (selected_page) 599 619 try: 600 620 self.sim_page.draw_page() 601 621 except: 602 # that page is already deleted no need to remove check box on603 # 622 ## that page is already deleted no need to remove check box on 623 ##non existing page 604 624 pass 605 625 try: 606 626 self.batch_page.draw_page() 607 627 except: 608 # that page is already deleted no need to remove check box on609 # 628 ## that page is already deleted no need to remove check box on 629 ##non existing page 610 630 pass -
src/sas/sasgui/perspectives/fitting/fitting.py
r286c757 r286c757 593 593 : param datainfo: data 594 594 """ 595 from pagestate import PageState 596 from simfitpage import SimFitPageState 597 if isinstance(state, PageState): 595 #state = self.state_reader.get_state() 596 if state != None: 598 597 state = state.clone() 598 # store fitting state in temp_state 599 599 self.temp_state.append(state) 600 elif isinstance(state, SimFitPageState):601 state.load_from_save_state(self)602 600 else: 603 601 self.temp_state = [] -
src/sas/sasgui/perspectives/fitting/pagestate.py
re6de6b8 r6c382da 2 2 Class that holds a fit page state 3 3 """ 4 # 4 #TODO: Refactor code so we don't need to use getattr/setattr 5 5 ################################################################################ 6 # 7 # 8 # 6 #This software was developed by the University of Tennessee as part of the 7 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 8 #project funded by the US National Science Foundation. 9 9 # 10 # 10 #See the license text in license.txt 11 11 # 12 # 12 #copyright 2009, University of Tennessee 13 13 ################################################################################ 14 14 import time … … 30 30 from sas.sascalc.dataloader.readers.cansas_reader import Reader as CansasReader 31 31 from sas.sascalc.dataloader.readers.cansas_reader import get_content, write_node 32 from sas.sascalc.dataloader.data_info import Data2D, Collimation, Detector 33 from sas.sascalc.dataloader.data_info import Process, Aperture 34 # Information to read/write state as xml 32 from sas.sascalc.dataloader.data_info import Data2D 33 from sas.sascalc.dataloader.data_info import Collimation 34 from sas.sascalc.dataloader.data_info import Detector 35 from sas.sascalc.dataloader.data_info import Process 36 from sas.sascalc.dataloader.data_info import Aperture 37 #Information to read/write state as xml 35 38 FITTING_NODE_NAME = 'fitting_plug_in' 36 39 CANSAS_NS = "cansas1d/1.0" … … 120 123 try: 121 124 return node.get(item[0]).strip() == "True" 125 122 126 except: 123 127 return None … … 142 146 """ 143 147 self.file = None 144 # 148 #Time of state creation 145 149 self.timestamp = time.time() 146 # Data member to store the dispersion object created150 ## Data member to store the dispersion object created 147 151 self._disp_obj_dict = {} 148 # 149 # 152 #------------------------ 153 #Data used for fitting 150 154 self.data = data 151 155 # model data 152 156 self.theory_data = None 153 # 157 #Is 2D 154 158 self.is_2D = False 155 159 self.images = None 156 160 157 # save additional information on data that dataloader.reader 158 # does not read 161 #save additional information on data that dataloader.reader does not read 159 162 self.is_data = None 160 163 self.data_name = "" … … 169 172 self.data_group_id = self.data.group_id 170 173 171 # reset True change the state of existing button174 ## reset True change the state of exsiting button 172 175 self.reset = False 173 176 … … 177 180 self.model = model 178 181 self.m_name = None 179 # 182 #list of process done to model 180 183 self.process = [] 181 # 184 #fit page manager 182 185 self.manager = None 183 # 186 #Store the parent of this panel parent 184 187 # For this application fitpanel is the parent 185 188 self.parent = parent 186 189 # Event_owner is the owner of model event 187 190 self.event_owner = None 188 # 191 ##page name 189 192 self.page_name = "" 190 193 # Contains link between model, all its parameters, and panel organization … … 193 196 self.str_parameters = [] 194 197 # Contains list of parameters that cannot be fitted and reference to 195 # 198 #panel objects 196 199 self.fixed_param = [] 197 200 # Contains list of parameters with dispersity and reference to 198 # 201 #panel objects 199 202 self.fittable_param = [] 200 # orientation parameters203 ## orientation parameters 201 204 self.orientation_params = [] 202 # orientation parameters for gaussian dispersity205 ## orientation parameters for gaussian dispersity 203 206 self.orientation_params_disp = [] 204 # smearer info207 ## smearer info 205 208 self.smearer = None 206 209 self.smear_type = None … … 211 214 self.dxl = None 212 215 self.dxw = None 213 # 216 #list of dispersion parameters 214 217 self.disp_list = [] 215 218 if self.model is not None: … … 220 223 self.weights = {} 221 224 222 # 225 #contains link between a model and selected parameters to fit 223 226 self.param_toFit = [] 224 # 227 ##dictionary of model type and model class 225 228 self.model_list_box = None 226 # save the state of the context menu229 ## save the state of the context menu 227 230 self.saved_states = {} 228 # save selection of combobox231 ## save selection of combobox 229 232 self.formfactorcombobox = None 230 233 self.categorycombobox = None 231 234 self.structurecombobox = None 232 235 233 # radio box to select type of model234 # 235 # 236 # 237 # 238 # the indice of the current selection236 ## radio box to select type of model 237 #self.shape_rbutton = False 238 #self.shape_indep_rbutton = False 239 #self.struct_rbutton = False 240 #self.plugin_rbutton = False 241 ## the indice of the current selection 239 242 self.disp_box = 0 240 # Qrange241 # Q range243 ## Qrange 244 ## Q range 242 245 self.qmin = 0.001 243 246 self.qmax = 0.1 244 # 247 #reset data range 245 248 self.qmax_x = None 246 249 self.qmin_x = None … … 250 253 self.multi_factor = None 251 254 self.magnetic_on = False 252 # enable smearering state255 ## enable smearering state 253 256 self.enable_smearer = False 254 257 self.disable_smearer = True … … 260 263 self.dI_sqrdata = False 261 264 self.dI_idata = False 262 # disperity selection265 ## disperity selection 263 266 self.enable_disp = False 264 267 self.disable_disp = True 265 268 266 # state of selected all check button269 ## state of selected all check button 267 270 self.cb1 = False 268 # store value of chisqr271 ## store value of chisqr 269 272 self.tcChi = None 270 273 … … 290 293 obj.structurecombobox = self.structurecombobox 291 294 292 # 293 # 294 # 295 # 295 #obj.shape_rbutton = self.shape_rbutton 296 #obj.shape_indep_rbutton = self.shape_indep_rbutton 297 #obj.struct_rbutton = self.struct_rbutton 298 #obj.plugin_rbutton = self.plugin_rbutton 296 299 297 300 obj.manager = self.manager … … 378 381 379 382 rep += "State created: %s\n" % time_str 380 rep += "State form factor combobox selection: %s\n" % \ 381 self.formfactorcombobox 382 rep += "State structure factor combobox selection: %s\n" % \ 383 self.structurecombobox 383 rep += "State form factor combobox selection: %s\n" % self.formfactorcombobox 384 rep += "State structure factor combobox selection: %s\n" % self.structurecombobox 384 385 rep += "is data : %s\n" % self.is_data 385 386 rep += "data's name : %s\n" % self.data_name 386 387 rep += "data's id : %s\n" % self.data_id 387 if self.model is notNone:388 if self.model != None: 388 389 m_name = self.model.__class__.__name__ 389 390 if m_name == 'Model': … … 396 397 rep += "model type (Category) selected: %s\n" % self.categorycombobox 397 398 rep += "data : %s\n" % str(self.data) 398 rep += "Plotting Range: min: %s, max: %s, steps: %s\n" % \399 (str(self.qmin),str(self.qmax), str(self.npts))399 rep += "Plotting Range: min: %s, max: %s, steps: %s\n" % (str(self.qmin), 400 str(self.qmax), str(self.npts)) 400 401 rep += "Dispersion selection : %s\n" % str(self.disp_box) 401 402 rep += "Smearing enable : %s\n" % str(self.enable_smearer) … … 413 414 414 415 rep += "2D enable : %s\n" % str(self.enable2D) 415 rep += "All parameters checkbox selected: %s\n" % str(self.cb1)416 rep += "All parameters checkbox selected: %s\n" % (self.cb1) 416 417 rep += "Value of Chisqr : %s\n" % str(self.tcChi) 417 418 rep += "Smear object : %s\n" % str(self.smearer) 418 rep += "Smear type : %s\n" % str(self.smear_type)419 rep += "Smear type : %s\n" % (self.smear_type) 419 420 rep += "dq_l : %s\n" % self.dq_l 420 421 rep += "dq_r : %s\n" % self.dq_r … … 433 434 if not self.is_2D: 434 435 for item in self.parameters: 435 if item notin self.orientation_params:436 if not item in self.orientation_params: 436 437 temp_parameters.append(item) 437 438 for item in self.fittable_param: 438 if item notin self.orientation_params_disp:439 if not item in self.orientation_params_disp: 439 440 temp_fittable_param.append(item) 440 441 else: … … 442 443 temp_fittable_param = self.fittable_param 443 444 444 rep += "number parameters(self.parameters): %s\n" % \ 445 len(temp_parameters) 445 rep += "number parameters(self.parameters): %s\n" % len(temp_parameters) 446 446 rep = self._repr_helper(list=temp_parameters, rep=rep) 447 rep += "number str_parameters(self.str_parameters): %s\n" % \ 448 len(self.str_parameters) 447 rep += "number str_parameters(self.str_parameters): %s\n" % len(self.str_parameters) 449 448 rep = self._repr_helper(list=self.str_parameters, rep=rep) 450 rep += "number fittable_param(self.fittable_param): %s\n" % \ 451 len(temp_fittable_param) 449 rep += "number fittable_param(self.fittable_param): %s\n" % len(temp_fittable_param) 452 450 rep = self._repr_helper(list=temp_fittable_param, rep=rep) 453 451 return rep … … 553 551 paramval_string += CENTRE % param + "\n" 554 552 555 text_string = "\n\n\n%s\n\n%s\n%s\n%s\n\n%s" % \ 556 (title, file, q_name, chi2, paramval) 553 text_string = "\n\n\n%s\n\n%s\n%s\n%s\n\n%s" % (title, file, q_name, chi2, paramval) 557 554 558 555 title_name = self._check_html_format(title_name) … … 635 632 element.appendChild(sub_element) 636 633 637 def toXML(self, file="fitting_state.fitv", doc=None, 638 entry_node=None, batch_fit_state=None): 639 """ 640 Writes the state of the fit panel to file, as XML. 634 def toXML(self, file="fitting_state.fitv", doc=None, entry_node=None): 635 """ 636 Writes the state of the InversionControl panel to file, as XML. 641 637 642 638 Compatible with standalone writing, or appending to an 643 already existing XML document. In that case, the XML document is644 required. An optional entry node in the XML document may also be given.639 already existing XML document. In that case, the XML document 640 is required. An optional entry node in the XML document may also be given. 645 641 646 642 :param file: file to write to 647 643 :param doc: XML document object [optional] 648 :param entry_node: XML node within the XML document at which we 649 will append the data [optional] 644 :param entry_node: XML node within the XML document at which we will append the data [optional] 645 650 646 """ 651 647 from xml.dom.minidom import getDOMImplementation … … 695 691 element.setAttributeNode(attr) 696 692 top_element.appendChild(element) 697 698 693 # Inputs 699 694 inputs = newdoc.createElement("Attributes") … … 746 741 for item in LIST_OF_STATE_PARAMETERS: 747 742 element = newdoc.createElement(item[0]) 748 self._toXML_helper(thelist=getattr(self, item[1]), 749 element=element, newdoc=newdoc) 743 self._toXML_helper(thelist=getattr(self, item[1]), element=element, newdoc=newdoc) 750 744 inputs.appendChild(element) 751 752 # Combined and Simultaneous Fit Parameters753 if batch_fit_state is not None:754 batch_combo = newdoc.createElement('simultaneous_fit')755 top_element.appendChild(batch_combo)756 757 # Simultaneous Fit Number For Linking Later758 element = newdoc.createElement('sim_fit_number')759 element.setAttribute('fit_number', str(batch_fit_state.fit_page_no))760 batch_combo.appendChild(element)761 762 # Save constraints763 constraints = newdoc.createElement('constraints')764 batch_combo.appendChild(constraints)765 for constraint in batch_fit_state.constraints_list:766 if constraint.model_cbox.GetValue() != "":767 # model_cbox, param_cbox, egal_txt, constraint, btRemove, sizer768 doc_cons = newdoc.createElement('constraint')769 doc_cons.setAttribute('model_cbox',770 str(constraint.model_cbox.GetValue()))771 doc_cons.setAttribute('param_cbox',772 str(constraint.param_cbox.GetValue()))773 doc_cons.setAttribute('egal_txt',774 str(constraint.egal_txt.GetLabel()))775 doc_cons.setAttribute('constraint',776 str(constraint.constraint.GetValue()))777 constraints.appendChild(doc_cons)778 779 # Save all models780 models = newdoc.createElement('model_list')781 batch_combo.appendChild(models)782 for model in batch_fit_state.model_list:783 doc_model = newdoc.createElement('model_list_item')784 doc_model.setAttribute('checked', str(model[0].GetValue()))785 keys = model[1].keys()786 doc_model.setAttribute('name', str(keys[0]))787 values = model[1].get(keys[0])788 doc_model.setAttribute('fit_number', str(model[2]))789 doc_model.setAttribute('fit_page_source', str(model[3]))790 doc_model.setAttribute('model_name', str(values.model.id))791 models.appendChild(doc_model)792 793 # Select All Checkbox794 element = newdoc.createElement('select_all')795 if batch_fit_state.select_all:796 element.setAttribute('checked', 'True')797 else:798 element.setAttribute('checked', 'False')799 batch_combo.appendChild(element)800 745 801 746 # Save the file … … 864 809 :param file: .fitv file 865 810 :param node: node of a XML document to read from 811 866 812 """ 867 813 if file is not None: … … 870 816 raise RuntimeError, msg 871 817 872 if node.get('version') 818 if node.get('version')and node.get('version') == '1.0': 873 819 874 820 # Get file name … … 916 862 value = cls.type 917 863 except Exception: 918 base ="unable to load distribution %r for %s"919 logging.error(base% (value, parameter))864 logging.error("unable to load distribution %r for %s" 865 % (value, parameter)) 920 866 continue 921 867 _disp_obj_dict = getattr(self, varname) … … 1014 960 self.cansas = cansas 1015 961 self.state = None 1016 # batch fitting params for saving1017 self.batchfit_params = []1018 962 1019 963 def get_state(self): … … 1040 984 raise RuntimeError, "The cansas writer expects a Data2D instance" 1041 985 1042 title = "cansas1d/%s" % self.version1043 title += "http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd"1044 986 doc = xml.dom.minidom.Document() 1045 987 main_node = doc.createElement("SASroot") 1046 988 main_node.setAttribute("version", self.version) 1047 989 main_node.setAttribute("xmlns", "cansas1d/%s" % self.version) 1048 main_node.setAttribute("xmlns:xsi", 1049 "http://www.w3.org/2001/XMLSchema-instance")1050 main_node.setAttribute("xsi:schemaLocation", title)990 main_node.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance") 991 main_node.setAttribute("xsi:schemaLocation", 992 "cansas1d/%s http://svn.smallangles.net/svn/canSAS/1dwg/trunk/cansas1d.xsd" % self.version) 1051 993 1052 994 doc.appendChild(main_node) … … 1057 999 write_node(doc, entry_node, "Title", datainfo.title) 1058 1000 if datainfo is not None: 1059 write_node(doc, entry_node, "data_class", 1060 datainfo.__class__.__name__) 1001 write_node(doc, entry_node, "data_class", datainfo.__class__.__name__) 1061 1002 for item in datainfo.run: 1062 1003 runname = {} 1063 if datainfo.run_name.has_key(item) and \ 1064 len(str(datainfo.run_name[item])) > 1: 1004 if datainfo.run_name.has_key(item) and len(str(datainfo.run_name[item])) > 1: 1065 1005 runname = {'name': datainfo.run_name[item]} 1066 1006 write_node(doc, entry_node, "Run", item, runname) … … 1279 1219 1280 1220 :param entry: XML node to read from 1221 1281 1222 :return: PageState object 1282 1223 """ … … 1287 1228 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, 1288 1229 namespaces={'ns': CANSAS_NS}) 1289 if nodes :1230 if nodes != []: 1290 1231 # Create an empty state 1291 1232 state = PageState() … … 1297 1238 1298 1239 return state 1299 1300 def _parse_simfit_state(self, entry):1301 """1302 Parses the saved data for a simultaneous fit1303 :param entry: XML object to read from1304 :return: XML object for a simultaneous fit or None1305 """1306 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME,1307 namespaces={'ns': CANSAS_NS})1308 if nodes:1309 simfitstate = nodes[0].xpath('ns:simultaneous_fit',1310 namespaces={'ns': CANSAS_NS})1311 if simfitstate:1312 from simfitpage import SimFitPageState1313 sim_fit_state = SimFitPageState()1314 simfitstate_0 = simfitstate[0]1315 all = simfitstate_0.xpath('ns:select_all',1316 namespaces={'ns': CANSAS_NS})1317 atts = all[0].attrib1318 checked = atts.get('checked')1319 sim_fit_state.select_all = bool(checked)1320 model_list = simfitstate_0.xpath('ns:model_list',1321 namespaces={'ns': CANSAS_NS})1322 model_list_items = model_list[0].xpath('ns:model_list_item',1323 namespaces={'ns': CANSAS_NS})1324 for model in model_list_items:1325 attrs = model.attrib1326 sim_fit_state.model_list.append(attrs)1327 1328 constraints = simfitstate_0.xpath('ns:constraints',1329 namespaces={'ns': CANSAS_NS})1330 constraint_list = constraints[0].xpath('ns:constraint',1331 namespaces={'ns': CANSAS_NS})1332 for constraint in constraint_list:1333 attrs = constraint.attrib1334 sim_fit_state.constraints_list.append(attrs)1335 1336 return sim_fit_state1337 else:1338 return None1339 1240 1340 1241 def _parse_save_state_entry(self, dom): … … 1397 1298 data_info.notes.append(note_value) 1398 1299 except Exception: 1399 err_mess = "cansas_reader.read: error processing entry notes\n" 1400 err_mess += " %s" % sys.exc_value 1300 err_mess = "cansas_reader.read: error processing entry notes\n %s" % sys.exc_value 1401 1301 self.errors.append(err_mess) 1402 1302 logging.error(err_mess) … … 1408 1308 1409 1309 self._store_content('ns:SASsample/ns:ID', dom, 'ID', data_info.sample) 1410 self._store_float('ns:SASsample/ns:thickness', dom, 'thickness', 1411 data_info.sample) 1412 self._store_float('ns:SASsample/ns:transmission', dom, 'transmission', 1413 data_info.sample) 1414 self._store_float('ns:SASsample/ns:temperature', dom, 'temperature', 1415 data_info.sample) 1416 1417 nodes = dom.xpath('ns:SASsample/ns:details', 1418 namespaces={'ns': CANSAS_NS}) 1310 self._store_float('ns:SASsample/ns:thickness', dom, 'thickness', data_info.sample) 1311 self._store_float('ns:SASsample/ns:transmission', dom, 'transmission', data_info.sample) 1312 self._store_float('ns:SASsample/ns:temperature', dom, 'temperature', data_info.sample) 1313 1314 nodes = dom.xpath('ns:SASsample/ns:details', namespaces={'ns': CANSAS_NS}) 1419 1315 for item in nodes: 1420 1316 try: … … 1424 1320 data_info.sample.details.append(detail_value) 1425 1321 except Exception: 1426 err_mess = "cansas_reader.read: error processing entry notes\n" 1427 err_mess += " %s" % sys.exc_value 1322 err_mess = "cansas_reader.read: error processing sample details\n %s" % sys.exc_value 1428 1323 self.errors.append(err_mess) 1429 1324 logging.error(err_mess) 1430 1325 1431 1326 # Position (as a vector) 1432 self._store_float('ns:SASsample/ns:position/ns:x', dom, 'position.x', 1433 data_info.sample) 1434 self._store_float('ns:SASsample/ns:position/ns:y', dom, 'position.y', 1435 data_info.sample) 1436 self._store_float('ns:SASsample/ns:position/ns:z', dom, 'position.z', 1437 data_info.sample) 1327 self._store_float('ns:SASsample/ns:position/ns:x', dom, 'position.x', data_info.sample) 1328 self._store_float('ns:SASsample/ns:position/ns:y', dom, 'position.y', data_info.sample) 1329 self._store_float('ns:SASsample/ns:position/ns:z', dom, 'position.z', data_info.sample) 1438 1330 1439 1331 # Orientation (as a vector) … … 1569 1461 process.term.append(term_attr) 1570 1462 except: 1571 err_mess = "cansas_reader.read: error processing " 1572 err_mess += "entry notes\n %s" % sys.exc_value 1463 err_mess = "cansas_reader.read: error processing process term\n %s" % sys.exc_value 1573 1464 self.errors.append(err_mess) 1574 1465 logging.error(err_mess) … … 1585 1476 nodes = dom.xpath('ns:SASdata', namespaces={'ns': CANSAS_NS}) 1586 1477 if len(nodes) > 1: 1587 raise RuntimeError, "CanSAS reader is not compatible with" + \ 1588 " multiple SASdata entries" 1478 raise RuntimeError, "CanSAS reader is not compatible with multiple SASdata entries" 1589 1479 1590 1480 for entry in nodes: … … 1598 1488 value_list = [] 1599 1489 if field is not None: 1600 value_list = \ 1601 [parse_entry_helper(node, item) for node in field] 1490 value_list = [parse_entry_helper(node, item) for node in field] 1602 1491 if len(value_list) < 2: 1603 1492 setattr(data_info, item[0], None) … … 1609 1498 def _read_cansas(self, path): 1610 1499 """ 1611 Load data and fittinginformation from a CanSAS XML file.1500 Load data and P(r) information from a CanSAS XML file. 1612 1501 1613 1502 :param path: file path 1503 1614 1504 :return: Data1D object if a single SASentry was found, 1615 1505 or a list of Data1D objects if multiple entries were found, 1616 1506 or None of nothing was found 1507 1617 1508 :raise RuntimeError: when the file can't be opened 1618 1509 :raise ValueError: when the length of the data vectors are inconsistent 1510 1619 1511 """ 1620 1512 output = [] 1621 simfitstate = None1622 1513 basename = os.path.basename(path) 1623 1514 root, extension = os.path.splitext(basename) … … 1625 1516 try: 1626 1517 if os.path.isfile(path): 1627 if ext in self.ext or ext == '.xml': 1518 1519 #TODO: eventually remove the check for .xml once 1520 # the P(r) writer/reader is truly complete. 1521 if ext in self.ext or \ 1522 ext == '.xml': 1523 1628 1524 tree = etree.parse(path, parser=etree.ETCompatXMLParser()) 1629 1525 # Check the format version number 1630 # Specifying the namespace will take care of the file 1631 # format version 1526 # Specifying the namespace will take care of the file format version 1632 1527 root = tree.getroot() 1633 1528 entry_list = root.xpath('ns:SASentry', 1634 1529 namespaces={'ns': CANSAS_NS}) 1635 name_map = {}1636 1530 for entry in entry_list: 1637 1531 try: … … 1641 1535 fitstate = self._parse_state(entry) 1642 1536 1643 # 1644 # 1645 if fitstate is notNone:1537 #state could be None when .svs file is loaded 1538 #in this case, skip appending to output 1539 if fitstate != None: 1646 1540 sas_entry.meta_data['fitstate'] = fitstate 1647 1541 sas_entry.filename = fitstate.file 1648 1542 output.append(sas_entry) 1649 1650 1543 else: 1651 1544 self.call_back(format=ext) … … 1687 1580 name = original_fname 1688 1581 state.data.group_id = name 1689 # 1582 #store state in fitting 1690 1583 self.call_back(state=state, 1691 1584 datainfo=output[ind], format=ext) 1692 1585 self.state = state 1693 simfitstate = self._parse_simfit_state(entry)1694 if simfitstate is not None:1695 self.call_back(state=simfitstate)1696 1697 1586 return output 1698 1587 except: … … 1710 1599 """ 1711 1600 # Sanity check 1712 if self.cansas :1601 if self.cansas == True: 1713 1602 # Add fitting information to the XML document 1714 1603 doc = self.write_toXML(datainfo, fitstate) … … 1722 1611 fd.close() 1723 1612 1724 def write_toXML(self, datainfo=None, state=None , batchfit=None):1613 def write_toXML(self, datainfo=None, state=None): 1725 1614 """ 1726 1615 Write toXML, a helper for write(), … … 1730 1619 """ 1731 1620 1732 self.batchfit_params = batchfit1733 if state.data is None or not state.data.is_data:1621 if state.data is None: 1622 data = sas.sascalc.dataloader.data_info.Data1D(x=[], y=[]) 1734 1623 return None 1735 # make sure title and data run are filled. 1736 if state.data.title is None or state.data.title == '': 1737 state.data.title = state.data.name 1738 if state.data.run_name is None or state.data.run_name == {}: 1739 state.data.run = [str(state.data.name)] 1740 state.data.run_name[0] = state.data.name 1741 1742 if issubclass(state.data.__class__, 1743 sas.sascalc.dataloader.data_info.Data1D): 1744 data = state.data 1745 doc, sasentry = self._to_xml_doc(data) 1624 elif not state.data.is_data: 1625 return None 1746 1626 else: 1747 data = state.data 1748 doc, sasentry = self._data2d_to_xml_doc(data) 1627 #make sure title and data run is filled up. 1628 if state.data.title == None or state.data.title == '': 1629 state.data.title = state.data.name 1630 if state.data.run_name == None or state.data.run_name == {}: 1631 state.data.run = [str(state.data.name)] 1632 state.data.run_name[0] = state.data.name 1633 1634 if issubclass(state.data.__class__, 1635 sas.sascalc.dataloader.data_info.Data1D): 1636 data = state.data 1637 doc, sasentry = self._to_xml_doc(data) 1638 else: 1639 data = state.data 1640 doc, sasentry = self._data2d_to_xml_doc(data) 1749 1641 1750 1642 if state is not None: 1751 doc = state.toXML(doc=doc, file=data.filename, entry_node=sasentry, 1752 batch_fit_state=self.batchfit_params) 1643 doc = state.toXML(doc=doc, file=data.filename, entry_node=sasentry) 1753 1644 1754 1645 return doc 1646 1647 # Simple html report templet 1648 HEADER = "<html>\n" 1649 HEADER += "<head>\n" 1650 HEADER += "<meta http-equiv=Content-Type content='text/html; " 1651 HEADER += "charset=windows-1252'> \n" 1652 HEADER += "<meta name=Generator >\n" 1653 HEADER += "</head>\n" 1654 HEADER += "<body lang=EN-US>\n" 1655 HEADER += "<div class=WordSection1>\n" 1656 HEADER += "<p class=MsoNormal><b><span ><center><font size='4' >" 1657 HEADER += "%s</font></center></span></center></b></p>" 1658 HEADER += "<p class=MsoNormal> </p>" 1659 PARA = "<p class=MsoNormal><font size='4' > %s \n" 1660 PARA += "</font></p>" 1661 CENTRE = "<p class=MsoNormal><center><font size='4' > %s \n" 1662 CENTRE += "</font></center></p>" 1663 FEET_1 = \ 1664 """ 1665 <p class=MsoNormal> </p> 1666 <br> 1667 <p class=MsoNormal><b><span ><center> <font size='4' > Graph 1668 </font></span></center></b></p> 1669 <p class=MsoNormal> </p> 1670 <center> 1671 <br><font size='4' >Model Computation</font> 1672 <br><font size='4' >Data: "%s"</font><br> 1673 """ 1674 FEET_2 = \ 1675 """ 1676 <img src="%s" > 1677 </img> 1678 """ 1679 FEET_3 = \ 1680 """ 1681 </center> 1682 </div> 1683 </body> 1684 </html> 1685 """ 1686 ELINE = "<p class=MsoNormal> </p>" 1687 1688 if __name__ == "__main__": 1689 state = PageState(parent=None) 1690 #state.toXML() 1691 """ 1692 1693 file = open("test_state", "w") 1694 pickle.dump(state, file) 1695 print pickle.dumps(state) 1696 state.data_name = "hello---->" 1697 pickle.dump(state, file) 1698 file = open("test_state", "r") 1699 new_state= pickle.load(file) 1700 print "new state", new_state 1701 new_state= pickle.load(file) 1702 print "new state", new_state 1703 #print "state", state 1704 """ 1705 import bsddb 1706 import pickle 1707 db = bsddb.btopen('file_state.db', 'c') 1708 val = (pickle.dumps(state), "hello", "hi") 1709 db['state1'] = pickle.dumps(val) 1710 print pickle.loads(db['state1']) 1711 state.data_name = "hello---->22" 1712 db['state2'] = pickle.dumps(state) 1713 state.data_name = "hello---->2" 1714 db['state3'] = pickle.dumps(state) 1715 del db['state3'] 1716 state.data_name = "hello---->3" 1717 db['state4'] = pickle.dumps(state) 1718 new_state = pickle.loads(db['state1']) 1719 #print db.last() 1720 db.set_location('state2') 1721 state.data_name = "hello---->5" 1722 db['aastate5'] = pickle.dumps(state) 1723 db.keys().sort() 1724 print pickle.loads(db['state2']) 1725 1726 db.close() -
src/sas/sasgui/perspectives/fitting/simfitpage.py
r998ca90 r4cafdff 9 9 from wx.lib.scrolledpanel import ScrolledPanel 10 10 11 from sas.sasgui.guiframe.events import StatusEvent , PanelOnFocusEvent11 from sas.sasgui.guiframe.events import StatusEvent 12 12 from sas.sasgui.guiframe.panel_base import PanelBase 13 from sas.sasgui.guiframe.events import PanelOnFocusEvent 13 14 from sas.sasgui.guiframe.utils import IdList 14 15 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 15 16 16 # Control panel width17 #Control panel width 17 18 if sys.platform.count("darwin") == 0: 18 19 PANEL_WID = 420 … … 28 29 'model_cbox param_cbox egal_txt constraint btRemove sizer') 29 30 30 31 31 def get_fittableParam(model): 32 32 """ … … 47 47 return fittable_param 48 48 49 50 49 class SimultaneousFitPage(ScrolledPanel, PanelBase): 51 50 """ … … 54 53 two data members window_name and window_caption 55 54 """ 56 # Internal name for the AUI manager57 window_name = " Simultaneous Fit Page"58 # Title to appear on top of the window55 ## Internal name for the AUI manager 56 window_name = "simultaneous Fit page" 57 ## Title to appear on top of the window 59 58 window_caption = "Simultaneous Fit Page" 60 59 ID_DOC = wx.NewId() … … 75 74 self._ids = iter(self._id_pool) 76 75 self.SetupScrolling() 77 # 76 ##Font size 78 77 self.SetWindowVariant(variant=FONT_VARIANT) 79 78 self.uid = wx.NewId() 80 79 self.parent = parent 81 80 self.batch_on = batch_on 82 # store page_finder81 ## store page_finder 83 82 self.page_finder = page_finder 84 # list containing info to set constraint85 # look like self.constraint_dict[page_id]= page83 ## list containing info to set constraint 84 ## look like self.constraint_dict[page_id]= page 86 85 self.constraint_dict = {} 87 # item list88 # self.constraints_list=[combobox1, combobox2,=,textcrtl, button ]86 ## item list 87 ## self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 89 88 self.constraints_list = [] 90 # list of current model89 ## list of current model 91 90 self.model_list = [] 92 # selected model to fit93 self.model_to _fit = []94 # Control the fit state91 ## selected mdoel to fit 92 self.model_toFit = [] 93 ## Control the fit state 95 94 self.fit_started = False 96 # number of constraint95 ## number of constraint 97 96 self.nb_constraint = 0 98 self.state = SimFitPageState()99 97 self.model_cbox_left = None 100 98 self.model_cbox_right = None 101 # draw page99 ## draw page 102 100 self.define_page_structure() 103 101 self.draw_page() … … 109 107 """ 110 108 self.vbox = wx.BoxSizer(wx.VERTICAL) 111 self. data_selection_sizer= wx.BoxSizer(wx.VERTICAL)112 self. constraints_sizer= wx.BoxSizer(wx.VERTICAL)113 self. run_fit_sizer= wx.BoxSizer(wx.VERTICAL)114 115 self. data_selection_sizer.SetMinSize((PANEL_WID, -1))116 self. constraints_sizer.SetMinSize((PANEL_WID, -1))117 self. run_fit_sizer.SetMinSize((PANEL_WID, -1))118 self.vbox.Add(self. data_selection_sizer)119 self.vbox.Add(self. constraints_sizer)120 self.vbox.Add(self. run_fit_sizer)109 self.sizer1 = wx.BoxSizer(wx.VERTICAL) 110 self.sizer2 = wx.BoxSizer(wx.VERTICAL) 111 self.sizer3 = wx.BoxSizer(wx.VERTICAL) 112 113 self.sizer1.SetMinSize((PANEL_WID, -1)) 114 self.sizer2.SetMinSize((PANEL_WID, -1)) 115 self.sizer3.SetMinSize((PANEL_WID, -1)) 116 self.vbox.Add(self.sizer1) 117 self.vbox.Add(self.sizer2) 118 self.vbox.Add(self.sizer3) 121 119 self.SetSizer(self.vbox) 122 120 self.Centre() 123 124 def set_state(self):125 """126 Define a set of state parameters for saving simultaneous fits.127 """128 self._set_constraint()129 self.state.fit_page_no = self.uid130 self.state.select_all = self.cb1.GetValue()131 self.state.model_list = self.model_list132 self.state.model_to_fit = self.model_to_fit133 self.state.no_constraint = self.nb_constraint134 self.state.constraint_dict = self.constraint_dict135 self.state.constraints_list = self.constraints_list136 return self.get_state()137 138 def get_state(self):139 """140 Return the state of the current page141 :return: self.state142 """143 return self.state144 121 145 122 def draw_page(self): … … 154 131 # create blank list of constraints 155 132 self.model_list = [] 156 self.model_to _fit = []133 self.model_toFit = [] 157 134 self.constraints_list = [] 158 135 self.constraint_dict = {} … … 167 144 168 145 #------------------------------------------------------- 169 # setup sizer1 (which fitpages to include)170 self. data_selection_sizer.Clear(True)146 ## setup sizer1 (which fitpages to include) 147 self.sizer1.Clear(True) 171 148 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Combinations") 172 149 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) … … 174 151 sizer_couples = wx.GridBagSizer(5, 5) 175 152 176 # The wx GUI has a flag to enable a menu item, but can still be177 # reached via scripting. There is no guearantee future GUI178 # implementations force this check, either.179 # IMHO, this if statement should stay -- JRK 2016-OCT-05153 #This if statement should be obsolete and can be removed in version 4 154 #Leave it here for now as no time to thoroughly test. However if no 155 #fit page is found the menu item that calls this page is inactive 156 # Nov. 22 2015 --PDB 180 157 if len(self.page_finder) == 0: 181 158 msg = " No fit combinations are found! \n\n" … … 184 161 sizer_title.Add(wx.StaticText(self, wx.ID_ANY, msg)) 185 162 else: 186 # store model163 ## store model 187 164 self._store_model() 188 165 … … 194 171 wx.TOP | wx.BOTTOM | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 195 172 sizer_title.Add(self.cb1, 0, 196 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 197 border=5) 198 199 # draw list of model and data names 173 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 174 175 ## draw list of model and data names 200 176 self._fill_sizer_model_list(sizer_couples) 201 177 202 178 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=5) 203 179 boxsizer1.Add(sizer_couples, 1, flag=wx.TOP | wx.BOTTOM, border=5) 204 self. data_selection_sizer.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10)205 #self.sizer1.Layout()180 self.sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10) 181 # self.sizer1.Layout() 206 182 207 183 #-------------------------------------------------------- 208 # set up the other 2 sizers: the constraints list and the 209 # buttons (fit, help etc) sizer at the bottom of the page. 210 # Note: the if statement should be removed along with the above 211 # if statement as soon as it can be properly tested. 212 # Nov. 22 2015 --PDB 213 # As above, this page can be accessed through other means than the 214 # base SasView GUI. 215 # Oct. 5, 2016 --JRK 184 ## set up the other 2 sizers: the constraints list and the 185 ## buttons (fit, help etc) sizer at the bottom of the page. 186 ## Note: the if statement should be removed along with the above 187 ## if statement as soon as it can be properly tested. 188 ## Nov. 22 2015 --PDB 216 189 if len(self.page_finder) > 0: 217 # draw the sizer containing constraint info190 ## draw the sizer containing constraint info 218 191 if not self.batch_on: 219 192 self._fill_sizer_constraint() 220 # draw fit button sizer193 ## draw fit button sizer 221 194 self._fill_sizer_fit() 195 222 196 223 197 def _fill_sizer_model_list(self, sizer): … … 227 201 ix = 0 228 202 iy = 0 203 list = [] 229 204 sizer.Clear(True) 230 205 … … 234 209 new_name.SetForegroundColour(wx.WHITE) 235 210 sizer.Add(new_name, (iy, ix), (1, 1), 236 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)211 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 237 212 ix += 2 238 213 model_type = wx.StaticText(self, wx.ID_ANY, ' Model ') … … 240 215 model_type.SetForegroundColour(wx.WHITE) 241 216 sizer.Add(model_type, (iy, ix), (1, 1), 242 wx.EXPAND | wx.ADJUST_MINSIZE, 0)217 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 243 218 ix += 1 244 219 data_used = wx.StaticText(self, wx.ID_ANY, ' Data ') … … 246 221 data_used.SetForegroundColour(wx.WHITE) 247 222 sizer.Add(data_used, (iy, ix), (1, 1), 248 wx.EXPAND | wx.ADJUST_MINSIZE, 0)223 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 249 224 ix += 1 250 225 tab_used = wx.StaticText(self, wx.ID_ANY, ' FitPage ') … … 327 302 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 328 303 329 self. constraints_sizer.Clear(True)304 self.sizer2.Clear(True) 330 305 if self.batch_on: 331 if self. constraints_sizer.IsShown():332 self. constraints_sizer.Show(False)306 if self.sizer2.IsShown(): 307 self.sizer2.Show(False) 333 308 return 334 309 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Constraints") 335 box _sizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)310 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 336 311 sizer_title = wx.BoxSizer(wx.HORIZONTAL) 337 312 self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL) … … 363 338 364 339 self.btAdd = wx.Button(self, self.ID_ADD, 'Add') 365 self.btAdd.Bind(wx.EVT_BUTTON, self._on _add_constraint,340 self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint, 366 341 id=self.btAdd.GetId()) 367 342 self.btAdd.SetToolTipString("Add another constraint?") … … 369 344 370 345 text_hint = wx.StaticText(self, wx.ID_ANY, 371 "Example: [M0][param eter] = M1.parameter")346 "Example: [M0][paramter] = M1.parameter") 372 347 sizer_button.Add(text_hint, 0, 373 348 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) … … 375 350 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 376 351 377 box_sizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 378 box_sizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 379 border=10) 380 box_sizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 381 border=10) 382 box_sizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 383 384 self.constraints_sizer.Add(box_sizer1, 0, wx.EXPAND | wx.ALL, 10) 352 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 353 boxsizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 354 border=10) 355 boxsizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 356 border=10) 357 boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 358 359 self.sizer2.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 360 385 361 386 362 def _fill_sizer_fit(self): … … 388 364 Draw fit button 389 365 """ 390 self. run_fit_sizer.Clear(True)366 self.sizer3.Clear(True) 391 367 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit ") 392 368 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 393 369 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 394 370 395 # 371 #Fit button 396 372 self.btFit = wx.Button(self, self.ID_FIT, 'Fit', size=wx.DefaultSize) 397 self.btFit.Bind(wx.EVT_BUTTON, self.on _fit, id=self.btFit.GetId())373 self.btFit.Bind(wx.EVT_BUTTON, self.onFit, id=self.btFit.GetId()) 398 374 self.btFit.SetToolTipString("Perform fit.") 399 375 400 # 376 #General Help button 401 377 self.btHelp = wx.Button(self, wx.ID_HELP, 'HELP') 402 378 self.btHelp.SetToolTipString("Simultaneous/Constrained Fitting help.") 403 self.btHelp.Bind(wx.EVT_BUTTON, self._on _help)404 405 # 379 self.btHelp.Bind(wx.EVT_BUTTON, self._onHelp) 380 381 #hint text on button line 406 382 if self.batch_on: 407 383 text = " Fit in Parallel all Data sets\n" … … 417 393 418 394 boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 419 self. run_fit_sizer.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10)420 421 def on _remove(self, event):395 self.sizer3.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 396 397 def onRemove(self, event): 422 398 """ 423 399 Remove constraint fields … … 430 406 return 431 407 wx.CallAfter(self._remove_after, event.GetId()) 432 # 408 #self._onAdd_constraint(None) 433 409 434 410 def _remove_after(self, id): … … 440 416 self.constraints_list.remove(item) 441 417 self.nb_constraint -= 1 442 self. constraints_sizer.Layout()418 self.sizer2.Layout() 443 419 self.FitInside() 444 420 break 445 421 446 def on _fit(self, event):422 def onFit(self, event): 447 423 """ 448 424 signal for fitting … … 459 435 flag = (self._manager.sim_page.uid == self.uid) 460 436 461 # making sure all parameters content a constraint437 ## making sure all parameters content a constraint 462 438 if not self.batch_on and self.show_constraint.GetValue(): 463 439 if not self._set_constraint(): 464 440 return 465 # model was actually selected from this page to be fit466 if len(self.model_to _fit) >= 1:441 ## model was actually selected from this page to be fit 442 if len(self.model_toFit) >= 1: 467 443 self.manager._reset_schedule_problem(value=0) 468 444 for item in self.model_list: … … 480 456 msg = "Select at least one model check box to fit " 481 457 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 482 self.set_state()483 458 484 459 def _on_fit_complete(self): … … 492 467 """ 493 468 Attempt to stop the fitting thread 494 495 :param event: Event handler when stop fit is clicked 496 """ 497 if event is not None: 469 """ 470 if event != None: 498 471 event.Skip() 499 472 self.manager.stop_fit(self.uid) … … 512 485 self.btFit.Enable(True) 513 486 514 def _on _help(self, event):487 def _onHelp(self, event): 515 488 """ 516 489 Bring up the simultaneous Fitting Documentation whenever the HELP … … 521 494 versions of Wx (before 2.9) and thus not the release version of 522 495 installers, the help comes up at the top level of the file as 523 web 496 webbrowser does not pass anything past the # to the browser when it is 524 497 running "file:///...." 525 498 526 :param ev ent: Triggers on clicking the help button499 :param evt: Triggers on clicking the help button 527 500 """ 528 501 _TreeLocation = "user/sasgui/perspectives/fitting/fitting_help.html" … … 537 510 538 511 :param manager: instance of plugin fitting 512 539 513 """ 540 514 self.manager = manager … … 544 518 check all models names 545 519 """ 546 self.model_to _fit = []547 if self.cb1.GetValue() :520 self.model_toFit = [] 521 if self.cb1.GetValue() == True: 548 522 for item in self.model_list: 549 523 if item[0].IsEnabled(): 550 524 item[0].SetValue(True) 551 self.model_to _fit.append(item)552 553 # constraint info525 self.model_toFit.append(item) 526 527 ## constraint info 554 528 self._store_model() 555 529 if not self.batch_on: 556 # display constraint fields530 ## display constraint fields 557 531 if (self.show_constraint.GetValue() and 558 532 len(self.constraints_list) == 0): … … 564 538 565 539 if not self.batch_on: 566 # 540 ##constraint info 567 541 self._hide_constraint() 568 542 … … 570 544 self.FitInside() 571 545 546 572 547 def check_model_name(self, event): 573 548 """ 574 549 Save information related to checkbox and their states 575 550 """ 576 self.model_to_fit = [] 551 self.model_toFit = [] 552 cbox = event.GetEventObject() 577 553 for item in self.model_list: 578 if item[0].GetValue() :579 self.model_to _fit.append(item)554 if item[0].GetValue() == True: 555 self.model_toFit.append(item) 580 556 else: 581 if item in self.model_to _fit:582 self.model_to _fit.remove(item)557 if item in self.model_toFit: 558 self.model_toFit.remove(item) 583 559 self.cb1.SetValue(False) 584 560 585 # display constraint fields586 if len(self.model_to _fit) >= 1:561 ## display constraint fields 562 if len(self.model_toFit) >= 1: 587 563 self._store_model() 588 564 if not self.batch_on and self.show_constraint.GetValue() and\ … … 591 567 self._show_constraint() 592 568 593 elif len(self.model_to _fit) < 1:594 # 569 elif len(self.model_toFit) < 1: 570 ##constraint info 595 571 self._hide_constraint() 596 572 597 573 self._update_easy_setup_cb() 598 # set the value of the main check button599 if len(self.model_list) == len(self.model_to _fit):574 ## set the value of the main check button 575 if len(self.model_list) == len(self.model_toFit): 600 576 self.cb1.SetValue(True) 601 577 self.FitInside() … … 609 585 Update easy setup combobox on selecting a model 610 586 """ 611 if self.model_cbox_left is None or self.model_cbox_right isNone:612 return 613 614 models = [(item[3].name, item[3]) for item in self.model_to _fit]587 if self.model_cbox_left == None or self.model_cbox_right == None: 588 return 589 590 models = [(item[3].name, item[3]) for item in self.model_toFit] 615 591 setComboBoxItems(self.model_cbox_left, models) 616 592 setComboBoxItems(self.model_cbox_right, models) … … 619 595 if self.model_cbox_left.GetSelection() == wx.NOT_FOUND: 620 596 self.model_cbox_left.SetSelection(0) 621 self. constraints_sizer.Layout()597 self.sizer2.Layout() 622 598 623 599 def _store_model(self): … … 625 601 Store selected model 626 602 """ 627 if len(self.model_to _fit) < 1:628 return 629 for item in self.model_to _fit:603 if len(self.model_toFit) < 1: 604 return 605 for item in self.model_toFit: 630 606 model = item[3] 631 607 page_id = item[2] … … 636 612 Show fields to add constraint 637 613 """ 638 if len(self.model_to _fit) < 1:614 if len(self.model_toFit) < 1: 639 615 msg = "Select at least 1 model to add constraint " 640 616 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 641 # hide button617 ## hide button 642 618 self._hide_constraint() 643 619 return … … 656 632 """ 657 633 box_description = wx.StaticBox(self, wx.ID_ANY, "Easy Setup ") 658 box _sizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL)634 boxsizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL) 659 635 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 660 636 self.model_cbox_left = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) … … 674 650 675 651 for id, model in self.constraint_dict.iteritems(): 676 # check if all parameters have been selected for constraint677 # then do not allow add constraint on parameters652 ## check if all parameters have been selected for constraint 653 ## then do not allow add constraint on parameters 678 654 self.model_cbox_left.Append(str(model.name), model) 679 655 self.model_cbox_left.Select(0) 680 656 for id, model in self.constraint_dict.iteritems(): 681 # check if all parameters have been selected for constraint682 # then do not allow add constraint on parameters657 ## check if all parameters have been selected for constraint 658 ## then do not allow add constraint on parameters 683 659 self.model_cbox_right.Append(str(model.name), model) 684 box _sizer.Add(self.model_cbox_left,660 boxsizer.Add(self.model_cbox_left, 685 661 flag=wx.RIGHT | wx.EXPAND, border=10) 686 # box_sizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"),662 #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 687 663 # flag=wx.RIGHT | wx.EXPAND, border=5) 688 box _sizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5)689 box _sizer.Add(self.model_cbox_right,664 boxsizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 665 boxsizer.Add(self.model_cbox_right, 690 666 flag=wx.RIGHT | wx.EXPAND, border=10) 691 # box_sizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"),667 #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 692 668 # flag=wx.RIGHT | wx.EXPAND, border=5) 693 box _sizer.Add((20, -1))694 box _sizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5)695 sizer_constraint.Add(box _sizer, flag=wx.RIGHT | wx.EXPAND, border=5)669 boxsizer.Add((20, -1)) 670 boxsizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5) 671 sizer_constraint.Add(boxsizer, flag=wx.RIGHT | wx.EXPAND, border=5) 696 672 self.sizer_all_constraints.Insert(before=0, 697 673 item=sizer_constraint, … … 723 699 return 724 700 param_list = [] 725 param_list _b= []701 param_listB = [] 726 702 selection = self.model_cbox_left.GetCurrentSelection() 727 703 model_left = self.model_cbox_left.GetValue() 728 704 model = self.model_cbox_left.GetClientData(selection) 729 selection _b= self.model_cbox_right.GetCurrentSelection()705 selectionB = self.model_cbox_right.GetCurrentSelection() 730 706 model_right = self.model_cbox_right.GetValue() 731 model _b = self.model_cbox_right.GetClientData(selection_b)707 modelB = self.model_cbox_right.GetClientData(selectionB) 732 708 for id, dic_model in self.constraint_dict.iteritems(): 733 709 if model == dic_model: 734 710 param_list = self.page_finder[id].get_param2fit() 735 if model _b== dic_model:736 param_list _b= self.page_finder[id].get_param2fit()737 if len(param_list) > 0 and len(param_list _b) > 0:711 if modelB == dic_model: 712 param_listB = self.page_finder[id].get_param2fit() 713 if len(param_list) > 0 and len(param_listB) > 0: 738 714 break 739 715 num_cbox = 0 … … 741 717 for param in param_list: 742 718 num_cbox += 1 743 if param in param_list _b:719 if param in param_listB: 744 720 item = self.constraints_list[-1] 745 721 item.model_cbox.SetStringSelection(model_left) … … 768 744 """ 769 745 Show constraint fields 770 :param dict: dictionary mapping constraint values771 746 """ 772 747 self.btAdd.Show(True) … … 775 750 for id, model in self.constraint_dict.iteritems(): 776 751 nb_fit_param += len(self.page_finder[id].get_param2fit()) 777 # 752 ##Don't add anymore 778 753 if len(self.constraints_list) == nb_fit_param: 779 754 msg = "Cannot add another constraint. Maximum of number " … … 781 756 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 782 757 self.sizer_constraints.Layout() 783 self. constraints_sizer.Layout()758 self.sizer2.Layout() 784 759 return 785 if len(self.model_to _fit) < 1:760 if len(self.model_toFit) < 1: 786 761 msg = "Select at least 1 model to add constraint " 787 762 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 788 763 self.sizer_constraints.Layout() 789 self. constraints_sizer.Layout()764 self.sizer2.Layout() 790 765 return 791 766 … … 796 771 model_cbox.Clear() 797 772 for id, model in self.constraint_dict.iteritems(): 798 # check if all parameters have been selected for constraint799 # then do not allow add constraint on parameters773 ## check if all parameters have been selected for constraint 774 ## then do not allow add constraint on parameters 800 775 model_cbox.Append(str(model.name), model) 801 776 wx.EVT_COMBOBOX(model_cbox, wx.ID_ANY, self._on_select_model) … … 814 789 # Remove button 815 790 #btRemove = wx.Button(self, self.ID_REMOVE, 'Remove') 816 bt _remove = wx.Button(self, self._ids.next(), 'Remove')817 bt _remove.Bind(wx.EVT_BUTTON, self.on_remove,818 id=bt _remove.GetId())819 bt _remove.SetToolTipString("Remove constraint.")820 bt _remove.Hide()791 btRemove = wx.Button(self, self._ids.next(), 'Remove') 792 btRemove.Bind(wx.EVT_BUTTON, self.onRemove, 793 id=btRemove.GetId()) 794 btRemove.SetToolTipString("Remove constraint.") 795 btRemove.Hide() 821 796 822 797 # Hid the add button, if it exists … … 829 804 sizer_constraint.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 830 805 sizer_constraint.Add(constraint, flag=wx.RIGHT | wx.EXPAND, border=10) 831 sizer_constraint.Add(bt _remove, flag=wx.RIGHT | wx.EXPAND, border=10)806 sizer_constraint.Add(btRemove, flag=wx.RIGHT | wx.EXPAND, border=10) 832 807 833 808 self.sizer_constraints.Insert(before=self.nb_constraint, … … 835 810 border=5) 836 811 c = ConstraintLine(model_cbox, param_cbox, egal_txt, 837 constraint, bt _remove, sizer_constraint)812 constraint, btRemove, sizer_constraint) 838 813 self.constraints_list.append(c) 839 814 840 815 self.nb_constraint += 1 841 816 self.sizer_constraints.Layout() 842 self. constraints_sizer.Layout()843 self.Layout ()817 self.sizer2.Layout() 818 self.Layout 844 819 845 820 def _hide_constraint(self): … … 866 841 self.sizer_constraints.Clear(True) 867 842 self.sizer_constraints.Layout() 868 self. constraints_sizer.Layout()869 self.Layout ()843 self.sizer2.Layout() 844 self.Layout 870 845 self.FitInside() 871 846 872 847 def _on_select_model(self, event): 873 848 """ 874 fill combo box with list of parameters849 fill combox box with list of parameters 875 850 """ 876 851 if not self.constraints_list: 877 852 return 878 853 879 # 854 ##This way PC/MAC both work, instead of using event.GetClientData(). 880 855 model_cbox = self.constraints_list[-1].model_cbox 881 856 n = model_cbox.GetCurrentSelection() … … 892 867 param_cbox = self.constraints_list[-1].param_cbox 893 868 param_cbox.Clear() 894 # insert only fittable paramaters869 ## insert only fittable paramaters 895 870 for param in param_list: 896 871 param_cbox.Append(str(param), model) 897 872 param_cbox.Show(True) 898 873 899 bt _remove = self.constraints_list[-1].btRemove900 bt _remove.Show(True)874 btRemove = self.constraints_list[-1].btRemove 875 btRemove.Show(True) 901 876 self.btAdd.Show(True) 902 877 # self.Layout() … … 907 882 Store the appropriate constraint in the page_finder 908 883 """ 909 # 910 # 911 # 912 # 884 ##This way PC/MAC both work, instead of using event.GetClientData(). 885 #n = self.param_cbox.GetCurrentSelection() 886 #model = self.param_cbox.GetClientData(n) 887 #param = event.GetString() 913 888 914 889 if self.constraints_list: … … 916 891 self.constraints_list[-1].constraint.Show(True) 917 892 918 def _on _add_constraint(self, event):893 def _onAdd_constraint(self, event): 919 894 """ 920 895 Add another line for constraint … … 924 899 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 925 900 return 926 # check that a constraint is added901 ## check that a constraint is added 927 902 # before allow to add another constraint 928 903 for item in self.constraints_list: … … 938 913 model = item.param_cbox.GetClientData( 939 914 item.param_cbox.GetCurrentSelection()) 940 if model is notNone:915 if model != None: 941 916 msg = " Enter a constraint for %s.%s! " % (model.name, 942 917 item.param_cbox.GetString(0)) … … 945 920 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 946 921 return 947 # some model or parameters can be constrained922 ## some model or parameters can be constrained 948 923 self._show_constraint() 949 924 self.FitInside() … … 1005 980 def on_set_focus(self, event=None): 1006 981 """ 1007 The derivative class is on focus if implemented982 The derivative class is on focus if implemented 1008 983 """ 1009 984 if self.parent is not None: … … 1020 995 cbox.Append(name, value) 1021 996 cbox.SetStringSelection(selected) 1022 1023 1024 class SimFitPageState:1025 """1026 State of the simultaneous fit page for saving purposes1027 """1028 1029 def __init__(self):1030 # Sim Fit Page Number1031 self.fit_page_no = None1032 # Select all data1033 self.select_all = False1034 # Data sets sent to fit page1035 self.model_list = []1036 # Data sets to be fit1037 self.model_to_fit = []1038 # Number of constraints1039 self.no_constraint = 01040 # Dictionary of constraints1041 self.constraint_dict = {}1042 # List of constraints1043 self.constraints_list = []1044 1045 def load_from_save_state(self, fit):1046 """1047 Load in a simultaneous/constrained fit from a save state1048 :param fit: Fitpanel object1049 :return: None1050 """1051 1052 model_map = {}1053 if fit.fit_panel.sim_page is None:1054 fit.fit_panel.add_sim_page()1055 sim_page = fit.fit_panel.sim_page1056 1057 # Process each model and associate old M# with new M#1058 i = 01059 for model in sim_page.model_list:1060 model_id = self._format_id(model[1].keys()[0])1061 for saved_model in self.model_list:1062 save_id = saved_model.pop('name')1063 saved_model['name'] = save_id1064 save_id = self._format_id(save_id)1065 if save_id == model_id:1066 model_map[saved_model.pop('fit_page_source')] = \1067 model[3].name1068 check = bool(saved_model.pop('checked'))1069 sim_page.model_list[i][0].SetValue(check)1070 break1071 i += 11072 sim_page.check_model_name(None)1073 1074 if len(self.constraints_list) > 0:1075 sim_page.hide_constraint.SetValue(False)1076 sim_page.show_constraint.SetValue(True)1077 sim_page._display_constraint(None)1078 1079 for index, item in enumerate(self.constraints_list):1080 model_cbox = item.pop('model_cbox')1081 if model_cbox != "":1082 constraint_value = item.pop('constraint')1083 param = item.pop('param_cbox')1084 equality = item.pop('egal_txt')1085 for key, value in model_map.iteritems():1086 model_cbox.replace(key, value)1087 constraint_value.replace(key, value)1088 1089 sim_page.constraints_list[index][0].SetValue(model_cbox)1090 sim_page._on_select_model(None)1091 sim_page.constraints_list[index][1].SetValue(param)1092 sim_page.constraints_list[index][2].SetLabel(equality)1093 sim_page.constraints_list[index][3].SetValue(constraint_value)1094 sim_page._on_add_constraint(None)1095 1096 def _format_id(self, original_id):1097 original_id = original_id.rstrip('1234567890.')1098 new_id_list = original_id.split()1099 new_id = ' '.join(new_id_list)1100 return new_id
Note: See TracChangeset
for help on using the changeset viewer.