def get_merged_rect(self, grid, key, rect): """Returns cell rect for normal or merged cells and None for merged""" row, col, tab = key # Check if cell is merged: cell_attributes = grid.code_array.cell_attributes merge_area = cell_attributes[(row, col, tab)]["merge_area"] if merge_area is None: return rect else: # We have a merged cell top, left, bottom, right = merge_area # Are we drawing the top left cell? if top == row and left == col: # Set rect to merge area ul_rect = grid.CellToRect(row, col) br_rect = grid.CellToRect(bottom, right) width = br_rect.x - ul_rect.x + br_rect.width height = br_rect.y - ul_rect.y + br_rect.height rect = wx.Rect(ul_rect.x, ul_rect.y, width, height) return rect
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_cursor(self, dc, grid, row, col, pen=None, brush=None): """Draws cursor as Rectangle in lower right corner""" # If in full screen mode draw no cursor if grid.main_window.IsFullScreen(): return key = row, col, grid.current_table rect = grid.CellToRect(row, col) rect = self.get_merged_rect(grid, key, rect) # Check if cell is invisible if rect is None: return size = self.get_zoomed_size(1.0) caret_length = int(min([rect.width, rect.height]) / 5.0) color = get_color(config["text_color"]) if pen is None: pen = wx.Pen(color) if brush is None: brush = wx.Brush(color) pen.SetWidth(size) # Inner right and lower borders border_left = rect.x + size - 1 border_right = rect.x + rect.width - size - 1 border_upper = rect.y + size - 1 border_lower = rect.y + rect.height - size - 1 points_lr = [ (border_right, border_lower - caret_length), (border_right, border_lower), (border_right - caret_length, border_lower), (border_right, border_lower), ] points_ur = [ (border_right, border_upper + caret_length), (border_right, border_upper), (border_right - caret_length, border_upper), (border_right, border_upper), ] points_ul = [ (border_left, border_upper + caret_length), (border_left, border_upper), (border_left + caret_length, border_upper), (border_left, border_upper), ] points_ll = [ (border_left, border_lower - caret_length), (border_left, border_lower), (border_left + caret_length, border_lower), (border_left, border_lower), ] point_list = [points_lr, points_ur, points_ul, points_ll] dc.DrawPolygonList(point_list, pens=pen, brushes=brush) self.old_cursor_row_col = 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 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_cursor(self, dc, grid, row, col, pen=wx.BLACK_PEN, brush=wx.BLACK_BRUSH): """Draws cursor as Rectangle in lower right corner""" key = row, col, grid.current_table rect = grid.CellToRect(row, col) rect = self.get_merged_rect(grid, key, rect) # Check if cell is invisible if rect is None: return size = self.get_zoomed_size(1.0) caret_length = int(min([rect.width, rect.height]) / 5.0) pen.SetWidth(size) # Inner right and lower borders border_left = rect.x border_right = rect.x + rect.width - size - 1 border_upper = rect.y border_lower = rect.y + rect.height - size - 1 points_lr = [ (border_right, border_lower - caret_length), (border_right, border_lower), (border_right - caret_length, border_lower), (border_right, border_lower), ] points_ur = [ (border_right, border_upper + caret_length), (border_right, border_upper), (border_right - caret_length, border_upper), (border_right, border_upper), ] points_ul = [ (border_left, border_upper + caret_length), (border_left, border_upper), (border_left + caret_length, border_upper), (border_left, border_upper), ] points_ll = [ (border_left, border_lower - caret_length), (border_left, border_lower), (border_left + caret_length, border_lower), (border_left, border_lower), ] point_list = [points_lr, points_ur, points_ul, points_ll] dc.DrawPolygonList(point_list, pens=pen, brushes=brush) self.old_cursor_row_col = row, col