[61184df] | 1 | """ |
---|
| 2 | Utilities to manage models |
---|
| 3 | """ |
---|
[d89f09b] | 4 | import wx |
---|
[b30f001] | 5 | import imp |
---|
[9466f2d6] | 6 | import os |
---|
| 7 | import sys |
---|
| 8 | import math |
---|
[d89f09b] | 9 | import os.path |
---|
[33afff7] | 10 | # Time is needed by the log method |
---|
| 11 | import time |
---|
[23ccf07] | 12 | import logging |
---|
[5d1c1f4] | 13 | import py_compile |
---|
[96814e1] | 14 | import shutil |
---|
[f32d144] | 15 | from sans.guiframe.events import StatusEvent |
---|
[33afff7] | 16 | # Explicitly import from the pluginmodel module so that py2exe |
---|
| 17 | # places it in the distribution. The Model1DPlugin class is used |
---|
| 18 | # as the base class of plug-in models. |
---|
| 19 | from sans.models.pluginmodel import Model1DPlugin |
---|
[df7a7e3] | 20 | from sans.models.BaseComponent import BaseComponent |
---|
[9466f2d6] | 21 | |
---|
[f32d144] | 22 | PLUGIN_DIR = 'plugin_models' |
---|
| 23 | |
---|
[df7a7e3] | 24 | def get_model_python_path(): |
---|
| 25 | return os.path.dirname(__file__) |
---|
| 26 | |
---|
[9466f2d6] | 27 | |
---|
[b30f001] | 28 | def log(message): |
---|
[5062bbf] | 29 | """ |
---|
[61184df] | 30 | Log a message in a file located in the user's home directory |
---|
[5062bbf] | 31 | """ |
---|
[94d6752] | 32 | dir = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR) |
---|
[b30ed8f] | 33 | out = open(os.path.join(dir, "plugins.log"), 'a') |
---|
[b30f001] | 34 | out.write("%10g: %s\n" % (time.clock(), message)) |
---|
| 35 | out.close() |
---|
| 36 | |
---|
[9466f2d6] | 37 | |
---|
[bfe4644] | 38 | def _check_plugin(model, name): |
---|
| 39 | """ |
---|
[5062bbf] | 40 | Do some checking before model adding plugins in the list |
---|
| 41 | |
---|
| 42 | :param model: class model to add into the plugin list |
---|
| 43 | :param name:name of the module plugin |
---|
| 44 | |
---|
| 45 | :return model: model if valid model or None if not valid |
---|
| 46 | |
---|
[bfe4644] | 47 | """ |
---|
| 48 | #Check is the plugin is of type Model1DPlugin |
---|
| 49 | if not issubclass(model, Model1DPlugin): |
---|
[61184df] | 50 | msg = "Plugin %s must be of type Model1DPlugin \n" % str(name) |
---|
[bfe4644] | 51 | log(msg) |
---|
[8d78399] | 52 | return None |
---|
[f32d144] | 53 | if model.__name__ != "Model": |
---|
| 54 | msg = "Plugin %s class name must be Model \n" % str(name) |
---|
[bfe4644] | 55 | log(msg) |
---|
[8d78399] | 56 | return None |
---|
[bfe4644] | 57 | try: |
---|
[f32d144] | 58 | new_instance = model() |
---|
[bfe4644] | 59 | except: |
---|
[f32d144] | 60 | msg = "Plugin %s error in __init__ \n\t: %s %s\n" % (str(name), |
---|
[61184df] | 61 | str(sys.exc_type), sys.exc_value) |
---|
[bfe4644] | 62 | log(msg) |
---|
[8d78399] | 63 | return None |
---|
[bfe4644] | 64 | |
---|
[f32d144] | 65 | if hasattr(new_instance, "function"): |
---|
[bfe4644] | 66 | try: |
---|
[f32d144] | 67 | value = new_instance.function() |
---|
[bfe4644] | 68 | except: |
---|
[f32d144] | 69 | msg = "Plugin %s: error writing function \n\t :%s %s\n " % (str(name), |
---|
[61184df] | 70 | str(sys.exc_type), sys.exc_value) |
---|
[f32d144] | 71 | log(msg) |
---|
| 72 | return None |
---|
[bfe4644] | 73 | else: |
---|
[f32d144] | 74 | msg = "Plugin %s needs a method called function \n" % str(name) |
---|
| 75 | log(msg) |
---|
| 76 | return None |
---|
[bfe4644] | 77 | return model |
---|
| 78 | |
---|
[f32d144] | 79 | |
---|
[5d1c1f4] | 80 | def find_plugins_dir(): |
---|
[5062bbf] | 81 | """ |
---|
[96814e1] | 82 | Find path of the plugins directory. |
---|
| 83 | The plugin directory is located in the user's home directory. |
---|
[5062bbf] | 84 | """ |
---|
[94d6752] | 85 | dir = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR) |
---|
[96814e1] | 86 | |
---|
| 87 | # If the plugin directory doesn't exist, create it |
---|
[a0986f6] | 88 | if not os.path.isdir(dir): |
---|
[96814e1] | 89 | os.makedirs(dir) |
---|
| 90 | |
---|
[8ab3302] | 91 | # Find paths needed |
---|
| 92 | try: |
---|
| 93 | # For source |
---|
| 94 | if os.path.isdir(os.path.dirname(__file__)): |
---|
[f32d144] | 95 | p_dir = os.path.join(os.path.dirname(__file__), PLUGIN_DIR) |
---|
[8ab3302] | 96 | else: |
---|
| 97 | raise |
---|
| 98 | except: |
---|
| 99 | # Check for data path next to exe/zip file. |
---|
| 100 | #Look for maximum n_dir up of the current dir to find plugins dir |
---|
| 101 | n_dir = 12 |
---|
| 102 | p_dir = None |
---|
| 103 | f_dir = os.path.join(os.path.dirname(__file__)) |
---|
| 104 | for i in range(n_dir): |
---|
| 105 | if i > 1: |
---|
| 106 | f_dir, _ = os.path.split(f_dir) |
---|
| 107 | plugin_path = os.path.join(f_dir, PLUGIN_DIR) |
---|
| 108 | if os.path.isdir(plugin_path): |
---|
| 109 | p_dir = plugin_path |
---|
| 110 | break |
---|
| 111 | if not p_dir: |
---|
| 112 | raise |
---|
[96814e1] | 113 | # Place example user models as needed |
---|
[19e614a] | 114 | if os.path.isdir(p_dir): |
---|
| 115 | for file in os.listdir(p_dir): |
---|
| 116 | file_path = os.path.join(p_dir, file) |
---|
| 117 | if os.path.isfile(file_path): |
---|
| 118 | if file.split(".")[-1] == 'py' and\ |
---|
| 119 | file.split(".")[0] != '__init__': |
---|
| 120 | if not os.path.isfile(os.path.join(dir, file)): |
---|
| 121 | shutil.copy(file_path, dir) |
---|
| 122 | |
---|
[5d1c1f4] | 123 | return dir |
---|
| 124 | |
---|
[f32d144] | 125 | |
---|
[5d1c1f4] | 126 | class ReportProblem: |
---|
| 127 | def __nonzero__(self): |
---|
| 128 | type, value, traceback = sys.exc_info() |
---|
| 129 | if type is not None and issubclass(type, py_compile.PyCompileError): |
---|
| 130 | print "Problem with", repr(value) |
---|
| 131 | raise type, value, traceback |
---|
| 132 | return 1 |
---|
| 133 | |
---|
| 134 | report_problem = ReportProblem() |
---|
| 135 | |
---|
[f32d144] | 136 | |
---|
[5d1c1f4] | 137 | def compile_file(dir): |
---|
| 138 | """ |
---|
| 139 | Compile a py file |
---|
| 140 | """ |
---|
| 141 | try: |
---|
| 142 | import compileall |
---|
[f32d144] | 143 | compileall.compile_dir(dir=dir, ddir=dir, force=1, |
---|
| 144 | quiet=report_problem) |
---|
[5d1c1f4] | 145 | except: |
---|
| 146 | type, value, traceback = sys.exc_info() |
---|
| 147 | return value |
---|
| 148 | return None |
---|
| 149 | |
---|
[f32d144] | 150 | |
---|
[5d1c1f4] | 151 | def _findModels(dir): |
---|
| 152 | """ |
---|
| 153 | """ |
---|
| 154 | # List of plugin objects |
---|
| 155 | plugins = {} |
---|
| 156 | # Go through files in plug-in directory |
---|
| 157 | #always recompile the folder plugin |
---|
| 158 | dir = find_plugins_dir() |
---|
[a0986f6] | 159 | if not os.path.isdir(dir): |
---|
| 160 | msg = "SansView couldn't locate Model plugin folder." |
---|
| 161 | msg += """ "%s" does not exist""" % dir |
---|
| 162 | logging.warning(msg) |
---|
| 163 | return plugins |
---|
| 164 | else: |
---|
| 165 | log("looking for models in: %s" % str(dir)) |
---|
[5d1c1f4] | 166 | compile_file(dir) |
---|
[a0986f6] | 167 | logging.info("pluging model dir: %s\n" % str(dir)) |
---|
[1c66bc5] | 168 | try: |
---|
| 169 | list = os.listdir(dir) |
---|
| 170 | for item in list: |
---|
| 171 | toks = os.path.splitext(os.path.basename(item)) |
---|
[f32d144] | 172 | if toks[1] == '.py' and not toks[0] == '__init__': |
---|
[1c66bc5] | 173 | name = toks[0] |
---|
| 174 | |
---|
| 175 | path = [os.path.abspath(dir)] |
---|
| 176 | file = None |
---|
| 177 | try: |
---|
| 178 | (file, path, info) = imp.find_module(name, path) |
---|
[f32d144] | 179 | module = imp.load_module(name, file, item, info) |
---|
[1c66bc5] | 180 | if hasattr(module, "Model"): |
---|
| 181 | try: |
---|
[f32d144] | 182 | if _check_plugin(module.Model, name) != None: |
---|
[b2d9826] | 183 | plugins[name] = module.Model |
---|
[1c66bc5] | 184 | except: |
---|
[f32d144] | 185 | msg = "Error accessing Model" |
---|
| 186 | msg += "in %s\n %s %s\n" % (name, |
---|
[bfe4644] | 187 | str(sys.exc_type), sys.exc_value) |
---|
| 188 | log(msg) |
---|
[1c66bc5] | 189 | except: |
---|
[f32d144] | 190 | msg = "Error accessing Model" |
---|
| 191 | msg += " in %s\n %s %s \n" % (name, |
---|
[bfe4644] | 192 | str(sys.exc_type), sys.exc_value) |
---|
| 193 | log(msg) |
---|
[1c66bc5] | 194 | finally: |
---|
[a92d51b] | 195 | |
---|
[f32d144] | 196 | if not file == None: |
---|
[1c66bc5] | 197 | file.close() |
---|
| 198 | except: |
---|
[33afff7] | 199 | # Don't deal with bad plug-in imports. Just skip. |
---|
[23ccf07] | 200 | msg = "Could not import model plugin: %s\n" % sys.exc_value |
---|
| 201 | log(msg) |
---|
[1c66bc5] | 202 | pass |
---|
| 203 | return plugins |
---|
[bb18ef1] | 204 | |
---|
[f32d144] | 205 | |
---|
[bb18ef1] | 206 | class ModelList(object): |
---|
| 207 | """ |
---|
[5062bbf] | 208 | Contains dictionary of model and their type |
---|
[bb18ef1] | 209 | """ |
---|
| 210 | def __init__(self): |
---|
[5062bbf] | 211 | """ |
---|
| 212 | """ |
---|
| 213 | self.mydict = {} |
---|
[bb18ef1] | 214 | |
---|
| 215 | def set_list(self, name, mylist): |
---|
| 216 | """ |
---|
[5062bbf] | 217 | :param name: the type of the list |
---|
| 218 | :param mylist: the list to add |
---|
| 219 | |
---|
[bb18ef1] | 220 | """ |
---|
| 221 | if name not in self.mydict.keys(): |
---|
[916f5c0] | 222 | self.reset_list(name, mylist) |
---|
[bb18ef1] | 223 | |
---|
[916f5c0] | 224 | def reset_list(self, name, mylist): |
---|
| 225 | """ |
---|
| 226 | :param name: the type of the list |
---|
| 227 | :param mylist: the list to add |
---|
| 228 | """ |
---|
[f32d144] | 229 | self.mydict[name] = mylist |
---|
[bb18ef1] | 230 | |
---|
| 231 | def get_list(self): |
---|
| 232 | """ |
---|
[5062bbf] | 233 | return all the list stored in a dictionary object |
---|
[bb18ef1] | 234 | """ |
---|
| 235 | return self.mydict |
---|
| 236 | |
---|
[f32d144] | 237 | |
---|
[bb9f322] | 238 | class ModelManagerBase: |
---|
[5062bbf] | 239 | """ |
---|
[61184df] | 240 | Base class for the model manager |
---|
[5062bbf] | 241 | """ |
---|
[bb18ef1] | 242 | ## external dict for models |
---|
| 243 | model_combobox = ModelList() |
---|
| 244 | ## Dictionary of form models |
---|
| 245 | form_factor_dict = {} |
---|
| 246 | ## dictionary of other |
---|
| 247 | struct_factor_dict = {} |
---|
| 248 | ##list of form factors |
---|
[b2d9826] | 249 | shape_list = [] |
---|
[bb18ef1] | 250 | ## independent shape model list |
---|
| 251 | shape_indep_list = [] |
---|
[f32d144] | 252 | ##list of structure factors |
---|
[b2d9826] | 253 | struct_list = [] |
---|
[376916c] | 254 | ##list of model allowing multiplication |
---|
[b2d9826] | 255 | multiplication_factor = [] |
---|
[e87f9fc] | 256 | ##list of multifunctional shapes |
---|
[b2d9826] | 257 | multi_func_list = [] |
---|
[bb18ef1] | 258 | ## list of added models |
---|
[b2d9826] | 259 | plugins = [] |
---|
[bb18ef1] | 260 | ## Event owner (guiframe) |
---|
[d89f09b] | 261 | event_owner = None |
---|
[9466f2d6] | 262 | last_time_dir_modified = 0 |
---|
[f32d144] | 263 | |
---|
[6bbeacd4] | 264 | def __init__(self): |
---|
| 265 | """ |
---|
| 266 | """ |
---|
[df7a7e3] | 267 | self.model_dictionary = {} |
---|
[b2d9826] | 268 | self.stored_plugins = {} |
---|
[6bbeacd4] | 269 | self._getModelList() |
---|
| 270 | |
---|
[9466f2d6] | 271 | def findModels(self): |
---|
| 272 | """ |
---|
| 273 | find plugin model in directory of plugin .recompile all file |
---|
| 274 | in the directory if file were modified |
---|
| 275 | """ |
---|
[23ccf07] | 276 | temp = {} |
---|
[9466f2d6] | 277 | if self.is_changed(): |
---|
[a0986f6] | 278 | return _findModels(dir) |
---|
[23ccf07] | 279 | logging.info("pluging model : %s\n" % str(temp)) |
---|
| 280 | return temp |
---|
| 281 | |
---|
[d89f09b] | 282 | def _getModelList(self): |
---|
| 283 | """ |
---|
[5062bbf] | 284 | List of models we want to make available by default |
---|
| 285 | for this application |
---|
| 286 | |
---|
| 287 | :return: the next free event ID following the new menu events |
---|
[e7b1ccf] | 288 | |
---|
[d89f09b] | 289 | """ |
---|
[df7a7e3] | 290 | |
---|
| 291 | |
---|
[7c8d3093] | 292 | # regular model names only |
---|
| 293 | self.model_name_list = [] |
---|
[442895f] | 294 | from sans.models.SphereModel import SphereModel |
---|
[df7a7e3] | 295 | self.model_dictionary[SphereModel.__name__] = SphereModel |
---|
[bb18ef1] | 296 | self.shape_list.append(SphereModel) |
---|
[376916c] | 297 | self.multiplication_factor.append(SphereModel) |
---|
[7c8d3093] | 298 | self.model_name_list.append(SphereModel.__name__) |
---|
[442895f] | 299 | |
---|
[1a395a6] | 300 | from sans.models.BinaryHSModel import BinaryHSModel |
---|
[df7a7e3] | 301 | self.model_dictionary[BinaryHSModel.__name__] = BinaryHSModel |
---|
[1a395a6] | 302 | self.shape_list.append(BinaryHSModel) |
---|
[7c8d3093] | 303 | self.model_name_list.append(BinaryHSModel.__name__) |
---|
[1a395a6] | 304 | |
---|
[ce07fa8] | 305 | from sans.models.FuzzySphereModel import FuzzySphereModel |
---|
[df7a7e3] | 306 | self.model_dictionary[FuzzySphereModel.__name__] = FuzzySphereModel |
---|
[ce07fa8] | 307 | self.shape_list.append(FuzzySphereModel) |
---|
| 308 | self.multiplication_factor.append(FuzzySphereModel) |
---|
[7c8d3093] | 309 | self.model_name_list.append(FuzzySphereModel.__name__) |
---|
[3764dbd7] | 310 | |
---|
| 311 | from sans.models.RaspBerryModel import RaspBerryModel |
---|
[df7a7e3] | 312 | self.model_dictionary[RaspBerryModel.__name__] = RaspBerryModel |
---|
[3764dbd7] | 313 | self.shape_list.append(RaspBerryModel) |
---|
| 314 | self.model_name_list.append(RaspBerryModel.__name__) |
---|
| 315 | |
---|
[442895f] | 316 | from sans.models.CoreShellModel import CoreShellModel |
---|
[df7a7e3] | 317 | self.model_dictionary[CoreShellModel.__name__] = CoreShellModel |
---|
[bb18ef1] | 318 | self.shape_list.append(CoreShellModel) |
---|
[5eb9154] | 319 | self.multiplication_factor.append(CoreShellModel) |
---|
[7c8d3093] | 320 | self.model_name_list.append(CoreShellModel.__name__) |
---|
[4523b68] | 321 | |
---|
[7289627] | 322 | from sans.models.Core2ndMomentModel import Core2ndMomentModel |
---|
[df7a7e3] | 323 | self.model_dictionary[Core2ndMomentModel.__name__] = Core2ndMomentModel |
---|
[7289627] | 324 | self.shape_list.append(Core2ndMomentModel) |
---|
| 325 | self.model_name_list.append(Core2ndMomentModel.__name__) |
---|
| 326 | |
---|
[4523b68] | 327 | from sans.models.CoreMultiShellModel import CoreMultiShellModel |
---|
[df7a7e3] | 328 | self.model_dictionary[CoreMultiShellModel.__name__] = CoreMultiShellModel |
---|
[4523b68] | 329 | self.shape_list.append(CoreMultiShellModel) |
---|
| 330 | self.multiplication_factor.append(CoreMultiShellModel) |
---|
[a1b2471] | 331 | self.multi_func_list.append(CoreMultiShellModel) |
---|
[fb59ed9] | 332 | |
---|
[eddff027] | 333 | from sans.models.VesicleModel import VesicleModel |
---|
[df7a7e3] | 334 | self.model_dictionary[VesicleModel.__name__] = VesicleModel |
---|
[eddff027] | 335 | self.shape_list.append(VesicleModel) |
---|
[5eb9154] | 336 | self.multiplication_factor.append(VesicleModel) |
---|
[7c8d3093] | 337 | self.model_name_list.append(VesicleModel.__name__) |
---|
[5eb9154] | 338 | |
---|
| 339 | from sans.models.MultiShellModel import MultiShellModel |
---|
[df7a7e3] | 340 | self.model_dictionary[MultiShellModel.__name__] = MultiShellModel |
---|
[5eb9154] | 341 | self.shape_list.append(MultiShellModel) |
---|
| 342 | self.multiplication_factor.append(MultiShellModel) |
---|
[7c8d3093] | 343 | self.model_name_list.append(MultiShellModel.__name__) |
---|
[eddff027] | 344 | |
---|
[1a395a6] | 345 | from sans.models.OnionExpShellModel import OnionExpShellModel |
---|
[df7a7e3] | 346 | self.model_dictionary[OnionExpShellModel.__name__] = OnionExpShellModel |
---|
[1a395a6] | 347 | self.shape_list.append(OnionExpShellModel) |
---|
| 348 | self.multiplication_factor.append(OnionExpShellModel) |
---|
| 349 | self.multi_func_list.append(OnionExpShellModel) |
---|
[463eb76e] | 350 | |
---|
[1a395a6] | 351 | from sans.models.SphericalSLDModel import SphericalSLDModel |
---|
[df7a7e3] | 352 | self.model_dictionary[SphericalSLDModel.__name__] = SphericalSLDModel |
---|
[1a395a6] | 353 | self.shape_list.append(SphericalSLDModel) |
---|
| 354 | self.multiplication_factor.append(SphericalSLDModel) |
---|
| 355 | self.multi_func_list.append(SphericalSLDModel) |
---|
[a8d3b4f] | 356 | |
---|
[cee6867] | 357 | |
---|
[d9547e7] | 358 | from sans.models.LinearPearlsModel import LinearPearlsModel |
---|
[df7a7e3] | 359 | self.model_dictionary[LinearPearlsModel.__name__] = LinearPearlsModel |
---|
[d9547e7] | 360 | self.shape_list.append(LinearPearlsModel) |
---|
| 361 | self.model_name_list.append(LinearPearlsModel.__name__) |
---|
| 362 | |
---|
[4ad076b] | 363 | from sans.models.PearlNecklaceModel import PearlNecklaceModel |
---|
[df7a7e3] | 364 | self.model_dictionary[PearlNecklaceModel.__name__] = PearlNecklaceModel |
---|
[4ad076b] | 365 | self.shape_list.append(PearlNecklaceModel) |
---|
[7c8d3093] | 366 | self.model_name_list.append(PearlNecklaceModel.__name__) |
---|
[4ad076b] | 367 | #self.multiplication_factor.append(PearlNecklaceModel) |
---|
| 368 | |
---|
[eddff027] | 369 | from sans.models.CylinderModel import CylinderModel |
---|
[df7a7e3] | 370 | self.model_dictionary[CylinderModel.__name__] = CylinderModel |
---|
[eddff027] | 371 | self.shape_list.append(CylinderModel) |
---|
| 372 | self.multiplication_factor.append(CylinderModel) |
---|
[7c8d3093] | 373 | self.model_name_list.append(CylinderModel.__name__) |
---|
[eddff027] | 374 | |
---|
| 375 | from sans.models.CoreShellCylinderModel import CoreShellCylinderModel |
---|
[df7a7e3] | 376 | self.model_dictionary[CoreShellCylinderModel.__name__] = CoreShellCylinderModel |
---|
[eddff027] | 377 | self.shape_list.append(CoreShellCylinderModel) |
---|
[5eb9154] | 378 | self.multiplication_factor.append(CoreShellCylinderModel) |
---|
[7c8d3093] | 379 | self.model_name_list.append(CoreShellCylinderModel.__name__) |
---|
[cee6867] | 380 | |
---|
[543d1bd] | 381 | from sans.models.CoreShellBicelleModel import CoreShellBicelleModel |
---|
[df7a7e3] | 382 | self.model_dictionary[CoreShellBicelleModel.__name__] = CoreShellBicelleModel |
---|
[543d1bd] | 383 | self.shape_list.append(CoreShellBicelleModel) |
---|
| 384 | self.multiplication_factor.append(CoreShellBicelleModel) |
---|
| 385 | self.model_name_list.append(CoreShellBicelleModel.__name__) |
---|
| 386 | |
---|
[cee6867] | 387 | from sans.models.HollowCylinderModel import HollowCylinderModel |
---|
[df7a7e3] | 388 | self.model_dictionary[HollowCylinderModel.__name__] = HollowCylinderModel |
---|
[cee6867] | 389 | self.shape_list.append(HollowCylinderModel) |
---|
[5eb9154] | 390 | self.multiplication_factor.append(HollowCylinderModel) |
---|
[7c8d3093] | 391 | self.model_name_list.append(HollowCylinderModel.__name__) |
---|
[eddff027] | 392 | |
---|
| 393 | from sans.models.FlexibleCylinderModel import FlexibleCylinderModel |
---|
[df7a7e3] | 394 | self.model_dictionary[FlexibleCylinderModel.__name__] = FlexibleCylinderModel |
---|
[eddff027] | 395 | self.shape_list.append(FlexibleCylinderModel) |
---|
[7c8d3093] | 396 | self.model_name_list.append(FlexibleCylinderModel.__name__) |
---|
[72f719b] | 397 | |
---|
[ce07fa8] | 398 | from sans.models.FlexCylEllipXModel import FlexCylEllipXModel |
---|
[df7a7e3] | 399 | self.model_dictionary[FlexCylEllipXModel.__name__] = FlexCylEllipXModel |
---|
[ce07fa8] | 400 | self.shape_list.append(FlexCylEllipXModel) |
---|
[7c8d3093] | 401 | self.model_name_list.append(FlexCylEllipXModel.__name__) |
---|
[eddff027] | 402 | |
---|
| 403 | from sans.models.StackedDisksModel import StackedDisksModel |
---|
[df7a7e3] | 404 | self.model_dictionary[StackedDisksModel.__name__] = StackedDisksModel |
---|
[eddff027] | 405 | self.shape_list.append(StackedDisksModel) |
---|
[5eb9154] | 406 | self.multiplication_factor.append(StackedDisksModel) |
---|
[7c8d3093] | 407 | self.model_name_list.append(StackedDisksModel.__name__) |
---|
[eddff027] | 408 | |
---|
| 409 | from sans.models.ParallelepipedModel import ParallelepipedModel |
---|
[df7a7e3] | 410 | self.model_dictionary[ParallelepipedModel.__name__] = ParallelepipedModel |
---|
[eddff027] | 411 | self.shape_list.append(ParallelepipedModel) |
---|
[72f719b] | 412 | self.multiplication_factor.append(ParallelepipedModel) |
---|
[7c8d3093] | 413 | self.model_name_list.append(ParallelepipedModel.__name__) |
---|
[cee6867] | 414 | |
---|
[fb59ed9] | 415 | from sans.models.CSParallelepipedModel import CSParallelepipedModel |
---|
[df7a7e3] | 416 | self.model_dictionary[CSParallelepipedModel.__name__] = CSParallelepipedModel |
---|
[fb59ed9] | 417 | self.shape_list.append(CSParallelepipedModel) |
---|
| 418 | self.multiplication_factor.append(CSParallelepipedModel) |
---|
[7c8d3093] | 419 | self.model_name_list.append(CSParallelepipedModel.__name__) |
---|
[fb59ed9] | 420 | |
---|
[442895f] | 421 | from sans.models.EllipticalCylinderModel import EllipticalCylinderModel |
---|
[df7a7e3] | 422 | self.model_dictionary[EllipticalCylinderModel.__name__] = EllipticalCylinderModel |
---|
[bb18ef1] | 423 | self.shape_list.append(EllipticalCylinderModel) |
---|
[72f719b] | 424 | self.multiplication_factor.append(EllipticalCylinderModel) |
---|
[7c8d3093] | 425 | self.model_name_list.append(EllipticalCylinderModel.__name__) |
---|
[fb59ed9] | 426 | |
---|
| 427 | from sans.models.BarBellModel import BarBellModel |
---|
[df7a7e3] | 428 | self.model_dictionary[BarBellModel.__name__] = BarBellModel |
---|
[fb59ed9] | 429 | self.shape_list.append(BarBellModel) |
---|
[7c8d3093] | 430 | self.model_name_list.append(BarBellModel.__name__) |
---|
[fb59ed9] | 431 | # not implemeted yet! |
---|
| 432 | #self.multiplication_factor.append(BarBellModel) |
---|
| 433 | |
---|
| 434 | from sans.models.CappedCylinderModel import CappedCylinderModel |
---|
[df7a7e3] | 435 | self.model_dictionary[CappedCylinderModel.__name__] = CappedCylinderModel |
---|
[fb59ed9] | 436 | self.shape_list.append(CappedCylinderModel) |
---|
[7c8d3093] | 437 | self.model_name_list.append(CappedCylinderModel.__name__) |
---|
[fb59ed9] | 438 | # not implemeted yet! |
---|
| 439 | #self.multiplication_factor.append(CappedCylinderModel) |
---|
| 440 | |
---|
[442895f] | 441 | from sans.models.EllipsoidModel import EllipsoidModel |
---|
[df7a7e3] | 442 | self.model_dictionary[EllipsoidModel.__name__] = EllipsoidModel |
---|
[bb18ef1] | 443 | self.shape_list.append(EllipsoidModel) |
---|
[376916c] | 444 | self.multiplication_factor.append(EllipsoidModel) |
---|
[7c8d3093] | 445 | self.model_name_list.append(EllipsoidModel.__name__) |
---|
[eddff027] | 446 | |
---|
| 447 | from sans.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel |
---|
[df7a7e3] | 448 | self.model_dictionary[CoreShellEllipsoidModel.__name__] = CoreShellEllipsoidModel |
---|
[eddff027] | 449 | self.shape_list.append(CoreShellEllipsoidModel) |
---|
[5eb9154] | 450 | self.multiplication_factor.append(CoreShellEllipsoidModel) |
---|
[7c8d3093] | 451 | self.model_name_list.append(CoreShellEllipsoidModel.__name__) |
---|
[bb18ef1] | 452 | |
---|
[e65050e] | 453 | from sans.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel |
---|
[df7a7e3] | 454 | self.model_dictionary[TriaxialEllipsoidModel.__name__] = TriaxialEllipsoidModel |
---|
[e65050e] | 455 | self.shape_list.append(TriaxialEllipsoidModel) |
---|
[9002927] | 456 | self.multiplication_factor.append(TriaxialEllipsoidModel) |
---|
[7c8d3093] | 457 | self.model_name_list.append(TriaxialEllipsoidModel.__name__) |
---|
[e65050e] | 458 | |
---|
| 459 | from sans.models.LamellarModel import LamellarModel |
---|
[df7a7e3] | 460 | self.model_dictionary[LamellarModel.__name__] = LamellarModel |
---|
[e65050e] | 461 | self.shape_list.append(LamellarModel) |
---|
[7c8d3093] | 462 | self.model_name_list.append(LamellarModel.__name__) |
---|
[e65050e] | 463 | |
---|
| 464 | from sans.models.LamellarFFHGModel import LamellarFFHGModel |
---|
[df7a7e3] | 465 | self.model_dictionary[LamellarFFHGModel.__name__] = LamellarFFHGModel |
---|
[e65050e] | 466 | self.shape_list.append(LamellarFFHGModel) |
---|
[7c8d3093] | 467 | self.model_name_list.append(LamellarFFHGModel.__name__) |
---|
[e65050e] | 468 | |
---|
| 469 | from sans.models.LamellarPSModel import LamellarPSModel |
---|
[df7a7e3] | 470 | self.model_dictionary[LamellarPSModel.__name__] = LamellarPSModel |
---|
[e65050e] | 471 | self.shape_list.append(LamellarPSModel) |
---|
[7c8d3093] | 472 | self.model_name_list.append(LamellarPSModel.__name__) |
---|
[7a69683] | 473 | |
---|
[e65050e] | 474 | from sans.models.LamellarPSHGModel import LamellarPSHGModel |
---|
[df7a7e3] | 475 | self.model_dictionary[LamellarPSHGModel.__name__] = LamellarPSHGModel |
---|
[e65050e] | 476 | self.shape_list.append(LamellarPSHGModel) |
---|
[7c8d3093] | 477 | self.model_name_list.append(LamellarPSHGModel.__name__) |
---|
[fb59ed9] | 478 | |
---|
| 479 | from sans.models.LamellarPCrystalModel import LamellarPCrystalModel |
---|
[df7a7e3] | 480 | self.model_dictionary[LamellarPCrystalModel.__name__] = LamellarPCrystalModel |
---|
[fb59ed9] | 481 | self.shape_list.append(LamellarPCrystalModel) |
---|
[7c8d3093] | 482 | self.model_name_list.append(LamellarPCrystalModel.__name__) |
---|
[fb59ed9] | 483 | |
---|
| 484 | from sans.models.SCCrystalModel import SCCrystalModel |
---|
[df7a7e3] | 485 | self.model_dictionary[SCCrystalModel.__name__] = SCCrystalModel |
---|
[fb59ed9] | 486 | self.shape_list.append(SCCrystalModel) |
---|
[7c8d3093] | 487 | self.model_name_list.append(SCCrystalModel.__name__) |
---|
[fb59ed9] | 488 | |
---|
| 489 | from sans.models.FCCrystalModel import FCCrystalModel |
---|
[df7a7e3] | 490 | self.model_dictionary[FCCrystalModel.__name__] = FCCrystalModel |
---|
[fb59ed9] | 491 | self.shape_list.append(FCCrystalModel) |
---|
[7c8d3093] | 492 | self.model_name_list.append(FCCrystalModel.__name__) |
---|
[fb59ed9] | 493 | |
---|
| 494 | from sans.models.BCCrystalModel import BCCrystalModel |
---|
[df7a7e3] | 495 | self.model_dictionary[BCCrystalModel.__name__] = BCCrystalModel |
---|
[fb59ed9] | 496 | self.shape_list.append(BCCrystalModel) |
---|
[7c8d3093] | 497 | self.model_name_list.append(BCCrystalModel.__name__) |
---|
[7a69683] | 498 | |
---|
[f32d144] | 499 | ## Structure factor |
---|
[8346667] | 500 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
[df7a7e3] | 501 | self.model_dictionary[SquareWellStructure.__name__] = SquareWellStructure |
---|
[bb18ef1] | 502 | self.struct_list.append(SquareWellStructure) |
---|
[7c8d3093] | 503 | self.model_name_list.append(SquareWellStructure.__name__) |
---|
[8346667] | 504 | |
---|
| 505 | from sans.models.HardsphereStructure import HardsphereStructure |
---|
[df7a7e3] | 506 | self.model_dictionary[HardsphereStructure.__name__] = HardsphereStructure |
---|
[bb18ef1] | 507 | self.struct_list.append(HardsphereStructure) |
---|
[7c8d3093] | 508 | self.model_name_list.append(HardsphereStructure.__name__) |
---|
[bb18ef1] | 509 | |
---|
[8346667] | 510 | from sans.models.StickyHSStructure import StickyHSStructure |
---|
[df7a7e3] | 511 | self.model_dictionary[StickyHSStructure.__name__] = StickyHSStructure |
---|
[bb18ef1] | 512 | self.struct_list.append(StickyHSStructure) |
---|
[7c8d3093] | 513 | self.model_name_list.append(StickyHSStructure.__name__) |
---|
[8346667] | 514 | |
---|
| 515 | from sans.models.HayterMSAStructure import HayterMSAStructure |
---|
[df7a7e3] | 516 | self.model_dictionary[HayterMSAStructure.__name__] = HayterMSAStructure |
---|
[bb18ef1] | 517 | self.struct_list.append(HayterMSAStructure) |
---|
[7c8d3093] | 518 | self.model_name_list.append(HayterMSAStructure.__name__) |
---|
[a8d3b4f] | 519 | |
---|
| 520 | |
---|
[fb59ed9] | 521 | ##shape-independent models |
---|
[ce07fa8] | 522 | from sans.models.PowerLawAbsModel import PowerLawAbsModel |
---|
[df7a7e3] | 523 | self.model_dictionary[PowerLawAbsModel.__name__] = PowerLawAbsModel |
---|
[f32d144] | 524 | self.shape_indep_list.append(PowerLawAbsModel) |
---|
[7c8d3093] | 525 | self.model_name_list.append(PowerLawAbsModel.__name__) |
---|
[ce07fa8] | 526 | |
---|
[442895f] | 527 | from sans.models.BEPolyelectrolyte import BEPolyelectrolyte |
---|
[df7a7e3] | 528 | self.model_dictionary[BEPolyelectrolyte.__name__] = BEPolyelectrolyte |
---|
[f32d144] | 529 | self.shape_indep_list.append(BEPolyelectrolyte) |
---|
[7c8d3093] | 530 | self.model_name_list.append(BEPolyelectrolyte.__name__) |
---|
[bb18ef1] | 531 | self.form_factor_dict[str(wx.NewId())] = [SphereModel] |
---|
[fb59ed9] | 532 | |
---|
| 533 | from sans.models.BroadPeakModel import BroadPeakModel |
---|
[df7a7e3] | 534 | self.model_dictionary[BroadPeakModel.__name__] = BroadPeakModel |
---|
[fb59ed9] | 535 | self.shape_indep_list.append(BroadPeakModel) |
---|
[7c8d3093] | 536 | self.model_name_list.append(BroadPeakModel.__name__) |
---|
[fb59ed9] | 537 | |
---|
| 538 | from sans.models.CorrLengthModel import CorrLengthModel |
---|
[df7a7e3] | 539 | self.model_dictionary[CorrLengthModel.__name__] = CorrLengthModel |
---|
[fb59ed9] | 540 | self.shape_indep_list.append(CorrLengthModel) |
---|
[7c8d3093] | 541 | self.model_name_list.append(CorrLengthModel.__name__) |
---|
[fb59ed9] | 542 | |
---|
[442895f] | 543 | from sans.models.DABModel import DABModel |
---|
[df7a7e3] | 544 | self.model_dictionary[DABModel.__name__] = DABModel |
---|
[f32d144] | 545 | self.shape_indep_list.append(DABModel) |
---|
[7c8d3093] | 546 | self.model_name_list.append(DABModel.__name__) |
---|
[442895f] | 547 | |
---|
[ce07fa8] | 548 | from sans.models.DebyeModel import DebyeModel |
---|
[df7a7e3] | 549 | self.model_dictionary[DebyeModel.__name__] = DebyeModel |
---|
[f32d144] | 550 | self.shape_indep_list.append(DebyeModel) |
---|
[7c8d3093] | 551 | self.model_name_list.append(DebyeModel.__name__) |
---|
[ce07fa8] | 552 | |
---|
| 553 | from sans.models.FractalModel import FractalModel |
---|
[df7a7e3] | 554 | self.model_dictionary[FractalModel.__name__] = FractalModel |
---|
[f32d144] | 555 | self.shape_indep_list.append(FractalModel) |
---|
[7c8d3093] | 556 | self.model_name_list.append(FractalModel.__name__) |
---|
[bb18ef1] | 557 | |
---|
[fb59ed9] | 558 | from sans.models.FractalCoreShellModel import FractalCoreShellModel |
---|
[df7a7e3] | 559 | self.model_dictionary[FractalCoreShellModel.__name__] = FractalCoreShellModel |
---|
[f32d144] | 560 | self.shape_indep_list.append(FractalCoreShellModel) |
---|
[7c8d3093] | 561 | self.model_name_list.append(FractalCoreShellModel.__name__) |
---|
[fb59ed9] | 562 | |
---|
| 563 | from sans.models.GaussLorentzGelModel import GaussLorentzGelModel |
---|
[df7a7e3] | 564 | self.model_dictionary[GaussLorentzGelModel.__name__] = GaussLorentzGelModel |
---|
[f32d144] | 565 | self.shape_indep_list.append(GaussLorentzGelModel) |
---|
[7c8d3093] | 566 | self.model_name_list.append(GaussLorentzGelModel.__name__) |
---|
[fb59ed9] | 567 | |
---|
| 568 | from sans.models.GuinierModel import GuinierModel |
---|
[df7a7e3] | 569 | self.model_dictionary[GuinierModel.__name__] = GuinierModel |
---|
[f32d144] | 570 | self.shape_indep_list.append(GuinierModel) |
---|
[7c8d3093] | 571 | self.model_name_list.append(GuinierModel.__name__) |
---|
[fb59ed9] | 572 | |
---|
| 573 | from sans.models.GuinierPorodModel import GuinierPorodModel |
---|
[df7a7e3] | 574 | self.model_dictionary[GuinierPorodModel.__name__] = GuinierPorodModel |
---|
[f32d144] | 575 | self.shape_indep_list.append(GuinierPorodModel) |
---|
[7c8d3093] | 576 | self.model_name_list.append(GuinierPorodModel.__name__) |
---|
[fb59ed9] | 577 | |
---|
[ce07fa8] | 578 | from sans.models.LorentzModel import LorentzModel |
---|
[df7a7e3] | 579 | self.model_dictionary[LorentzModel.__name__] = LorentzModel |
---|
[f32d144] | 580 | self.shape_indep_list.append(LorentzModel) |
---|
[7c8d3093] | 581 | self.model_name_list.append(LorentzModel.__name__) |
---|
[51da9dc] | 582 | |
---|
| 583 | from sans.models.MassFractalModel import MassFractalModel |
---|
[df7a7e3] | 584 | self.model_dictionary[MassFractalModel.__name__] = MassFractalModel |
---|
[51da9dc] | 585 | self.shape_indep_list.append(MassFractalModel) |
---|
| 586 | self.model_name_list.append(MassFractalModel.__name__) |
---|
| 587 | |
---|
| 588 | from sans.models.MassSurfaceFractal import MassSurfaceFractal |
---|
[df7a7e3] | 589 | self.model_dictionary[MassSurfaceFractal.__name__] = MassSurfaceFractal |
---|
[51da9dc] | 590 | self.shape_indep_list.append(MassSurfaceFractal) |
---|
| 591 | self.model_name_list.append(MassSurfaceFractal.__name__) |
---|
[442895f] | 592 | |
---|
[cee6867] | 593 | from sans.models.PeakGaussModel import PeakGaussModel |
---|
[df7a7e3] | 594 | self.model_dictionary[PeakGaussModel.__name__] = PeakGaussModel |
---|
[cee6867] | 595 | self.shape_indep_list.append(PeakGaussModel) |
---|
[7c8d3093] | 596 | self.model_name_list.append(PeakGaussModel.__name__) |
---|
[cee6867] | 597 | |
---|
| 598 | from sans.models.PeakLorentzModel import PeakLorentzModel |
---|
[df7a7e3] | 599 | self.model_dictionary[PeakLorentzModel.__name__] = PeakLorentzModel |
---|
[cee6867] | 600 | self.shape_indep_list.append(PeakLorentzModel) |
---|
[f32d144] | 601 | self.model_name_list.append(PeakLorentzModel.__name__) |
---|
[cee6867] | 602 | |
---|
[ce07fa8] | 603 | from sans.models.Poly_GaussCoil import Poly_GaussCoil |
---|
[df7a7e3] | 604 | self.model_dictionary[Poly_GaussCoil.__name__] = Poly_GaussCoil |
---|
[ce07fa8] | 605 | self.shape_indep_list.append(Poly_GaussCoil) |
---|
[7c8d3093] | 606 | self.model_name_list.append(Poly_GaussCoil.__name__) |
---|
[fb59ed9] | 607 | |
---|
| 608 | from sans.models.PolymerExclVolume import PolymerExclVolume |
---|
[df7a7e3] | 609 | self.model_dictionary[PolymerExclVolume.__name__] = PolymerExclVolume |
---|
[fb59ed9] | 610 | self.shape_indep_list.append(PolymerExclVolume) |
---|
[7c8d3093] | 611 | self.model_name_list.append(PolymerExclVolume.__name__) |
---|
[fb59ed9] | 612 | |
---|
[ce07fa8] | 613 | from sans.models.PorodModel import PorodModel |
---|
[df7a7e3] | 614 | self.model_dictionary[PorodModel.__name__] = PorodModel |
---|
[f32d144] | 615 | self.shape_indep_list.append(PorodModel) |
---|
| 616 | self.model_name_list.append(PorodModel.__name__) |
---|
[442895f] | 617 | |
---|
[fb59ed9] | 618 | from sans.models.RPA10Model import RPA10Model |
---|
[df7a7e3] | 619 | self.model_dictionary[RPA10Model.__name__] = RPA10Model |
---|
[fb59ed9] | 620 | self.shape_indep_list.append(RPA10Model) |
---|
| 621 | self.multi_func_list.append(RPA10Model) |
---|
[51da9dc] | 622 | |
---|
[082c565] | 623 | from sans.models.StarPolymer import StarPolymer |
---|
[df7a7e3] | 624 | self.model_dictionary[StarPolymer.__name__] = StarPolymer |
---|
[082c565] | 625 | self.shape_indep_list.append(StarPolymer) |
---|
| 626 | self.model_name_list.append(StarPolymer.__name__) |
---|
| 627 | |
---|
[51da9dc] | 628 | from sans.models.SurfaceFractalModel import SurfaceFractalModel |
---|
[df7a7e3] | 629 | self.model_dictionary[SurfaceFractalModel.__name__] = SurfaceFractalModel |
---|
[51da9dc] | 630 | self.shape_indep_list.append(SurfaceFractalModel) |
---|
| 631 | self.model_name_list.append(SurfaceFractalModel.__name__) |
---|
[81bece4] | 632 | |
---|
[442895f] | 633 | from sans.models.TeubnerStreyModel import TeubnerStreyModel |
---|
[df7a7e3] | 634 | self.model_dictionary[TeubnerStreyModel.__name__] = TeubnerStreyModel |
---|
[f32d144] | 635 | self.shape_indep_list.append(TeubnerStreyModel) |
---|
[7c8d3093] | 636 | self.model_name_list.append(TeubnerStreyModel.__name__) |
---|
[a269378] | 637 | |
---|
[fb59ed9] | 638 | from sans.models.TwoLorentzianModel import TwoLorentzianModel |
---|
[df7a7e3] | 639 | self.model_dictionary[TwoLorentzianModel.__name__] = TwoLorentzianModel |
---|
[f32d144] | 640 | self.shape_indep_list.append(TwoLorentzianModel) |
---|
[7c8d3093] | 641 | self.model_name_list.append(TwoLorentzianModel.__name__) |
---|
[fb59ed9] | 642 | |
---|
| 643 | from sans.models.TwoPowerLawModel import TwoPowerLawModel |
---|
[df7a7e3] | 644 | self.model_dictionary[TwoPowerLawModel.__name__] = TwoPowerLawModel |
---|
[f32d144] | 645 | self.shape_indep_list.append(TwoPowerLawModel) |
---|
[7c8d3093] | 646 | self.model_name_list.append(TwoPowerLawModel.__name__) |
---|
[fb59ed9] | 647 | |
---|
| 648 | from sans.models.UnifiedPowerRgModel import UnifiedPowerRgModel |
---|
[df7a7e3] | 649 | self.model_dictionary[UnifiedPowerRgModel.__name__] = UnifiedPowerRgModel |
---|
[f32d144] | 650 | self.shape_indep_list.append(UnifiedPowerRgModel) |
---|
[fb59ed9] | 651 | self.multi_func_list.append(UnifiedPowerRgModel) |
---|
[5da3cc5] | 652 | |
---|
[eddff027] | 653 | from sans.models.LineModel import LineModel |
---|
[df7a7e3] | 654 | self.model_dictionary[LineModel.__name__] = LineModel |
---|
[eddff027] | 655 | self.shape_indep_list.append(LineModel) |
---|
[7c8d3093] | 656 | self.model_name_list.append(LineModel.__name__) |
---|
[5062bbf] | 657 | |
---|
[fb59ed9] | 658 | from sans.models.ReflectivityModel import ReflectivityModel |
---|
[df7a7e3] | 659 | self.model_dictionary[ReflectivityModel.__name__] = ReflectivityModel |
---|
[19e614a] | 660 | self.shape_indep_list.append(ReflectivityModel) |
---|
[fb59ed9] | 661 | self.multi_func_list.append(ReflectivityModel) |
---|
[1cc23fd] | 662 | |
---|
| 663 | from sans.models.ReflectivityIIModel import ReflectivityIIModel |
---|
[df7a7e3] | 664 | self.model_dictionary[ReflectivityIIModel.__name__] = ReflectivityIIModel |
---|
[19e614a] | 665 | self.shape_indep_list.append(ReflectivityIIModel) |
---|
[1cc23fd] | 666 | self.multi_func_list.append(ReflectivityIIModel) |
---|
[0da4eba] | 667 | |
---|
| 668 | from sans.models.GelFitModel import GelFitModel |
---|
[df7a7e3] | 669 | self.model_dictionary[GelFitModel.__name__] = GelFitModel |
---|
[0da4eba] | 670 | self.shape_indep_list.append(GelFitModel) |
---|
| 671 | self.model_name_list.append(GelFitModel.__name__) |
---|
[df7a7e3] | 672 | |
---|
| 673 | #from sans.models.FractalO_Z import FractalO_Z |
---|
| 674 | #self.model_dictionary[FractalO_Z.__name__] = FractalO_Z |
---|
| 675 | #self.shape_indep_list.append(FractalO_Z) |
---|
| 676 | #self.model_name_list.append(FractalO_Z.__name__) |
---|
| 677 | |
---|
[49b7efa] | 678 | #Looking for plugins |
---|
[9466f2d6] | 679 | self.stored_plugins = self.findModels() |
---|
[b2d9826] | 680 | self.plugins = self.stored_plugins.values() |
---|
[ea5fa58] | 681 | for name, plug in self.stored_plugins.iteritems(): |
---|
| 682 | self.model_dictionary[name] = plug |
---|
| 683 | |
---|
[b2d9826] | 684 | self._get_multifunc_models() |
---|
| 685 | |
---|
[d89f09b] | 686 | return 0 |
---|
| 687 | |
---|
[9466f2d6] | 688 | def is_changed(self): |
---|
| 689 | """ |
---|
| 690 | check the last time the plugin dir has changed and return true |
---|
| 691 | is the directory was modified else return false |
---|
| 692 | """ |
---|
| 693 | is_modified = False |
---|
[96814e1] | 694 | plugin_dir = find_plugins_dir() |
---|
| 695 | if os.path.isdir(plugin_dir): |
---|
[f32d144] | 696 | temp = os.path.getmtime(plugin_dir) |
---|
[9466f2d6] | 697 | if self.last_time_dir_modified != temp: |
---|
| 698 | is_modified = True |
---|
| 699 | self.last_time_dir_modified = temp |
---|
[bb9f322] | 700 | |
---|
[9466f2d6] | 701 | return is_modified |
---|
[d89f09b] | 702 | |
---|
[b2d9826] | 703 | def update(self): |
---|
| 704 | """ |
---|
[f32d144] | 705 | return a dictionary of model if |
---|
[9466f2d6] | 706 | new models were added else return empty dictionary |
---|
[b2d9826] | 707 | """ |
---|
[9466f2d6] | 708 | new_plugins = self.findModels() |
---|
| 709 | if len(new_plugins) > 0: |
---|
| 710 | for name, plug in new_plugins.iteritems(): |
---|
| 711 | if name not in self.stored_plugins.keys(): |
---|
| 712 | self.stored_plugins[name] = plug |
---|
| 713 | self.plugins.append(plug) |
---|
[ea5fa58] | 714 | self.model_dictionary[name] = plug |
---|
[9466f2d6] | 715 | self.model_combobox.set_list("Customized Models", self.plugins) |
---|
| 716 | return self.model_combobox.get_list() |
---|
| 717 | else: |
---|
| 718 | return {} |
---|
[5d1c1f4] | 719 | |
---|
[916f5c0] | 720 | def pulgins_reset(self): |
---|
| 721 | """ |
---|
| 722 | return a dictionary of model |
---|
| 723 | """ |
---|
| 724 | self.plugins = [] |
---|
| 725 | new_plugins = _findModels(dir) |
---|
| 726 | for name, plug in new_plugins.iteritems(): |
---|
| 727 | for stored_name, stored_plug in self.stored_plugins.iteritems(): |
---|
| 728 | if name == stored_name: |
---|
| 729 | del self.stored_plugins[name] |
---|
[ea5fa58] | 730 | del self.model_dictionary[name] |
---|
[916f5c0] | 731 | break |
---|
| 732 | self.stored_plugins[name] = plug |
---|
| 733 | self.plugins.append(plug) |
---|
[ea5fa58] | 734 | self.model_dictionary[name] = plug |
---|
[19e614a] | 735 | |
---|
[916f5c0] | 736 | self.model_combobox.reset_list("Customized Models", self.plugins) |
---|
| 737 | return self.model_combobox.get_list() |
---|
| 738 | |
---|
[d89f09b] | 739 | def populate_menu(self, modelmenu, event_owner): |
---|
| 740 | """ |
---|
[5062bbf] | 741 | Populate a menu with our models |
---|
| 742 | |
---|
| 743 | :param id: first menu event ID to use when binding the menu events |
---|
| 744 | :param modelmenu: wx.Menu object to populate |
---|
| 745 | :param event_owner: wx object to bind the menu events to |
---|
| 746 | |
---|
| 747 | :return: the next free event ID following the new menu events |
---|
| 748 | |
---|
[d89f09b] | 749 | """ |
---|
[bb18ef1] | 750 | ## Fill model lists |
---|
[d89f09b] | 751 | self._getModelList() |
---|
[bb18ef1] | 752 | ## store reference to model menu of guiframe |
---|
| 753 | self.modelmenu = modelmenu |
---|
| 754 | ## guiframe reference |
---|
[d89f09b] | 755 | self.event_owner = event_owner |
---|
[bb18ef1] | 756 | |
---|
| 757 | shape_submenu = wx.Menu() |
---|
| 758 | shape_indep_submenu = wx.Menu() |
---|
| 759 | structure_factor = wx.Menu() |
---|
[b30f001] | 760 | added_models = wx.Menu() |
---|
[376916c] | 761 | multip_models = wx.Menu() |
---|
[bb18ef1] | 762 | ## create menu with shape |
---|
[f32d144] | 763 | self._fill_simple_menu(menuinfo=["Shapes", |
---|
| 764 | shape_submenu, |
---|
| 765 | " simple shape"], |
---|
[5062bbf] | 766 | list1=self.shape_list) |
---|
[376916c] | 767 | |
---|
[f32d144] | 768 | self._fill_simple_menu(menuinfo=["Shape-Independent", |
---|
| 769 | shape_indep_submenu, |
---|
| 770 | "List of shape-independent models"], |
---|
| 771 | list1=self.shape_indep_list) |
---|
[bb18ef1] | 772 | |
---|
[f32d144] | 773 | self._fill_simple_menu(menuinfo=["Structure Factors", |
---|
| 774 | structure_factor, |
---|
| 775 | "List of Structure factors models"], |
---|
[5062bbf] | 776 | list1=self.struct_list) |
---|
[bb18ef1] | 777 | |
---|
[5062bbf] | 778 | self._fill_plugin_menu(menuinfo=["Customized Models", added_models, |
---|
[376916c] | 779 | "List of additional models"], |
---|
[5062bbf] | 780 | list1=self.plugins) |
---|
[376916c] | 781 | |
---|
[f32d144] | 782 | self._fill_menu(menuinfo=["P(Q)*S(Q)", multip_models, |
---|
[376916c] | 783 | "mulplication of 2 models"], |
---|
[f32d144] | 784 | list1=self.multiplication_factor, |
---|
| 785 | list2=self.struct_list) |
---|
[d89f09b] | 786 | return 0 |
---|
| 787 | |
---|
[5062bbf] | 788 | def _fill_plugin_menu(self, menuinfo, list1): |
---|
[bfe4644] | 789 | """ |
---|
[5062bbf] | 790 | fill the plugin menu with costumized models |
---|
[bfe4644] | 791 | """ |
---|
[f32d144] | 792 | if len(list1) == 0: |
---|
| 793 | id = wx.NewId() |
---|
| 794 | msg = "No model available check plugins.log for errors to fix problem" |
---|
| 795 | menuinfo[1].Append(int(id), "Empty", msg) |
---|
| 796 | self._fill_simple_menu(menuinfo, list1) |
---|
[bfe4644] | 797 | |
---|
[5062bbf] | 798 | def _fill_simple_menu(self, menuinfo, list1): |
---|
[bb18ef1] | 799 | """ |
---|
[5062bbf] | 800 | Fill the menu with list item |
---|
| 801 | |
---|
| 802 | :param modelmenu: the menu to fill |
---|
| 803 | :param menuinfo: submenu item for the first column of this modelmenu |
---|
| 804 | with info.Should be a list : |
---|
| 805 | [name(string) , menu(wx.menu), help(string)] |
---|
| 806 | :param list1: contains item (form factor )to fill modelmenu second column |
---|
| 807 | |
---|
[bb18ef1] | 808 | """ |
---|
[f32d144] | 809 | if len(list1) > 0: |
---|
| 810 | self.model_combobox.set_list(menuinfo[0], list1) |
---|
[e7b1ccf] | 811 | |
---|
[bb18ef1] | 812 | for item in list1: |
---|
[e7b1ccf] | 813 | try: |
---|
[f32d144] | 814 | id = wx.NewId() |
---|
| 815 | struct_factor = item() |
---|
[e7b1ccf] | 816 | struct_name = struct_factor.__class__.__name__ |
---|
| 817 | if hasattr(struct_factor, "name"): |
---|
| 818 | struct_name = struct_factor.name |
---|
| 819 | |
---|
[f32d144] | 820 | menuinfo[1].Append(int(id), struct_name, struct_name) |
---|
[e7b1ccf] | 821 | if not item in self.struct_factor_dict.itervalues(): |
---|
[f32d144] | 822 | self.struct_factor_dict[str(id)] = item |
---|
[e7b1ccf] | 823 | wx.EVT_MENU(self.event_owner, int(id), self._on_model) |
---|
| 824 | except: |
---|
[f32d144] | 825 | msg = "Error Occured: %s" % sys.exc_value |
---|
[e7b1ccf] | 826 | wx.PostEvent(self.event_owner, StatusEvent(status=msg)) |
---|
[bb18ef1] | 827 | |
---|
[f32d144] | 828 | id = wx.NewId() |
---|
| 829 | self.modelmenu.AppendMenu(id, menuinfo[0], menuinfo[1], menuinfo[2]) |
---|
[bb18ef1] | 830 | |
---|
[5062bbf] | 831 | def _fill_menu(self, menuinfo, list1, list2): |
---|
[bb18ef1] | 832 | """ |
---|
[5062bbf] | 833 | Fill the menu with list item |
---|
| 834 | |
---|
| 835 | :param menuinfo: submenu item for the first column of this modelmenu |
---|
| 836 | with info.Should be a list : |
---|
| 837 | [name(string) , menu(wx.menu), help(string)] |
---|
| 838 | :param list1: contains item (form factor )to fill modelmenu second column |
---|
[f32d144] | 839 | :param list2: contains item (Structure factor )to fill modelmenu |
---|
[5062bbf] | 840 | third column |
---|
| 841 | |
---|
[bb18ef1] | 842 | """ |
---|
[f32d144] | 843 | if len(list1) > 0: |
---|
| 844 | self.model_combobox.set_list(menuinfo[0], list1) |
---|
[bb18ef1] | 845 | |
---|
[f32d144] | 846 | for item in list1: |
---|
| 847 | form_factor = item() |
---|
[bb18ef1] | 848 | form_name = form_factor.__class__.__name__ |
---|
| 849 | if hasattr(form_factor, "name"): |
---|
| 850 | form_name = form_factor.name |
---|
[f32d144] | 851 | ### store form factor to return to other users |
---|
| 852 | newmenu = wx.Menu() |
---|
| 853 | if len(list2) > 0: |
---|
[bb18ef1] | 854 | for model in list2: |
---|
| 855 | id = wx.NewId() |
---|
| 856 | struct_factor = model() |
---|
| 857 | name = struct_factor.__class__.__name__ |
---|
| 858 | if hasattr(struct_factor, "name"): |
---|
| 859 | name = struct_factor.name |
---|
[f32d144] | 860 | newmenu.Append(id, name, name) |
---|
[bb18ef1] | 861 | wx.EVT_MENU(self.event_owner, int(id), self._on_model) |
---|
| 862 | ## save form_fact and struct_fact |
---|
[f32d144] | 863 | self.form_factor_dict[int(id)] = [form_factor, |
---|
| 864 | struct_factor] |
---|
[bb18ef1] | 865 | |
---|
[f32d144] | 866 | form_id = wx.NewId() |
---|
| 867 | menuinfo[1].AppendMenu(int(form_id), form_name, |
---|
| 868 | newmenu, menuinfo[2]) |
---|
| 869 | id = wx.NewId() |
---|
| 870 | self.modelmenu.AppendMenu(id, menuinfo[0], menuinfo[1], menuinfo[2]) |
---|
[bb18ef1] | 871 | |
---|
[d89f09b] | 872 | def _on_model(self, evt): |
---|
| 873 | """ |
---|
[5062bbf] | 874 | React to a model menu event |
---|
| 875 | |
---|
| 876 | :param event: wx menu event |
---|
| 877 | |
---|
[d89f09b] | 878 | """ |
---|
[bb18ef1] | 879 | if int(evt.GetId()) in self.form_factor_dict.keys(): |
---|
| 880 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
[df7a7e3] | 881 | self.model_dictionary[MultiplicationModel.__name__] = MultiplicationModel |
---|
[bb18ef1] | 882 | model1, model2 = self.form_factor_dict[int(evt.GetId())] |
---|
[f32d144] | 883 | model = MultiplicationModel(model1, model2) |
---|
[bb18ef1] | 884 | else: |
---|
[f32d144] | 885 | model = self.struct_factor_dict[str(evt.GetId())]() |
---|
[61184df] | 886 | |
---|
| 887 | #TODO: investigate why the following two lines were left in the code |
---|
| 888 | # even though the ModelEvent class doesn't exist |
---|
| 889 | #evt = ModelEvent(model=model) |
---|
| 890 | #wx.PostEvent(self.event_owner, evt) |
---|
[d89f09b] | 891 | |
---|
[fb59ed9] | 892 | def _get_multifunc_models(self): |
---|
| 893 | """ |
---|
| 894 | Get the multifunctional models |
---|
| 895 | """ |
---|
| 896 | for item in self.plugins: |
---|
| 897 | try: |
---|
| 898 | # check the multiplicity if any |
---|
| 899 | if item.multiplicity_info[0] > 1: |
---|
| 900 | self.multi_func_list.append(item) |
---|
| 901 | except: |
---|
| 902 | # pass to other items |
---|
| 903 | pass |
---|
| 904 | |
---|
[f32d144] | 905 | def get_model_list(self): |
---|
[5062bbf] | 906 | """ |
---|
[f32d144] | 907 | return dictionary of models for fitpanel use |
---|
[5062bbf] | 908 | |
---|
| 909 | """ |
---|
[6bbeacd4] | 910 | self.model_combobox.set_list("Shapes", self.shape_list) |
---|
[f32d144] | 911 | self.model_combobox.set_list("Shape-Independent", |
---|
| 912 | self.shape_indep_list) |
---|
[6bbeacd4] | 913 | self.model_combobox.set_list("Structure Factors", self.struct_list) |
---|
| 914 | self.model_combobox.set_list("Customized Models", self.plugins) |
---|
| 915 | self.model_combobox.set_list("P(Q)*S(Q)", self.multiplication_factor) |
---|
[f32d144] | 916 | self.model_combobox.set_list("multiplication", |
---|
| 917 | self.multiplication_factor) |
---|
[e87f9fc] | 918 | self.model_combobox.set_list("Multi-Functions", self.multi_func_list) |
---|
[b2d9826] | 919 | return self.model_combobox.get_list() |
---|
[d89f09b] | 920 | |
---|
[7c8d3093] | 921 | def get_model_name_list(self): |
---|
| 922 | """ |
---|
| 923 | return regular model name list |
---|
| 924 | """ |
---|
| 925 | return self.model_name_list |
---|
[df7a7e3] | 926 | |
---|
| 927 | def get_model_dictionary(self): |
---|
| 928 | """ |
---|
| 929 | return dictionary linking model names to objects |
---|
| 930 | """ |
---|
| 931 | return self.model_dictionary |
---|
[376916c] | 932 | |
---|
[bb18ef1] | 933 | |
---|
[bb9f322] | 934 | class ModelManager(object): |
---|
| 935 | """ |
---|
[f32d144] | 936 | implement model |
---|
[bb9f322] | 937 | """ |
---|
| 938 | __modelmanager = ModelManagerBase() |
---|
| 939 | |
---|
| 940 | def findModels(self): |
---|
| 941 | return self.__modelmanager.findModels() |
---|
| 942 | |
---|
| 943 | def _getModelList(self): |
---|
| 944 | return self.__modelmanager._getModelList() |
---|
| 945 | |
---|
| 946 | def is_changed(self): |
---|
| 947 | return self.__modelmanager.is_changed() |
---|
| 948 | |
---|
| 949 | def update(self): |
---|
| 950 | return self.__modelmanager.update() |
---|
| 951 | |
---|
[916f5c0] | 952 | def pulgins_reset(self): |
---|
| 953 | return self.__modelmanager.pulgins_reset() |
---|
| 954 | |
---|
[bb9f322] | 955 | def populate_menu(self, modelmenu, event_owner): |
---|
| 956 | return self.__modelmanager.populate_menu(modelmenu, event_owner) |
---|
| 957 | |
---|
| 958 | def _on_model(self, evt): |
---|
| 959 | return self.__modelmanager._on_model(evt) |
---|
| 960 | |
---|
| 961 | def _get_multifunc_models(self): |
---|
| 962 | return self.__modelmanager._get_multifunc_models() |
---|
| 963 | |
---|
[f32d144] | 964 | def get_model_list(self): |
---|
[bb9f322] | 965 | return self.__modelmanager.get_model_list() |
---|
[bb18ef1] | 966 | |
---|
[7c8d3093] | 967 | def get_model_name_list(self): |
---|
| 968 | return self.__modelmanager.get_model_name_list() |
---|
[df7a7e3] | 969 | |
---|
| 970 | def get_model_dictionary(self): |
---|
| 971 | return self.__modelmanager.get_model_dictionary() |
---|