コード例 #1
0
ファイル: test_mainwindow.py プロジェクト: weizx208/gaphor
 def test_show_diagram(self):
     main_w = Application.get_service("main_window")
     element_factory = Application.get_service("element_factory")
     diagram = element_factory.create(UML.Diagram)
     main_w.open()
     self.component_registry.handle(DiagramShow(diagram))
     self.assertEqual(self.get_current_diagram(), diagram)
コード例 #2
0
    def test_connect_comment_and_actor(self):
        """Test connect/disconnect on comment and actor using comment-line.
        """
        element_factory = Application.get_service("element_factory")
        diagram = element_factory.create(UML.Diagram)
        self.event_manager.handle(DiagramShow(diagram))
        comment = diagram.create(CommentItem,
                                 subject=element_factory.create(UML.Comment))

        line = diagram.create(CommentLineItem)

        view = self.get_diagram_view(diagram)
        assert view, "View should be available here"

        tool = ConnectHandleTool(view)

        # Connect one end to the Comment:
        handle = line.handles()[0]
        tool.grab_handle(line, handle)

        handle.pos = (0, 0)
        sink = tool.glue(line, handle, handle.pos)
        assert sink is not None
        assert sink.item is comment

        tool.connect(line, handle, handle.pos)
        cinfo = diagram.canvas.get_connection(handle)
        assert cinfo is not None, None
        assert cinfo.item is line
        assert cinfo.connected is comment

        # Connect the other end to the Actor:
        actor = diagram.create(ActorItem,
                               subject=element_factory.create(UML.Actor))

        handle = line.handles()[-1]
        tool.grab_handle(line, handle)

        handle.pos = (0, 0)
        sink = tool.glue(line, handle, handle.pos)
        assert sink, f"No sink at {handle.pos}"
        assert sink.item is actor
        tool.connect(line, handle, handle.pos)

        cinfo = view.canvas.get_connection(handle)
        assert cinfo.item is line
        assert cinfo.connected is actor

        # Try to connect far away from any item will only do a full disconnect
        self.assertEqual(len(comment.subject.annotatedElement), 1,
                         comment.subject.annotatedElement)
        assert actor.subject in comment.subject.annotatedElement

        sink = tool.glue(line, handle, (500, 500))
        assert sink is None, sink
        tool.connect(line, handle, (500, 500))

        cinfo = view.canvas.get_connection(handle)
        assert cinfo is None
コード例 #3
0
 def _new_model_content(self, event):
     """
     Open the toplevel element and load toplevel diagrams.
     """
     # TODO: Make handlers for ModelFactoryEvent from within the GUI obj
     for diagram in self.element_factory.select(lambda e: e.isKindOf(
             UML.Diagram) and not (e.namespace and e.namespace.namespace)):
         self.event_manager.handle(DiagramShow(diagram))
コード例 #4
0
ファイル: test_diagramtools.py プロジェクト: przor3n/gaphor
 def setUp(self):
     super().setUp()
     self.component_registry = self.get_service("component_registry")
     self.event_manager = self.get_service("event_manager")
     mw = self.get_service("main_window")
     mw.open()
     self.main_window = mw
     self.event_manager.handle(DiagramShow(self.diagram))
コード例 #5
0
ファイル: namespace.py プロジェクト: weizx208/gaphor
    def tree_view_open_selected(self):
        element = self._namespace.get_selected_element()
        # TODO: Candidate for adapter?
        if isinstance(element, UML.Diagram):
            self.component_registry.handle(DiagramShow(element))

        else:
            log.debug("No action defined for element %s" % type(element).__name__)
コード例 #6
0
ファイル: test_mainwindow.py プロジェクト: przor3n/gaphor
def test_show_diagram(application):
    element_factory = application.get_service("element_factory")
    diagram = element_factory.create(UML.Diagram)
    main_w = application.get_service("main_window")
    main_w.open()
    event_manager = application.get_service("event_manager")
    event_manager.handle(DiagramShow(diagram))
    assert get_current_diagram(application) == diagram
コード例 #7
0
ファイル: test_handletool.py プロジェクト: weizx208/gaphor
    def test_iconnect_2(self):
        """Test connect/disconnect on comment and actor using comment-line.
        """
        element_factory = Application.get_service("element_factory")
        diagram = element_factory.create(UML.Diagram)
        self.component_registry.handle(DiagramShow(diagram))
        comment = diagram.create(CommentItem,
                                 subject=element_factory.create(UML.Comment))
        actor = diagram.create(ActorItem,
                               subject=element_factory.create(UML.Actor))
        line = diagram.create(CommentLineItem)

        view = self.get_diagram_view(diagram)
        assert view, "View should be available here"

        tool = ConnectHandleTool(view)

        # Connect one end to the Comment:
        handle = line.handles()[0]
        tool.grab_handle(line, handle)

        comment_bb = view.get_item_bounding_box(comment)
        handle.pos = (comment_bb.x1, comment_bb.y1)
        sink = tool.glue(line, handle, handle.pos)
        assert sink is not None
        assert sink.item is comment

        tool.connect(line, handle, handle.pos)
        cinfo = diagram.canvas.get_connection(handle)
        self.assertTrue(cinfo is not None, None)
        self.assertTrue(cinfo.item is line)
        self.assertTrue(cinfo.connected is comment)

        # Connect the other end to the Actor:
        handle = line.handles()[-1]
        tool.grab_handle(line, handle)
        actor_bb = view.get_item_bounding_box(actor)

        handle.pos = actor_bb.x1, actor_bb.y1
        sink = tool.glue(line, handle, handle.pos)
        self.assertTrue(sink.item is actor)
        tool.connect(line, handle, handle.pos)

        cinfo = view.canvas.get_connection(handle)
        self.assertTrue(cinfo.item is line)
        self.assertTrue(cinfo.connected is actor)

        # Try to connect far away from any item will only do a full disconnect
        self.assertEqual(len(comment.subject.annotatedElement), 1,
                         comment.subject.annotatedElement)
        self.assertTrue(actor.subject in comment.subject.annotatedElement)

        sink = tool.glue(line, handle, (500, 500))
        self.assertTrue(sink is None, sink)
        tool.connect(line, handle, (500, 500))

        cinfo = view.canvas.get_connection(handle)
        self.assertTrue(cinfo is None)
コード例 #8
0
ファイル: namespace.py プロジェクト: Mitchell-boop/gaphor
    def tree_view_open_selected(self):
        element = self._namespace.get_selected_element()
        # TODO: Candidate for adapter?
        if isinstance(element, UML.Diagram):
            self.event_manager.handle(DiagramShow(element))

        else:
            log.debug(
                f"No action defined for element {type(element).__name__}")
コード例 #9
0
ファイル: namespace.py プロジェクト: weizx208/gaphor
    def tree_view_create_diagram(self):
        element = self._namespace.get_selected_element()
        diagram = self.element_factory.create(UML.Diagram)
        diagram.package = element

        if element:
            diagram.name = "%s diagram" % element.name
        else:
            diagram.name = "New diagram"

        self.select_element(diagram)
        self.component_registry.handle(DiagramShow(diagram))
        self.tree_view_rename_selected()
コード例 #10
0
ファイル: namespace.py プロジェクト: Mitchell-boop/gaphor
    def tree_view_create_diagram(self):
        element = self._namespace.get_selected_element()
        diagram = self.element_factory.create(UML.Diagram)
        diagram.package = element

        if element:
            diagram.name = f"{element.name} diagram"
        else:
            diagram.name = "New diagram"

        self.select_element(diagram)
        self.event_manager.handle(DiagramShow(diagram))
        self.tree_view_rename_selected()
コード例 #11
0
    def test_iconnect(self):
        """
        Test basic glue functionality using CommentItem and CommentLine
        items.
        """
        element_factory = Application.get_service("element_factory")
        diagram = element_factory.create(UML.Diagram)
        self.event_manager.handle(DiagramShow(diagram))
        comment = diagram.create(CommentItem,
                                 subject=element_factory.create(UML.Comment))

        actor = diagram.create(ActorItem,
                               subject=element_factory.create(UML.Actor))
        actor.matrix.translate(200, 200)
        diagram.canvas.update_matrix(actor)

        line = diagram.create(CommentLineItem)

        view = self.get_diagram_view(diagram)
        assert view, "View should be available here"
        comment_bb = view.get_item_bounding_box(comment)

        # select handle:
        handle = line.handles()[-1]
        tool = ConnectHandleTool(view=view)

        tool.grab_handle(line, handle)
        handle.pos = (comment_bb.x, comment_bb.y)
        item = tool.glue(line, handle, handle.pos)
        assert item is not None

        tool.connect(line, handle, handle.pos)
        cinfo = diagram.canvas.get_connection(handle)
        assert cinfo.constraint is not None
        assert cinfo.connected is actor, cinfo.connected

        Connector(line, handle).disconnect()

        cinfo = diagram.canvas.get_connection(handle)

        assert cinfo is None
コード例 #12
0
 def setUp(self):
     super(DiagramItemConnectorTestCase, self).setUp()
     mw = self.get_service("main_window")
     mw.open()
     self.main_window = mw
     self.event_manager.handle(DiagramShow(self.diagram))
コード例 #13
0
 def setUp(self):
     super(DiagramItemConnectorTestCase, self).setUp()
     mw = self.get_service("main_window")
     mw.open()
     self.main_window = mw
     self.component_registry.handle(DiagramShow(self.diagram))