| 1 |
# (C) Copyright 2007-2025 Enthought, Inc., Austin, TX |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is provided without warranty under the terms of the BSD |
| 5 |
# license included in LICENSE.txt and may be redistributed only under |
| 6 |
# the conditions described in the aforementioned license. The license |
| 7 |
# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 |
# |
| 9 |
# Thanks for using Enthought open source! |
| 10 |
""" A menu builder that doesn't build real actions! """ |
| 11 |
|
| 12 |
from pyface.action.api import Action, Group, MenuBarManager, MenuManager |
| 13 |
|
| 14 |
# Enthought library imports. |
| 15 |
from envisage.ui.action.api import AbstractActionManagerBuilder |
| 16 |
|
| 17 |
|
| 18 |
class DummyActionManagerBuilder(AbstractActionManagerBuilder): |
| 19 |
"""An action manager builder that doesn't build real actions! |
| 20 |
|
| 21 |
This makes it very easy to test! |
| 22 |
|
| 23 |
""" |
| 24 |
|
| 25 |
########################################################################### |
| 26 |
# 'DummyActionManagerBuilder' interface. |
| 27 |
########################################################################### |
| 28 |
|
| 29 |
def create_menu_bar_manager(self, root): |
| 30 |
"""Create a menu bar manager from the builder's action sets.""" |
| 31 |
|
| 32 |
menu_bar_manager = MenuBarManager(id="MenuBar") |
| 33 |
|
| 34 |
self.initialize_action_manager(menu_bar_manager, root) |
| 35 |
|
| 36 |
return menu_bar_manager |
| 37 |
|
| 38 |
########################################################################### |
| 39 |
# Protected 'AbstractActionManagerBuilder' interface. |
| 40 |
########################################################################### |
| 41 |
|
| 42 |
def _create_action(self, action_definition): |
| 43 |
"""Create an action implementation from a definition.""" |
| 44 |
|
| 45 |
return Action(name=action_definition.class_name) |
| 46 |
|
| 47 |
def _create_group(self, group_definition): |
| 48 |
"""Create a group implementation from a definition.""" |
| 49 |
|
| 50 |
return Group(id=group_definition.id) |
| 51 |
|
| 52 |
def _create_menu_manager(self, menu_definition): |
| 53 |
"""Create a menu manager implementation from a definition.""" |
| 54 |
|
| 55 |
menu_manager = MenuManager(id=menu_definition.id) |
| 56 |
for group_definition in menu_definition.groups: |
| 57 |
menu_manager.insert(-1, Group(id=group_definition.id)) |
| 58 |
|
| 59 |
return menu_manager |