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)
def __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super().__init__(**traits) # Create an action that exits the application. exit_action = Action(name="E&xit", on_perform=self.close) self.exit_action = exit_action # Test action to toggle visibility of exit action and some action groups test_action = Action(name="&Toggle", on_perform=self.toggle) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager(exit_action, name="&File") ) # Add some tool bars, with the first one subdivided into action groups self.tool_bar_managers = [ ToolBarManager( Group(exit_action, exit_action, id="a"), Group(id="b"), # empty, so will remain hidden Group(exit_action, exit_action, id="c"), Group(exit_action, test_action, exit_action, id="d"), name="Tool Bar 1", show_tool_names=True, ), ToolBarManager( exit_action, name="Tool Bar 2", show_tool_names=True ), ToolBarManager( test_action, name="Tool Bar 3", show_tool_names=True ), ] # Add a status bar. self.status_bar_manager = StatusBarManager() self.status_bar_manager.message = "Example application window"
def __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super(MainWindow, self).__init__(**traits) # Create an action that exits the application. exit_action = Action(name='E&xit', on_perform=self.close) self.exit_action = exit_action # Test action to toggle visibility of exit action and some action groups test_action = Action(name='&Toggle', on_perform=self.toggle) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager(exit_action, name='&File')) # Add some tool bars, with the first one subdivided into action groups self.tool_bar_managers = [ ToolBarManager( Group(exit_action, exit_action, id='a'), Group(id='b'), # empty, so will remain hidden Group(exit_action, exit_action, id='c'), Group(exit_action, test_action, exit_action, id='d'), name='Tool Bar 1', show_tool_names=False), ToolBarManager(exit_action, name='Tool Bar 2', show_tool_names=False), ToolBarManager(test_action, name='Tool Bar 3', show_tool_names=False), ] # Add a status bar. self.status_bar_manager = StatusBarManager() self.status_bar_manager.message = 'Example application window' return
def _create_action_bars(self): """ Creates the window's menu, tool and status bars. """ # Common actions. highest = Action(name='Highest', style='radio') higher = Action(name='Higher', style='radio', checked=True) lower = Action(name='Lower', style='radio') lowest = Action(name='Lowest', style='radio') self._actions = [highest, higher, lower, lowest] # Menu bar. self.menu_bar_manager = MenuBarManager( MenuManager( ExampleAction(name='Foogle'), Separator(), highest, higher, lower, lowest, Separator(), Action(name='E&xit', on_perform=self.close), name='&File', )) # Tool bar. self.tool_bar_manager = ToolBarManager(ExampleAction(name='Foo'), Separator(), ExampleAction(name='Bar'), Separator(), ExampleAction(name='Baz'), Separator(), highest, higher, lower, lowest) # Status bar. self.status_bar_manager = StatusBarManager() return
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') extra_actions = [ SchemaAddition( path='MenuBar', factory=(lambda: extra_group), id='DummyActionsSMenu'), ] # Build the final menu. builder = TaskActionManagerBuilder(task=Task( menu_bar=schema, extra_actions=extra_actions)) actual = builder.create_menu_bar_manager() desired = MenuBarManager( MenuManager( Group( self.action1, id='FileGroup'), id='FileSchema'), Group( self.action2, id='FileSchema'), id='MenuBar') self.assertActionElementsEqual(actual, desired)
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)
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)
def __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super(MainWindow, self).__init__(**traits) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager( Group( Action( name="&Open...", accelerator="Ctrl+O", on_perform=self.on_open_file, ), Action( name="&Save", accelerator="Ctrl+S", on_perform=self.on_save_file, ), id="document_group", ), Action( name="&Close", accelerator="Ctrl+W", on_perform=self.close ), name="&File", ) ) # Add a tool bar if we are using qt4 - wx has layout issues if toolkit_object.toolkit == "qt4": from pygments.styles import STYLE_MAP styles = list(STYLE_MAP) self.tool_bar_manager = ToolBarManager( Group( Action(name="Open...", on_perform=self.on_open_file), Action(name="Save", on_perform=self.on_save_file), Action(name="Close", on_perform=self.close), id="document_group", ), Group( Action( name="Lines", style="toggle", on_perform=self.on_show_line_numbers, checked=True, ), FieldAction( name="Style", field_type=ComboField, field_defaults={ "values": styles, "value": "default", "tooltip": "Style", }, on_perform=self.on_style_changed, ), ), )
def test_field_menu(self): self._create_widget_control() self.widget.menu = MenuManager(Action(name="Test"), name="Test") self.gui.process_events()
def __file_menu_default(self): """ Trait initialiser. """ return MenuManager(self._exit_action, name="&File")
import os, sys # Put the Enthought library on the Python path. sys.path.append(os.path.abspath(r'..\..\..')) # Local imports. from pyface.action.api import Action from pyface.action.api import Group, MenuManager, Separator file_menu = MenuManager( Group( Action(name='New Project...'), Action(name='Open Project...'), id='OpenGroup', ), Group(Action(name='Close Project'), Action(name='Close Active Editor'), id='CloseGroup'), Group(Action(name='Export to HTML...'), Action(name='Print...'), id='ExportGroup'), Group(Action(name='Exit'), id='ExitGroup'), ) file_menu.dump() ############################################################################### file_menu = MenuManager( Action(name='New Project...'), Action(name='Open Project...'), Separator(), Action(name='Close Project'),
def get_context_menu(self, pos): """ Return a context menu containing split/collapse actions. Parameters ---------- pos : QtCore.QPoint Mouse position in global coordinates for which the context menu was requested. Returns ------- menu : pyface.action.menu_manager.MenuManager or None Context menu, or None if the given position doesn't correspond to any of the tab widgets. """ menu = MenuManager() for tabwidget in self.tabwidgets(): widget_pos = tabwidget.mapFromGlobal(pos) if tabwidget.rect().contains(widget_pos): splitter = tabwidget.parent() break else: # no split/collapse context menu for positions outside any # tabwidget region return None # add split actions (only show for non-empty tabwidgets) if not splitter.is_empty(): split_group = Group( Action( id="split_hor", name="Create new pane to the right", on_perform=lambda: splitter.split(orientation=QtCore.Qt. Horizontal), ), Action( id="split_ver", name="Create new pane below", on_perform=lambda: splitter.split(orientation=QtCore.Qt. Vertical), ), id="split", ) menu.append(split_group) # add collapse action (only show for collapsible splitters) if splitter.is_collapsible(): if splitter is splitter.parent().leftchild: if splitter.parent().orientation() == QtCore.Qt.Horizontal: text = "Merge with right pane" else: text = "Merge with bottom pane" else: if splitter.parent().orientation() == QtCore.Qt.Horizontal: text = "Merge with left pane" else: text = "Merge with top pane" collapse_group = Group( Action( id="merge", name=text, on_perform=lambda: splitter.collapse(), ), id="collapse", ) menu.append(collapse_group) return menu
# # Thanks for using Enthought open source! """ Menu Manager example. """ from pyface.action.api import Action from pyface.action.api import Group, MenuManager, Separator file_menu = MenuManager( Group( Action(name="New Project..."), Action(name="Open Project..."), id="OpenGroup", ), Group( Action(name="Close Project"), Action(name="Close Active Editor"), id="CloseGroup", ), Group( Action(name="Export to HTML..."), Action(name="Print..."), id="ExportGroup", ), Group(Action(name="Exit"), id="ExitGroup"), ) file_menu.dump() # ---------------------------------------------------------------------------- file_menu = MenuManager( Action(name="New Project..."), Action(name="Open Project..."),
def get_context_menu(self, pos): """ Returns a context menu containing split/collapse actions pos : position (in global coordinates) where the context menu was requested """ menu = MenuManager() splitter = None splitter = None for tabwidget in self.tabwidgets(): # obtain tabwidget's bounding rectangle in global coordinates global_rect = QtCore.QRect( tabwidget.mapToGlobal(QtCore.QPoint(0, 0)), tabwidget.size()) if global_rect.contains(pos): splitter = tabwidget.parent() # no split/collapse context menu for positions outside any tabwidget # region if not splitter: return # add split actions (only show for non-empty tabwidgets) if not splitter.is_empty(): actions = [ Action(id='split_hor', name='Create new pane to the right', on_perform=lambda: splitter.split(orientation=QtCore.Qt. Horizontal)), Action(id='split_ver', name='Create new pane to the bottom', on_perform=lambda: splitter.split(orientation=QtCore.Qt. Vertical)) ] splitgroup = Group(*actions, id='split') menu.append(splitgroup) # add collapse action (only show for collapsible splitters) if splitter.is_collapsible(): if splitter is splitter.parent().leftchild: if splitter.parent().orientation() is QtCore.Qt.Horizontal: text = 'Merge with right pane' else: text = 'Merge with bottom pane' else: if splitter.parent().orientation() is QtCore.Qt.Horizontal: text = 'Merge with left pane' else: text = 'Merge with top pane' actions = [ Action(id='merge', name=text, on_perform=lambda: splitter.collapse()) ] collapsegroup = Group(*actions, id='collapse') menu.append(collapsegroup) # return QMenu object return menu
def _menu_manager_default(self): return MenuManager(Group(*self.actions))