Changeset 5d1c1f4 in sasview for fittingview/src


Ignore:
Timestamp:
Dec 7, 2011 2:56:35 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:
8bac371
Parents:
a41034c
Message:

added compile, run and help in pyeditor

Location:
fittingview/src/sans/perspectives/fitting
Files:
2 edited

Legend:

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

    r7b1ca97 r5d1c1f4  
    219219         
    220220        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() 
    222229        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) 
    227232        #create  menubar items 
    228233        return [(self.menu1, self.sub_menu)] 
     
    232237        Get the python editor panel 
    233238        """ 
    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) 
    237245        self.put_icon(frame) 
    238246        frame.Show(True)  
    239247         
     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 
    240267    def put_icon(self, frame): 
    241268        """ 
  • fittingview/src/sans/perspectives/fitting/models.py

    r4ad076b r5d1c1f4  
    1010import time 
    1111import logging 
    12  
     12import py_compile 
    1313from sans.guiframe.events import StatusEvent   
    1414# Explicitly import from the pluginmodel module so that py2exe 
     
    6969    return model 
    7070   
    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 
     71def find_plugins_dir(): 
     72    """ 
     73    Find path of the plugins dir 
     74    """ 
    8075    dir = os.path.abspath(PLUGIN_DIR) 
    8176    if not os.path.isdir(dir): 
     
    8580    if not os.path.isdir(dir): 
    8681        dir = os.path.join(os.path.dirname(os.path.sys.path[0]), PLUGIN_DIR) 
     82    return dir 
     83 
     84class 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     
     92report_problem = ReportProblem() 
     93 
     94def 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 
     106def _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() 
    87115    if not os.path.isdir(dir): 
    88116        msg = "SansView couldn't locate Model plugin folder." 
     
    92120    else: 
    93121        log("looking for models in: %s" % str(dir)) 
    94         compileall.compile_dir(dir=dir, ddir=dir, force=1, quiet=True) 
     122        compile_file(dir) 
    95123        logging.info("pluging model dir: %s\n" % str(dir)) 
    96124    try: 
     
    438466        is_modified = False 
    439467        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) 
    441470            if  self.last_time_dir_modified != temp: 
    442471                is_modified = True 
     
    460489        else: 
    461490            return {} 
    462          
     491     
     492              
    463493    def populate_menu(self, modelmenu, event_owner): 
    464494        """ 
Note: See TracChangeset for help on using the changeset viewer.