Changeset 5d1c1f4 in sasview for fittingview/src
- Timestamp:
- Dec 7, 2011 2:56:35 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:
- 8bac371
- Parents:
- a41034c
- Location:
- fittingview/src/sans/perspectives/fitting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/fitting.py
r7b1ca97 r5d1c1f4 219 219 220 220 self.menu1.AppendSeparator() 221 self.id_editmodel = wx.NewId() 221 self.edit_model_menu = wx.Menu() 222 # Find and put files name in menu 223 try: 224 self.set_edit_menu(owner=owner) 225 except: 226 raise 227 228 self.id_edit = wx.NewId() 222 229 editmodel_help = "Edit cusomized model sample file" 223 self.menu1.Append(self.id_editmodel, "Edit Custom Model", 224 editmodel_help) 225 wx.EVT_MENU(owner, self.id_editmodel, self.edit_custom_model) 226 230 self.menu1.AppendMenu(self.id_edit, "Edit Custom Model", 231 self.edit_model_menu, editmodel_help) 227 232 #create menubar items 228 233 return [(self.menu1, self.sub_menu)] … … 232 237 Get the python editor panel 233 238 """ 234 from editmodel import PyConsole 235 filename = os.path.join("plugins", "testmodel.py") 236 frame = PyConsole(parent=self.parent, filename=filename) 239 id = event.GetId() 240 label = self.edit_model_menu.GetLabel(id) 241 from sans.perspectives.calculator.pyconsole import PyConsole 242 filename = os.path.join(models.find_plugins_dir(), label) 243 frame = PyConsole(parent=self.parent, manager=self, panel= self.fit_panel, 244 title='Custom Model Editor', filename=filename) 237 245 self.put_icon(frame) 238 246 frame.Show(True) 239 247 248 def set_edit_menu(self, owner): 249 """ 250 Set list of the edit model menu labels 251 """ 252 list_fnames = os.listdir(models.find_plugins_dir()) 253 for item in list_fnames: 254 name = os.path.basename(item) 255 toks = os.path.splitext(name) 256 if toks[1]=='.py' and not toks[0]=='__init__': 257 has_file = False 258 for item in self.edit_model_menu.GetMenuItems(): 259 if name == self.edit_model_menu.GetLabel(item.GetId()): 260 has_file = True 261 if not has_file: 262 id = wx.NewId() 263 self.edit_model_menu.Append(id, name) 264 wx.EVT_MENU(owner, id, self.edit_custom_model) 265 has_file = False 266 240 267 def put_icon(self, frame): 241 268 """ -
fittingview/src/sans/perspectives/fitting/models.py
r4ad076b r5d1c1f4 10 10 import time 11 11 import logging 12 12 import py_compile 13 13 from sans.guiframe.events import StatusEvent 14 14 # Explicitly import from the pluginmodel module so that py2exe … … 69 69 return model 70 70 71 72 def _findModels(dir): 73 """ 74 """ 75 # List of plugin objects 76 plugins = {} 77 # Go through files in plug-in directory 78 #always recompile the folder plugin 79 import compileall 71 def find_plugins_dir(): 72 """ 73 Find path of the plugins dir 74 """ 80 75 dir = os.path.abspath(PLUGIN_DIR) 81 76 if not os.path.isdir(dir): … … 85 80 if not os.path.isdir(dir): 86 81 dir = os.path.join(os.path.dirname(os.path.sys.path[0]), PLUGIN_DIR) 82 return dir 83 84 class ReportProblem: 85 def __nonzero__(self): 86 type, value, traceback = sys.exc_info() 87 if type is not None and issubclass(type, py_compile.PyCompileError): 88 print "Problem with", repr(value) 89 raise type, value, traceback 90 return 1 91 92 report_problem = ReportProblem() 93 94 def compile_file(dir): 95 """ 96 Compile a py file 97 """ 98 try: 99 import compileall 100 compileall.compile_dir(dir=dir, ddir=dir, force=1, quiet=report_problem) 101 except: 102 type, value, traceback = sys.exc_info() 103 return value 104 return None 105 106 def _findModels(dir): 107 """ 108 """ 109 # List of plugin objects 110 plugins = {} 111 # Go through files in plug-in directory 112 #always recompile the folder plugin 113 import compileall 114 dir = find_plugins_dir() 87 115 if not os.path.isdir(dir): 88 116 msg = "SansView couldn't locate Model plugin folder." … … 92 120 else: 93 121 log("looking for models in: %s" % str(dir)) 94 compile all.compile_dir(dir=dir, ddir=dir, force=1, quiet=True)122 compile_file(dir) 95 123 logging.info("pluging model dir: %s\n" % str(dir)) 96 124 try: … … 438 466 is_modified = False 439 467 if os.path.isdir(PLUGIN_DIR): 440 temp = os.path.getmtime(PLUGIN_DIR) 468 # getmtime doesn't seem to work well: use getatime 469 temp = os.path.getatime(PLUGIN_DIR) 441 470 if self.last_time_dir_modified != temp: 442 471 is_modified = True … … 460 489 else: 461 490 return {} 462 491 492 463 493 def populate_menu(self, modelmenu, event_owner): 464 494 """
Note: See TracChangeset
for help on using the changeset viewer.