def drawGlyphIntoBackground(layer, info): # Due to internal Glyphs.app structure, we need to catch and print exceptions # of these callback functions with try/except like so: try: # Your drawing code here NSColor.yellowColor().set() layer.background.bezierPath.fill() # Error. Print exception. except: import traceback print traceback.format_exc()
def drawGlyphIntoBackground(layer, info): # Due to internal Glyphs.app structure, we need to catch and print exceptions # of these callback functions with try/except like so: try: # Your drawing code here NSColor.yellowColor().set() layer.background.bezierPath.fill() # Error. Print exception. except: import traceback print traceback.format_exc()
def __init__(self, drawGrid=False): self.w = Window((600, 500), "", minSize=(300, 250)) grp = Group((0, 0, 0, 0)) grp.button = Button((10, 10, -10, 20), "Toggle", self.buttonCallback) self.view1 = TestSplitSubview((0, 0, 0, 0), NSColor.redColor()) paneDescriptions2 = [ dict(view=self.view1, canCollapse=True, size=50, identifier="pane1"), dict(view=grp, identifier="pane2"), dict(view=TestSplitSubview((0, 0, 0, 0), NSColor.greenColor()), minSize=50, identifier="pane3"), dict(view=TestSplitSubview((0, 0, 0, 0), NSColor.yellowColor()), identifier="pane4"), ] self.nestedSplit = SplitView((0, 0, 0, 0), paneDescriptions2, isVertical=True) paneDescriptions1 = [ dict(view=self.nestedSplit, identifier="pane5"), dict( view=TestSplitSubview((0, 0, 0, 0), NSColor.magentaColor()), minSize=100, size=100, canCollapse=True, identifier="pane6", ), ] self.w.splitView = SplitView((10, 10, -10, -10), paneDescriptions1, isVertical=False) if drawGrid: self.drawGrid() self.w.open()
def addColorToPalette(self, sender=None): # add a new color to the current palette # find a new palette index paletteIndices = sorted(self.cfont.palettes[0].keys(), key=lambda k: int(k)) if len(paletteIndices) > 0: newIndex = int(paletteIndices[-1]) + 1 else: newIndex = 0 if newIndex < 0xffff: # add new color to current palette self.w.colorpalette.append({ "Index": newIndex, "Color": NSColor.yellowColor() }) # add new color to all other palettes for p in self.cfont.palettes: p[newIndex] = "#ffff0bff" self.cfont.save_settings = True self._paletteWriteToColorFont() self.currentPaletteChanged = False else: print("ERROR: Color Index 0xffff is reserved.")
def __init__(self, drawGrid=False): self.w = Window((600, 500), "", minSize=(300, 250)) grp = Group((0, 0, 0, 0)) grp.button = Button((10, 10, -10, 20), "Toggle", self.buttonCallback) self.view1 = TestSplitSubview((0, 0, 0, 0), NSColor.redColor()) paneDescriptions2 = [ dict(view=self.view1, canCollapse=True, size=50, identifier="pane1"), dict(view=grp, identifier="pane2"), dict(view=TestSplitSubview((0, 0, 0, 0), NSColor.greenColor()), minSize=50, identifier="pane3"), dict(view=TestSplitSubview((0, 0, 0, 0), NSColor.yellowColor()), identifier="pane4"), ] self.nestedSplit = SplitView((0, 0, 0, 0), paneDescriptions2, isVertical=True) paneDescriptions1 = [ dict(view=self.nestedSplit, identifier="pane5"), dict(view=TestSplitSubview((0, 0, 0, 0), NSColor.magentaColor()), minSize=100, size=100, canCollapse=True, identifier="pane6"), ] self.w.splitView = SplitView((10, 10, -10, -10), paneDescriptions1, isVertical=False) if drawGrid: self.drawGrid() self.w.open()
coor_y2 = half_xh + tolerance # ---------------- newPath = GSPath() nu_nodes = [(coor_x1, coor_y1), (coor_x1, coor_y2), (coor_x2, coor_y2), (coor_x2, coor_y1)] for n in nu_nodes: newNode = GSNode() newNode.type = GSLINE newNode.position = n newPath.nodes.append(newNode) newPath.closed = True background_layer.paths.append(newPath) NSColor.yellowColor().set() layer.background.bezierPath.fill() def glyphs_width(): node_coor = {} for layer in Font.selectedLayers: glyph = layer.parent gname = glyph.name node_coor[gname] = font.glyphs[gname].layers[0].width return node_coor Glyphs.addCallback(drawGlyphIntoBackground, DRAWBACKGROUND)
lightGreenColor = getRGBA(75, 211, 154) darkGreenColor = getRGBA(41, 120, 37) lightestGrayColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0.98, 0.98, 0.98, 1) lightestGreyColor = lightestGrayColor lightGrayColor = NSColor.lightGrayColor() lightGreyColor = lightGrayColor magentaColor = NSColor.magentaColor() orangeColor = NSColor.orangeColor() lightOrangeColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0.98, 0.81, 0.32, 1) purpleColor = NSColor.purpleColor() opaquePurpleColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 1, 0, 1, 0.3) redColor = NSColor.redColor() opaqueRedColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 0, 0, 0.3) whiteColor = NSColor.whiteColor() opaqueWhiteColor = getRGBA(255, 255, 255, 0.5) yellowColor = NSColor.yellowColor() # Interface presets. UIGray = getRGBA(31, 38, 46) UIOpaqueGray = getRGBA(31, 38, 46, 0.5) UIOpaqueGrey = UIOpaqueGray UIGrey = UIGray UILightGray = getRGBA(100, 121, 146) UILightGrey = UILightGray UIBlue = getRGBA(13, 48, 54) UILightBlue = getRGBA(86, 196, 229)
#!/usr/bin/env python3 from Foundation import NSURL, NSString from AppKit import NSColor import Quartz as Quartz import sys, os os.environ["PDFKIT_LOG_ANNOTATIONS"] = 'True' # You will need to change these filepaths to a local test pdf and an output file. outfile = '/path/to/file.pdf' infile = '/path/to/file.pdf' myYellow = NSColor.yellowColor() if __name__ == "__main__": myRect = Quartz.CGRectMake(100, 100, 10, 14) pdfURL = NSURL.fileURLWithPath_(infile) myPDF = Quartz.PDFDocument.alloc().initWithURL_(pdfURL) if myPDF: pages = myPDF.pageCount() myNote = Quartz.PDFAnnotation.alloc( ).initWithBounds_forType_withProperties_(myRect, "Text", None) myNote.setContents_("Qwe qwe qwe ") myNote.setColor_(myYellow) page = myPDF.pageAtIndex_(0) page.addAnnotation_(myNote) myPDF.writeToFile_(outfile) else:
self.ns_color = ns_color Color.BLACK = Color(NSColor.blackColor()) Color.BLUE = Color(NSColor.blueColor()) Color.BROWN = Color(NSColor.brownColor()) Color.CYAN = Color(NSColor.cyanColor()) Color.DARK_GRAY = Color(NSColor.darkGrayColor()) Color.GRAY = Color(NSColor.grayColor()) Color.GREEN = Color(NSColor.greenColor()) Color.MAGENTA = Color(NSColor.magentaColor()) Color.ORANGE = Color(NSColor.orangeColor()) Color.PURPLE = Color(NSColor.purpleColor()) Color.RED = Color(NSColor.redColor()) Color.WHITE = Color(NSColor.whiteColor()) Color.YELLOW = Color(NSColor.yellowColor()) class Font: """ Text font """ def __init__(self, name, size): self.ns_font = NSFont.fontWithName_size_(name, size) class Sound: """ A system sound """ def __init__(self, path): self.path = path self.ns_sound = None
coor_x2 = o.width coor_y1 = half_xh - tolerance coor_y2 = half_xh + tolerance # ---------------- newPath = GSPath() nu_nodes = [(coor_x1, coor_y1), (coor_x1, coor_y2), (coor_x2, coor_y2), (coor_x2, coor_y1)] for n in nu_nodes: newNode = GSNode() newNode.type = GSLINE newNode.position = n newPath.nodes.append(newNode) newPath.closed = True background_layer.paths.append(newPath) NSColor.yellowColor().set() layer.background.bezierPath.fill() def glyphs_width(): node_coor = {} for layer in Font.selectedLayers: glyph = layer.parent gname = glyph.name node_coor[gname] = font.glyphs[gname].layers[0].width return node_coor Glyphs.addCallback(drawGlyphIntoBackground, DRAWBACKGROUND)