Example #1
0
    def OnPaint(self, event):
        'EVT_PAINT handling'
        dc = AutoBufferedPaintDC(self)
        rect = RectS(self.Size)

        # draw the background
        background = self.Parent.hoverbg if self.hover else self.Parent.normalbg
        background.Draw(dc, rect)

        margins = self.Parent.margins
        padding = self.Parent.padding

        # Font setup
        font = None
        sp = self.Parent.menu.spine
        sel = sp.Selection
        if sel > len(sp.items): sel = sp.Selection = -1

        if sel != -1 and sel < len(
                sp.items) and sel >= 0 and sp.items[sel].font:
            font = sp.items[sel].font
            #font.PointSize=self.Font.PointSize
        else:
            font = self.Font

        dc.Font = font
        color = self.Parent.hoverfc if self.hover else self.Parent.normalfc
        dc.TextForeground = color
        fontHeight = font.Height

        # initial cursor setup

        if self.Parent.ForceTextFieldBackground:
            self.Parent.activebg.Draw(dc, rect)

        label = self.DisplayLabel

        # Draw text if value is just a string
        if isinstance(label, basestring):
            cursor = Point(rect.x + margins.left + padding.x,
                           margins.top + padding.y)
            if not label and self.empty_text:
                text = self.empty_text
                dc.SetTextForeground(self.Parent.hintfc)
            else:
                text = label

            text_rect = Rect(cursor.x, cursor.y,
                             rect.width - cursor.x - margins.right - padding.x,
                             fontHeight)
            text_rect, text = self.music_note_hack(dc, text_rect, text,
                                                   fontHeight)
            dc.DrawTruncatedText(text.split('\n', 1)[0],
                                 text_rect,
                                 alignment=wx.ALIGN_LEFT | wx.ALIGN_TOP)

        # or draw each part of the value
        else:
            cursor = Point(rect.x + margins.left + padding.x,
                           ((rect.height - margins.top - margins.bottom) / 2) +
                           margins.top)
            if label is not None:
                for i in label.content:
                    if isinstance(i, Bitmap):
                        dc.DrawBitmapPoint(i,
                                           (cursor.x, cursor.y - i.Height / 2),
                                           True)
                        cursor += Point(i.Width + padding.x, 0)

                    elif isinstance(i, basestring):
                        dc.DrawTruncatedText(
                            i.split('\n', 1)[0],
                            wx.Rect(
                                cursor.x, cursor.y - fontHeight / 2,
                                rect.width - cursor.x - margins.right -
                                padding.x, fontHeight),
                            alignment=wx.ALIGN_LEFT | wx.ALIGN_CENTRE_VERTICAL)
                        cursor += Point(dc.GetTextExtent(i)[0] + padding.x, 0)

        # Draw a background for the textfield
        if self.txtfld.Shown:  # or self.Parent.ForceTextFieldBackground:
            #            dc.Brush = wx.Brush(self.Parent.activebg)
            #            dc.Pen   = wx.TRANSPARENT_PEN
            #
            #            dc.DrawRectangleRect(rect)
            self.Parent.activebg.Draw(dc, rect)