Exemple #1
0
    def doExportAsMovie(self, fname, frames=60, fps=30):
        # Only load QTSupport when necessary.
        # QTSupport loads QTKit, which wants to establish a connection to the window server.
        # If we load QTSupport before something is on screen, the connection to the window server
        # cannot be established.
        from nodebox.util import QTSupport
        try:
            os.unlink(fname)
        except:
            pass
        try:
            fp = open(fname, 'w')
            fp.close()
        except:
            errorAlert(
                "File Error",
                "Could not create file '%s'. Perhaps it is locked or busy." %
                fname)
            return

        movie = None

        pb = ProgressBarController.alloc().init()
        pb.begin("Generating %s frames..." % frames, frames)
        try:
            if not self.cleanRun(self._execScript): return
            self._pageNumber = 1
            self._frame = 1

            movie = QTSupport.Movie(fname, fps)
            # If the speed is set, we are dealing with animation
            if self.canvas.speed is None:
                for i in range(frames):
                    if i > 0:  # Run has already happened first time
                        self.fastRun(self._execScript, newSeed=True)
                    movie.add(self.canvas)
                    self.graphicsView.setNeedsDisplay_(True)
                    pb.inc()
                    self._pageNumber += 1
                    self._frame += 1
            else:
                if self.namespace.has_key("setup"):
                    self.fastRun(self.namespace["setup"])
                for i in range(frames):
                    self.fastRun(self.namespace["draw"], newSeed=True)
                    movie.add(self.canvas)
                    self.graphicsView.setNeedsDisplay_(True)
                    pb.inc()
                    self._pageNumber += 1
                    self._frame += 1
                if self.namespace.has_key("stop"):
                    success, output = self._boxedRun(self.namespace["stop"])
                    self._flushOutput(output)
        except KeyboardInterrupt:
            pass
        pb.end()
        del pb
        movie.save()
        self._pageNumber = 1
        self._frame = 1
Exemple #2
0
    def doExportAsMovie(self, fname, frames=60, fps=30):
        # Only load QTSupport when necessary.
        # QTSupport loads QTKit, which wants to establish a connection to the window server.
        # If we load QTSupport before something is on screen, the connection to the window server
        # cannot be established.
        from nodebox.util import QTSupport

        try:
            os.unlink(fname)
        except:
            pass
        try:
            fp = open(fname, "w")
            fp.close()
        except:
            errorAlert("File Error", "Could not create file '%s'. Perhaps it is locked or busy." % fname)
            return

        movie = None

        pb = ProgressBarController.alloc().init()
        pb.begin("Generating %s frames..." % frames, frames)
        try:
            if not self.cleanRun(self._execScript):
                return
            self._pageNumber = 1
            self._frame = 1

            movie = QTSupport.Movie(fname, fps)
            # If the speed is set, we are dealing with animation
            if self.canvas.speed is None:
                for i in range(frames):
                    if i > 0:  # Run has already happened first time
                        self.fastRun(self._execScript, newSeed=True)
                    movie.add(self.canvas)
                    self.graphicsView.setNeedsDisplay_(True)
                    pb.inc()
                    self._pageNumber += 1
                    self._frame += 1
            else:
                if self.namespace.has_key("setup"):
                    self.fastRun(self.namespace["setup"])
                for i in range(frames):
                    self.fastRun(self.namespace["draw"], newSeed=True)
                    movie.add(self.canvas)
                    self.graphicsView.setNeedsDisplay_(True)
                    pb.inc()
                    self._pageNumber += 1
                    self._frame += 1
                if self.namespace.has_key("stop"):
                    success, output = self._boxedRun(self.namespace["stop"])
                    self._flushOutput(output)
        except KeyboardInterrupt:
            pass
        pb.end()
        del pb
        movie.save()
        self._pageNumber = 1
        self._frame = 1
Exemple #3
0
    def doExportAsImage(self, fname, format, pages=1):
        basename, ext = os.path.splitext(fname)
        # When saving one page (the default), just save the current graphics
        # context. When generating multiple pages, we run the script again
        # (so we don't use the current displayed view) for the first page,
        # and then for every next page.
        if pages == 1:
            if self.graphicsView.canvas is None:
                self.runScript()
            self.canvas.save(fname, format)
        elif pages > 1:
            pb = ProgressBarController.alloc().init()
            pb.begin("Generating %s images..." % pages, pages)
            try:
                if not self.cleanRun(self._execScript):
                    return
                self._pageNumber = 1
                self._frame = 1

                # If the speed is set, we are dealing with animation
                if self.canvas.speed is None:
                    for i in range(pages):
                        if i > 0:  # Run has already happened first time
                            self.fastRun(self._execScript, newSeed=True)
                        counterAsString = "-%5d" % self._pageNumber
                        counterAsString = counterAsString.replace(" ", "0")
                        exportName = basename + counterAsString + ext

                        self.canvas.save(exportName, format)
                        self.graphicsView.setNeedsDisplay_(True)
                        self._pageNumber += 1
                        self._frame += 1
                        pb.inc()
                else:
                    if self.namespace.has_key("setup"):
                        self.fastRun(self.namespace["setup"])
                    for i in range(pages):
                        self.fastRun(self.namespace["draw"], newSeed=True)
                        counterAsString = "-%5d" % self._pageNumber
                        counterAsString = counterAsString.replace(" ", "0")
                        exportName = basename + counterAsString + ext
                        self.canvas.save(exportName, format)
                        self.graphicsView.setNeedsDisplay_(True)
                        self._pageNumber += 1
                        self._frame += 1
                        pb.inc()
                    if self.namespace.has_key("stop"):
                        success, output = self._boxedRun(self.namespace["stop"])
                        self._flushOutput(output)
            except KeyboardInterrupt:
                pass
            pb.end()
            del pb
        self._pageNumber = 1
        self._frame = 1
Exemple #4
0
    def doExportAsImage(self, fname, format, pages=1):
        basename, ext = os.path.splitext(fname)
        # When saving one page (the default), just save the current graphics
        # context. When generating multiple pages, we run the script again
        # (so we don't use the current displayed view) for the first page,
        # and then for every next page.
        if pages == 1:
            if self.graphicsView.canvas is None:
                self.runScript()
            self.canvas.save(fname, format)
        elif pages > 1:
            pb = ProgressBarController.alloc().init()
            pb.begin("Generating %s images..." % pages, pages)
            try:
                if not self.cleanRun(self._execScript): return
                self._pageNumber = 1
                self._frame = 1

                # If the speed is set, we are dealing with animation
                if self.canvas.speed is None:
                    for i in range(pages):
                        if i > 0:  # Run has already happened first time
                            self.fastRun(self._execScript, newSeed=True)
                        counterAsString = "-%5d" % self._pageNumber
                        counterAsString = counterAsString.replace(' ', '0')
                        exportName = basename + counterAsString + ext

                        self.canvas.save(exportName, format)
                        self.graphicsView.setNeedsDisplay_(True)
                        self._pageNumber += 1
                        self._frame += 1
                        pb.inc()
                else:
                    if self.namespace.has_key("setup"):
                        self.fastRun(self.namespace["setup"])
                    for i in range(pages):
                        self.fastRun(self.namespace["draw"], newSeed=True)
                        counterAsString = "-%5d" % self._pageNumber
                        counterAsString = counterAsString.replace(' ', '0')
                        exportName = basename + counterAsString + ext
                        self.canvas.save(exportName, format)
                        self.graphicsView.setNeedsDisplay_(True)
                        self._pageNumber += 1
                        self._frame += 1
                        pb.inc()
                    if self.namespace.has_key("stop"):
                        success, output = self._boxedRun(
                            self.namespace["stop"])
                        self._flushOutput(output)
            except KeyboardInterrupt:
                pass
            pb.end()
            del pb
        self._pageNumber = 1
        self._frame = 1
    def doExportAsMovie(self, fname, frames=60, fps=30):
        try:
            os.unlink(fname)
        except:
            pass
        try:
            fp = open(fname, "w")
            fp.close()
        except:
            errorAlert("File Error", "Could not create file '%s'. Perhaps it is locked or busy." % fname)
            return

        movie = None

        pb = ProgressBarController.alloc().init()
        pb.begin("Generating %s frames..." % frames, frames)
        try:
            if not self.cleanRun(self._execScript):
                return
            self._pageNumber = 1
            self._frame = 1

            movie = QTSupport.Movie(fname, fps)
            # If the speed is set, we are dealing with animation
            if self.canvas.speed is None:
                for i in range(frames):
                    if i > 0:  # Run has already happened first time
                        self.fastRun(self._execScript, newSeed=True)
                    movie.add(self.canvas)
                    self.graphicsView.setNeedsDisplay_(True)
                    pb.inc()
                    self._pageNumber += 1
                    self._frame += 1
            else:
                if self.namespace.has_key("setup"):
                    self.fastRun(self.namespace["setup"])
                for i in range(frames):
                    self.fastRun(self.namespace["draw"], newSeed=True)
                    movie.add(self.canvas)
                    self.graphicsView.setNeedsDisplay_(True)
                    pb.inc()
                    self._pageNumber += 1
                    self._frame += 1

        except KeyboardInterrupt:
            pass
        pb.end()
        del pb
        movie.save()
        self._pageNumber = 1
        self._frame = 1
    def doExportAsMovie(self, fname, frames=60, fps=30):
        try:
            os.unlink(fname)
        except:
            pass
        try:
            fp = open(fname, 'w')
            fp.close()
        except:
            errorAlert("File Error", "Could not create file '%s'. Perhaps it is locked or busy." % fname)
            return

        movie = None

        pb = ProgressBarController.alloc().init()
        pb.begin("Generating %s frames..." % frames, frames)
        try:
            if not self.cleanRun(self._execScript): return
            self._pageNumber = 1
            self._frame = 1

            movie = QTSupport.Movie(fname, fps)
            # If the speed is set, we are dealing with animation
            if self.canvas.speed is None:
                for i in range(frames):
                    if i > 0: # Run has already happened first time
                        self.fastRun(self._execScript, newSeed=True)
                    movie.add(self.canvas)
                    self.graphicsView.setNeedsDisplay_(True)
                    pb.inc()
                    self._pageNumber += 1
                    self._frame += 1
            else:
                if self.namespace.has_key("setup"):
                    self.fastRun(self.namespace["setup"])
                for i in range(frames):
                    self.fastRun(self.namespace["draw"], newSeed=True)
                    movie.add(self.canvas)
                    self.graphicsView.setNeedsDisplay_(True)
                    pb.inc()
                    self._pageNumber += 1
                    self._frame += 1

        except KeyboardInterrupt:
            pass
        pb.end()
        del pb
        movie.save()
        self._pageNumber = 1
        self._frame = 1