Changeset 439420f9 in sasview
- Timestamp:
- Apr 5, 2015 7:01:01 PM (10 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:
- 18ac46b
- Parents:
- 7b1f4e3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/calculator/model_editor.py
r7b1f4e3 r439420f9 283 283 def check_name(self, event=None): 284 284 """ 285 Check name if exist already 286 """ 285 Check that proposed new model name is a valid Python module name 286 and that it does not already exist. If not show error message and 287 pink background in text box else call on_apply 288 289 :TODO this should be separated out from the GUI code. For that we 290 need to pass it the name (or if we want to keep the default name 291 option also need to pass the self._operator attribute) We just need 292 the function to return an error code that the name is good or if 293 not why (not a valid name, name exists already). The rest of the 294 error handling should be done in this module. so on_apply would then 295 start by checking the name and then either raise errors or do the 296 deed. 297 """ 298 #Get the function/file name 287 299 mname = M_NAME 288 300 self.on_change_name(None) 289 list_fnames = os.listdir(self.plugin_dir)290 # fake existing regular model name list291 m_list = [model + ".py" for model in self.model_list]292 list_fnames.append(m_list)293 # function/file name294 301 title = self.name_tcl.GetValue().lstrip().rstrip() 295 302 if title == '': … … 303 310 self.name = title 304 311 t_fname = title + '.py' 305 if not self.overwrite_name: 312 313 #First check if the name is a valid Python name 314 if re.match('^[A-Za-z0-9_]*$',title): 315 self.good_name = True 316 else: 317 self.good_name = False 318 msg = ("%s is not a valid Python name. Only alphanumeric \n" \ 319 "and underscore allowed" % self.name) 320 321 #Now check if the name already exists 322 if not self.overwrite_name and self.good_name: 323 #Create list of existing model names for comparison 324 list_fnames = os.listdir(self.plugin_dir) 325 # fake existing regular model name list 326 m_list = [model + ".py" for model in self.model_list] 327 list_fnames.append(m_list) 306 328 if t_fname in list_fnames and title != mname: 307 self.name_tcl.SetBackgroundColour('pink')308 329 self.good_name = False 309 info = 'Error'310 330 msg = "Name exists already." 311 wx.MessageBox(msg, info) 312 self._notes = msg 313 color = 'red' 314 self._msg_box.SetLabel(msg) 315 self._msg_box.SetForegroundColour(color) 316 return self.good_name 331 332 if self.good_name == False: 333 self.name_tcl.SetBackgroundColour('pink') 334 info = 'Error' 335 wx.MessageBox(msg, info) 336 self._notes = msg 337 color = 'red' 338 self._msg_box.SetLabel(msg) 339 self._msg_box.SetForegroundColour(color) 340 return self.good_name 317 341 self.fname = os.path.join(self.plugin_dir, t_fname) 318 342 s_title = title … … 435 459 """ 436 460 437 self._type = type438 461 name = '' 439 462 440 if self._type == '*':463 if type == '*': 441 464 name = 'Multi' 442 465 factor = 'BackGround' … … 448 471 449 472 self.factor = factor 450 self._operator = self._type473 self._operator = type 451 474 self.explanation = " Custom Model = %s %s (model1 %s model2)\n" % \ 452 475 (self.factor, f_oper, self._operator)
Note: See TracChangeset
for help on using the changeset viewer.