def doImport(self, document): """Import data. Returns a list of datasets which were imported. """ p = self.params # open stream to import data from if p.filename is not None: stream = simpleread.FileStream( utils.openEncoding(p.filename, p.encoding)) elif p.datastr is not None: stream = simpleread.StringStream(p.datastr) else: raise RuntimeError, "No filename or string" # do the import self.simpleread.clearState() self.simpleread.readData(stream, useblocks=p.useblocks, ignoretext=p.ignoretext) # associate linked file LF = None if p.linked: assert p.filename LF = linked.LinkedFile(p) # actually set the data in the document self.outdatasets = self.simpleread.setInDocument(document, linkedfile=LF, prefix=p.prefix, suffix=p.suffix) self.outinvalids = self.simpleread.getInvalidConversions()
def doImport(self, document): """Import data. Returns a list of datasets which were imported. """ p = self.params # open stream to import data from if p.filename is not None: stream = simpleread.FileStream( utils.openEncoding(p.filename, p.encoding)) elif p.datastr is not None: stream = simpleread.StringStream(p.datastr) else: raise RuntimeError, "No filename or string" # do the import self.simpleread.clearState() self.simpleread.readData(stream, useblocks=p.useblocks, ignoretext=p.ignoretext) # associate linked file LF = None if p.linked: assert p.filename LF = linked.LinkedFile(p) # actually set the data in the document self.outdatasets = self.simpleread.setInDocument( document, linkedfile=LF, prefix=p.prefix, suffix=p.suffix) self.outinvalids = self.simpleread.getInvalidConversions()
def doPreview(self, filename, encoding): """Preview 2d dataset files.""" try: ifile = utils.openEncoding(filename, encoding) text = ifile.read(4096)+'\n' if len(ifile.read(1)) != 0: # if there is remaining data add ... text += '...\n' self.twod_previewedit.setPlainText(text) return True except (UnicodeError, EnvironmentError): self.twod_previewedit.setPlainText('') return False
def doPreview(self, filename, encoding): """Standard preview - show start of text.""" try: ifile = utils.openEncoding(filename, encoding) text = ifile.read(4096)+'\n' if len(ifile.read(1)) != 0: # if there is remaining data add ... text += '...\n' self.previewedit.setPlainText(text) return True except (UnicodeError, IOError): self.previewedit.setPlainText('') return False
def doPreview(self, filename, encoding): """Preview 2d dataset files.""" try: ifile = utils.openEncoding(filename, encoding) text = ifile.read(4096) + '\n' if len(ifile.read(1)) != 0: # if there is remaining data add ... text += '...\n' self.twod_previewedit.setPlainText(text) return True except (UnicodeError, EnvironmentError): self.twod_previewedit.setPlainText('') return False
def doImport(self, document): """Import data.""" p = self.params # get stream if p.filename is not None: stream = simpleread.FileStream( utils.openEncoding(p.filename, p.encoding) ) elif p.datastr is not None: stream = simpleread.StringStream(p.datastr) else: assert False # linked file LF = None if p.linked: assert p.filename LF = linked.LinkedFile2D(p) for name in p.datasetnames: sr = simpleread.SimpleRead2D(name, p) sr.readData(stream) self.outdatasets += sr.setInDocument(document, linkedfile=LF)
def doImport(self, document): """Import data.""" p = self.params # get stream if p.filename is not None: stream = simpleread.FileStream( utils.openEncoding(p.filename, p.encoding)) elif p.datastr is not None: stream = simpleread.StringStream(p.datastr) else: assert False # linked file LF = None if p.linked: assert p.filename LF = linked.LinkedFile2D(p) for name in p.datasetnames: sr = simpleread.SimpleRead2D(name, p) sr.readData(stream) self.outdatasets += sr.setInDocument(document, linkedfile=LF)
def openFileWithEncoding(self): """Helper to open filename but respecting encoding.""" return utils.openEncoding(self.filename, self.encoding)