Пример #1
0
 def handleNewFromTemplate(self, instr_templ=''):
     new_instr_req = self.view.showNewInstrFromTemplateDialog(os.path.join(self.state.getWorkDir(), os.path.basename(str(instr_templ))))
     if new_instr_req != '':
         text = McGuiUtils.getFileContents(instr_templ)
         new_instr = McGuiUtils.saveInstrumentFile(new_instr_req, text)
         self.state.loadInstrument(new_instr)
         self.emitter.status("Instrument created: " + os.path.basename(str(new_instr)))
Пример #2
0
def main():
    try:
        McGuiUtils.loadUserConfig(mccode_config.configuration["MCCODE"],mccode_config.configuration["MCCODE_VERSION"])
        
        mcguiApp = QtGui.QApplication(sys.argv)
        mcguiApp.ctr = McGuiAppController()
        
        sys.exit(mcguiApp.exec_())

    except Exception, e: 
        handleExceptionMsg(e.message)
Пример #3
0
 def handleSaveAs(self):
     oldinstr = self.state.getInstrumentFile()
     if oldinstr != '':
         newinstr = self.view.showSaveAsDialog(oldinstr)
     
     if newinstr != '':
         self.state.unloadInstrument()
         text = McGuiUtils.getFileContents(oldinstr)
         created_instr = McGuiUtils.saveInstrumentFile(newinstr, text)
         if created_instr != '':
             self.state.loadInstrument(created_instr)
             self.emitter.status("Instrument saved as: " + newinstr)
Пример #4
0
 def initConfigData(self, args):
     # comboboxes
     mcrun_lst, mcplot_lst, mcdisplay_lst = McGuiUtils.getMcCodeConfigOptions(mccode_config.configuration["MCCODE"])
     
     # mcrun combobox
     selected_val = mccode_config.configuration["MCRUN"]
     i = 0
     for val in mcrun_lst: 
         self.ui.cbxMcrun.addItem(val)
         if val == selected_val:
             self.ui.cbxMcrun.setCurrentIndex(i)
         i += 1
     self.ui.cbxMcrun.conf_var = "MCRUN"
     self.ui.cbxMcrun.conf_org_value = mccode_config.configuration["MCRUN"]
     self.ui.cbxMcrun.conf_options_lst = mcrun_lst
     
     # mcplot combobox
     selected_val = mccode_config.configuration["MCPLOT"]
     i = 0
     for val in mcplot_lst: 
         self.ui.cbxMcPlot.addItem(val)
         if val == selected_val:
             self.ui.cbxMcPlot.setCurrentIndex(i)
         i += 1
     self.ui.cbxMcPlot.conf_var = "MCPLOT"
     self.ui.cbxMcPlot.conf_org_value = mccode_config.configuration["MCPLOT"]
     self.ui.cbxMcPlot.conf_options_lst = mcplot_lst
     
     # mcdisplay combobox
     selected_val = mccode_config.configuration["MCDISPLAY"]
     i = 0
     for val in mcdisplay_lst: 
         self.ui.cbxMcdisplay.addItem(val)
         if val == selected_val:
             self.ui.cbxMcdisplay.setCurrentIndex(i)
         i += 1
     self.ui.cbxMcdisplay.conf_var = "MCDISPLAY"
     self.ui.cbxMcdisplay.conf_org_value = mccode_config.configuration["MCDISPLAY"]
     self.ui.cbxMcdisplay.conf_options_lst = mcdisplay_lst
     
     # line edits
     self.ui.edtCC.setText(mccode_config.compilation["CC"])
     self.ui.edtCC.conf_var = "CC"
     
     self.ui.edtCflags.setText(mccode_config.compilation["CFLAGS"])
     self.ui.edtCflags.conf_var = "CFLAGS"
     
     self.ui.edtMpicc.setText(mccode_config.compilation["MPICC"])
     self.ui.edtMpicc.conf_var = "MPICC"
     
     self.ui.edtMPIrun.setText(mccode_config.compilation["MPIRUN"])
     self.ui.edtMPIrun.conf_var = "MPIRUN"
     
     self.ui.edtNumNodes.setText(mccode_config.compilation["MPINODES"])
     self.ui.edtNumNodes.conf_var = "MPINODES"
Пример #5
0
 def handleNewInstrument(self):
     new_instr_req = self.view.showNewInstrDialog(self.state.getWorkDir())
     if new_instr_req != '':
         template_text_header = open(os.path.join(mccode_config.configuration["MCCODE_LIB_DIR"], "examples", "template_header_simple.instr")).read()
         template_text_body = open(os.path.join(mccode_config.configuration["MCCODE_LIB_DIR"], "examples", "template_body_simple.instr")).read()
         new_instr = McGuiUtils.saveInstrumentFile(new_instr_req, template_text_header + template_text_body)
         if new_instr != '':
             self.state.unloadInstrument()
             self.state.loadInstrument(new_instr)
             self.view.showCodeEditorWindow(new_instr)
             self.emitter.status("Editing new instrument: " + os.path.basename(str(new_instr)))
Пример #6
0
 def initDynamicView(self):
     # load installed mcstas instruments:
     # construct args = [site, instr_fullpath[], instr_path_lst[]]
     args = []
     files_instr, files_comp = McGuiUtils.getInstrumentAndComponentFiles(mccode_config.configuration["MCCODE_LIB_DIR"])
     
     # temporary list consisting of instrument files with site names: 
     files_instr_and_site = []
     for f in files_instr:
         files_instr_and_site.append([f, McGuiUtils.getInstrumentSite(f)])
     
     # order instrument files by site:
     sites = {s for s in map(lambda f: f[1], files_instr_and_site)}
     for s in sites:
         # extract instruments file paths of this site
         instr_path_lst = map(lambda f: f[0], filter(lambda f: f[1] in [s], files_instr_and_site))
         # sort instrument of this site by file name
         instr_path_lst.sort(key=lambda instrpath: os.path.splitext(os.path.basename(instrpath))[0])
         # extract file names
         instr_name_lst = map(lambda instrpath: os.path.splitext(os.path.basename(instrpath))[0], instr_path_lst)
         arg = []
         arg.append(s)
         arg.append(instr_name_lst)
         arg.append(instr_path_lst)
         args.append(arg)
     
     # sort sites 
     args.sort(key=lambda arg: arg[0])    
     
     # hand on for menu generation
     self.view.initMainWindowDynamicElements(args, self.handleNewFromTemplate)
     
     # load installed mcstas components:
     # args - [category, comp_names[], comp_parsers[]]
     args = []
     categories = {0 : 'Source', 1 : 'Optics', 2 : 'Sample', 3 : 'Monitor', 4 : 'Misc', 5 : 'Contrib', 6 : 'Obsolete'}
     dirnames = {0 : 'sources', 1 : 'optics', 2 : 'samples', 3 : 'monitors', 4 : 'misc', 5 : 'contrib', 6 : 'obsolete'}
     i = 0
     while i < 7:
         arg = [] # arg - category, comp_names[], comp_parsers[]
         compnames = []
         parsers = []
         
         for f in files_comp:
             if re.search(dirnames[i], f):
                 compnames.append(os.path.splitext(os.path.basename(f))[0]) # get filename without extension - this is the component name
                 parsers.append(McComponentParser(f)) # append a parser, for ease of parsing on-the-fly
         
         arg.append(categories[i])
         arg.append(compnames)
         arg.append(parsers)
         args.append(arg)
         
         i += 1
     
     # sort components in each category (using Python default string sort on filename)
     for arg in args:
         arg[1].sort()
         arg[2].sort(key=lambda parser: os.path.splitext(os.path.basename(parser.file))[0])
     
     # hand on for menu generation
     self.view.initCodeEditorComponentMenu(args)
Пример #7
0
 def saveInstrumentIfFileExists(self, text):
     instr = self.getInstrumentFile()
     if not os.path.exists(instr):
         return False
     McGuiUtils.saveInstrumentFile(instr, text)
     return True
Пример #8
0
 def save(self):
     self.__pullValuesTo_mccode_config()
     McGuiUtils.saveUserConfig(mccode_config,mccode_config.configuration["MCCODE"],mccode_config.configuration["MCCODE_VERSION"])
     
     # finally
     super(McConfigDialog, self).accept()