Пример #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 self.displayNotSavedWhitespaceError(lambda: self.state.checkInstrFileCandidate(new_instr_req))==False:
         return
     
     if new_instr_req != '':
         if self.view.closeCodeEditorWindow():
             text = get_file_contents(instr_templ)
             self.state.unloadInstrument()
             new_instr = save_instrfile(new_instr_req, text)
             self.state.loadInstrument(new_instr)
             self.emitter.status("Instrument created: " + os.path.basename(str(new_instr)))
Пример #2
0
 def handleSaveAs(self):
     oldinstr = self.state.getInstrumentFile()
     if oldinstr != '':
         newinstr = self.view.showSaveAsDialog(oldinstr)
         if self.displayNotSavedWhitespaceError(lambda: self.state.checkInstrFileCandidate(newinstr))==False:
             return
     
     if newinstr != '':
         self.state.unloadInstrument()
         text = get_file_contents(oldinstr)
         created_instr = save_instrfile(newinstr, text)
         if created_instr != '':
             self.state.loadInstrument(created_instr)
             self.emitter.status("Instrument saved as: " + newinstr)
Пример #3
0
 def handleNewInstrument(self):
     new_instr_req = self.view.showNewInstrDialog(self.state.getWorkDir())
     if self.displayNotSavedWhitespaceError(lambda: self.state.checkInstrFileCandidate(new_instr_req))==False:
         return
     
     if new_instr_req != '':
         template_text = open(os.path.join(mccode_config.configuration["MCCODE_LIB_DIR"], "examples", "template_simple.instr")).read()
         new_instr = save_instrfile(new_instr_req, template_text)
         if new_instr != '':
             if self.view.closeCodeEditorWindow():
                 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)))
Пример #4
0
 def saveInstrumentIfFileExists(self, text):
     instr = self.getInstrumentFile()
     if not os.path.exists(instr):
         return False
     save_instrfile(instr, text)
     return True