Ejemplo n.º 1
0
    def Draw(self, grid, attr, dc, rect, row, col, isSelected):
        if (isSelected):
            color = grid.GetSelectionBackground()
        else:
            color = attr.GetBackgroundColour()

        self.ColorDraw(dc, rect, color)
Ejemplo n.º 2
0
    def Draw(self, grid, attr, dc, rect, row, col, isSelected):
        """
        Takes care of drawing everything in the cell; aligns the text
        """
        text = grid.GetCellValue(row, col)
        (align, text) = self._getvalue(row, col)
        if isSelected:
            bg = grid.GetSelectionBackground()
        else:
            bg = ["white", (240, 240, 240)][row%2]
        dc.SetTextBackground(bg)
        dc.SetBrush(wx.Brush(bg, wx.SOLID))
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.SetFont(attr.GetFont())
        dc.DrawRectangleRect(rect)
        dc.SetClippingRect(rect)
        # Format the text
        if align == -1: # left alignment
            (width, height) = dc.GetTextExtent(str(text))
            x = rect[0]+1
            y = rect[1]+0.5*(rect[3]-height)

            for (style, part) in text:
                if isSelected:
                    fg = grid.GetSelectionForeground()
                else:
                    fg = self.colormap[style.fg]
                dc.SetTextForeground(fg)
                (w, h) = dc.GetTextExtent(part)
                dc.DrawText(part, x, y)
                x += w
        elif align == 0: # center alignment
            (width, height) = dc.GetTextExtent(str(text))
            x = rect[0]+0.5*(rect[2]-width)
            y = rect[1]+0.5*(rect[3]-height)
            for (style, part) in text:
                if isSelected:
                    fg = grid.GetSelectionForeground()
                else:
                    fg = self.colormap[style.fg]
                dc.SetTextForeground(fg)
                (w, h) = dc.GetTextExtent(part)
                dc.DrawText(part, x, y)
                x += w
        else:  # right alignment
            (width, height) = dc.GetTextExtent(str(text))
            x = rect[0]+rect[2]-1
            y = rect[1]+0.5*(rect[3]-height)
            for (style, part) in reversed(text):
                (w, h) = dc.GetTextExtent(part)
                x -= w
                if isSelected:
                    fg = grid.GetSelectionForeground()
                else:
                    fg = self.colormap[style.fg]
                dc.SetTextForeground(fg)
                dc.DrawText(part, x, y)
        dc.DestroyClippingRegion()
Ejemplo n.º 3
0
    def Draw(self, grid, attr, dc, rect, row, col, isSelected):
        text = grid.GetCellValue(row, col)
        hAlign, vAlign = attr.GetAlignment()
        dc.SetFont(attr.GetFont())
        if isSelected:
            bg = grid.GetSelectionBackground()
            fg = grid.GetSelectionForeground()
        else:
            bg = random.choice(["pink", "sky blue", "cyan", "yellow", "plum"])
            fg = attr.GetTextColour()

        dc.SetTextBackground(bg)
        dc.SetTextForeground(fg)
        dc.SetBrush(wx.Brush(bg, wx.SOLID))
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.DrawRectangleRect(rect)
        grid.DrawTextRectangle(dc, text, rect, hAlign, vAlign)
Ejemplo n.º 4
0
 def Draw(self, grid, attr, dc, rect, row, col, isSelected):
     text = grid.GetCellValue(row, col)
     dc.SetFont(attr.GetFont())
     suggest_width = grid.GetColSize(col)
     text = self._wordwrap(text, suggest_width, dc, breakLongWords=False)
     hAlign, vAlign = attr.GetAlignment()
     if isSelected:
         bg = grid.GetSelectionBackground()
         fg = grid.GetSelectionForeground()
     else:
         bg = attr.GetBackgroundColour()
         fg = attr.GetTextColour()
     dc.SetTextBackground(bg)
     dc.SetTextForeground(fg)
     dc.SetBrush(wx.Brush(bg, wx.SOLID))
     dc.SetPen(wx.TRANSPARENT_PEN)
     dc.DrawRectangle(rect)
     grid.DrawTextRectangle(dc, text, rect, hAlign, vAlign)
Ejemplo n.º 5
0
 def Draw(self, grid, attr, dc, rect, row, col, isSelected):
     text = grid.GetCellValue(row, col)
     hAlign, vAlign = attr.GetAlignment()
     dc.SetFont(attr.GetFont())
     if isSelected:
         bg = grid.GetSelectionBackground()
         fg = grid.GetSelectionForeground()
     else:
         bg = attr.GetBackgroundColour()
         fg = attr.GetTextColour()
     dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height)
     dc.SetTextBackground(bg)
     dc.SetTextForeground(fg)
     dc.SetBrush(wx.Brush(bg, wx.SOLID))
     dc.SetPen(wx.TRANSPARENT_PEN)
     dc.DrawRectangleRect(rect)
     wx.lib.fancytext.RenderToDC(text, dc, rect.x + 2, rect.y + 2)
     dc.DestroyClippingRegion()
Ejemplo n.º 6
0
    def Draw(self, grid, attr, dc, rect, row, col, isSelected):
        text = grid.GetCellValue(row, col)
        prog = 0
        try:
            prog = float(ProgressCellRenderer.re_percent.search(text).group(1))
        except:
            pass

        if prog > 100:
            prog = 100

        total_width = rect.width
        units = int(float(prog / 100.0) * rect.width)

        prog_rect = wx.Rect(rect.x, rect.y, units, rect.height)
        other_rect = wx.Rect(rect.x + units, rect.y,
                             rect.width - prog_rect.width, rect.height)
        hAlign, vAlign = attr.GetAlignment()

        dc.SetFont(attr.GetFont())

        if isSelected:
            bg = grid.GetSelectionBackground()
        else:
            bg = wx.Colour(255, 255, 255)

        dc.SetBrush(wx.Brush(self.progColor, wx.SOLID))
        #dc.SetPen(wx.BLACK_PEN)
        dc.DrawRectangleRect(prog_rect)

        # This fills in the rest of the cell background so it doesn't shear
        dc.SetBrush(wx.Brush(bg, wx.SOLID))
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.DrawRectangleRect(other_rect)

        dc.SetTextForeground(wx.Colour(0, 0, 0))
        grid.DrawTextRectangle(dc, text, rect, hAlign, vAlign)