24 def __init__(self, default_width, max_width, auto_fit, word_wrap=True):
25 wx.grid.GridCellRenderer.__init__(self)
34 def _wordwrap(self, text, width, dc, breakLongWords=True, margin=0):
36 text = text.split(
'\n')
38 pte = dc.GetPartialTextExtents(line)
39 wid = (width - (2 * margin + 1) * dc.GetTextExtent(
' ')[0])
44 while idx < len(line):
50 if pte[idx] - start > wid
and (spcIdx != -1
or breakLongWords):
52 idx = min(spcIdx + 1, len(pte) - 1)
53 wrapped_lines.append(
' ' * margin + line[startIdx: idx] +
' ' * margin)
60 wrapped_lines.append(
' ' * margin + line[startIdx: idx] +
' ' * margin)
62 return '\n'.join(wrapped_lines)
64 def Draw(self, grid, attr, dc, rect, row, col, isSelected):
65 text = grid.GetCellValue(row, col)
66 dc.SetFont(attr.GetFont())
67 suggest_width = grid.GetColSize(col)
68 text = self.
_wordwrap_wordwrap(text, suggest_width, dc, breakLongWords=
False)
69 hAlign, vAlign = attr.GetAlignment()
71 bg = grid.GetSelectionBackground()
72 fg = grid.GetSelectionForeground()
74 bg = attr.GetBackgroundColour()
75 fg = attr.GetTextColour()
76 dc.SetTextBackground(bg)
77 dc.SetTextForeground(fg)
78 dc.SetBrush(wx.Brush(bg, wx.SOLID))
79 dc.SetPen(wx.TRANSPARENT_PEN)
80 dc.DrawRectangle(rect)
81 grid.DrawTextRectangle(dc, text, rect, hAlign, vAlign)
87 text = grid.GetCellValue(row, col)
88 dc.SetFont(attr.GetFont())
90 w, h = dc.GetTextExtent(
'00')
92 grid.SetRowMinimalAcceptableHeight(
int(h+h/2))
93 grid.SetColMinimalAcceptableWidth(
int(w+w/2))
95 w, h = dc.GetTextExtent(text)
97 col_width = min(w, self.
max_widthmax_width)
102 suggest_width = max(grid.GetColSize(col), col_width)
103 text = self.
_wordwrap_wordwrap(text, suggest_width, dc, breakLongWords=
False)
104 w, h = dc.GetMultiLineTextExtent(text)
106 col_width = min(w, col_width)
110 return wx.Size(col_width, row_height)
GridCellAutoWrapStringRenderer()
def _wordwrap(self, text, width, dc, breakLongWords=True, margin=0)
modification of original wordwrap function without extra space
def Draw(self, grid, attr, dc, rect, row, col, isSelected)
def __init__(self, default_width, max_width, auto_fit, word_wrap=True)
def GetBestSize(self, grid, attr, dc, row, col)
The width will be between values col size and max col size These can be changed in user preferences.
def Clone(self)
Clone(self) -> GridCellRenderer.