How to use the gaphas.painter.BoundingBoxPainter function in gaphas

To help you get started, we’ve selected a few gaphas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gaphor / gaphor / gaphor / ui / diagrampage.py View on Github external
def set_drawing_style(self, sloppiness=0.0):
        """
        Set the drawing style for the diagram. 0.0 is straight,
        2.0 is very sloppy.  If the sloppiness is set to be anything
        greater than 0.0, the FreeHandPainter instances will be used
        for both the item painter and the box painter.  Otherwise, by
        default, the ItemPainter is used for the item and
        BoundingBoxPainter for the box.
        """
        assert self.view
        view = self.view

        if sloppiness:
            item_painter = FreeHandPainter(ItemPainter(), sloppiness=sloppiness)
            box_painter = FreeHandPainter(BoundingBoxPainter(), sloppiness=sloppiness)
        else:
            item_painter = ItemPainter()
            box_painter = BoundingBoxPainter()

        view.painter = (
            PainterChain()
            .append(item_painter)
            .append(HandlePainter())
            .append(FocusedItemPainter())
            .append(ToolPainter())
        )

        view.bounding_box_painter = box_painter

        view.queue_draw_refresh()
github gaphor / gaphor / gaphor / plugins / diagramexport / __init__.py View on Github external
def update_painters(self, view):
        sloppiness = self.properties.get("diagram.sloppiness", 0)

        if sloppiness:
            view.painter = FreeHandPainter(ItemPainter(), sloppiness)
            view.bounding_box_painter = FreeHandPainter(
                BoundingBoxPainter(), sloppiness
            )
        else:
            view.painter = ItemPainter()
github gaphor / gaphor / gaphor / ui / diagrampage.py View on Github external
Set the drawing style for the diagram. 0.0 is straight,
        2.0 is very sloppy.  If the sloppiness is set to be anything
        greater than 0.0, the FreeHandPainter instances will be used
        for both the item painter and the box painter.  Otherwise, by
        default, the ItemPainter is used for the item and
        BoundingBoxPainter for the box.
        """
        assert self.view
        view = self.view

        if sloppiness:
            item_painter = FreeHandPainter(ItemPainter(), sloppiness=sloppiness)
            box_painter = FreeHandPainter(BoundingBoxPainter(), sloppiness=sloppiness)
        else:
            item_painter = ItemPainter()
            box_painter = BoundingBoxPainter()

        view.painter = (
            PainterChain()
            .append(item_painter)
            .append(HandlePainter())
            .append(FocusedItemPainter())
            .append(ToolPainter())
        )

        view.bounding_box_painter = box_painter

        view.queue_draw_refresh()
github DLR-RM / RAFCON / source / rafcon / gui / mygaphas / painter.py View on Github external
cr.set_line_width(self.view.get_zoom_factor() / 4.)
            cr.identity_matrix()
            m = Matrix(*view.get_matrix_i2v(item))

            cr.set_antialias(ANTIALIAS_NONE)
            cr.translate(*m.transform_point(cx, cy))
            cr.rectangle(-side_length / 2., -side_length / 2., side_length, side_length)
            cr.set_source_rgba(*get_col_rgba(self.fill_color))
            cr.fill_preserve()
            cr.set_source_rgba(*get_col_rgba(self.border_color))
            cr.set_line_width(1)
            cr.stroke()
            cr.restore()


class BoundingBoxPainter(gaphas.painter.BoundingBoxPainter):
    """
    This specific case of an ItemPainter is used to calculate the bounding
    boxes (in canvas coordinates) for the items.
    """

    draw_all = True

    def _draw_item(self, item, cairo, area=None):
        cairo = gaphas.painter.CairoBoundingBoxContext(cairo)
        super(gaphas.painter.BoundingBoxPainter, self)._draw_item(item, cairo)
        bounds = cairo.get_bounds()

        view = self.view
        if isinstance(item, (StateView, NameView)):
            i2v = view.get_matrix_i2v(item).transform_point
            for index, handle in enumerate(item.handles()):
github DLR-RM / RAFCON / source / rafcon / gui / mygaphas / painter.py View on Github external
def _draw_item(self, item, cairo, area=None):
        cairo = gaphas.painter.CairoBoundingBoxContext(cairo)
        super(gaphas.painter.BoundingBoxPainter, self)._draw_item(item, cairo)
        bounds = cairo.get_bounds()

        view = self.view
        if isinstance(item, (StateView, NameView)):
            i2v = view.get_matrix_i2v(item).transform_point
            for index, handle in enumerate(item.handles()):
                if index >= 4:
                    break
                side_length = get_side_length_of_resize_handle(view, item)
                cx, cy = i2v(*handle.pos)
                bounds += (cx - side_length / 2, cy - side_length / 2, side_length, side_length)
        elif isinstance(item, ConnectionView):
            i2v = view.get_matrix_i2v(item).transform_point
            for h in item.handles():
                cx, cy = i2v(*h.pos)
                bounds += (cx, cy, 1, 1)