Logo Search packages:      
Sourcecode: ocempgui version File versions  Download package

def themes::default::DefaultEngine::DefaultEngine::draw_label (   self,
  label 
)

D.draw_label (...) -> Surface

Creates the surface for the passed Label widget.

Definition at line 657 of file DefaultEngine.py.

00657                                 :
        """D.draw_label (...) -> Surface

        Creates the surface for the passed Label widget.
        """
        cls = label.__class__
        st = label.style
        width = 2 * label.padding
        height = 2 * label.padding

        labels = []
        rtext = None
        if not label.multiline:
            # Draw a single line.
            if label.mnemonic[0] != -1:
                rtext = self.draw_string_with_mnemonic (label.text, label.state,
                                                        label.mnemonic[0], cls,
                                                        st)
            else:
                rtext = self.draw_string (label.text, label.state, cls, st)
            rect = rtext.get_rect ()
            width += rect.width
            height += rect.height
            labels.append ((rtext, rect))
        else:
            # Multiple lines.
            cur = 0 # Current postion marker for the mnemonic.
            lines = label.get_lines ()
            mnemonic = label.mnemonic[0]
            last = len(lines) - 1
            for i, line in enumerate(lines):
                if (mnemonic != -1) and (cur <= mnemonic) and \
                   ((cur + len (line)) > mnemonic):
                    rtext = self.draw_string_with_mnemonic (line, label.state,
                                                            mnemonic - cur,
                                                            cls, st)
                else:
                    rtext = self.draw_string (line, label.state, cls, st)
                rect = rtext.get_rect ()
                if width < rect.width:
                    width = rect.width + 2 * label.padding
                if (label.linespace != 0) and (i != last):
                    # Do not consider linespace for the last line
                    rect.height += label.linespace
                height += rect.height
                labels.append ((rtext, rect))
                cur += len (line) + 1
        
        # Guarantee size.
        width, height = label.check_sizes (width, height)

        surface = self.draw_rect (width, height, label.state, cls, st)
        blit = surface.blit
        
        posy = label.padding
        totalheight = 0
        totalwidth = 0
        for rtext, rect in labels:
            totalheight += rect.height
            totalwidth = max (totalwidth, rect.width)
        
        # Blit all in the center using centered justification.
        posx = (width - totalwidth) / 2
        posy = (height - totalheight) / 2
        for rtext, rect in labels:
            rect.topleft = posx, posy
            posy += rect.height

        if label.align & ALIGN_TOP == ALIGN_TOP:
            posy = label.padding
            for rtext, rect in labels:
                rect.top = posy
                posy += rect.height
        
        elif label.align & ALIGN_BOTTOM == ALIGN_BOTTOM:
            posy = height - label.padding - totalheight
            for rtext, rect in labels:
                rect.top = posy
                posy += rect.height

        if label.align & ALIGN_LEFT == ALIGN_LEFT:
            for rtext, rect in labels:
                rect.left = label.padding

        elif label.align & ALIGN_RIGHT == ALIGN_RIGHT:
            right = width - label.padding
            for rtext, rect in labels:
                rect.right = right
        else:
            for rtext, rect in labels:
                rect.left = (width - rect.width) / 2
        
        for rtext, rect in labels:
            blit (rtext, rect)
            
        return surface

    def draw_button (self, button):


Generated by  Doxygen 1.6.0   Back to index