コード例 #1
0
    def _extra_actions_default(self):
        """ Extra application-wide menu items

        This adds a collection of standard Tasks application menu items and
        groups to a Task's set of menus.  Whether or not they actually appear
        depends on whether the appropriate menus are provided by the Task.

        These default additions assume that the window will hold an editor pane
        so that Ctrl-N and Ctrl-W will be bound to creating/closing new editors
        rather than new task windows.
        """
        from pyface.action.api import (
            AboutAction,
            CloseActiveWindowAction,
            ExitAction,
        )
        from pyface.action.schema.api import SMenu, SchemaAddition
        from pyface.tasks.action.api import (
            CreateTaskWindowAction,
            TaskWindowToggleGroup,
        )

        return [
            SchemaAddition(
                factory=CreateTaskWindowAction.factory(
                    application=self, accelerator="Ctrl+Shift+N"
                ),
                path="MenuBar/File/new_group",
            ),
            SchemaAddition(
                id="close_action",
                factory=CloseActiveWindowAction.factory(
                    application=self, accelerator="Ctrl+Shift+W"
                ),
                path="MenuBar/File/close_group",
            ),
            SchemaAddition(
                id="exit_action",
                factory=ExitAction.factory(application=self),
                path="MenuBar/File/close_group",
                absolute_position="last",
            ),
            SchemaAddition(
                # id='Window',
                factory=lambda: SMenu(
                    TaskWindowToggleGroup(application=self),
                    id="Window",
                    name="&Window",
                ),
                path="MenuBar",
                after="View",
                before="Help",
            ),
            SchemaAddition(
                id="about_action",
                factory=AboutAction.factory(application=self),
                path="MenuBar/Help",
                absolute_position="first",
            ),
        ]
コード例 #2
0
 def test_absolute_and_before_after(self):
     """ Does specifying absolute_position along with before, after work?
     """
     schema = MenuBarSchema(
         MenuSchema(
             GroupSchema(self.action1, self.action2, id="FileGroup"),
             id="File",
         ))
     extras = [
         SchemaAddition(
             factory=lambda: self.action3,
             id="action3",
             after="action2",
             path="MenuBar/File/FileGroup",
         ),
         SchemaAddition(
             factory=lambda: self.action4,
             after="action3",
             path="MenuBar/File/FileGroup",
         ),
         SchemaAddition(
             factory=lambda: self.action5,
             id="action5",
             absolute_position="last",
             path="MenuBar/File/FileGroup",
         ),
         SchemaAddition(
             factory=lambda: self.action6,
             absolute_position="last",
             before="action5",
             path="MenuBar/File/FileGroup",
         ),
     ]
     builder = TaskActionManagerBuilder(
         task=Task(menu_bar=schema, extra_actions=extras))
     actual = builder.create_menu_bar_manager()
     desired = MenuBarManager(
         MenuManager(
             Group(
                 self.action1,
                 self.action2,
                 self.action3,
                 self.action4,
                 self.action6,
                 self.action5,
                 id="FileGroup",
             ),
             id="File",
         ),
         id="MenuBar",
     )
     self.assertActionElementsEqual(actual, desired)
コード例 #3
0
    def test_merging_redundant_items_that_are_not_schemas(self):
        """ Items that are not schemas cannot be merged, but we should
        not crash, either. """

        # Initial menu.
        schema = MenuBarSchema(
            # This menu is not a schema...
            MenuManager(Group(self.action1, id="FileGroup"), id="FileMenu"))

        # Contributed menus.
        extra_menu = MenuSchema(GroupSchema(self.action2, id="FileGroup"),
                                id="FileMenu")

        additions = [
            SchemaAddition(
                path="MenuBar",
                factory=lambda: extra_menu,
                id="DummyActionsSMenu",
            )
        ]

        # Build the final menu.
        builder = ActionManagerBuilder(additions=additions)
        actual = builder.create_action_manager(schema)

        desired = MenuBarManager(
            MenuManager(Group(self.action1, id="FileGroup"), id="FileMenu"),
            MenuManager(Group(self.action2, id="FileGroup"), id="FileMenu"),
            id="MenuBar",
        )
        self.assertActionElementsEqual(actual, desired)
コード例 #4
0
    def test_merging_items_with_same_id_but_different_class(self):
        """ Schemas with the same path but different types (menus, groups)
        are not merged together.

        Having a group and a menu with the same path is of course bad practice,
        but we need a predictable outcome.

        """

        # Initial menu.
        schema = MenuBarSchema(
            MenuSchema(GroupSchema(self.action1, id="FileGroup"),
                       id="FileSchema"))

        # Contributed menus.
        extra_group = GroupSchema(self.action2, id="FileSchema")

        additions = [
            SchemaAddition(
                path="MenuBar",
                factory=(lambda: extra_group),
                id="DummyActionsSMenu",
            )
        ]

        # Build the final menu.
        builder = ActionManagerBuilder(additions=additions)
        actual = builder.create_action_manager(schema)

        desired = MenuBarManager(
            MenuManager(Group(self.action1, id="FileGroup"), id="FileSchema"),
            Group(self.action2, id="FileSchema"),
            id="MenuBar",
        )
        self.assertActionElementsEqual(actual, desired)
コード例 #5
0
    def test_extra_menu(self):
        """ Test contributing a whole new menu to the menu bar. """

        # Initial menu.
        schema = MenuBarSchema(
            MenuSchema(GroupSchema(self.action1, id="FileGroup"),
                       id="FileMenu"))

        # Contributed menu.
        extra_menu = MenuSchema(GroupSchema(self.action2, id="BarGroup"),
                                id="DummyActionsMenu")

        additions = [
            SchemaAddition(
                path="MenuBar",
                factory=lambda: extra_menu,
                id="DummyActionsSMenu",
            )
        ]

        # Build the final menu.
        builder = ActionManagerBuilder(additions=additions)
        actual = builder.create_action_manager(schema)

        desired = MenuBarManager(
            MenuManager(Group(self.action1, id="FileGroup"), id="FileMenu"),
            MenuManager(Group(self.action2, id="BarGroup"),
                        id="DummyActionsMenu"),
            id="MenuBar",
        )

        self.assertActionElementsEqual(actual, desired)
コード例 #6
0
 def test_absolute_ordering(self):
     """ Does specifying absolute_position work?
     """
     schema = MenuBarSchema(
         MenuSchema(
             GroupSchema(self.action1, self.action2, id="FileGroup"),
             id="File",
         ))
     additions = [
         SchemaAddition(
             factory=lambda: self.action3,
             absolute_position="last",
             path="MenuBar/File/FileGroup",
         ),
         SchemaAddition(
             factory=lambda: self.action4,
             absolute_position="first",
             path="MenuBar/File/FileGroup",
         ),
         SchemaAddition(
             factory=lambda: self.action5,
             absolute_position="first",
             path="MenuBar/File/FileGroup",
         ),
     ]
     builder = ActionManagerBuilder(additions=additions)
     actual = builder.create_action_manager(schema)
     desired = MenuBarManager(
         MenuManager(
             Group(
                 self.action4,
                 self.action5,
                 self.action1,
                 self.action2,
                 self.action3,
                 id="FileGroup",
             ),
             id="File",
         ),
         id="MenuBar",
     )
     self.assertActionElementsEqual(actual, desired)
コード例 #7
0
 def test_additions_menu_bar(self):
     """ Does constructing a menu with a few additions work?
     """
     schema = MenuBarSchema(
         MenuSchema(
             GroupSchema(self.action1, self.action2, id="FileGroup"),
             id="File",
         ))
     extras = [
         SchemaAddition(
             factory=lambda: self.action3,
             before="action1",
             path="MenuBar/File/FileGroup",
         ),
         SchemaAddition(
             factory=lambda: self.action4,
             before="action1",
             path="MenuBar/File/FileGroup",
         ),
         SchemaAddition(factory=lambda: self.action5,
                        path="MenuBar/File/FileGroup"),
     ]
     builder = TaskActionManagerBuilder(
         task=Task(menu_bar=schema, extra_actions=extras))
     actual = builder.create_menu_bar_manager()
     desired = MenuBarManager(
         MenuManager(
             Group(
                 self.action3,
                 self.action4,
                 self.action1,
                 self.action2,
                 self.action5,
                 id="FileGroup",
             ),
             id="File",
         ),
         id="MenuBar",
     )
     self.assertActionElementsEqual(actual, desired)
コード例 #8
0
    def test_unwanted_merge(self):
        """ Test that we don't have automatic merges due to forgetting to set
        a schema ID. """

        with self.unique_id_context_manager():
            # Initial menu.
            schema = MenuBarSchema(
                MenuSchema(GroupSchema(self.action1, id="FileGroup"),
                           name="File 1"))

            # Contributed menus.
            extra_menu = MenuSchema(GroupSchema(self.action2, id="FileGroup"),
                                    name="File 2")

            additions = [
                SchemaAddition(
                    path="MenuBar",
                    factory=lambda: extra_menu,
                    id="DummyActionsSMenu",
                )
            ]

            # Build the final menu.
            builder = ActionManagerBuilder(additions=additions)
            actual = builder.create_action_manager(schema)

            # Note that we expect the name of the menu to be inherited from
            # the menu in the menu bar schema that is defined first.
            desired = MenuBarManager(
                MenuManager(
                    Group(self.action1, id="FileGroup"),
                    name="File 1",
                    id="MenuSchema_1",
                ),
                MenuManager(
                    Group(self.action2, id="FileGroup"),
                    name="File 2",
                    id="MenuSchema_2",
                ),
                id="MenuBar",
            )
            self.assertActionElementsEqual(actual, desired)
コード例 #9
0
    def test_merging_redundant_items(self):
        """ Menus and groups with matching path are merged together. """

        # Initial menu.
        schema = MenuBarSchema(
            MenuSchema(
                GroupSchema(self.action1, id="FileGroup"),
                name="File menu number one",
                id="FileMenu",
            ))

        # Contributed menus.
        extra_menu = MenuSchema(
            GroupSchema(self.action2, id="FileGroup"),
            name="File menu number two",
            id="FileMenu",
        )

        extra_actions = [
            SchemaAddition(
                path="MenuBar",
                factory=lambda: extra_menu,
                id="DummyActionsSMenu",
            )
        ]

        # Build the final menu.
        builder = TaskActionManagerBuilder(
            task=Task(menu_bar=schema, extra_actions=extra_actions))
        actual = builder.create_menu_bar_manager()

        # Note that we expect the name of the menu to be inherited from
        # the menu in the menu bar schema that is defined first.
        desired = MenuBarManager(
            MenuManager(
                Group(self.action1, self.action2, id="FileGroup"),
                name="File menu number one",
                id="FileMenu",
            ),
            id="MenuBar",
        )
        self.assertActionElementsEqual(actual, desired)