Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
 def openFileWithEncoding(self):
     """Helper to open filename but respecting encoding."""
     return utils.openEncoding(self.filename, self.encoding)
Exemplo n.º 9
0
 def openFileWithEncoding(self):
     """Helper to open filename but respecting encoding."""
     return utils.openEncoding(self.filename, self.encoding)