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
def _turnOn(self): pref_as_is = getDefault('glyphZoomViewShowItems') pref_new = dict() for i in pref_as_is: if i in turnOnItems: pref_new[i] = 1 else: pref_new[i] = pref_as_is[i] setDefault('glyphZoomViewShowItems', pref_new) preferencesChanged()
def _turnOff(self): pref_as_is = getDefault('glyphZoomViewShowItems') setExtensionDefault('restoreGlyphZoomViewShowItems', pref_as_is) pref_new = dict() for i in pref_as_is: if i in turnOffItems: pref_new[i] = 0 else: pref_new[i] = pref_as_is[i] setDefault('glyphZoomViewShowItems', pref_new) preferencesChanged()
def restoreGlyphViewItems(self): pref_as_is = getDefault('glyphZoomViewShowItems') pref_new = dict() for i in pref_as_is: if i in turnOffItems: # global gridWasOn # gridWasOn = pref_as_is[i] pref_new[i] = 1 else: pref_new[i] = pref_as_is[i] setDefault('glyphZoomViewShowItems', pref_new) PostNotification("doodle.preferencesChanged")
def setColorTheme(colorTheme): notification = "PyDEUserDefaultChanged" # set token colors setDefault("PyDETokenColors", colorTheme['tokens']) # set background color colorBackground = rgbToNSColor(hexToRGB(colorTheme['background'])) setDefaultColor("PyDEbackgroundColor", colorBackground) # set highlight color colorHighlight = rgbToNSColor(hexToRGB(colorTheme['highlight'])) setDefaultColor("PyDEHightLightColor", colorHighlight) # update code editor nc = NSNotificationCenter.defaultCenter() nc.postNotificationName_object_userInfo_(notification, None, None)
def saverCallback(self, sender): print("saving input text") csc = CurrentSpaceCenter() string = csc.getRaw() print("string is", string) before = getDefault("spaceCenterInputSamples") print("before is ", before) after = list(before) print("after is ", after) if string not in after: after.append(string) print("after2 is ", after) setDefault("spaceCenterInputSamples", after) print("saved input text.") else: print("did nothing.") preferencesChanged()
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
def mouseUpCallback(self, info): setDefault("glyphViewCloseContourSnapDistance", 0)
def mouseDownCallback(self, info): setDefault("glyphViewCloseContourSnapDistance", self.snapToCloseDistance)
def _restoreGlyphViewItems(self): setDefault('glyphZoomViewShowItems', getExtensionDefault('restoreGlyphZoomViewShowItems')) preferencesChanged()
# For the big box layer, draw a big box if layer.name == "big_box": # Clear the old box, if you're rerunning this script with different measurements l_g.clear() l_g.appendComponent("box_templates") setBoxDisplay(layer) l_g.changed() # For the small box layer, draw/redraw a small box elif layer.name == "small_box": # Clear the old box, if you're rerunning this script with different measurements l_g.clear() l_g.appendComponent("box_templates") setBoxDisplay(layer) l_g.changed() # Removing foreground blanks, to reveal glyph templates fore = f.getLayer("foreground") if g_name in fore: g = fore[g_name] if g.components == () and g.contours == (): fore.removeGlyph(g_name) # Set your preferences such that each time you add a glyph, its width is correct setDefault("newGlyphWidth", set_width)
-- Andy Clymer, github.com/andyclymer """ """ ---------------------------------------------------------------------- Set the menu bar name to include the RoboFont version number """ menu = AppKit.NSApp().mainMenu() roboFontItem = menu.itemWithTitle_("RoboFont") if roboFontItem: roboFontItem.submenu().setTitle_("RoboFont %s " % version) """ ---------------------------------------------------------------------- Turn on all deprecation warnings, useful when updating code for RF3 """ alwaysWarn = False if alwaysWarn: if version[0] == "3": print("RF3 Beta: Turning on deprecation warnings") import warnings # The default is to only warn once: # warnings.simplefilter("once") # Warn always: warnings.simplefilter("always") """ ---------------------------------------------------------------------- Show full kerning group names """ setDefault("showFullKernGroupNames", True)
def _set_size(self, value): self._size = value setDefault("glyphViewGridx", value) setDefault("glyphViewGridy", value) PostNotification("doodle.preferencesChanged")