def checkSyntax(self, sender=None): # get the code code = self.code() # get te path of the document (will be None for an untitled document) path = self.path() # when enabled clear the output text view if getDefault("PyDEClearOutput", True): self.outPutView.set("") # create a new std output, catching all print statements and tracebacks self.output = [] self.stdout = StdOutput(self.output) self.stderr = StdOutput(self.output, True) # run the code, but with the optional flag checkSyntaxOnly so it will just compile the code ScriptRunner(code, path, stdout=self.stdout, stderr=self.stderr, checkSyntaxOnly=True) # set the catched print statements and tracebacks in the the output text view for text, isError in self.output: self.outPutView.append(text, isError) # clean up self.output = None self.stdout = None self.stderr = None
def runCode(self): self._errorView.set("") if not self._code: return self._drawingTools._reset() if getDefault("PyDEClearOutput", True): self._errorView.clear() self.stdout = Output(self._errorView) self.stderr = Output(self._errorView, True) path = self.getPath() namespace = dict() for name in self._drawingTools.__all__: namespace[name] = getattr(self._drawingTools, name) ScriptRunner(text=self._code, path=path, stdout=self.stdout, stderr=self.stderr, namespace=namespace)
def runCode(self, sender=None): code = self.codeEditor.get() container = self.merzView.getMerzContainer() container.clearSublayers() namespace = dict(container=container, merz=merz) if getDefault("PyDEClearOutput", True): self.outputEditor.clear() self.output = [] self.stdout = StdOutput(self.output) self.stderr = StdOutput(self.output, True) ScriptRunner(code, "<Merz Playground>", namespace=namespace, stdout=self.stdout, stderr=self.stderr) for text, isError in self.output: self.outputEditor.append(text, isError) self.output = None self.stdout = None self.stderr = None
def runCode(self, liveCoding=False): # get the code code = self.code() # save the code in the defaults, if something goes wrong setDefault("pythonCodeBackup", code) # get te path of the document (will be None for an untitled document) path = self.path() # reset the internal warning system warnings.resetWarnings() # reset the drawing tool _drawBotDrawingTool.newDrawing() # create a namespace namespace = DrawBotNamespace(_drawBotDrawingTool, _drawBotDrawingTool._magicVariables) # add the tool callbacks in the name space _drawBotDrawingTool._addToNamespace(namespace) # when enabled clear the output text view if getDefault("PyDEClearOutput", True): self.outPutView.clear() # create a new std output, catching all print statements and tracebacks self.output = [] self.stdout = StdOutput(self.output) self.stderr = StdOutput(self.output, True) # warnings should show the warnings warnings.shouldShowWarnings = True # run the code ScriptRunner(code, path, namespace=namespace, stdout=self.stdout, stderr=self.stderr) # warnings should stop posting them warnings.shouldShowWarnings = False # set context, only when the panes are visible if self.w.split.isPaneVisible( "drawView") or self.w.split.isPaneVisible("thumbnails"): def createContext(context): # draw the tool in to the context _drawBotDrawingTool._drawInContext(context) # create a context to draw in context = DrawBotContext() # savely run the callback and track all traceback back the the output CallbackRunner(createContext, stdout=self.stdout, stderr=self.stderr, args=[context]) # get the pdf document and set in the draw view pdfDocument = context.getNSPDFDocument() if not liveCoding or (pdfDocument and pdfDocument.pageCount()): self.drawView.setPDFDocument(pdfDocument) # scroll down self.drawView.scrollDown() else: # if the panes are not visible, clear the draw view self.drawView.setPDFDocument(None) # set the catched print statements and tracebacks in the the output text view for text, isError in self.output: if liveCoding and isError: continue self.outPutView.append(text, isError) # reset the code backup if the script runs with any crashes setDefault("pythonCodeBackup", None) # clean up self.output = None self.stdout = None self.stderr = None