def write_text(self, text, x, y, font, *args, **kwargs): # Set font family and size if font: write_font = font elif self.native.font: write_font = self.native.font else: raise ValueError("No font to write with") width, height = write_font.measure(text) textAttributes = NSMutableDictionary.alloc().init() textAttributes[NSFontAttributeName] = write_font._impl.native if "stroke_color" in kwargs and "fill_color" in kwargs: textAttributes[NSStrokeColorAttributeName] = native_color( kwargs["stroke_color"]) # Apply negative NSStrokeWidthAttributeName to get stroke and fill textAttributes[ NSStrokeWidthAttributeName] = -1 * kwargs["text_line_width"] textAttributes[NSForegroundColorAttributeName] = native_color( kwargs["fill_color"]) elif "stroke_color" in kwargs: textAttributes[NSStrokeColorAttributeName] = native_color( kwargs["stroke_color"]) textAttributes[NSStrokeWidthAttributeName] = kwargs[ "text_line_width"] elif "fill_color" in kwargs: textAttributes[NSForegroundColorAttributeName] = native_color( kwargs["fill_color"]) else: raise ValueError("No stroke or fill of write text") text_string = NSAttributedString.alloc().initWithString_attributes_( text, textAttributes) text_string.drawAtPoint(NSPoint(x, y - height))
def write_text(self, text, x, y, font, *args, **kwargs): width, height = self.measure_text(text, font) textAttributes = NSMutableDictionary.alloc().init() textAttributes[NSFontAttributeName] = font.bind( self.interface.factory).native if "stroke_color" in kwargs and "fill_color" in kwargs: textAttributes[NSStrokeColorAttributeName] = native_color( kwargs["stroke_color"]) # Apply negative NSStrokeWidthAttributeName to get stroke and fill textAttributes[ NSStrokeWidthAttributeName] = -1 * kwargs["text_line_width"] textAttributes[NSForegroundColorAttributeName] = native_color( kwargs["fill_color"]) elif "stroke_color" in kwargs: textAttributes[NSStrokeColorAttributeName] = native_color( kwargs["stroke_color"]) textAttributes[NSStrokeWidthAttributeName] = kwargs[ "text_line_width"] elif "fill_color" in kwargs: textAttributes[NSForegroundColorAttributeName] = native_color( kwargs["fill_color"]) else: raise ValueError("No stroke or fill of write text") text_string = NSAttributedString.alloc().initWithString_attributes_( text, textAttributes) text_string.drawAtPoint(NSPoint(x, y - height))
def set_background_color(self, color): if color is TRANSPARENT: self.native.backgroundColor = NSColor.clearColor self.native.drawsBackground = False else: self.native.backgroundColor = native_color(color) self.native.drawsBackground = True
def set_background_color(self, color): if color is None: self.native.backgroundColor = NSColor.windowBackgroundColor else: self.native.backgroundColor = native_color(color)
def set_color(self, value): if value: self.native.textColor = native_color(value)
def set_color(self, color): if color: self.native.textColor = native_color(color) else: self.native.textColor = NSColor.labelColor