Exemplo n.º 1
0
    def draw(self):
        pos = self.image.width, self.y
        # Max number of chars for this entry's label
        max_chars = 20
        # Simple trick to get the maximum label width for the current font size
        self.width = getLabel('W'*max_chars, font_size=self.font_size).width
        if self.selected:
            selected_color = self.style.get('selected-color', (0.4,) * 4)
            set_color(*selected_color)
            drawCSSRectangle(pos=(0, self.y), size=self.size, style=self.style)
        kwargs = {'pos': pos, 'anchor_x': 'left', 'anchor_y': 'bottom', 'font_size':self.style['font-size'],
                  'color':self.style['color']}
        drawLabel(label=self.striptext(self.label_txt, max_chars), **kwargs )

        self.image.pos = (0, self.y)
        self.image.draw()
Exemplo n.º 2
0
 def draw(self):
     pos = self.image.width, self.y
     # Max number of chars for this entry's label
     max_chars = 20
     # Simple trick to get the maximum label width for the current font size
     self.width = getLabel('W' * max_chars, font_size=self.font_size).width
     if self.selected:
         selected_color = self.style.get('selected-color', (0.4, ) * 4)
         set_color(*selected_color)
         drawCSSRectangle(pos=(0, self.y), size=self.size, style=self.style)
     drawLabel(label=self.striptext(self.label_txt, max_chars),
               pos=pos,
               anchor_x='left',
               anchor_y='bottom',
               font_size=self.style.get('font-size'),
               color=self.style.get('color'))
     self.image.pos = (0, self.y)
     self.image.draw()
Exemplo n.º 3
0
    def __init__(self, **kwargs):
        kwargs.setdefault('markup', False)
        kwargs.setdefault('anchor_x', 'left')
        kwargs.setdefault('anchor_y', 'bottom')
        kwargs.setdefault('autowidth', False)
        kwargs.setdefault('autoheight', False)
        kwargs.setdefault('autosize', False)
        kwargs.setdefault('label', '')
        kwargs.setdefault('multiline', False)

        self.kwargs = {}

        self.multiline  = kwargs['multiline']
        self.autowidth  = kwargs['autowidth']
        self.autoheight = kwargs['autoheight']
        self.autosize   = kwargs['autosize']
        self.anchor_x   = kwargs['anchor_x']
        self.anchor_y   = kwargs['anchor_y']
        self.label      = kwargs['label']
        del kwargs['autowidth']
        del kwargs['autoheight']
        del kwargs['autosize']
        del kwargs['label']
        del kwargs['multiline']

        super(MTLabel, self).__init__(**kwargs)

        size_specified = 'size' in kwargs or 'width' in kwargs or 'height' in kwargs
        for item in ('size', 'pos'):
            if item in kwargs:
                del kwargs[item]

        if self.multiline:
            kwargs['size'] = (self.width, None)

        self.kwargs = kwargs

        # copy style to inline one (needed for css reloading)
        if 'color' in kwargs:
            self._inline_style['color'] = kwargs['color']
        if 'font_name' in kwargs:
            self._inline_style['font-name'] = kwargs['font_name']
        if 'font_size' in kwargs:
            self._inline_style['font-size'] = kwargs['font_size']
        if 'bold' in kwargs and 'italic' in kwargs and \
            kwargs['bold'] and kwargs['italic']:
            self._inline_style['font-weight'] = 'bolditalic'
        elif 'bold' in kwargs and kwargs['bold']:
            self._inline_style['font-weight'] = 'bold'
        elif 'italic' in kwargs and kwargs['italic']:
            self._inline_style['font-weight'] = 'italic'
        if 'padding' in kwargs:
            self._inline_style['padding'] = kwargs['padding']

        # update from inline
        self.apply_css(self._inline_style)

        # update this label size
        label = getLabel(label=self.label, **kwargs)
        if not size_specified:
            self.size = label.size
        self._update_size(*label.size)
        self._used_label = label
Exemplo n.º 4
0
    def __init__(self, **kwargs):
        kwargs.setdefault('markup', False)
        kwargs.setdefault('anchor_x', 'left')
        kwargs.setdefault('anchor_y', 'bottom')
        kwargs.setdefault('autowidth', False)
        kwargs.setdefault('autoheight', False)
        kwargs.setdefault('autosize', False)
        kwargs.setdefault('label', '')
        kwargs.setdefault('multiline', False)

        self.kwargs = {}

        self.multiline = kwargs['multiline']
        self.autowidth = kwargs['autowidth']
        self.autoheight = kwargs['autoheight']
        self.autosize = kwargs['autosize']
        self.anchor_x = kwargs['anchor_x']
        self.anchor_y = kwargs['anchor_y']
        self.label = kwargs['label']
        del kwargs['autowidth']
        del kwargs['autoheight']
        del kwargs['autosize']
        del kwargs['label']
        del kwargs['multiline']

        super(MTLabel, self).__init__(**kwargs)

        size_specified = 'size' in kwargs or 'width' in kwargs or 'height' in kwargs
        for item in ('size', 'pos'):
            if item in kwargs:
                del kwargs[item]

        if self.multiline:
            kwargs['size'] = (self.width, None)

        self.kwargs = kwargs

        # copy style to inline one (needed for css reloading)
        if 'color' in kwargs:
            self._inline_style['color'] = kwargs['color']
        if 'font_name' in kwargs:
            self._inline_style['font-name'] = kwargs['font_name']
        if 'font_size' in kwargs:
            self._inline_style['font-size'] = kwargs['font_size']
        if 'bold' in kwargs and 'italic' in kwargs and \
            kwargs['bold'] and kwargs['italic']:
            self._inline_style['font-weight'] = 'bolditalic'
        elif 'bold' in kwargs and kwargs['bold']:
            self._inline_style['font-weight'] = 'bold'
        elif 'italic' in kwargs and kwargs['italic']:
            self._inline_style['font-weight'] = 'italic'
        if 'padding' in kwargs:
            self._inline_style['padding'] = kwargs['padding']

        # update from inline
        self.apply_css(self._inline_style)

        # update this label size
        label = getLabel(label=self.label, **kwargs)
        if not size_specified:
            self.size = label.size
        self._update_size(*label.size)
        self._used_label = label