Exemple #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()
Exemple #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()
Exemple #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)
Exemple #4
0
def view(diagram):
    view = GtkView(model=diagram, selection=Selection())
    view._qtree.resize((-100, -100, 400, 400))
    item_painter = ItemPainter(view.selection)
    view.painter = item_painter
    view.bounding_box_painter = BoundingBoxPainter(item_painter)
    return view
Exemple #5
0
    def __init__(self):
        self.session = Session(services=self.services)
        self.element_factory = self.session.get_service("element_factory")
        self.modeling_language = self.session.get_service("modeling_language")
        assert len(list(self.element_factory.select())) == 0, list(
            self.element_factory.select())
        self.diagram = self.element_factory.create(UML.Diagram)

        # We need to hook up a view for now, so updates are done instantly
        self.view = GtkView(self.diagram, selection=Selection())
        self.view.painter = ItemPainter(self.view.selection)
        self.view.bounding_box_painter = BoundingBoxPainter(self.view.painter)
        assert len(list(self.element_factory.select())) == 1, list(
            self.element_factory.select())