Example #1
0
    def draw(self, rtl, ctx, pc, layout, fascent, fheight,
             baseline_x, baseline_y):
        """Draw this index item to the provided Cairo context. It prints the
        label, the squares definition and the dotted line, with respect to the
        RTL setting.

        Args:
            rtl (boolean): right-to-left localization.
            ctx (cairo.Context): the Cairo context to draw to.
            pc (pangocairo.PangoCairo): the PangoCairo context for text
                drawing.
            layout (pango.Layout): the Pango layout to use for text
                rendering, pre-configured with the appropriate font.
            fascent (int): font ascent.
            fheight (int): font height.
            baseline_x (int): X axis coordinate of the baseline.
            baseline_y (int): Y axis coordinate of the baseline.
        """

        ctx.save()
        if not rtl:
            for i,line in enumerate(self.label.split('\n')):
                _, _, line_start, new_baseline_y = draw_utils.draw_text_left(ctx, pc, layout,
                                                             fascent, fheight,
                                                             baseline_x, baseline_y,
                                                             line)
                prev_baseline_y = baseline_y
                baseline_y = new_baseline_y
            
            line_end, _, _, _ = draw_utils.draw_text_right(ctx, pc, layout,
                                                        fascent, fheight,
                                                        baseline_x, prev_baseline_y,
                                                        self.location_str or '???')
        else:
            orig_baseline_y = baseline_y
            _, _, line_start, _ = draw_utils.draw_text_left(ctx, pc, layout,
                                                         fascent, fheight,
                                                         baseline_x, baseline_y,
                                                         self.location_str or '???')
            for i,line in enumerate(self.label.split('\n')):
                line_end, _, _, new_baseline_y = draw_utils.draw_text_right(ctx, pc, layout,
                                                            fascent, fheight,
                                                            baseline_x, baseline_y,
                                                            line)
                prev_baseline_y = baseline_y
                baseline_y = new_baseline_y

            prev_baseline_y = orig_baseline_y

        draw_utils.draw_dotted_line(ctx, max(fheight/12, 1),
                                    line_start + fheight/4, prev_baseline_y,
                                    line_end - line_start - fheight/2)
        ctx.restore()
        return i+1
Example #2
0
    def draw(self, rtl, ctx, pc, column_layout, fascent, fheight,
             baseline_x, baseline_y,
             label_layout=None, label_height=0, location_width=0):
        """Draw this index item to the provided Cairo context. It prints the
        label, the squares definition and the dotted line, with respect to the
        RTL setting.

        Args:
            rtl (boolean): right-to-left localization.
            ctx (cairo.Context): the Cairo context to draw to.
            pc (pangocairo.PangoCairo): the PangoCairo context for text
                drawing.
            column_layout (pango.Layout): the Pango layout to use for text
                rendering, pre-configured with the appropriate font.
            fascent (int): font ascent.
            fheight (int): font height.
            baseline_x (int): X axis coordinate of the baseline.
            baseline_y (int): Y axis coordinate of the baseline.
        Optional args (in case of label wrapping):
            label_layout (pango.Layout): the Pango layout to use for text
                rendering, in case the label should be wrapped
            label_height (int): height of the big label
            location_width (int): width of the 'location' part
        """

        # Fallbacks in case we dont't have a wrapping label
        if label_layout == None:
            label_layout = column_layout
        if label_height == 0:
            label_height = fheight

        if not self.location_str:
            location_str = '???'
        else:
            location_str = self.location_str

        ctx.save()
        if not rtl:
            _, _, line_start = draw_utils.draw_text_left(ctx, pc, label_layout,
                                                         fascent, fheight,
                                                         baseline_x, baseline_y,
                                                         self.label)
            line_end, _, _ = draw_utils.draw_text_right(ctx, pc, column_layout,
                                                        fascent, fheight,
                                                        baseline_x, baseline_y,
                                                        location_str)
        else:
            _, _, line_start = draw_utils.draw_text_left(ctx, pc, column_layout,
                                                         fascent, fheight,
                                                         baseline_x, baseline_y,
                                                         location_str)
            line_end, _, _ = draw_utils.draw_text_right(ctx, pc, label_layout,
                                                        fascent, fheight,
                                                        (baseline_x
                                                         + location_width),
                                                        baseline_y,
                                                        self.label)

        # In case of empty label, we don't draw the dots
        if self.label != '':
            draw_utils.draw_dotted_line(ctx, fheight/12,
                                        line_start + fheight/4, baseline_y,
                                        line_end - line_start - fheight/2)
        ctx.restore()
Example #3
0
    def draw(self, rtl, ctx, pc, column_layout, fascent, fheight,
             baseline_x, baseline_y,
             label_layout=None, label_height=0, location_width=0):
        """Draw this index item to the provided Cairo context. It prints the
        label, the squares definition and the dotted line, with respect to the
        RTL setting.

        Args:
            rtl (boolean): right-to-left localization.
            ctx (cairo.Context): the Cairo context to draw to.
            pc (pangocairo.PangoCairo): the PangoCairo context for text
                drawing.
            column_layout (pango.Layout): the Pango layout to use for text
                rendering, pre-configured with the appropriate font.
            fascent (int): font ascent.
            fheight (int): font height.
            baseline_x (int): X axis coordinate of the baseline.
            baseline_y (int): Y axis coordinate of the baseline.
        Optional args (in case of label wrapping):
            label_layout (pango.Layout): the Pango layout to use for text
                rendering, in case the label should be wrapped
            label_height (int): height of the big label
            location_width (int): width of the 'location' part
        """

        # Fallbacks in case we dont't have a wrapping label
        if label_layout == None:
            label_layout = column_layout
        if label_height == 0:
            label_height = fheight

        if not self.location_str:
            location_str = '???'
        else:
            location_str = self.location_str

        ctx.save()
        if not rtl:
            _, _, line_start = draw_utils.draw_text_left(ctx, pc, label_layout,
                                                         fascent, fheight,
                                                         baseline_x, baseline_y,
                                                         self.label)
            line_end, _, _ = draw_utils.draw_text_right(ctx, pc, column_layout,
                                                        fascent, fheight,
                                                        baseline_x, baseline_y,
                                                        location_str)
        else:
            _, _, line_start = draw_utils.draw_text_left(ctx, pc, column_layout,
                                                         fascent, fheight,
                                                         baseline_x, baseline_y,
                                                         location_str)
            line_end, _, _ = draw_utils.draw_text_right(ctx, pc, label_layout,
                                                        fascent, fheight,
                                                        (baseline_x
                                                         + location_width),
                                                        baseline_y,
                                                        self.label)

        # In case of empty label, we don't draw the dots
        if self.label != '':
            draw_utils.draw_dotted_line(ctx, max(fheight/12, 1),
                                        line_start + fheight/4, baseline_y,
                                        line_end - line_start - fheight/2)
        ctx.restore()