def _draw_legend(self, categories): """ Draw legend for the given categories. Box in lower left corner: +----------+ | Name O | | Name O | +----------+ """ num_categories = len(categories) if num_categories == 0: return def calc_sizes(dc): """Return (width, height, item_height).""" width = 0 height = INNER_PADDING item_heights = 0 for cat in categories: tw, th = self.dc.GetTextExtent(cat.name) height = height + th + INNER_PADDING item_heights += th if tw > width: width = tw item_height = item_heights / num_categories return (width + 4 * INNER_PADDING + item_height, height, item_height) self.dc.SetFont(self.small_text_font) self.dc.SetTextForeground((0, 0, 0)) width, height, item_height = calc_sizes(self.dc) # Draw big box self.dc.SetBrush(self.white_solid_brush) self.dc.SetPen(self.black_solid_pen) box_rect = (OUTER_PADDING, self.metrics.height - height - OUTER_PADDING, width, height) if 'phoenix' in wx.PlatformInfo: self.dc.DrawRectangle(box_rect) else : self.dc.DrawRectangleRect(box_rect) # Draw text and color boxes cur_y = self.metrics.height - height - OUTER_PADDING + INNER_PADDING for cat in categories: base_color = cat.color border_color = drawing.darken_color(base_color) self.dc.SetBrush(wx.Brush(base_color, wx.SOLID)) self.dc.SetPen(wx.Pen(border_color, 1, wx.SOLID)) color_box_rect = (OUTER_PADDING + width - item_height - INNER_PADDING, cur_y, item_height, item_height) if 'phoenix' in wx.PlatformInfo: self.dc.DrawRectangle(color_box_rect) else : self.dc.DrawRectangleRect(color_box_rect) self.dc.DrawText(cat.name, OUTER_PADDING + INNER_PADDING, cur_y) cur_y = cur_y + item_height + INNER_PADDING
def _draw_legend(self, categories): """ Draw legend for the given categories. Box in lower left corner: +----------+ | Name O | | Name O | +----------+ """ num_categories = len(categories) if num_categories == 0: return def calc_sizes(dc): """Return (width, height, item_height).""" width = 0 height = INNER_PADDING item_heights = 0 for cat in categories: tw, th = self.dc.GetTextExtent(cat.name) height = height + th + INNER_PADDING item_heights += th if tw > width: width = tw item_height = item_heights / num_categories return (width + 4 * INNER_PADDING + item_height, height, item_height) self.dc.SetFont(self.small_text_font) self.dc.SetTextForeground((0, 0, 0)) width, height, item_height = calc_sizes(self.dc) # Draw big box self.dc.SetBrush(self.white_solid_brush) self.dc.SetPen(self.black_solid_pen) box_rect = (OUTER_PADDING, self.metrics.height - height - OUTER_PADDING, width, height) self.dc.DrawRectangleRect(box_rect) # Draw text and color boxes cur_y = self.metrics.height - height - OUTER_PADDING + INNER_PADDING for cat in categories: base_color = cat.color border_color = drawing.darken_color(base_color) self.dc.SetBrush(wx.Brush(base_color, wx.SOLID)) self.dc.SetPen(wx.Pen(border_color, 1, wx.SOLID)) color_box_rect = (OUTER_PADDING + width - item_height - INNER_PADDING, cur_y, item_height, item_height) self.dc.DrawRectangleRect(color_box_rect) self.dc.DrawText(cat.name, OUTER_PADDING + INNER_PADDING, cur_y) cur_y = cur_y + item_height + INNER_PADDING
def _draw_events(self): """Draw all event boxes and the text inside them.""" self.dc.SetFont(self.small_text_font) self.dc.SetTextForeground((0, 0, 0)) for (event, rect) in self.event_data: # Ensure that we can't draw outside rectangle self.dc.DestroyClippingRegion() self.dc.SetClippingRect(rect) # Draw the box self.dc.SetBrush(self._get_box_brush(event)) self.dc.SetPen(self._get_box_pen(event)) self.dc.DrawRectangleRect(rect) # Ensure that we can't draw content outside inner rectangle self.dc.DestroyClippingRegion() rect_copy = wx.Rect(*rect) rect_copy.Deflate(INNER_PADDING, INNER_PADDING) self.dc.SetClippingRect(rect_copy) if rect_copy.Width > 0: # Draw the text (if there is room for it) text_x = rect.X + INNER_PADDING text_y = rect.Y + INNER_PADDING if text_x < INNER_PADDING: text_x = INNER_PADDING self.dc.DrawText(event.text, text_x, text_y) # Draw data contents indicator self.dc.DestroyClippingRegion() self.dc.SetClippingRect(rect) if event.has_data(): self._draw_contents_indicator(event, rect) # Draw selection and handles if event.selected: small_rect = wx.Rect(*rect) small_rect.Deflate(1, 1) border_color = self._get_border_color(event) border_color = drawing.darken_color(border_color) pen = wx.Pen(border_color, 1, wx.SOLID) self.dc.SetBrush(wx.TRANSPARENT_BRUSH) self.dc.SetPen(pen) self.dc.DrawRectangleRect(small_rect) self._draw_handles(rect) # Reset this when we are done self.dc.DestroyClippingRegion()
def _get_box_indicator_brush(self, event): base_color = self._get_base_color(event) darker_color = drawing.darken_color(base_color, 0.6) brush = wx.Brush(darker_color, wx.SOLID) return brush
def _get_border_color(self, event): base_color = self._get_base_color(event) border_color = drawing.darken_color(base_color) return border_color