def isWindowOnDockingSide(self, dockingWindow): ''' checks whenever dragged docking window is above any dock bar ''' winX, winY, winW, winH = dockingWindow.getPosSize() titleBarHeight = self._calculateParentWindowTitlebarHeight() x, y = (winX + winW / 2, winY - titleBarHeight / 2) px, py, pw, ph = self.getParentWindowPosSize() titleBarMiddlePoint = NSPoint(pw - (px - x) - pw, (py - y) + ph) isDockingWindowAbove = False dockingPosition = None for position in self.dockingRectPosSizes.keys(): dockingSideObj = getattr(self, f'{position}_dockbar', None) if dockingSideObj is not None: view = dockingSideObj.getNSView().hitTest_(titleBarMiddlePoint) if view is not None: dockingSideObj.getNSView().layer().setBackgroundColor_( NSColor.orangeColor().CGColor()) dockingPosition = position isDockingWindowAbove = True else: dockingSideObj.getNSView().layer().setBackgroundColor_( NSColor.clearColor().CGColor()) if isDockingWindowAbove: dockingWindow.getNSWindow().setAlphaValue_(.4) else: dockingWindow.getNSWindow().setAlphaValue_(1) return dockingPosition, self
def __init__(self): '''Initialize the dialog.''' x = y = padding = 10 buttonHeight = 20 windowWidth = 400 rows = 4.5 self.w = FloatingWindow( (windowWidth, buttonHeight * rows + padding * (rows)), "Glyph Fax Machine") self.fonts = {} # self.w.textBox = TextBox((x, y, -padding, buttonHeight), "Glyphs to Copy") # y += buttonHeight self.w.editText = EditText( (x, y, -padding, buttonHeight * 2 + padding), placeholder="Space-separated list of glyphs to copy") y += buttonHeight * 2 + padding * 2 # self.w.overwriteGlyphsCheckBox = CheckBox((x, y, -padding, buttonHeight), "Overwrite Glyphs", value=False, callback=self.overwriteGlyphsOptions) # y += buttonHeight + padding self.w.overwriteNormalWidthGlyphsCheckBox = CheckBox( (x, y, -padding, buttonHeight), "Overwrite 600w Glyphs", value=False, sizeStyle="small") # self.w.overwriteNormalWidthGlyphsCheckBox.show(False) self.w.overwriteAdjustedWidthGlyphsCheckBox = CheckBox( (windowWidth * 0.4, y, -padding, buttonHeight), "Overwrite non-600w Glyphs", value=False, sizeStyle="small") # self.w.overwriteAdjustedWidthGlyphsCheckBox.show(False) self.w.colorWell = ColorWell( (windowWidth * 0.85, y, -padding, buttonHeight), color=NSColor.orangeColor()) y += buttonHeight + padding self.w.sans2mono = Button( (x, y, windowWidth / 3 - padding / 2, buttonHeight), "Sans → Mono", callback=self.sans2monoCallback) self.w.mono2sans = Button( (windowWidth / 3 + padding, y, -padding, buttonHeight), "Mono → Sans", callback=self.mono2SansCallback) self.w.open()
def transformedValue_(self, priority): if priority > 4: return NSColor.redColor() elif priority > 3: return NSColor.orangeColor() elif priority > 2: return NSColor.blueColor() elif priority > 1: return NSColor.greenColor() elif priority > 0: return NSColor.brownColor() else: return NSColor.blackColor()
def drawRect_(self, rect): # self._layer.drawInFrame_(bounds) # used in Georgs GlyphView try: bounds = self.bounds() NSColor.textBackgroundColor().set() NSRectFill(bounds) scaleFactor = self._scaleFactor thisGlyph = self._layer.parent layerWidth = self._layer.width * scaleFactor descender = self._layer.glyphMetrics()[3] * scaleFactor ascender = self._layer.glyphMetrics()[1] * scaleFactor ## This order is important! Wont work the other way around. bezierPathOnly = self._layer.bezierPath # Path Only if bezierPathOnly is not None: bezierPathOnly = bezierPathOnly.copy() bezierPathWithComponents = self._layer.completeBezierPath # Path & Components bezierPathOpenWithComponents = self._layer.completeOpenBezierPath # Path & Components # Set the scale #-------------- scale = NSAffineTransform.transform() scale.translateXBy_yBy_((bounds.size.width - layerWidth) / 2.0, (bounds.size.height - ascender + descender) / 2.0 - descender) scale.scaleBy_(scaleFactor) # Draw only path in black #------------------------ if thisGlyph.export: pathColor = NSColor.textColor() componentColor = NSColor.secondaryLabelColor() else: pathColor = NSColor.orangeColor() componentColor = NSColor.orangeColor() if bezierPathWithComponents: bezierPathWithComponents.transformUsingAffineTransform_(scale) componentColor.set() # Draw components in gray bezierPathWithComponents.fill() if bezierPathOnly: pathColor.set() bezierPathOnly.transformUsingAffineTransform_(scale) bezierPathOnly.fill() if bezierPathOpenWithComponents: pathColor.set() bezierPathOpenWithComponents.transformUsingAffineTransform_(scale) bezierPathOpenWithComponents.stroke() # Draw non-exported glyphs in orange #----------------------------------- else: NSColor.orangeColor().set() bezierPathWithComponents.transformUsingAffineTransform_(scale) bezierPathWithComponents.fill() attributes = {} attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(14) attributes[NSForegroundColorAttributeName] = NSColor.secondaryLabelColor() thisLKG = thisGlyph.leftKerningGroup thisRKG = thisGlyph.rightKerningGroup if thisLKG is not None: String = NSAttributedString.alloc().initWithString_attributes_(thisLKG, attributes) String.drawAtPoint_alignment_((12, 5), 0) if thisRKG is not None: String = NSAttributedString.alloc().initWithString_attributes_(thisRKG, attributes) String.drawAtPoint_alignment_((bounds.size.width - 12, 5), 2) # AUTO-WIDTH LABEL #----------------- if self._layer.hasAlignedWidth(): attributes[NSForegroundColorAttributeName] = NSColor.lightGrayColor() attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(11) String = NSAttributedString.alloc().initWithString_attributes_("Auto-Width", attributes) String.drawAtPoint_alignment_((bounds.size.width / 2.0, 5), 1) except: print(traceback.format_exc())
cyanColor = NSColor.cyanColor() darkGrayColor = getRGBA(80, 80, 80) darkGreyColor = darkGrayColor grayColor = NSColor.grayColor() greyColor = grayColor grayColor = NSColor.grayColor() greenColor = NSColor.greenColor() 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)
class Color: """ A class representing a color """ def __init__(self, ns_color): 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 drawRect_(self, rect): ## needs to be `drawRect_` -- nothing else bounds = self.bounds() # thisUPM = self._layer.parent.parent.upm scaleFactor = self._scaleFactor thisUPM = self._upm * scaleFactor rectX, rectY, rectWidth, rectHeight = 0, 0, thisUPM, thisUPM self.rect = rect # self._layer.drawInFrame_(bounds) # used in Georgs GlyphView try: layerWidth = self._layer.width * scaleFactor descender = self._layer.glyphMetrics()[3] * scaleFactor ## this order is important! Wont work the other way around try: # pre Glyphs 2.3 bezierPathOnly = self._layer.copy().bezierPath() # Path Only bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath() # Path & Components except: # Glyphs 2.3 bezierPathOnly = self._layer.copy().bezierPath # Path Only bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath # Path & Components scale = NSAffineTransform.transform() scale.translateXBy_yBy_( rectWidth/2 - (layerWidth / 2.0) + self._margin/2, -descender + self._margin/2 ) scale.scaleBy_( scaleFactor ) if bezierPathWithComponents: bezierPathWithComponents.transformUsingAffineTransform_( scale ) if bezierPathOnly: bezierPathOnly.transformUsingAffineTransform_( scale ) ## DRAW COMPONENTS IN GRAY NSColor.darkGrayColor().set() # lightGrayColor bezierPathWithComponents.fill() ## CHANGE COLOR FOR NON-EXPORTED GLYPHS thisGlyph = self._layer.parent if thisGlyph.export: NSColor.blackColor().set() ## DRAW ONLY PATH IN BLACK if bezierPathOnly: bezierPathOnly.fill() else: NSColor.orangeColor().set() bezierPathWithComponents.fill() # print self.bounds() ## AUTO-WIDTH LABEL if self._layer.hasAlignedWidth(): paragraphStyle = NSMutableParagraphStyle.alloc().init() paragraphStyle.setAlignment_(2) ## 0=L, 1=R, 2=C, 3=justified attributes = {} attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(10) attributes[NSForegroundColorAttributeName] = NSColor.lightGrayColor() attributes[NSParagraphStyleAttributeName] = paragraphStyle String = NSAttributedString.alloc().initWithString_attributes_("Auto-Width", attributes) # String.drawAtPoint_((rectWidth, 0)) NSColor.redColor().set() # NSRectFill(((0, 0), (self.rect.size.width, 15))) String.drawInRect_(((0, 0), (self.rect.size.width, 15))) except: # pass print traceback.format_exc()
def drawRect_(self, rect): ## must be `drawRect_` - nothing else bounds = self.bounds() scaleFactor = self._scaleFactor thisUPM = self._upm * scaleFactor # = self._layer.parent.parent.upm rectX, rectY, rectWidth, rectHeight = 0, 0, thisUPM, thisUPM self.rect = rect # self._layer.drawInFrame_(bounds) # used in Georgs GlyphView try: thisGlyph = self._layer.parent layerWidth = self._layer.width * scaleFactor descender = self._layer.glyphMetrics()[3] * scaleFactor # ## This order is important! Wont work the other way around. # try: # pre Glyphs 2.3 # bezierPathOnly = self._layer.copy().bezierPath() # Path Only # bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath() # Path & Components # except: # Glyphs 2.3 # bezierPathOnly = self._layer.copy().bezierPath # Path Only # bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath # Path & Components ## This order is important! Wont work the other way around. try: # Glyphs 2.3 bezierPathOnly = self._layer.copy().bezierPath # Path Only bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath # Path & Components except: # Glyphs 2.4 bezierPathOnly = self._layer.copy().bezierPath # Path Only bezierPathWithComponents = self._layer.completeBezierPath # Path & Components # Set the scale #-------------- scale = NSAffineTransform.transform() scale.translateXBy_yBy_( rectWidth/2 - (layerWidth / 2.0) + self._margin/2, -descender + self._margin/2 ) scale.scaleBy_( scaleFactor ) if bezierPathWithComponents: bezierPathWithComponents.transformUsingAffineTransform_( scale ) if bezierPathOnly: bezierPathOnly.transformUsingAffineTransform_( scale ) # Draw components in gray #------------------------ NSColor.darkGrayColor().set() # lightGrayColor bezierPathWithComponents.fill() # Draw only path in black #------------------------ if thisGlyph.export: NSColor.blackColor().set() if bezierPathOnly: bezierPathOnly.fill() # Draw non-exported glyphs in orange #----------------------------------- else: NSColor.orangeColor().set() bezierPathWithComponents.fill() # AUTO-WIDTH LABEL #----------------- if self._layer.hasAlignedWidth(): paragraphStyle = NSMutableParagraphStyle.alloc().init() paragraphStyle.setAlignment_(2) ## 0=L, 1=R, 2=C, 3=justified attributes = {} attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(10) attributes[NSForegroundColorAttributeName] = NSColor.lightGrayColor() attributes[NSParagraphStyleAttributeName] = paragraphStyle String = NSAttributedString.alloc().initWithString_attributes_("Auto-Width", attributes) # String.drawAtPoint_((rectWidth, 0)) NSColor.redColor().set() # NSRectFill(((0, 0), (self.rect.size.width, 15))) String.drawInRect_(((0, 0), (self.rect.size.width, 15))) except: pass # print traceback.format_exc()
def foreground(self, Layer): """ Whatever you draw here will be displayed IN FRONT OF the paths. Setting a color: NSColor.colorWithCalibratedRed_green_blue_alpha_( 1.0, 1.0, 1.0, 1.0 ).set() # sets RGBA values between 0.0 and 1.0 NSColor.redColor().set() # predefined colors: blackColor, blueColor, brownColor, clearColor, cyanColor, darkGrayColor, grayColor, greenColor, lightGrayColor, magentaColor, orangeColor, purpleColor, redColor, whiteColor, yellowColor Drawing a path: myPath = NSBezierPath.alloc().init() # initialize a path object myPath myPath.appendBezierPath_( subpath ) # add subpath to myPath myPath.fill() # fill myPath with the current NSColor myPath.stroke() # stroke myPath with the current NSColor To get an NSBezierPath from a GSPath, use the bezierPath() method: myPath.bezierPath().fill() You can apply that to a full layer at once: if len( myLayer.paths > 0 ): myLayer.bezierPath() # all closed paths myLayer.openBezierPath() # all open paths See: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/Reference/Reference.html https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSColor_Class/Reference/Reference.html """ try: thisGlyph = Layer.parent Font = thisGlyph.parent xHeight = Font.selectedFontMaster.xHeight angle = Font.selectedFontMaster.italicAngle yPos = -100 # rotation point is half of x-height offset = math.tan(math.radians(angle)) * xHeight / 2 shift = math.tan(math.radians(angle)) * yPos - offset glyphLeftMetricsKey = thisGlyph.leftMetricsKey glyphRightMetricsKey = thisGlyph.rightMetricsKey layerLeftMetricsKey = Layer.leftMetricsKey() layerRightMetricsKey = Layer.rightMetricsKey() layerWidth = Layer.width + 10.0 leftMetricsKeyString = "Glyph: '%s'\nLayer: '%s'" % ( glyphLeftMetricsKey, layerLeftMetricsKey) rightMetricsKeyString = "Glyph: '%s'\nLayer: '%s'" % ( glyphRightMetricsKey, layerRightMetricsKey) leftMetricsKeyString = leftMetricsKeyString.replace("'None'", "-") rightMetricsKeyString = rightMetricsKeyString.replace( "'None'", "-") # Text Alignments: # top left: 6 # top center: 7 # top right: 8 # center left: 3 # center center: 4 # center right: 5 # bottom left: 0 # bottom center: 1 # bottom right: 2 self.drawTextAtPoint(leftMetricsKeyString, NSPoint(-10.0 + shift, yPos), fontSize=9.0, textAlignment=2, fontColor=NSColor.orangeColor()) self.drawTextAtPoint(rightMetricsKeyString, NSPoint(layerWidth + shift, yPos), fontSize=9.0, textAlignment=0, fontColor=NSColor.orangeColor()) except Exception as e: self.logToConsole("drawForegroundForLayer_: %s" % str(e))