def test_get_pen_from_data(pendata, width, color): """Unit test for get_pen_from_data""" pen = get_pen_from_data(pendata) assert pen.GetColour() == color assert pen.GetWidth() == width
def draw_border_lines(self, dc): """Draws lines""" x, y, w, h = 0, 0, self.rect.width - 1, self.rect.height - 1 row, col, tab = key = self.key cell_attributes = self.data_array.cell_attributes # Get borderpens and bgbrushes for rects # Each cell draws its bottom and its right line only bottomline = x, y + h, x + w, y + h rightline = x + w, y, x + w, y + h lines = [bottomline, rightline] # Bottom line pen color = cell_attributes[key]["bordercolor_bottom"] width = cell_attributes[key]["borderwidth_bottom"] bottom_pen = get_pen_from_data((color, width, int(wx.SOLID))) # Right line pen color = cell_attributes[key]["bordercolor_right"] width = cell_attributes[key]["borderwidth_right"] right_pen = get_pen_from_data((color, width, int(wx.SOLID))) borderpens = [bottom_pen, right_pen] # Topmost line if in topmost cell if row == 0: lines.append((x, y, x + w, y)) topkey = -1, col, tab color = cell_attributes[topkey]["bordercolor_bottom"] width = cell_attributes[topkey]["borderwidth_bottom"] top_pen = get_pen_from_data((color, width, int(wx.SOLID))) borderpens.append(top_pen) # Leftmost line if in leftmost cell if col == 0: lines.append((x, y, x, y + h)) leftkey = row, -1, tab color = cell_attributes[leftkey]["bordercolor_bottom"] width = cell_attributes[leftkey]["borderwidth_bottom"] left_pen = get_pen_from_data((color, width, int(wx.SOLID))) borderpens.append(left_pen) zoomed_pens = [] get_zoomed_size = self.grid.grid_renderer.get_zoomed_size for pen in borderpens: bordercolor = pen.GetColour() borderwidth = pen.GetWidth() borderstyle = pen.GetStyle() zoomed_borderwidth = get_zoomed_size(borderwidth) zoomed_pen = wx.Pen(bordercolor, zoomed_borderwidth, borderstyle) zoomed_pen.SetJoin(wx.JOIN_MITER) zoomed_pens.append(zoomed_pen) dc.DrawLineList(lines, zoomed_pens) # end of class Background
def draw_border_lines(self, dc): """Draws lines""" x, y, w, h = 0, 0, self.rect.width - 1, self.rect.height - 1 row, col, tab = key = self.key cell_attributes = self.data_array.cell_attributes # Get borderpens and bgbrushes for rects # Each cell draws its bottom and its right line only bottomline = x, y + h, x + w, y + h rightline = x + w, y, x + w, y + h lines = [bottomline, rightline] # Bottom line pen bottom_color = cell_attributes[key]["bordercolor_bottom"] bottom_width = cell_attributes[key]["borderwidth_bottom"] bottom_pen = get_pen_from_data( (bottom_color, bottom_width, int(wx.SOLID))) # Right line pen right_color = cell_attributes[key]["bordercolor_right"] right_width = cell_attributes[key]["borderwidth_right"] right_pen = get_pen_from_data( (right_color, right_width, int(wx.SOLID))) borderpens = [bottom_pen, right_pen] # If 0 width then no border is drawn if bottom_width == 0: borderpens.pop(0) lines.pop(0) if right_width == 0: borderpens.pop(-1) lines.pop(-1) # Topmost line if in topmost cell if row == 0: lines.append((x, y, x + w, y)) topkey = -1, col, tab color = cell_attributes[topkey]["bordercolor_bottom"] width = cell_attributes[topkey]["borderwidth_bottom"] top_pen = get_pen_from_data((color, width, int(wx.SOLID))) borderpens.append(top_pen) # Leftmost line if in leftmost cell if col == 0: lines.append((x, y, x, y + h)) leftkey = row, -1, tab color = cell_attributes[leftkey]["bordercolor_bottom"] width = cell_attributes[leftkey]["borderwidth_bottom"] left_pen = get_pen_from_data((color, width, int(wx.SOLID))) borderpens.append(left_pen) zoomed_pens = [] get_zoomed_size = self.grid.grid_renderer.get_zoomed_size for pen in borderpens: bordercolor = pen.GetColour() borderwidth = pen.GetWidth() borderstyle = pen.GetStyle() zoomed_borderwidth = get_zoomed_size(borderwidth) zoomed_pen = wx.Pen(bordercolor, zoomed_borderwidth, borderstyle) zoomed_pen.SetJoin(wx.JOIN_MITER) zoomed_pens.append(zoomed_pen) dc.DrawLineList(lines, zoomed_pens) # Draw lower right rectangle if # 1) the next cell to the right has a greater bottom width and # 2) the next cell to the bottom has a greater right width if self.lower_right_rect_extents is not None: rx, ry, rw, rh = self.lower_right_rect_extents rwz = get_zoomed_size(rw) rhz = get_zoomed_size(rh) rxz = round(rx + rw - rwz / 2.0) ryz = round(ry + rh - rhz / 2.0) rect = wx.Rect(rxz, ryz, rwz, rhz) # The color of the lower right rectangle is the color of the # bottom line of the next cell to the right rightkey = row, col + 1, tab lr_color = wx.Colour() lr_color.SetRGB(cell_attributes[rightkey]["bordercolor_bottom"]) lr_brush = wx.Brush(lr_color, wx.SOLID) dc.SetPen(wx.TRANSPARENT_PEN) dc.SetBrush(lr_brush) dc.DrawRectangle(*rect)