コード例 #1
0
ファイル: canvas.py プロジェクト: rmansfeld/toga
    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))
コード例 #2
0
ファイル: canvas.py プロジェクト: obulat/toga
    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))
コード例 #3
0
ファイル: base.py プロジェクト: avafischer/BeePosiApp
 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
コード例 #4
0
ファイル: box.py プロジェクト: uranusjr/toga
 def set_background_color(self, color):
     if color is None:
         self.native.backgroundColor = NSColor.windowBackgroundColor
     else:
         self.native.backgroundColor = native_color(color)
コード例 #5
0
ファイル: factory.py プロジェクト: SamSchott/maestral-cocoa
 def set_color(self, value):
     if value:
         self.native.textColor = native_color(value)
コード例 #6
0
 def set_color(self, color):
     if color:
         self.native.textColor = native_color(color)
     else:
         self.native.textColor = NSColor.labelColor
コード例 #7
0
ファイル: label.py プロジェクト: pybee/toga
 def set_color(self, value):
     if value:
         self.native.textColor = native_color(value)