def _get_drawn_rect(self, grid, key, rect): """Replaces drawn rect if the one provided by wx is incorrect This handles merged rects including those that are partly off screen. """ rect = self.get_merged_rect(grid, key, rect) if rect is None: # Merged cell is drawn if grid.is_merged_cell_drawn(key): # Merging cell is outside view row, col, __ = key = self.get_merging_cell(grid, key) rect = grid.CellToRect(row, col) rect = self.get_merged_rect(grid, key, rect) else: return return rect
def Draw(self, grid, attr, dc, rect, row, col, isSelected, printing=False): """Draws the cell border and content""" key = row, col, grid.current_table rect = self.get_merged_rect(grid, key, rect) if rect is None: # Merged cell if grid.is_merged_cell_drawn(key): row, col, __ = key = self.get_merging_cell(grid, key) rect = grid.CellToRect(row, col) rect = self.get_merged_rect(grid, key, rect) else: return lower_right_rect_extents = self.get_lower_right_rect_extents(key, rect) if isSelected: grid.selection_present = True bg = Background(grid, rect, lower_right_rect_extents, self.data_array, row, col, grid.current_table, isSelected) else: width, height = rect.width, rect.height bg_components = [ "bgcolor", "borderwidth_bottom", "borderwidth_right", "bordercolor_bottom", "bordercolor_right" ] if grid._view_frozen: bg_components += ['frozen'] bg_components += [lower_right_rect_extents] bg_key = tuple([width, height] + [self.data_array.cell_attributes[key][bgc] for bgc in bg_components[:-1]] + \ [bg_components[-1]]) try: bg = self.backgrounds[bg_key] except KeyError: if len(self.backgrounds) > 10000: # self.backgrounds may grow quickly self.backgrounds = {} bg = self.backgrounds[bg_key] = \ Background(grid, rect, lower_right_rect_extents, self.data_array, *key) dc.Blit(rect.x, rect.y, rect.width, rect.height, bg.dc, 0, 0, wx.COPY) # Check if the dc is drawn manually be a return func try: res = self.data_array[row, col, grid.current_table] except IndexError: return if isinstance(res, types.FunctionType): # Add func_dict attribute # so that we are sure that it uses a dc try: res(grid, attr, dc, rect) except TypeError: pass elif isinstance(res, wx._gdi.Bitmap): # A bitmap is returned --> Draw it! self.draw_bitmap(dc, res, rect, grid, key) elif isinstance(res, matplotlib.pyplot.Figure): # A matplotlib figure is returned --> Draw it! self.draw_matplotlib_figure(dc, res, rect, grid, key) elif res is not None: self.draw_text_label(dc, res, rect, grid, key) if grid.actions.cursor[:2] == (row, col): self.update_cursor(dc, grid, row, col)
def Draw(self, grid, attr, dc, rect, row, col, isSelected, printing=False): """Draws the cell border and content""" key = row, col, grid.current_table rect = self.get_merged_rect(grid, key, rect) if rect is None: # Merged cell if grid.is_merged_cell_drawn(key): row, col, __ = key = self.get_merging_cell(grid, key) rect = grid.CellToRect(row, col) rect = self.get_merged_rect(grid, key, rect) else: return if isSelected: grid.selection_present = True bg = Background(grid, rect, self.data_array, row, col, grid.current_table, isSelected) else: width, height = rect.width, rect.height bg_components = ["bgcolor", "borderwidth_bottom", "borderwidth_right", "bordercolor_bottom", "bordercolor_right"] bg_key = tuple([width, height] + [self.data_array.cell_attributes[key][bgc] for bgc in bg_components]) try: bg = self.backgrounds[bg_key] except KeyError: if len(self.backgrounds) > 10000: # self.backgrounds may grow quickly self.backgrounds = {} bg = self.backgrounds[bg_key] = \ Background(grid, rect, self.data_array, *key) if "__WXGTK__" in wx.PlatformInfo and not printing: mask_type = wx.AND else: mask_type = wx.COPY dc.Blit(rect.x, rect.y, rect.width, rect.height, bg.dc, 0, 0, mask_type) # Check if the dc is drawn manually be a return func res = self.data_array[row, col, grid.current_table] if isinstance(res, types.FunctionType): # Add func_dict attribute # so that we are sure that it uses a dc try: res(grid, attr, dc, rect) except TypeError: pass elif isinstance(res, wx._gdi.Bitmap): # A bitmap is returned --> Draw it! self.draw_bitmap(dc, res, rect, grid, key) elif isinstance(res, matplotlib.pyplot.Figure): # A matplotlib figure is returned --> Draw it! self.draw_matplotlib_figure(dc, res, rect, grid, key) elif res is not None: self.draw_text_label(dc, res, rect, grid, key) if grid.actions.cursor[:2] == (row, col): self.update_cursor(dc, grid, row, col)