Ejemplo n.º 1
0
 def setUp(self):
     TestCase.setUp(self)
     diagram = self.diagram
     tab = DiagramPage(WindowOwner())
     tab.diagram = diagram
     tab.construct()
     self.tab = tab
Ejemplo n.º 2
0
def page(diagram, event_manager, element_factory, properties):
    page = DiagramPage(diagram, event_manager, element_factory, properties,
                       UMLModelingLanguage())
    page.construct()
    assert page.diagram == diagram
    assert page.view.model == diagram
    yield page
    page.close()
Ejemplo n.º 3
0
    def _on_show_diagram(self, event):
        """Show a Diagram element in the Notebook.

        If a diagram is already open on a Notebook page, show that one,
        otherwise create a new Notebook page.

        Args:
            event: The service event that is calling the method.
        """

        diagram = event.diagram

        # Try to find an existing diagram page and give it focus
        for page, widget in self.get_widgets_on_pages():
            if widget.diagram_page.get_diagram() is diagram:
                self._notebook.set_current_page(page)
                return widget.diagram_page

        # No existing diagram page found, creating one
        page = DiagramPage(diagram, self.event_manager, self.element_factory,
                           self.properties)
        widget = page.construct()
        widget.set_name("diagram-tab")
        widget.diagram_page = page
        page.set_drawing_style(self.properties.get("diagram.sloppiness", 0))

        self.create_tab(diagram.name, widget)
        return page
Ejemplo n.º 4
0
    def _on_show_diagram(self, event):
        """Show a Diagram element in the Notebook.

        If a diagram is already open on a Notebook page, show that one,
        otherwise create a new Notebook page.

        Args:
            event: The service event that is calling the method.
        """

        diagram = event.diagram

        # Try to find an existing diagram page and give it focus
        for page, widget in self.get_widgets_on_pages():
            if widget.diagram_page.get_diagram() is diagram:
                self._notebook.set_current_page(page)
                return widget.diagram_page

        # No existing diagram page found, creating one
        page = DiagramPage(diagram)
        widget = page.construct()
        try:
            widget.set_css_name("diagram-tab")
        except AttributeError:
            pass  # Gtk.Widget.set_css_name() is added in 3.20
        widget.set_name("diagram-tab")
        widget.diagram_page = page
        page.set_drawing_style(self.properties("diagram.sloppiness", 0))

        self.create_tab(diagram.name, widget)
        return page
Ejemplo n.º 5
0
def tab(event_manager, element_factory, properties):
    diagram = element_factory.create(UML.Diagram)
    tab = DiagramPage(diagram, event_manager, element_factory, properties,
                      UMLModelingLanguage())

    window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
    window.add(tab.construct())
    window.show()
    yield tab
    window.destroy()
Ejemplo n.º 6
0
def view(diagram, event_manager, element_factory):
    page = DiagramPage(diagram, event_manager, element_factory, {},
                       UMLModelingLanguage())
    page.construct()
    return page.view
Ejemplo n.º 7
0
class DiagramToolboxTestCase(TestCase):

    services = [
        "event_manager",
        "component_registry",
        "element_factory",
        "properties",
        "action_manager",
        "main_window",
    ]

    def setUp(self):
        TestCase.setUp(self)

        self.tab = DiagramPage(
            WindowOwner(),
            self.get_service("event_manager"),
            self.element_factory,
            self.get_service("properties"),
        )
        self.tab.diagram = self.diagram

        self.window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
        self.window.add(self.tab.construct())
        self.window.show()

    def tearDown(self):
        self.window.destroy()
        TestCase.tearDown(self)

    def test_toolbox_actions_shortcut_unique(self):

        shortcuts = {}

        for category, items in TOOLBOX_ACTIONS:

            for action_name, label, icon_name, shortcut in items:

                try:

                    shortcuts[shortcut].append(action_name)

                except KeyError:

                    shortcuts[shortcut] = [action_name]

        for key, val in list(shortcuts.items()):

            if key is not None:

                assert len(val) == 1, "Duplicate toolbox shortcut"

    def test_standalone_construct_with_diagram(self):
        pass  # is setUp()

    def _test_placement_action(self, action):
        tool = self.tab.toolbox.get_tool(action)

        # Ensure the factory is working
        tool.create_item((0, 0))
        self.diagram.canvas.update()

    def test_placement_pointer(self):
        self.tab.toolbox.action_group.get_action("toolbox-pointer").activate()

    def test_placement_comment(self):
        self._test_placement_action("toolbox-comment")

    def test_placement_comment_line(self):
        self._test_placement_action("toolbox-comment-line")

    # Classes:

    def test_placement_class(self):
        self._test_placement_action("toolbox-class")

    def test_placement_interface(self):
        self._test_placement_action("toolbox-interface")

    def test_placement_package(self):
        self._test_placement_action("toolbox-package")

    def test_placement_association(self):
        self._test_placement_action("toolbox-association")

    def test_placement_dependency(self):
        self._test_placement_action("toolbox-dependency")

    def test_placement_generalization(self):
        self._test_placement_action("toolbox-generalization")

    def test_placement_implementation(self):
        self._test_placement_action("toolbox-implementation")

    # Components:

    def test_placement_component(self):
        self._test_placement_action("toolbox-component")

    def test_placement_node(self):
        self._test_placement_action("toolbox-node")

    def test_placement_artifact(self):
        self._test_placement_action("toolbox-artifact")

    # Actions:

    def test_placement_action(self):
        self._test_placement_action("toolbox-action")

    def test_placement_initial_node(self):
        self._test_placement_action("toolbox-initial-node")

    def test_placement_activity_final_node(self):
        self._test_placement_action("toolbox-activity-final-node")

    def test_placement_flow_final_node(self):
        self._test_placement_action("toolbox-flow-final-node")

    def test_placement_decision_node(self):
        self._test_placement_action("toolbox-decision-node")

    def test_placement_fork_node(self):
        self._test_placement_action("toolbox-fork-node")

    def test_placement_object_node(self):
        self._test_placement_action("toolbox-object-node")
        assert 1 == len(self.kindof(UML.ObjectNode))

    def test_placement_partition(self):
        self._test_placement_action("toolbox-partition")
        assert 0 == len(self.kindof(UML.ActivityPartition))

    def test_placement_flow(self):
        self._test_placement_action("toolbox-flow")

    # Use cases:

    def test_use_case(self):
        self._test_placement_action("toolbox-use-case")

    def test_actor(self):
        self._test_placement_action("toolbox-actor")

    def test_use_case_association(self):
        self._test_placement_action("toolbox-use-case-association")

    def test_include(self):
        self._test_placement_action("toolbox-include")

    def test_extend(self):
        self._test_placement_action("toolbox-extend")

    # Profiles:

    def test_profile(self):
        self._test_placement_action("toolbox-profile")

    def test_metaclass(self):
        self._test_placement_action("toolbox-metaclass")

    def test_stereotype(self):
        self._test_placement_action("toolbox-stereotype")

    def test_extension(self):
        self._test_placement_action("toolbox-extension")