Changeset 796c4d4 in sasview
- Timestamp:
- Mar 27, 2012 1:36:24 PM (13 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:
- cdc2ee2
- Parents:
- 602c2f3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
calculatorview/src/sans/perspectives/calculator/model_editor.py
r0a90d92 r796c4d4 19 19 FONT_VARIANT = 0 20 20 PNL_WIDTH = 460 21 PNL_HITE = 21021 PNL_HITE = 300 22 22 else: 23 23 FONT_VARIANT = 1 24 24 PNL_WIDTH = 500 25 PNL_HITE = 25026 25 PNL_HITE = 370 26 M_NAME = 'SumModel' 27 27 EDITOR_WIDTH = 800 28 28 EDITOR_HEIGTH = 700 … … 57 57 Dialog for easy custom sum models 58 58 """ 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): 60 60 """ 61 61 Dialog window popup when selecting 'Easy Custom Sum' on the menu … … 63 63 wx.Dialog.__init__(self, parent=parent, id=id, 64 64 title=title, size=(PNL_WIDTH, PNL_HITE)) 65 self.parent = parent65 self.parent = base 66 66 #Font 67 67 self.SetWindowVariant(variant=FONT_VARIANT) 68 68 # 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 69 73 self.model_list = model_list 70 74 self.model1_string = "SphereModel" … … 73 77 self.model1_name = str(self.model1.GetValue()) 74 78 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 76 117 def _build_sizer(self): 77 118 """ … … 81 122 vbox = wx.BoxSizer(wx.VERTICAL) 82 123 sizer = wx.GridBagSizer(1, 3) 124 self._layout_name() 125 self._layout_description() 126 127 83 128 sum_description= wx.StaticBox(self, -1, 'Select', 84 129 size=(PNL_WIDTH-30, 70)) … … 99 144 # Buttons on the bottom 100 145 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', 103 149 size=(_BOX_WIDTH/2, 25)) 104 150 # Intro 105 151 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" 107 153 model_string = " Model%s (p%s):" 154 vbox.Add(self.name_hsizer) 155 vbox.Add(self.desc_sizer) 108 156 vbox.Add(sizer) 109 157 ix = 0 … … 135 183 self.SetSizer(vbox) 136 184 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 138 244 def _set_model_list(self): 139 245 """ … … 176 282 Write and Save file 177 283 """ 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 178 292 try: 179 out_f = open( fname,'w')293 out_f = open(path,'w') 180 294 except : 181 295 raise … … 186 300 elif line.count("import %s as P2"): 187 301 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") 188 306 else: 189 307 out_f.write(line + "\n") 190 out_f.close() 308 out_f.close() 309 #else: 310 # msg = "Name exists already." 191 311 192 312 def compile_file(self, path): … … 194 314 Compile the file in the path 195 315 """ 316 path = self.fname 196 317 _compileFile(path) 197 318 … … 220 341 self.reader = None 221 342 self.name = 'untitled' 222 self.overwrite_name = True343 self.overwrite_name = False 223 344 self.is_2d = False 224 345 self.fname = None … … 253 374 name_txt = wx.StaticText(self, -1, 'Function Name : ') 254 375 overwrite_cb = wx.CheckBox(self, -1, "Overwrite?", (10, 10)) 255 overwrite_cb.SetValue( True)376 overwrite_cb.SetValue(False) 256 377 overwrite_cb.SetToolTipString("Overwrite it if already exists?") 257 378 wx.EVT_CHECKBOX(self, overwrite_cb.GetId(), self.on_over_cb) 379 #overwrite_cb.Show(False) 258 380 self.name_tcl = wx.TextCtrl(self, -1, size=(PANEL_WIDTH*3/5, -1)) 259 381 self.name_tcl.Bind(wx.EVT_TEXT_ENTER, self.on_change_name) … … 695 817 p_model2 = P2() 696 818 ## 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) 702 827 703 828 ## Define parameters -
fittingview/src/sans/perspectives/fitting/fitting.py
rd2843a9 r796c4d4 279 279 model_manager = models.ModelManager() 280 280 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) 283 284 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 302 287 textdial.Destroy() 303 288
Note: See TracChangeset
for help on using the changeset viewer.