Example #1
0
    def _update(self):
        style = self.interface.style
        font = InterfaceFont(style.font_family, style.font_size)

        attributes = NSDictionary.dictionaryWithObjects(
            [self.interface.url,
             font.bind(self.interface.factory).native],
            forKeys=[NSLinkAttributeName, NSFontAttributeName],
        )
        self.attr_string = NSAttributedString.alloc().initWithString(
            self.interface.text, attributes=attributes)
        self.native.textStorage.setAttributedString(self.attr_string)
        self.rehint()
Example #2
0
 def apply(self, prop, value):
     if self._applicator:
         if prop == 'text_align':
             if value is None:
                 if self.text_direction is RTL:
                     value = RIGHT
                 else:
                     value = LEFT
             self._applicator.set_text_alignment(value)
         elif prop == 'color':
             self._applicator.set_color(value)
         elif prop == 'background_color':
             self._applicator.set_background_color(value)
         elif prop == 'visibility':
             hidden = False
             if value == HIDDEN:
                 hidden = True
             self._applicator.set_hidden(hidden)
         elif prop in ('font_family', 'font_size', 'font_style', 'font_variant', 'font_weight'):
             self._applicator.set_font(
                 Font(
                     self.font_family,
                     self.font_size,
                     style=self.font_style,
                     variant=self.font_variant,
                     weight=self.font_weight
                 )
             )
Example #3
0
 def test_set_font(self):
     root = TestNode('app',
                     style=Pack(font_family='Roboto',
                                font_size=12,
                                font_style='normal',
                                font_variant='small-caps',
                                font_weight='bold'))
     root.style.reapply()
     root._impl.set_font.assert_called_with(
         Font('Roboto', 12, 'normal', 'small-caps', 'bold'))
Example #4
0
    def get_text_width_height_descent(self, s, prop, ismath):
        """
        get the width and height in display coords of the string s
        with FontPropertry prop
        """

        if (prop.get_family()[0] == SANS_SERIF):
            font_family = SANS_SERIF
        elif (prop.get_family()[0] == CURSIVE):
            font_family = CURSIVE
        elif (prop.get_family()[0] == FANTASY):
            font_family = FANTASY
        elif (prop.get_family()[0] == MONOSPACE):
            font_family = MONOSPACE
        else:
            font_family = SERIF
        font = Font(family=font_family, size=int(prop.get_size()))

        w, h = font.measure(s)
        return w, h, 1
Example #5
0
    def get_font(self, prop):
        if prop.get_family()[0] == SANS_SERIF:
            font_family = SANS_SERIF
        elif prop.get_family()[0] == CURSIVE:
            font_family = CURSIVE
        elif prop.get_family()[0] == FANTASY:
            font_family = FANTASY
        elif prop.get_family()[0] == MONOSPACE:
            font_family = MONOSPACE
        else:
            font_family = SERIF

        size = int(prop.get_size_in_points())
        return Font(family=font_family, size=size)
Example #6
0
def _construct_alert(
        title,
        message,
        details=None,
        details_title="Traceback",
        button_labels=("Ok", ),
        checkbox_text=None,
        level="info",
        icon=None,
):
    a = NSAlert.alloc().init()
    a.alertStyle = alert_style_for_level_str[level]
    a.messageText = title
    a.informativeText = message
    a.icon = icon

    if details:
        scroll = NSScrollView.alloc().initWithFrame(NSMakeRect(0, 0, 500, 250))
        scroll.hasVerticalScroller = True
        scroll.hasHorizontalScroller = False
        scroll.autohidesScrollers = False
        scroll.borderType = NSBezelBorder

        trace = NSTextView.alloc().init()
        trace.editable = False
        trace.verticallyResizable = True
        trace.horizontallyResizable = True
        trace.insetText(details)

        scroll.documentView = trace

        title = NSTextField.labelWithString(details_title)
        title.font = Font(SYSTEM, 12, weight=BOLD).bind(factory).native

        stack = NSStackView.alloc().initWithFrame(NSMakeRect(0, 0, 500, 265))
        stack.orientation = NSUserInterfaceLayoutOrientationVertical
        stack.alignment = NSLayoutAttributeLeading
        stack.addView(title, inGravity=NSStackViewGravityBottom)
        stack.addView(scroll, inGravity=NSStackViewGravityBottom)

        a.accessoryView = stack

    if checkbox_text:
        a.showsSuppressionButton = True
        a.suppressionButton.title = checkbox_text

    for name in button_labels:
        a.addButtonWithTitle(name)

    return a
Example #7
0
    def write_text(self, text, x=0, y=0, font=None):
        """Constructs and returns a :class:`WriteText <WriteText>`.

        Writes a given text at the given (x,y) position. If no font is provided,
        then it will use the font assigned to the Canvas Widget, if it exists,
        or use the default font if there is no font assigned.

        Args:
            text (string): The text to fill.
            x (float, optional): The x coordinate of the text. Default to 0.
            y (float, optional): The y coordinate of the text. Default to 0.
            font (:class:`toga.Font`, optional): The font to write with.

        Returns:
            :class:`WriteText <WriteText>` object.

        """
        if font is None:
            font = Font(family=SYSTEM, size=self._canvas.style.font_size)
        write_text = WriteText(text, x, y, font)
        return self.add_draw_obj(write_text)