Ejemplo n.º 1
0
    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.
        """
        text = grid.GetCellValue(row, col)

        _font = attr.GetFont()
        dc.SetFont(_font)

        if len(text) == 0:
            return dc.GetTextExtent("  ")  # self.default_width

        w, h = dc.GetTextExtent(text)
        if self.auto_fit:
            col_width = min(w, self.max_width)
        else:
            col_width = min(w, self.default_width)
        row_height = h
        if self.word_wrap:
            suggest_width = max(grid.GetColSize(col), col_width)
            text = self._wordwrap(text,
                                  suggest_width,
                                  dc,
                                  breakLongWords=False)
            w, h = dc.GetMultiLineTextExtent(text)
            row_height = h
            if self.auto_fit:
                col_width = min(w, col_width)
            else:
                col_width = min(w, self.default_width)
        # do not shrink col size (subtract col margin which is 10 pixels )
        col_width = max(grid.GetColSize(col) - 10, col_width)
        return wx.Size(col_width, row_height)
Ejemplo n.º 2
0
    def __init__(self,
                 parent,
                 grid,
                 format=[],
                 total_col=None,
                 total_row=None,
                 rowLabels=True,
                 colLabels=True):
        if total_row is None:
            total_row = grid.GetNumberRows()
        if total_col is None:
            total_col = grid.GetNumberCols()

        self.total_row = total_row
        self.total_col = total_col
        self.grid = grid
        self.rowLabels = rowLabels
        self.colLabels = colLabels

        data = []
        for row in range(total_row):
            row_val = []
            if rowLabels:
                row_val.append(grid.GetRowLabelValue(row))

            for col in range(total_col):
                try:
                    row_val.append(grid.GetCellValueAsString(row, col))
                except:
                    row_val.append(grid.GetCellValue(row, col))
            data.append(row_val)

        if colLabels:
            label = [""] if rowLabels else []
            for col in range(total_col):
                value = grid.GetColLabelValue(col)
                label.append(value)

        d = float(grid.GetColSize(0))
        if format == []:
            if rowLabels:
                format.append(grid.GetRowLabelSize())
            for col in range(total_col):
                col_size = grid.GetColSize(col)
                #print("Column size:", col,'\t',col_size)
                format.append(col_size)

        self.table = PrintTable(parent, rowLabels, colLabels)
        if colLabels: self.table.label = label
        self.table.cell_left_margin = 0.0
        self.table.cell_right_margin = 0.0

        self.table.set_column = format
        self.table.data = data
Ejemplo n.º 3
0
    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.
        """
        text = grid.GetCellValue(row, col)
        dc.SetFont(attr.GetFont())

        w, h = dc.GetTextExtent('00')  # use 2 digits for size reference
        if self.auto_fit:
            grid.SetRowMinimalAcceptableHeight(h + h / 2)
            grid.SetColMinimalAcceptableWidth(w + w / 2)

        w, h = dc.GetTextExtent(text)
        if self.auto_fit:
            col_width = min(w, self.max_width)
        else:
            col_width = min(w, self.default_width)

        if self.word_wrap:
            suggest_width = max(grid.GetColSize(col), col_width)
            text = self._wordwrap(text,
                                  suggest_width,
                                  dc,
                                  breakLongWords=True,
                                  margin=1)
            w, h = dc.GetMultiLineTextExtent(text)
            if self.auto_fit:
                col_width = min(w, col_width)
            else:
                col_width = min(w, self.default_width)
        row_height = h
        return wx.Size(col_width, row_height)
Ejemplo n.º 4
0
 def on_column_resize(self, event):
     grid = self.grid
     col = event.GetRowOrCol()
     width = grid.GetColSize(col)
     table = grid.GetTable()
     self.column_size[col] = int(width * 1.1) / grid.CharWidth
     tm = wx.grid.GridTableMessage(
         self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
     grid.ProcessTableMessage(tm)
     grid.ForceRefresh()
Ejemplo n.º 5
0
    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.
        """
        text = grid.GetCellValue(row, col)

        _font = attr.GetFont()
        dc.SetFont(_font)

        if len(text) == 0:
            return dc.GetTextExtent("  ")  # self.default_width

        w, h = dc.GetTextExtent(text + " ")

        if self.auto_fit:
            suggest_width = grid.GetColSize(col)

        if self.word_wrap:
            if self.auto_fit:
                col_width = min(w, self.max_width)
                suggest_width = grid.GetColSize(col)
            else:
                col_width = self.default_width
                suggest_width = col_width
            text = wordwrap.wordwrap(text,
                                     suggest_width,
                                     dc,
                                     breakLongWords=False)
            w, h = dc.GetMultiLineTextExtent(text)
            row_height = h
        else:
            row_height = h
            if self.auto_fit:
                col_width = min(w, self.max_width)
            else:
                col_width = min(w, grid.GetColSize(col))

        return wx.Size(col_width, row_height)
Ejemplo n.º 6
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.º 7
0
    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.
        """
        text = grid.GetCellValue(row, col)

        _font = attr.GetFont()
        dc.SetFont(_font)

        col_width = grid.GetColSize(col)
        # margin = 2  # get border width into account when submitting optimal col size
        margin = 0
        w, h = _font.GetPixelSize()
        if len(text) > 0:
            w_sz = w * len(text) + 2 * w
        else:
            return wx.Size(2 * w, h)  # self.default_width

        if self.auto_fit:
            col_width = min(w_sz, col_width)
            if col_width > self.max_width:
                col_width = self.max_width
        else:
            col_width = min(w_sz, self.default_width)

        if self.word_wrap:
            text = wordwrap.wordwrap(text,
                                     col_width,
                                     dc,
                                     breakLongWords=False,
                                     margin=margin)
            w, h = dc.GetMultiLineTextExtent(text)
        else:
            w = col_width
        if self.auto_fit:
            if w_sz > self.max_width:
                w_sz = self.max_width
            w = max(w, w_sz)
        else:
            return wx.Size(self.default_width, h)
        return wx.Size(w, h)
Ejemplo n.º 8
0
 def fit_col_width(self):
     grid = self.getGrid()
     w, h = grid.GetClientSize()
     d = w - grid.GetRowLabelSize()-grid.GetColSize(1) - grid.GetColSize(0)
     grid.SetColSize(2, max([d, 80]))
Ejemplo n.º 9
0
 def resize_grid_to_fill_white_space(self, grid):
     col_size = grid.GetColSize(0)
     C, R = grid.GetSize()
     if C - col_size > 0:
         grid.SetColSize(1, C - col_size)