Changeset 5062bbf in sasview for sansview/perspectives/fitting/models.py
- Timestamp:
- Jun 7, 2010 10:26:43 AM (14 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b94945d
- Parents:
- 79ac6f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/models.py
rce07fa8 r5062bbf 1 #TODO: add comments to document this module2 #TODO: clean-up the exception handling.3 4 #TODO: clean-up the FractalAbsModel and PowerLawAbsModel menu items. Those5 # model definitions do not belong here. They belong with the rest of the6 # models.7 1 8 2 import wx … … 23 17 24 18 def log(message): 19 """ 20 """ 25 21 out = open("plugins.log", 'a') 26 22 out.write("%10g: %s\n" % (time.clock(), message)) … … 28 24 29 25 def findModels(): 26 """ 27 """ 30 28 log("looking for models in: %s/plugins" % os.getcwd()) 31 29 if os.path.isdir('plugins'): … … 35 33 def _check_plugin(model, name): 36 34 """ 37 Do some checking before model adding plugins in the list 38 @param model: class model to add into the plugin list 39 @param name:name of the module plugin 40 @return model: model if valid model or None if not valid 35 Do some checking before model adding plugins in the list 36 37 :param model: class model to add into the plugin list 38 :param name:name of the module plugin 39 40 :return model: model if valid model or None if not valid 41 41 42 """ 42 43 #Check is the plugin is of type Model1DPlugin … … 74 75 75 76 def _findModels(dir): 77 """ 78 """ 76 79 # List of plugin objects 77 80 plugins = [] … … 114 117 class ModelList(object): 115 118 """ 116 119 Contains dictionary of model and their type 117 120 """ 118 121 def __init__(self): 119 self.mydict={} 122 """ 123 """ 124 self.mydict = {} 120 125 121 126 def set_list(self, name, mylist): 122 127 """ 123 @param name: the type of the list 124 @param mylist: the list to add 128 :param name: the type of the list 129 :param mylist: the list to add 130 125 131 """ 126 132 if name not in self.mydict.keys(): … … 130 136 def get_list(self): 131 137 """ 132 138 return all the list stored in a dictionary object 133 139 """ 134 140 return self.mydict 135 141 136 142 class ModelManager: 143 """ 144 """ 137 145 ## external dict for models 138 146 model_combobox = ModelList() … … 156 164 def _getModelList(self): 157 165 """ 158 List of models we want to make available by default 159 for this application 160 161 @return: the next free event ID following the new menu events 166 List of models we want to make available by default 167 for this application 168 169 :return: the next free event ID following the new menu events 170 162 171 """ 163 172 ## form factor … … 255 264 from sans.models.HayterMSAStructure import HayterMSAStructure 256 265 self.struct_list.append(HayterMSAStructure) 257 258 259 ##shape-independent models 260 266 267 ##shape-independent models 261 268 from sans.models.PowerLawAbsModel import PowerLawAbsModel 262 269 self.shape_indep_list.append( PowerLawAbsModel ) … … 293 300 self.shape_indep_list.append(PorodModel ) 294 301 295 296 302 #FractalModel (a c-model)will be used. 297 303 #from sans.models.FractalAbsModel import FractalAbsModel … … 303 309 from sans.models.LineModel import LineModel 304 310 self.shape_indep_list.append(LineModel) 305 306 311 307 312 #Looking for plugins 308 313 self.plugins = findModels() 309 310 314 return 0 311 315 … … 313 317 def populate_menu(self, modelmenu, event_owner): 314 318 """ 315 Populate a menu with our models 316 317 @param id: first menu event ID to use when binding the menu events 318 @param modelmenu: wx.Menu object to populate 319 @param event_owner: wx object to bind the menu events to 320 @return: the next free event ID following the new menu events 319 Populate a menu with our models 320 321 :param id: first menu event ID to use when binding the menu events 322 :param modelmenu: wx.Menu object to populate 323 :param event_owner: wx object to bind the menu events to 324 325 :return: the next free event ID following the new menu events 326 321 327 """ 322 328 ## Fill model lists … … 327 333 self.event_owner = event_owner 328 334 329 330 335 shape_submenu = wx.Menu() 331 336 shape_indep_submenu = wx.Menu() … … 334 339 multip_models = wx.Menu() 335 340 ## create menu with shape 336 self._fill_simple_menu( menuinfo =["Shapes",shape_submenu," simple shape"],337 list1 = self.shape_list)338 339 self._fill_simple_menu( menuinfo =["Shape-Independent",shape_indep_submenu,341 self._fill_simple_menu(menuinfo=["Shapes",shape_submenu," simple shape"], 342 list1=self.shape_list) 343 344 self._fill_simple_menu(menuinfo=["Shape-Independent",shape_indep_submenu, 340 345 "List of shape-independent models"], 341 list1 =self.shape_indep_list )342 343 self._fill_simple_menu( menuinfo=["Structure Factors",structure_factor,346 list1=self.shape_indep_list ) 347 348 self._fill_simple_menu(menuinfo=["Structure Factors",structure_factor, 344 349 "List of Structure factors models" ], 345 list1= self.struct_list)346 347 self._fill_plugin_menu( menuinfo =["Customized Models", added_models,350 list1=self.struct_list) 351 352 self._fill_plugin_menu(menuinfo=["Customized Models", added_models, 348 353 "List of additional models"], 349 list1= self.plugins)354 list1=self.plugins) 350 355 351 356 self._fill_menu(menuinfo=["P(Q)*S(Q)",multip_models, 352 357 "mulplication of 2 models"], 353 list1 = self.multiplication_factor , 354 list2 = self.struct_list) 355 356 358 list1=self.multiplication_factor , 359 list2= self.struct_list) 357 360 return 0 358 361 359 def _fill_plugin_menu(self, menuinfo, list1):360 """ 361 362 def _fill_plugin_menu(self, menuinfo, list1): 363 """ 364 fill the plugin menu with costumized models 362 365 """ 363 366 if len(list1)==0: … … 367 370 self._fill_simple_menu( menuinfo,list1) 368 371 369 370 def _fill_simple_menu(self,menuinfo, list1): 371 """ 372 Fill the menu with list item 373 @param modelmenu: the menu to fill 374 @param menuinfo: submenu item for the first column of this modelmenu 375 with info.Should be a list : 376 [name(string) , menu(wx.menu), help(string)] 377 @param list1: contains item (form factor )to fill modelmenu second column 372 def _fill_simple_menu(self, menuinfo, list1): 373 """ 374 Fill the menu with list item 375 376 :param modelmenu: the menu to fill 377 :param menuinfo: submenu item for the first column of this modelmenu 378 with info.Should be a list : 379 [name(string) , menu(wx.menu), help(string)] 380 :param list1: contains item (form factor )to fill modelmenu second column 381 378 382 """ 379 383 if len(list1)>0: … … 399 403 self.modelmenu.AppendMenu(id, menuinfo[0],menuinfo[1],menuinfo[2]) 400 404 401 402 403 def _fill_menu(self,menuinfo, list1,list2 ): 404 """ 405 Fill the menu with list item 406 @param menuinfo: submenu item for the first column of this modelmenu 407 with info.Should be a list : 408 [name(string) , menu(wx.menu), help(string)] 409 @param list1: contains item (form factor )to fill modelmenu second column 410 @param list2: contains item (Structure factor )to fill modelmenu third column 405 def _fill_menu(self, menuinfo, list1, list2): 406 """ 407 Fill the menu with list item 408 409 :param menuinfo: submenu item for the first column of this modelmenu 410 with info.Should be a list : 411 [name(string) , menu(wx.menu), help(string)] 412 :param list1: contains item (form factor )to fill modelmenu second column 413 :param list2: contains item (Structure factor )to fill modelmenu 414 third column 415 411 416 """ 412 417 if len(list1)>0: … … 437 442 self.modelmenu.AppendMenu(id,menuinfo[0],menuinfo[1], menuinfo[2]) 438 443 439 440 441 442 444 def _on_model(self, evt): 443 445 """ 444 React to a model menu event 445 @param event: wx menu event 446 React to a model menu event 447 448 :param event: wx menu event 449 446 450 """ 447 451 if int(evt.GetId()) in self.form_factor_dict.keys(): 448 452 from sans.models.MultiplicationModel import MultiplicationModel 449 453 model1, model2 = self.form_factor_dict[int(evt.GetId())] 450 model = MultiplicationModel(model1, model2) 451 454 model = MultiplicationModel(model1, model2) 452 455 else: 453 456 model= self.struct_factor_dict[str(evt.GetId())]() 454 455 457 evt = ModelEvent( model= model ) 456 458 wx.PostEvent(self.event_owner, evt) 457 459 458 460 def get_model_list(self): 459 """ @ return dictionary of models for fitpanel use """ 461 """ 462 return dictionary of models for fitpanel use 463 464 """ 460 465 self.model_combobox.set_list("multiplication", self.multiplication_factor) 461 466 return self.model_combobox
Note: See TracChangeset
for help on using the changeset viewer.