From a0f0a6bc72c6d796329a598e10c25c40b117ae05 Mon Sep 17 00:00:00 2001 From: "g@localhost.localdomain" Date: Wed, 13 Dec 2006 00:44:44 +0100 Subject: [PATCH] Compress more the layout --- pysize/ui/gtk/pysize_widget_draw.py | 40 ++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/pysize/ui/gtk/pysize_widget_draw.py b/pysize/ui/gtk/pysize_widget_draw.py index 2ac9118..1af2cd6 100644 --- a/pysize/ui/gtk/pysize_widget_draw.py +++ b/pysize/ui/gtk/pysize_widget_draw.py @@ -28,7 +28,7 @@ import pangocairo from pysize.ui.utils import human_unit, min_size_to_consider, sanitize_string -RADIUS = 20.0 +RADIUS = 10.0 LINE_WIDTH = 4.0 class PysizeWidget_Draw(object): @@ -51,22 +51,27 @@ class PysizeWidget_Draw(object): x0, x1, y0, y1 = map(int, node.rectangle) self.queue_draw_area(x0, y0, x1 - x0, y1 - y0) - def _draw_text(self, context, text, x0, x1, y0, y1): + def _draw_text(self, context, text, (x0, x1, y0, y1), accept_ellipse=True): pl = self.create_pango_layout(text) pl.set_alignment(pango.ALIGN_CENTER) w = x1 - x0 h = y1 - y0 pl.set_width(int(w*pango.SCALE)) - pl.set_ellipsize(pango.ELLIPSIZE_MIDDLE) + if accept_ellipse: + ellipse_mode = pango.ELLIPSIZE_MIDDLE + else: + ellipse_mode = pango.ELLIPSIZE_NONE + pl.set_ellipsize(ellipse_mode) real_w, real_h = pl.get_pixel_size() - if real_h > self.max_text_height: - self.max_text_height = real_h - if real_h > h: - return False - context.move_to(x0, y0+(h-real_h)/2.0) - context.set_source_rgb(0, 0, 0) - context.show_layout(pl) - return True + line_count = pl.get_line_count() + line_height = float(real_h) / line_count + if line_height > self.max_text_height: + self.max_text_height = line_height + if line_count == text.count('\n') + 1 and real_w <= w and real_h <= h: + context.move_to(x0, y0 + (h - real_h) / 2.0) + context.set_source_rgb(0, 0, 0) + context.show_layout(pl) + return True def _get_node_colors(self, node, colors): def transform(colors, dr, dg, db): @@ -141,9 +146,16 @@ class PysizeWidget_Draw(object): name = sanitize_string(node.get_name()) size = human_unit(node.size) - self._draw_text(context, name + '\n' + size, x0, x1, y0, y1) or \ - self._draw_text(context, name, x0, x1, y0, y1) or \ - self._draw_text(context, size, x0, x1, y0, y1) + position = x0, x1, y0, y1 + attempt = lambda text, pos, *flags: \ + self._draw_text(context, text, pos, *flags) or \ + self._draw_text(context, text, + (pos[0] - 1, pos[1] + 1, pos[2] - 1, pos[3] + 1), + *flags) + attempt(name + '\n' + size, position) or \ + attempt(name + ' ' + size, position, False) or \ + attempt(name, position) or \ + attempt(size, position) def _draw_boxes(self, context, node, depth, offset): w = self.allocation.width -- 2.11.4.GIT