def icon_setter(self, _=False): if (self.started or not _) and self.render_icon: p = (sum(self.current_passthrough_volume) / len(self.current_passthrough_volume) * 2.5) ** 0.25 if _ else 0 img = NSImage.alloc().initWithSize_((11, 26)) img.lockFocus() fp = NSBezierPath.bezierPathWithRect_(((2, 2), (7, 22))) NSColor.darkGrayColor().set() fp.fill() rp = NSBezierPath.bezierPathWithRect_(((3, 3), (5, p * 20))) if p > 0.90: NSColor.colorWithRed_green_blue_alpha_((0.5 if self.dark else 1), 0.15, 0.15, 1).set() elif p > 0.60: NSColor.\ colorWithRed_green_blue_alpha_((0.5 if self.dark else 1), (0.5 if self.dark else 0.9), 0, 1).set() else: NSColor.colorWithRed_green_blue_alpha_(0, (0 if self.dark else 1), (0.5 if self.dark else 0), 1).set() rp.fill() img.unlockFocus() self._icon_nsimage = img try: self._nsapp.setStatusBarIcon() except AttributeError: pass
self.width = width self.height = height 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)
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 drawBackground(self, layer): try: self.drawTopsAndBottoms(layer, NSColor.darkGrayColor()) except Exception as e: self.logToConsole("drawBackground: %s" % str(e))
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()