def get_data_func (): theme = LevelColorThemeTango () colors = dict ((level, tuple ((c.gdk_color () for c in theme.colors[level])),) for level in Data.debug_levels if level != Data.debug_level_none) def level_data_func (cell_props, level): cell_props.text = level.name[0] if level in colors: cell_colors = colors[level] else: cell_colors = (None, None, None,) cell_props.foreground_gdk = cell_colors[0] cell_props.background_gdk = cell_colors[1] return level_data_func
def __draw_offscreen(self): dirty_start, dirty_stop = self.__offscreen_dirty if dirty_start == dirty_stop: return self.__offscreen_dirty = (0, 0) width, height = self.__offscreen_size ctx = cairo.Context(self.__offscreen) # Indicator (triangle) size is 8, so we need to draw surrounding areas # a bit: dirty_start -= 8 dirty_stop += 8 dirty_start = max(dirty_start, 0) dirty_stop = min(dirty_stop, width) ctx.rectangle(dirty_start, 0., dirty_stop, height) ctx.clip() # White background rectangle. ctx.set_line_width(0.) ctx.rectangle(0, 0, width, height) ctx.set_source_rgb(1., 1., 1.) ctx.fill() ctx.new_path() # Horizontal reference lines. ctx.set_line_width(1.) ctx.set_source_rgb(.95, .95, .95) for i in range(height // 16): y = i * 16 - .5 ctx.move_to(0, y) ctx.line_to(width, y) ctx.stroke() if self.process.freq_sentinel is None: return # Vertical reference lines. pixel_step = self.find_indicative_time_step() ctx.set_source_rgb(.9, .9, .9) start = dirty_start - dirty_start % pixel_step for x in range(start + pixel_step, dirty_stop, pixel_step): ctx.move_to(x - .5, 0) ctx.line_to(x - .5, height) ctx.stroke() if not self.process.freq_sentinel.data: self.logger.debug("frequency sentinel has no data yet") return ctx.translate(dirty_start, 0.) maximum = max(self.process.freq_sentinel.data) ctx.set_source_rgb(0., 0., 0.) data = self.process.freq_sentinel.data[dirty_start:dirty_stop] self.__draw_graph(ctx, height, maximum, data) if not self.process.dist_sentinel.data: self.logger.debug("level distribution sentinel has no data yet") return colors = LevelColorThemeTango().colors dist_data = self.process.dist_sentinel.data[dirty_start:dirty_stop] def cumulative_level_counts(*levels): for level_counts in dist_data: yield sum((level_counts[level] for level in levels)) level = Data.debug_level_info levels_prev = ( Data.debug_level_trace, Data.debug_level_fixme, Data.debug_level_log, Data.debug_level_debug, ) ctx.set_source_rgb(*(colors[level][1].float_tuple())) self.__draw_graph(ctx, height, maximum, list(cumulative_level_counts(level, *levels_prev))) level = Data.debug_level_debug levels_prev = ( Data.debug_level_trace, Data.debug_level_fixme, Data.debug_level_log, ) ctx.set_source_rgb(*(colors[level][1].float_tuple())) self.__draw_graph(ctx, height, maximum, list(cumulative_level_counts(level, *levels_prev))) level = Data.debug_level_log levels_prev = ( Data.debug_level_trace, Data.debug_level_fixme, ) ctx.set_source_rgb(*(colors[level][1].float_tuple())) self.__draw_graph(ctx, height, maximum, list(cumulative_level_counts(level, *levels_prev))) level = Data.debug_level_fixme levels_prev = (Data.debug_level_trace, ) ctx.set_source_rgb(*(colors[level][1].float_tuple())) self.__draw_graph(ctx, height, maximum, list(cumulative_level_counts(level, *levels_prev))) level = Data.debug_level_trace ctx.set_source_rgb(*(colors[level][1].float_tuple())) self.__draw_graph(ctx, height, maximum, [counts[level] for counts in dist_data]) # Draw error and warning triangle indicators: def triangle(ctx, size=8): ctx.move_to(-size // 2, 0) ctx.line_to((size + 1) // 2, 0) ctx.line_to(0, size / 1.41) ctx.close_path() for level in ( Data.debug_level_warning, Data.debug_level_error, ): ctx.set_source_rgb(*(colors[level][1].float_tuple())) for i, counts in enumerate(dist_data): if counts[level] == 0: continue ctx.translate(i, 0.) triangle(ctx) ctx.fill() ctx.translate(-i, 0.)