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)))
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)))
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)
def saveInstrumentIfFileExists(self, text): instr = self.getInstrumentFile() if not os.path.exists(instr): return False McGuiUtils.saveInstrumentFile(instr, text) return True