Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
Arquivo: box.py Projeto: uranusjr/toga
 def set_background_color(self, color):
     if color is None:
         self.native.backgroundColor = NSColor.windowBackgroundColor
     else:
         self.native.backgroundColor = native_color(color)
Exemplo n.º 5
0
 def set_color(self, value):
     if value:
         self.native.textColor = native_color(value)
Exemplo n.º 6
0
 def set_color(self, color):
     if color:
         self.native.textColor = native_color(color)
     else:
         self.native.textColor = NSColor.labelColor
Exemplo n.º 7
0
Arquivo: label.py Projeto: pybee/toga
 def set_color(self, value):
     if value:
         self.native.textColor = native_color(value)