Changeset 19e614a in sasview


Ignore:
Timestamp:
May 2, 2012 11:03:55 AM (12 years ago)
Author:
Jae Cho <jhjcho@…>
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:
3aab96b
Parents:
6246e00
Message:

let users be able to delete default custom models (WIN app only)

Files:
11 edited

Legend:

Unmodified
Added
Removed
  • fittingview/src/sans/perspectives/fitting/basepage.py

    r8df5faa r19e614a  
    28932893            name = self.formfactorbox.GetValue() 
    28942894        frame = HelpWindow(None, -1, pageToOpen=model_path) 
    2895         if frame.rhelp.HasAnchor(name): 
     2895        # If model name exists and model is not a custom model 
     2896        if frame.rhelp.HasAnchor(name) and not self.plugin_rbutton.GetValue(): 
    28962897            frame.Show(True) 
    28972898            frame.rhelp.ScrollToAnchor(name) 
  • fittingview/src/sans/perspectives/fitting/fitting.py

    rf32d144 r19e614a  
    262262                os.remove(p_path) 
    263263            self.update_custom_combo() 
    264             self.delete_menu.Delete(id) 
    265             for item in self.edit_menu.GetMenuItems(): 
    266                 if item.GetLabel() == label: 
    267                     self.edit_menu.DeleteItem(item) 
    268                     break 
     264            if os.path.isfile(p_path): 
     265                msg = "Sorry! Could not be able to delete the default " 
     266                msg += "custom model... \n" 
     267                msg += "Please manually remove the files (.py, .pyc) " 
     268                msg += "in the 'plugin_models' folder \n" 
     269                msg += "inside of the SansView application, " 
     270                msg += "and try it again." 
     271                wx.MessageBox(msg, 'Info') 
     272                #wx.PostEvent(self.parent, StatusEvent(status=msg, type='stop', 
     273                #                                      info='warning')) 
     274            else: 
     275                self.delete_menu.Delete(id) 
     276                for item in self.edit_menu.GetMenuItems(): 
     277                    if item.GetLabel() == label: 
     278                        self.edit_menu.DeleteItem(item) 
     279                        msg = "The custom model, %s, has been deleted."% label 
     280                        wx.PostEvent(self.parent, StatusEvent(status=msg,  
     281                                                type='stop', info='info')) 
     282                        break 
    269283        except: 
    270284            msg ='Delete Error: \nCould not delete the file; Check if in use.' 
    271             wx.MessageBox(msg) 
     285            wx.MessageBox(msg, 'Error') 
    272286     
    273287    def make_sum_model(self, event): 
     
    314328                    if hasattr(page, "formfactorbox"): 
    315329                        page.model_list_box = temp 
    316                         current_val = page.formfactorbox.GetValue() 
    317                         pos = page.formfactorbox.GetSelection() 
     330                        current_val = page.formfactorbox.GetLabel() 
     331                        #pos = page.formfactorbox.GetSelection() 
    318332                        page._show_combox_helper() 
    319                         new_val = page.formfactorbox.GetValue() 
     333                        new_val = page.formfactorbox.GetLabel() 
    320334                        if current_val != new_val and new_val != '': 
    321                             page.formfactorbox.SetValue(new_val) 
     335                            page.formfactorbox.SetLabel(new_val) 
    322336                        else: 
    323                             page.formfactorbox.SetValue(current_val) 
     337                            page.formfactorbox.SetLabel(current_val) 
    324338        except: 
    325339            pass 
  • fittingview/src/sans/perspectives/fitting/models.py

    rf32d144 r19e614a  
    107107        if not p_dir: 
    108108            raise 
    109  
    110109    # Place example user models as needed 
    111     for file in os.listdir(p_dir): 
    112         file_path = os.path.join(p_dir, file) 
    113         if os.path.isfile(file_path): 
    114             if file.split(".")[-1] == 'py' and\ 
    115                 file.split(".")[0] != '__init__': 
    116                 if not os.path.isfile(os.path.join(dir, file)): 
    117                     shutil.copy(file_path, dir) 
     110    if os.path.isdir(p_dir): 
     111        for file in os.listdir(p_dir): 
     112            file_path = os.path.join(p_dir, file) 
     113            if os.path.isfile(file_path): 
     114                if file.split(".")[-1] == 'py' and\ 
     115                    file.split(".")[0] != '__init__': 
     116                    if not os.path.isfile(os.path.join(dir, file)): 
     117                        shutil.copy(file_path, dir) 
     118 
    118119    return dir 
    119120 
     
    572573         
    573574        from sans.models.ReflectivityModel import ReflectivityModel 
     575        self.shape_indep_list.append(ReflectivityModel) 
    574576        self.multi_func_list.append(ReflectivityModel) 
    575577         
    576578        from sans.models.ReflectivityIIModel import ReflectivityIIModel 
     579        self.shape_indep_list.append(ReflectivityIIModel) 
    577580        self.multi_func_list.append(ReflectivityIIModel) 
    578581     
     
    580583        self.stored_plugins = self.findModels() 
    581584        self.plugins = self.stored_plugins.values() 
    582         self.plugins.append(ReflectivityModel) 
    583         self.plugins.append(ReflectivityIIModel) 
     585 
    584586        self._get_multifunc_models() 
    585587        
     
    630632            self.stored_plugins[name] = plug 
    631633            self.plugins.append(plug) 
    632         from sans.models.ReflectivityModel import ReflectivityModel 
    633         from sans.models.ReflectivityIIModel import ReflectivityIIModel 
    634         self.plugins.append(ReflectivityModel) 
    635         self.plugins.append(ReflectivityIIModel) 
     634 
    636635        self.model_combobox.reset_list("Customized Models", self.plugins) 
    637636        return self.model_combobox.get_list() 
  • fittingview/src/sans/perspectives/fitting/plugin_models/polynominal5.py

    re9bd127 r19e614a  
    3232    ## YOU CAN MODIFY THE LINE BELLOW. CHANGE ONLY WORDS BETWEEN " "  
    3333    ## TO RENAME YOUR MODEL: THIS NAME IS WHAT YOU SEE ON GUI. 
    34     name = "polynomial5"        ## <----- NAME OF THE MODEL    
     34    name = "polynomial5"        ## <----- FILE NAME (NAME OF THE MODEL)    
    3535                                 
    3636    def __init__(self):      ##DO NOT CHANGE THIS LINE!!! 
     
    4848        self.params['E'] = 0.0       ## <-----                   
    4949        self.params['F'] = 0.0       ## <-----    
    50          
     50        ## YOU CAN MODIFY THE LINE BELLOW.MODIFY WORDS BETWEEN """   """  ONLY!!!! 
     51        self.description = """ 
     52            a + b * x + c * math.pow(x,2) + d * math.pow(x,3) \n 
     53             + e * math.pow(x,4) + f * math.pow(x,5)   
     54        """                        ## <-----    
    5155        ## DEFINE DEFAULT DETAILS 
    5256        self.set_details()      ##DO NOT DELETE OR CHANGE THIS LINE!!! 
  • fittingview/src/sans/perspectives/fitting/plugin_models/sph_bessel_jn.py

    re9bd127 r19e614a  
    3636    ## YOU CAN MODIFY THE LINE BELLOW. CHANGE ONLY WORDS BETWEEN " "  
    3737    ## TO RENAME YOUR MODEL 
    38     name = "C*sph_jn(Ax+B)+D" ## <----- NAME OF THE MODEL    
     38    name = "sph_bessel_jn" ## <----- FILE NAME (NAME OF THE MODEL)    
    3939                                 
    4040    def __init__(self):      ##DO NOT CHANGE THIS LINE!!! 
  • fittingview/src/sans/perspectives/fitting/plugin_models/sum_Ap1_1_Ap2.py

    r2b4c8ca r19e614a  
    4343    Note: P(Q) refers to 'form factor' model. 
    4444    """ 
    45     name = "" 
     45    name = "sum_Ap1_1_Ap2" ## <----- FILE NAME (NAME OF THE MODEL)  
    4646    def __init__(self): 
    47         Model1DPlugin.__init__(self, name='') 
     47        Model1DPlugin.__init__(self, name=self.name) 
    4848        """ 
    4949        :param p_model1: a form factor, P(Q) 
     
    5353        p_model2 = P2() 
    5454        ## Setting  model name model description 
    55         self.description="" 
    56         self.name = self._get_name(p_model1.name, p_model2.name) 
    57         self.description = p_model1.name+"\n" 
    58         self.description += p_model2.name+"\n" 
     55        self.description = "" 
    5956        self.fill_description(p_model1, p_model2) 
    6057 
     
    391388        """ 
    392389        description = "" 
    393         description +="This model gives the summation of  %s and %s.\n"% \ 
     390        description +="This model gives the summation of (A*%s) and ((1-A)*%s).\n"% \ 
    394391                                        ( p_model1.name, p_model2.name ) 
    395392        self.description += description 
  • fittingview/src/sans/perspectives/fitting/plugin_models/sum_p1_p2.py

    r0e62f0f r19e614a  
    4848    Note: P(Q) refers to 'form factor' model. 
    4949    """ 
    50     name = "" 
     50    name = "sum_p1_p2" ## <----- FILE NAME (NAME OF THE MODEL)  
    5151    def __init__(self): 
    52         Model1DPlugin.__init__(self, name='') 
     52        Model1DPlugin.__init__(self, name=self.name) 
    5353        """ 
    5454        :param p_model1: a form factor, P(Q) 
     
    5959        ## Setting  model name model description 
    6060        self.description="" 
    61         self.name = self._get_name(p_model1.name, p_model2.name) 
     61         
    6262        self.description = p_model1.name+"\n" 
    6363        self.description += p_model2.name+"\n" 
  • fittingview/src/sans/perspectives/fitting/plugin_models/testmodel.py

    re9bd127 r19e614a  
    3636    ## YOU CAN MODIFY THE LINE BELLOW. CHANGE ONLY WORDS BETWEEN " "  
    3737    ## TO RENAME YOUR MODEL 
    38     name = "A+Bcos(2x)+Csin(2x)"      ## <----- NAME OF THE MODEL    
     38    name = "testmodel"      ## <----- FILE NAME (NAME OF THE MODEL)    
    3939     
    4040    def __init__(self): 
  • fittingview/src/sans/perspectives/fitting/plugin_models/testmodel_2.py

    r6f140f2 r19e614a  
    3535    ## YOU CAN MODIFY THE LINE BELLOW. CHANGE ONLY WORDS BETWEEN " "  
    3636    ## TO RENAME YOUR MODEL 
    37     name = "sin(poly)/(poly)" ## <----- NAME OF THE MODEL    
     37    name = "testmodel_2" ## <----- FILE NAME (NAME OF THE MODEL)   
    3838                                 
    3939    def __init__(self):      ##DO NOT CHANGE THIS LINE!!! 
  • sansguiframe/src/sans/guiframe/gui_manager.py

    r3184d964 r19e614a  
    33963396            self.frame.set_input_file(input_file=input_file) 
    33973397          
    3398              
     3398    def clean_plugin_models(self, path):  
     3399        """ 
     3400        Delete plugin models  in app folder 
     3401         
     3402        :param path: path of the plugin_models folder in app 
     3403        """ 
     3404        # do it only the first time app loaded 
     3405        # delete unused model folder     
     3406        model_folder = os.path.join(PATH_APP, path) 
     3407        if os.path.exists(model_folder) and os.path.isdir(model_folder): 
     3408            if len(os.listdir(model_folder)) > 0: 
     3409                try: 
     3410                    for file in os.listdir(model_folder): 
     3411                        file_path = os.path.join(model_folder, file) 
     3412                        if os.path.isfile(file_path): 
     3413                            os.remove(file_path) 
     3414                except: 
     3415                    pass 
     3416               
    33993417    def set_manager(self, manager): 
    34003418        """ 
  • sansview/sansview.py

    r5559171 r19e614a  
    3232# For py2exe, import config here 
    3333import local_config 
     34PLUGIN_MODEL_DIR = 'plugin_models' 
    3435 
    3536def run(): 
     
    104105        # Build the GUI 
    105106        self.gui.build_gui() 
    106          
     107        # delete unused model folder     
     108        self.gui.clean_plugin_models(PLUGIN_MODEL_DIR) 
    107109        # Start the main loop 
    108110        self.gui.MainLoop()   
Note: See TracChangeset for help on using the changeset viewer.