def openAfterMaybeSaveCallback(self, selected): """ Receives file selection info from the dialog created by openAfterMaybeSave, following user input. Extracts the file name and passes it to the decode method, which returns a new document doc, which is then set as the open document by newDocument. Calls finalizeImport and disconnects dialog signaling. """ if isinstance(selected, QStringList) or isinstance(selected, list): fname = selected[0] else: fname = selected if not fname or os.path.isdir(fname): return False fname = str(fname) self._writeFileOpenPath(os.path.dirname(fname)) self.newDocument(fname=fname) decode(self._document, file(fname).read()) if hasattr(self, "filesavedialog"): # user did save if self.fileopendialog != None: self.fileopendialog.filesSelected.disconnect(\ self.openAfterMaybeSaveCallback) # manual garbage collection to prevent hang (in osx) del self.fileopendialog self.fileopendialog = None
def openAfterMaybeSaveCallback(self, selected): """ Receives file selection info from the dialog created by openAfterMaybeSave, following user input. Extracts the file name and passes it to the decode method, which returns a new document doc, which is then set as the open document by newDocument. Calls finalizeImport and disconnects dialog signaling. """ if isinstance(selected, QStringList) or isinstance(selected, list): fname = selected[0] else: fname = selected if not fname or os.path.isdir(fname): return False fname = str(fname) self._writeFileOpenPath(os.path.dirname(fname)) self.newDocument(fname=fname) with open(fname) as fd: decode(self._document, fd.read()) if hasattr(self, "filesavedialog"): # user did save if self.fileopendialog != None: self.fileopendialog.filesSelected.disconnect(\ self.openAfterMaybeSaveCallback) # manual garbage collection to prevent hang (in osx) del self.fileopendialog self.fileopendialog = None
def openAfterMaybeSaveCallback(self, selected): """ Receives file selection info from the dialog created by openAfterMaybeSave, following user input. Extracts the file name and passes it to the decode method, which returns a new document doc, which is then set as the open document by newDocument. Calls finalizeImport and disconnects dialog signaling. """ if isinstance(selected, (list, tuple)): fname = selected[0] else: fname = selected if fname is None or fname == '' or os.path.isdir(fname): return False if not os.path.exists(fname): return False self._writeFileOpenPath(os.path.dirname(fname)) self.newDocument(fname=fname) with io.open(fname, 'r', encoding='utf-8') as fd: decode(self._document, fd.read()) if hasattr(self, "filesavedialog"): # user did save if self.fileopendialog is not None: self.fileopendialog.filesSelected.disconnect( self.openAfterMaybeSaveCallback) # manual garbage collection to prevent hang (in osx) del self.fileopendialog self.fileopendialog = None
def newDocument(self, isFirstNewDoc=False, fp=None): """ Creates a new document, ensuring that a document controller is also instantiated if required. If isFirstNewDoc is True, a new documentController is always instantiated. A new documentController will create a new document during __init__(). This method is called by finishInit() to ensure a document is created on application init. """ from controllers.documentcontroller import DocumentController defaultFile = fp or os.environ.get('CADNANO_DEFAULT_DOCUMENT', None) if defaultFile and isFirstNewDoc: defaultFile = path.expanduser(defaultFile) defaultFile = path.expandvars(defaultFile) dc = DocumentController() doc = dc.document() from model.io.decoder import decode decode(doc, file(defaultFile).read()) print "Loaded default document: %s" % doc else: dc = next(iter(self.documentControllers), None) # cadnano currently only supports ONE documentcontroller per app instance, controlling exactly ONE document. if dc: # if a documentcontroller already exists dc.newDocument() # currently, this just empties the existing document object. else: # first dc # A DocumentController creates a new doc during init and adds itself to app.documentControllers: dc = DocumentController() return dc.document()
def application_openFile_(self, app, f): if f == "main.py": # ignore return extension = os.path.splitext(f)[1].lower() if extension not in ('.nno', '.json', '.cadnano'): print("Could not open file %s (bad extension %s)" % (f, extension)) return dc = list(sharedCadnanoObj().documentControllers)[0] decode(dc.document(), file(str(f)).read()) return None
def application_openFile_(self, app, f): if f == "main.py": # ignore return extension = os.path.splitext(f)[1].lower() if extension not in ('.nno', '.json', '.cadnano'): print "Could not open file %s (bad extension %s)"%(f, extension) return dc = list(sharedCadnanoObj().documentControllers)[0] decode(dc.document(), file(str(f)).read()) return None
def __init__(self, fileName): self._fN=fileName self._doc=Document() self._numStaples=0 self._scaffoldLength=0 decode(self._doc,file(self._fN).read()) self.getModelInfo() self.printModelInfo() self.vhLoop() self.numberScaffold()
def newDocument(self, isFirstNewDoc=False): from controllers.documentcontroller import DocumentController defaultFile = os.environ.get('CADNANO_DEFAULT_DOCUMENT', None) if defaultFile and isFirstNewDoc: defaultFile = path.expanduser(defaultFile) defaultFile = path.expandvars(defaultFile) dc = DocumentController() doc = dc.document() from model.io.decoder import decode decode(doc, file(defaultFile).read()) print "Loaded default document: %s" % doc else: docCtrlrCount = len(self.documentControllers) if docCtrlrCount == 0: # first dc # dc adds itself to app.documentControllers dc = DocumentController() elif docCtrlrCount == 1: # dc already exists dc = list(self.documentControllers)[0] dc.newDocument() # tell it to make a new doucment return dc.document()
def getTestSequences(self, designname, sequencesToApply): """ Called by a sequence-verification functional test to read in a file (designname), apply scaffold sequence(s) to that design, and return the set of staple sequences.""" # set up the document from model.io.decoder import decode inputfile = "tests/functionaltestinputs/%s" % designname document = self.documentController.document() with file(inputfile) as f: decode(document, f.read()) self.setWidget(self.documentController.win, False, None) part = document.selectedPart() # apply one or more sequences to the design for sequenceName, startVhNum, startIdx in sequencesToApply: sequence = sequences.get(sequenceName, None) for vh in part.getVirtualHelices(): if vh.number() == startVhNum: strand = vh.scaffoldStrandSet().getStrand(startIdx) strand.oligo().applySequence(sequence) generatedSequences = part.getStapleSequences() return set(generatedSequences.splitlines())