コード例 #1
0
ファイル: igrid.py プロジェクト: minrk/ipython-svn-archive
    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()
コード例 #2
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)
コード例 #3
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)
コード例 #4
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()