Changeset 796c4d4 in sasview


Ignore:
Timestamp:
Mar 27, 2012 1:36:24 PM (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:
cdc2ee2
Parents:
602c2f3
Message:

new: overwright default changes; sum:added name control

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • calculatorview/src/sans/perspectives/calculator/model_editor.py

    r0a90d92 r796c4d4  
    1919    FONT_VARIANT = 0 
    2020    PNL_WIDTH = 460 
    21     PNL_HITE = 210 
     21    PNL_HITE = 300 
    2222else: 
    2323    FONT_VARIANT = 1 
    2424    PNL_WIDTH = 500 
    25     PNL_HITE = 250 
    26  
     25    PNL_HITE = 370 
     26M_NAME = 'SumModel' 
    2727EDITOR_WIDTH = 800 
    2828EDITOR_HEIGTH = 700 
     
    5757    Dialog for easy custom sum models   
    5858    """ 
    59     def __init__(self, parent=None, id=None, title='', model_list=[]): 
     59    def __init__(self, parent=None, base=None, id=None, title='', model_list=[], plugin_dir=None): 
    6060        """ 
    6161        Dialog window popup when selecting 'Easy Custom Sum' on the menu 
     
    6363        wx.Dialog.__init__(self, parent=parent, id=id,  
    6464                           title=title, size=(PNL_WIDTH, PNL_HITE)) 
    65         self.parent = parent 
     65        self.parent = base 
    6666        #Font 
    6767        self.SetWindowVariant(variant=FONT_VARIANT) 
    6868        # default 
     69        self.font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT) 
     70        self.font.SetPointSize(10) 
     71        self.overwrite_name = False 
     72        self.plugin_dir = plugin_dir 
    6973        self.model_list = model_list 
    7074        self.model1_string = "SphereModel" 
     
    7377        self.model1_name = str(self.model1.GetValue()) 
    7478        self.model2_name = str(self.model2.GetValue()) 
    75          
     79        self.good_name = True 
     80         
     81    def _layout_name(self): 
     82        """ 
     83        Do the layout for file/function name related widgets 
     84        """ 
     85        self.name_sizer = wx.BoxSizer(wx.VERTICAL) 
     86        self.name_hsizer = wx.BoxSizer(wx.HORIZONTAL) 
     87        #title name [string] 
     88        name_txt = wx.StaticText(self, -1, 'SumFunction Name : ')   
     89        self.name_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH*3/5, -1))  
     90        self.name_tcl.Bind(wx.EVT_TEXT_ENTER, self.on_change_name) 
     91        self.name_tcl.SetValue('') 
     92        self.name_tcl.SetFont(self.font) 
     93        hint_name = "Unique Sum Model Function Name." 
     94        self.name_tcl.SetToolTipString(hint_name) 
     95        self.name_hsizer.AddMany([(name_txt, 0, wx.LEFT|wx.TOP, 10), 
     96                            (self.name_tcl, 0, wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) 
     97        self.name_sizer.AddMany([(self.name_hsizer, 0,  
     98                                        wx.LEFT|wx.TOP, 10)]) 
     99         
     100         
     101    def _layout_description(self): 
     102        """ 
     103        Do the layout for description related widgets 
     104        """ 
     105        self.desc_sizer = wx.BoxSizer(wx.HORIZONTAL) 
     106        #title name [string] 
     107        desc_txt = wx.StaticText(self, -1, 'Description (optional) : ')   
     108        self.desc_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH*3/5, -1))  
     109        self.desc_tcl.SetValue('') 
     110        #self.name_tcl.SetFont(self.font) 
     111        hint_desc = "Write a short description of the sum model function." 
     112        self.desc_tcl.SetToolTipString(hint_desc) 
     113        self.desc_sizer.AddMany([(desc_txt, 0, wx.LEFT|wx.TOP, 10), 
     114                                       (self.desc_tcl, 0,  
     115                                        wx.RIGHT|wx.TOP|wx.BOTTOM, 10)])      
     116   
    76117    def _build_sizer(self): 
    77118        """ 
     
    81122        vbox  = wx.BoxSizer(wx.VERTICAL) 
    82123        sizer = wx.GridBagSizer(1, 3) 
     124        self._layout_name() 
     125        self._layout_description() 
     126         
     127         
    83128        sum_description= wx.StaticBox(self, -1, 'Select',  
    84129                                       size=(PNL_WIDTH-30, 70)) 
     
    99144         # Buttons on the bottom 
    100145        self.static_line_1 = wx.StaticLine(self, -1) 
    101         self.okButton = wx.Button(self,wx.ID_OK, 'OK', size=(_BOX_WIDTH/2, 25)) 
    102         self.closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel',  
     146        self.okButton = wx.Button(self,wx.ID_OK, 'Apply', size=(_BOX_WIDTH/2, 25)) 
     147        self.okButton.Bind(wx.EVT_BUTTON, self.check_name) 
     148        self.closeButton = wx.Button(self,wx.ID_CANCEL, 'Close',  
    103149                                     size=(_BOX_WIDTH/2, 25)) 
    104150        # Intro 
    105151        explanation  = "  custom model = scale_factor * (model1 + model2)\n" 
    106         explanation  += "  Note: This will overwrite the previous sum model.\n" 
     152        #explanation  += "  Note: This will overwrite the previous sum model.\n" 
    107153        model_string = " Model%s (p%s):" 
     154        vbox.Add(self.name_hsizer) 
     155        vbox.Add(self.desc_sizer) 
    108156        vbox.Add(sizer) 
    109157        ix = 0 
     
    135183        self.SetSizer(vbox) 
    136184        self.Centre() 
    137                   
     185         
     186    def on_change_name(self, event=None): 
     187        """ 
     188        Change name 
     189        """ 
     190        if event is not None: 
     191            event.Skip() 
     192        self.name_tcl.SetBackgroundColour('white') 
     193        self.Refresh() 
     194     
     195    def check_name(self, event=None): 
     196        """ 
     197        Check name if exist already 
     198        """ 
     199        self.on_change_name(None) 
     200        list_fnames = os.listdir(self.plugin_dir) 
     201 
     202        # function/file name 
     203        title = self.name_tcl.GetValue().lstrip().rstrip() 
     204        if title == '': 
     205            title = M_NAME 
     206        self.name = title 
     207        t_fname = title + '.py' 
     208        if not self.overwrite_name: 
     209            if t_fname in list_fnames and title != M_NAME: 
     210                self.name_tcl.SetBackgroundColour('pink') 
     211                self.good_name = False 
     212                info = 'Error' 
     213                msg = "Name exists already." 
     214                wx.MessageBox(msg, info)   
     215                return self.good_name 
     216        self.fname = os.path.join(self.plugin_dir, t_fname) 
     217        self._notes = "SumModel function name set " 
     218        self._notes += "to %s. \n" % str(title) 
     219        self.good_name = True 
     220        self.on_apply(self.fname) 
     221        return self.good_name 
     222     
     223    def on_apply(self, path): 
     224        """ 
     225        On Apply 
     226        """ 
     227        try: 
     228            label = self.getText() 
     229            fname = path 
     230            name1 = label[0] 
     231            name2 = label[1] 
     232            self.write_string(fname, name1, name2) 
     233            self.compile_file(fname) 
     234            self.parent.update_custom_combo() 
     235        except: 
     236            raise 
     237            if self.parent.parent != None: 
     238                from sans.guiframe.events import StatusEvent  
     239                msg= "Easy Custom Sum: Error occurred..." 
     240                wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 
     241            else: 
     242                raise 
     243                   
    138244    def _set_model_list(self): 
    139245        """ 
     
    176282        Write and Save file 
    177283        """ 
     284        self.fname = fname   
     285        description = self.desc_tcl.GetValue().lstrip().rstrip() 
     286        if description == '': 
     287            description = name1 + "+" + name2 
     288        name = self.name_tcl.GetValue().lstrip().rstrip() 
     289        if name == '': 
     290            name = M_NAME 
     291        path = self.fname 
    178292        try: 
    179             out_f =  open(fname,'w') 
     293            out_f =  open(path,'w') 
    180294        except : 
    181295            raise 
     
    186300            elif line.count("import %s as P2"): 
    187301                out_f.write(line % (name2, name2) + "\n") 
     302            elif line.count("self.description = '%s'"): 
     303                out_f.write(line % description + "\n") 
     304            elif line.count("self.name = '%s'"): 
     305                out_f.write(line % name + "\n") 
    188306            else: 
    189307                out_f.write(line + "\n") 
    190         out_f.close()  
     308        out_f.close() 
     309        #else: 
     310        #    msg = "Name exists already." 
    191311         
    192312    def compile_file(self, path): 
     
    194314        Compile the file in the path 
    195315        """ 
     316        path = self.fname 
    196317        _compileFile(path) 
    197318         
     
    220341        self.reader = None 
    221342        self.name = 'untitled' 
    222         self.overwrite_name = True 
     343        self.overwrite_name = False 
    223344        self.is_2d = False 
    224345        self.fname = None 
     
    253374        name_txt = wx.StaticText(self, -1, 'Function Name : ')   
    254375        overwrite_cb = wx.CheckBox(self, -1, "Overwrite?", (10, 10)) 
    255         overwrite_cb.SetValue(True) 
     376        overwrite_cb.SetValue(False) 
    256377        overwrite_cb.SetToolTipString("Overwrite it if already exists?") 
    257378        wx.EVT_CHECKBOX(self, overwrite_cb.GetId(), self.on_over_cb) 
     379        #overwrite_cb.Show(False) 
    258380        self.name_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH*3/5, -1))  
    259381        self.name_tcl.Bind(wx.EVT_TEXT_ENTER, self.on_change_name) 
     
    695817        p_model2 = P2() 
    696818        ## Setting  model name model description 
    697         self.description="" 
    698         self.name = self._get_name(p_model1.name, p_model2.name) 
    699         self.description = p_model1.name 
    700         self.description += p_model2.name 
    701         self.fill_description(p_model1, p_model2) 
     819        self.description = '%s' 
     820        self.name = '%s' 
     821        if self.name.rstrip().lstrip() == '': 
     822            self.name = self._get_name(p_model1.name, p_model2.name) 
     823        if self.description.rstrip().lstrip() == '': 
     824            self.description = p_model1.name 
     825            self.description += p_model2.name 
     826            self.fill_description(p_model1, p_model2) 
    702827 
    703828        ## Define parameters 
  • fittingview/src/sans/perspectives/fitting/fitting.py

    rd2843a9 r796c4d4  
    279279        model_manager = models.ModelManager() 
    280280        model_list = model_manager.get_model_name_list() 
    281  
    282         textdial = TextDialog(None, -1, 'Easy Sum(p1, p2)', model_list) 
     281        plug_dir = models.find_plugins_dir() 
     282        textdial = TextDialog(None, self, -1, 'Easy Sum(p1, p2)',  
     283                              model_list, plug_dir) 
    283284        self.put_icon(textdial) 
    284         if textdial.ShowModal() == wx.ID_OK: 
    285             try: 
    286                 label = textdial.getText() 
    287                 plug_dir = models.find_plugins_dir() 
    288                 fname = os.path.join(plug_dir, "easy_sum_of_p1_p2.py") 
    289                 name1 = label[0] 
    290                 name2 = label[1] 
    291                 textdial.write_string(fname, name1, name2) 
    292                 textdial.compile_file(fname) 
    293                 self.update_custom_combo() 
    294             except: 
    295                 raise 
    296                 if self.parent != None: 
    297                     from sans.guiframe.events import StatusEvent  
    298                     msg= "Easy Custom Sum: Error occurred..." 
    299                     wx.PostEvent(self.parent, StatusEvent(status = msg )) 
    300                 else: 
    301                     raise 
     285        dial = textdial.ShowModal() 
     286 
    302287        textdial.Destroy() 
    303288     
Note: See TracChangeset for help on using the changeset viewer.