def __init__(self): # Fonts and pens we use when drawing self.header_font = drawing.get_default_font(12, True) self.small_text_font = drawing.get_default_font(8) self.red_solid_pen = wx.Pen(wx.Colour(255,0, 0), 1, wx.SOLID) self.black_solid_pen = wx.Pen(wx.Colour(0, 0, 0), 1, wx.SOLID) self.darkred_solid_pen = wx.Pen(wx.Colour(200, 0, 0), 1, wx.SOLID) self.black_dashed_pen = wx.Pen(wx.Colour(200, 200, 200), 1, wx.USER_DASH) self.black_dashed_pen.SetDashes([2, 2]) self.black_dashed_pen.SetCap(wx.CAP_BUTT) self.grey_solid_pen = wx.Pen(wx.Colour(200, 200, 200), 1, wx.SOLID) self.white_solid_brush = wx.Brush(wx.Colour(255, 255, 255), wx.SOLID) self.black_solid_brush = wx.Brush(wx.Colour(0, 0, 0), wx.SOLID) self.lightgrey_solid_brush = wx.Brush(wx.Colour(230, 230, 230), wx.SOLID) self.DATA_ICON_WIDTH = 5
def __init__(self): # Fonts and pens we use when drawing self.header_font = drawing.get_default_font(12, True) self.small_text_font = drawing.get_default_font(8) self.red_solid_pen = wx.Pen(wx.Colour(255,0, 0), 1, wx.SOLID) self.black_solid_pen = wx.Pen(wx.Colour(0, 0, 0), 1, wx.SOLID) self.darkred_solid_pen = wx.Pen(wx.Colour(200, 0, 0), 1, wx.SOLID) self.black_dashed_pen = wx.Pen(wx.Colour(200, 200, 200), 1, wx.USER_DASH) self.black_dashed_pen.SetDashes([2, 2]) self.black_dashed_pen.SetCap(wx.CAP_BUTT) self.grey_solid_pen = wx.Pen(wx.Colour(200, 200, 200), 1, wx.SOLID) self.white_solid_brush = wx.Brush(wx.Colour(255, 255, 255), wx.SOLID) self.black_solid_brush = wx.Brush(wx.Colour(0, 0, 0), wx.SOLID) self.lightgrey_solid_brush = wx.Brush(wx.Colour(230, 230, 230), wx.SOLID) self.DATA_ICON_WIDTH = 5
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_ballon(self, event, event_rect): """Draw one ballon on a selected event that has 'description' data.""" # Constants MAX_TEXT_WIDTH = 200 MIN_WIDTH = 100 inner_rect_w = 0 inner_rect_h = 0 # Icon (iw, ih) = (0, 0) icon = event.get_data("icon") if icon != None: (iw, ih) = icon.Size inner_rect_w = iw inner_rect_h = ih # Text self.dc.SetFont(drawing.get_default_font(8)) font_h = self.dc.GetCharHeight() (tw, th) = (0, 0) description = event.get_data("description") lines = None if description != None: lines = break_text(description, self.dc, MAX_TEXT_WIDTH) th = len(lines) * self.dc.GetCharHeight() for line in lines: (lw, lh) = self.dc.GetTextExtent(line) tw = max(lw, tw) if icon != None: inner_rect_w += BALLOON_RADIUS inner_rect_w += min(tw, MAX_TEXT_WIDTH) inner_rect_h = max(inner_rect_h, th) inner_rect_w = max(MIN_WIDTH, inner_rect_w) # Calcule la position X du balloon x_balloon = event_rect.X + 20 if event_rect.X < 40 : x_balloon = 40 x, y = self._draw_balloon_bg(self.dc, (inner_rect_w, inner_rect_h), #(event_rect.X + event_rect.Width / 2, event_rect.Y), (x_balloon, event_rect.Y), True) if icon != None: self.dc.DrawBitmap(icon, x, y, False) x += iw + BALLOON_RADIUS if lines != None: ty = y for line in lines: self.dc.DrawText(line, x, ty) ty += font_h x += tw
def _draw_ballon(self, event, event_rect): """Draw one ballon on a selected event that has 'description' data.""" # Constants MAX_TEXT_WIDTH = 200 MIN_WIDTH = 100 inner_rect_w = 0 inner_rect_h = 0 # Icon (iw, ih) = (0, 0) icon = event.get_data("icon") if icon != None: (iw, ih) = icon.Size inner_rect_w = iw inner_rect_h = ih # Text self.dc.SetFont(drawing.get_default_font(8)) font_h = self.dc.GetCharHeight() (tw, th) = (0, 0) description = event.get_data("description") lines = None if description != None: lines = break_text(description, self.dc, MAX_TEXT_WIDTH) th = len(lines) * self.dc.GetCharHeight() for line in lines: (lw, lh) = self.dc.GetTextExtent(line) tw = max(lw, tw) if icon != None: inner_rect_w += BALLOON_RADIUS inner_rect_w += min(tw, MAX_TEXT_WIDTH) inner_rect_h = max(inner_rect_h, th) inner_rect_w = max(MIN_WIDTH, inner_rect_w) x, y = self._draw_balloon_bg(self.dc, (inner_rect_w, inner_rect_h), (event_rect.X + event_rect.Width / 2, event_rect.Y), True) if icon != None: self.dc.DrawBitmap(icon, x, y, False) x += iw + BALLOON_RADIUS if lines != None: ty = y for line in lines: self.dc.DrawText(line, x, ty) ty += font_h x += tw
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 _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
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