Example #1
0
    def set_drawing_style(self):
        """Set the drawing style for the diagram based on the active style
        sheet."""
        assert self.view
        assert self.diagram_css

        style = self.diagram.style(StyledDiagram(self.diagram, self.view))

        bg = style.get("background-color")
        self.diagram_css.load_from_data(
            f"diagramview {{ background-color: rgba({int(255*bg[0])}, {int(255*bg[1])}, {int(255*bg[2])}, {bg[3]}) }}"
            .encode() if bg else "".encode())

        sloppiness = style.get("line-style", 0.0)

        item_painter = ItemPainter()

        view = self.view

        if sloppiness:
            item_painter = FreeHandPainter(ItemPainter(),
                                           sloppiness=sloppiness)

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

        view.queue_draw_refresh()
Example #2
0
def new_painter(diagram):
    style = diagram.style(StyledDiagram(diagram))

    sloppiness = style.get("line-style", 0.0)

    if sloppiness:
        return FreeHandPainter(ItemPainter(), sloppiness)
    else:
        return ItemPainter()
Example #3
0
    def update_painters(self, view, diagram):
        style = diagram.style(StyledDiagram(diagram))

        sloppiness = style.get("line-style", 0.0)

        if sloppiness:
            view.painter = FreeHandPainter(ItemPainter(), sloppiness)
        else:
            view.painter = ItemPainter()
        view.bounding_box_painter = BoundingBoxPainter(view.painter)
Example #4
0
def test_diagram_has_no_parent(diagram):
    node = StyledDiagram(diagram)

    assert node.parent() is None