예제 #1
0
    def _runScript(self, compile=True, newSeed=True):
        if not self.cleanRun(self._execScript):
            pass

        # Check whether we are dealing with animation
        if self.canvas.speed is not None:
            if not self.namespace.has_key("draw"):
                errorAlert("Not a proper NodeBox animation", "NodeBox animations should have at least a draw() method.")
                return

            # Check if animationTimer is already running
            if self.animationTimer is not None:
                self.stopScript()

            self.speed = self.canvas.speed

            # Run setup routine
            if self.namespace.has_key("setup"):
                self.fastRun(self.namespace["setup"])
            window = self.currentView.window()
            window.makeFirstResponder_(self.currentView)

            # Start the timer
            self.animationTimer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
                1.0 / self.speed, self, objc.selector(self.doFrame, signature="v@:@"), None, True
            )

            # Start the spinner
            self.animationSpinner.startAnimation_(None)
예제 #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
예제 #3
0
    def _runScript(self, compile=True, newSeed=True):
        if not self.cleanRun(self._execScript):
            pass

        # Check whether we are dealing with animation
        if self.canvas.speed is not None:
            if not self.namespace.has_key("draw"):
                errorAlert(
                    "Not a proper NodeBox animation",
                    "NodeBox animations should have at least a draw() method.")
                return

            # Check if animationTimer is already running
            if self.animationTimer is not None:
                self.stopScript()

            self.speed = self.canvas.speed

            # Run setup routine
            if self.namespace.has_key("setup"):
                self.fastRun(self.namespace["setup"])
            window = self.currentView.window()
            window.makeFirstResponder_(self.currentView)

            # Start the timer
            self.animationTimer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
                1.0 / self.speed, self,
                objc.selector(self.doFrame, signature="v@:@"), None, True)

            # Start the spinner
            self.animationSpinner.startAnimation_(None)
예제 #4
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
예제 #5
0
    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
예제 #6
0
    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
예제 #7
0
            # XXX: Assertion doesn't actually assert.
            #assert len(self.lineStarts) == len(self.lineLengths) == len(self.lines)
            if lineIndex == len(self.lineStarts):
                return self.lineStarts[-1] + self.lineLengths[-1]
            return self.lineStarts[lineIndex]

    def numberOfLines(self):
        return len(self.lines)


_basicFont = NSFont.fontWithName_size_("Monaco", 10)
if _basicFont is None:
    import sys
    from nodebox.gui.mac.util import errorAlert
    errorAlert(
        "Monaco font not enabled",
        'NodeBox needs the "Monaco" font to work properly. Please enable it in Font Book.'
    )
    sys.exit(-1)

_BASICATTRS = {NSFontAttributeName: _basicFont, NSLigatureAttributeName: 0}
_SYNTAXCOLORS = {
    "keyword": {
        NSForegroundColorAttributeName: NSColor.blueColor()
    },
    "identifier": {
        NSForegroundColorAttributeName:
        NSColor.redColor().shadowWithLevel_(0.2)
    },
    "string": {
        NSForegroundColorAttributeName: NSColor.magentaColor()
    },
예제 #8
0
            for i in range(min(len(self.lines), lineIndex + 1) - len(self.lineStarts)):
                self.lineStarts.append(self.lineStarts[-1] + self.lineLengths[-1])
            # XXX: Assertion doesn't actually assert.
            #assert len(self.lineStarts) == len(self.lineLengths) == len(self.lines)
            if lineIndex == len(self.lineStarts):
                return self.lineStarts[-1] + self.lineLengths[-1]
            return self.lineStarts[lineIndex]

    def numberOfLines(self):
        return len(self.lines)

_basicFont = NSFont.fontWithName_size_("Monaco", 10)
if _basicFont is None:
    import sys
    from nodebox.gui.mac.util import errorAlert
    errorAlert("Monaco font not enabled", 'NodeBox needs the "Monaco" font to work properly. Please enable it in Font Book.')
    sys.exit(-1)

_BASICATTRS = {NSFontAttributeName: _basicFont,
               NSLigatureAttributeName: 0}
_SYNTAXCOLORS = {
    "keyword": {NSForegroundColorAttributeName: NSColor.blueColor()},
    "identifier": {NSForegroundColorAttributeName: NSColor.redColor().shadowWithLevel_(0.2)},
    "string": {NSForegroundColorAttributeName: NSColor.magentaColor()},
    "comment": {NSForegroundColorAttributeName: NSColor.grayColor()},
}
for key, value in _SYNTAXCOLORS.items():
    newVal = _BASICATTRS.copy()
    newVal.update(value)
    _SYNTAXCOLORS[key] = NSDictionary.dictionaryWithDictionary_(newVal)
_BASICATTRS = NSDictionary.dictionaryWithDictionary_(_BASICATTRS)