def _menu_bar_manager_default(self): menu_bar = MenuBarManager( MenuManager( Group( CloseWindowAction(window=self), id='close_group', ), name='&File', id='File', ), MenuManager( Group( RunFileAction(window=self), id='run_group', ), name='&Run', id='Run', ), MenuManager( Group( OpenURLAction( name='Python Documentation', id='python_docs', url=PYTHON_DOCS, ), id="documentation_group", ), name='&Help', id='Help', ), ) return menu_bar
def _menu_bar_manager_default(self): menu_bar = MenuBarManager( MenuManager( Group(CloseWindowAction(window=self), id="close_group"), name="&File", id="File", ), MenuManager( Group(RunFileAction(window=self), id="run_group"), name="&Run", id="Run", ), MenuManager( Group( OpenURLAction( name="Python Documentation", id="python_docs", url=PYTHON_DOCS, ), id="documentation_group", ), name="&Help", id="Help", ), ) return menu_bar
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', ) 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() desired = MenuBarManager(MenuManager(Group(self.action1, id='FileGroup'), id='FileMenu'), MenuManager(Group(self.action2, id='BarGroup'), id='DummyActionsMenu'), 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( Action( name='E&xit', on_perform=self.close), name='&File', )) # Add a menu bar at each location. self.add_tool_bar( ToolBarManager( Action(name='Foo'), orientation='horizontal')) self.add_tool_bar( ToolBarManager( Action(name='Bar'), orientation='horizontal'), location='bottom') self.add_tool_bar( ToolBarManager( Action(name='Baz'), orientation='vertical'), location='left') self.add_tool_bar( ToolBarManager( Action(name='Buz'), orientation='vertical'), location='right') return
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', ) 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() desired = MenuBarManager(MenuManager(Group(self.action1, id='FileGroup'), id='FileMenu'), MenuManager(Group(self.action2, id='FileGroup'), id='FileMenu'), id='MenuBar') self.assertActionElementsEqual(actual, desired)
def __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super().__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_absolute_ordering(self): """ Does specifying absolute_position work? """ schema = MenuBarSchema( MenuSchema( GroupSchema( self.action1, self.action2, id='FileGroup'), id='File')) extras = [ 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 = TaskActionManagerBuilder(task=Task( menu_bar=schema, extra_actions=extras)) actual = builder.create_menu_bar_manager() desired = MenuBarManager( MenuManager( Group( self.action4, self.action5, self.action1, self.action2, self.action3, id='FileGroup'), id='File'), id='MenuBar') self.assertActionElementsEqual(actual, desired)
def create_ivtk_menu(obj): """Creates a menu bar suitable for all IVTK windows. Parameters ---------- - obj : A Pyface application window. This is the window which requires the menu items. """ menu_bar_manager = MenuBarManager( MenuManager( SaveImageAction(obj), Separator(), ExitAction(obj), name='&File', ), MenuManager( SaveToClipboardAction(obj), name='&Edit', ), MenuManager( SpecialViewAction(obj, "&Reset Zoom", 'reset_zoom'), Separator(), SpecialViewAction(obj, "&Isometric", 'isometric_view'), SpecialViewAction(obj, "&X positive", 'x_plus_view'), SpecialViewAction(obj, "X negative", 'x_minus_view'), SpecialViewAction(obj, "&Y positive", 'y_plus_view'), SpecialViewAction(obj, "Y negative", 'y_minus_view'), SpecialViewAction(obj, "&Z positive", 'z_plus_view'), SpecialViewAction(obj, "Z negative", 'z_minus_view'), name='&View', )) return menu_bar_manager
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)
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 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_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)
def _create_my_menu_bar(self): """ Creates the window's menu bar. """ self.menu_bar_manager = MenuBarManager( MenuManager( SaveImageAction(self), Separator(), ExitAction(self), name='&File', ), MenuManager( SaveToClipboardAction(self), name='&Edit', ), MenuManager( SpecialViewAction(self, "&Reset Zoom", 'reset_zoom'), Separator(), SpecialViewAction(self, "&Isometric", 'isometric_view'), SpecialViewAction(self, "&X positive", 'x_plus_view'), SpecialViewAction(self, "X negative", 'x_minus_view'), SpecialViewAction(self, "&Y positive", 'y_plus_view'), SpecialViewAction(self, "Y negative", 'y_minus_view'), SpecialViewAction(self, "&Z positive", 'z_plus_view'), SpecialViewAction(self, "Z negative", 'z_minus_view'), name='&View', ))
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) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager(exit_action, name='&File')) # Add some tool bars. self.tool_bar_managers = [ ToolBarManager(exit_action, name='Tool Bar 1', show_tool_names=False), ToolBarManager(exit_action, name='Tool Bar 2', show_tool_names=False), ToolBarManager(exit_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 __init__(self, **traits): """ Creates a new application window. """ # Base class constructor. super().__init__(**traits) # Add a menu bar. self.menu_bar_manager = MenuBarManager( MenuManager( Action(name="E&xit", on_perform=self.close), name="&File" ) ) # Add a menu bar at each location. self.add_tool_bar( ToolBarManager(Action(name="Foo"), orientation="horizontal") ) self.add_tool_bar( ToolBarManager(Action(name="Bar"), orientation="horizontal"), location="bottom", ) self.add_tool_bar( ToolBarManager(Action(name="Baz"), orientation="vertical"), location="left", ) self.add_tool_bar( ToolBarManager(Action(name="Buz"), orientation="vertical"), location="right", ) return
def create_menu_bar_manager(self, root): """ Create a menu bar manager from the builder's action sets. """ menu_bar_manager = MenuBarManager(id="MenuBar") self.initialize_action_manager(menu_bar_manager, root) return menu_bar_manager
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(Action(name="E&xit", on_perform=self.close), name="&File")) return
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_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 __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(Action(name='&Open...', on_perform=self._open_file), Action(name='&Save', on_perform=self._save_file), Action(name='E&xit', on_perform=self.close), name='&File')) return
def _menu_bar_manager_default(self): # Create an action that exits the application. exit_action = Action(name='E&xit', on_perform=self.close) self.exit_action = exit_action file_menu = MenuManager(name='&File') file_menu.append(Group(exit_action)) self.undo = UndoAction(undo_manager=self.undo_manager, accelerator='Ctrl+Z') self.redo = RedoAction(undo_manager=self.undo_manager, accelerator='Ctrl+Shift+Z') menu_bar_manager = MenuBarManager( file_menu, MenuManager(self.undo, self.redo, name='&Edit')) return menu_bar_manager
def test_simple_menu_bar(self): """ Does constructing a simple menu with no additions work? """ schema = MenuBarSchema( MenuSchema(self.action1, self.action2, id='File', name='&File'), MenuSchema(self.action3, self.action4, id='Edit', name='&Edit')) builder = TaskActionManagerBuilder(task=Task(menu_bar=schema)) actual = builder.create_menu_bar_manager() desired = MenuBarManager(MenuManager(self.action1, self.action2, id='File', name='&File'), MenuManager(self.action3, self.action4, id='Edit', name='&Edit'), id='MenuBar') self.assertActionElementsEqual(actual, desired)
def test_simple_menu_bar(self): """ Does constructing a simple menu with no additions work? """ schema = MenuBarSchema( MenuSchema(self.action1, self.action2, id="File", name="&File"), MenuSchema(self.action3, self.action4, id="Edit", name="&Edit"), ) builder = ActionManagerBuilder() actual = builder.create_action_manager(schema) desired = MenuBarManager( MenuManager(self.action1, self.action2, id="File", name="&File"), MenuManager(self.action3, self.action4, id="Edit", name="&Edit"), 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( Action(name='Start Timer', on_perform=self._start_timer), Action(name='Stop Timer', on_perform=self._stop_timer), Action(name='E&xit', on_perform=self.close), name='&File', )) return
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( Action(name='E&xit', on_perform=self.close), name='&File', ), MDIWindowMenu(self)) # Set the size of the window self.size = (640, 480) return
def create_python_shell_window(application, **kwargs): """ Factory method for constructing application window instances. """ window = PythonShellWindow(**kwargs) # Override the window's menubar with an enhanced one. # One of the advantages of Tasks is that we can extend easily, rather # than just overriding. window.menu_bar_manager = MenuBarManager( MenuManager( Group( CreateWindowAction(application=application), id='new_group', ), Group( CloseActiveWindowAction(application=application), ExitAction(application=application), id='close_group', ), name='&File', id='File', ), MenuManager( Group( RunFileAction(window=window), id='run_group', ), name='&Run', id='Run', ), MenuManager( Group( OpenURLAction( name='Python Documentation', id='python_docs', url=PYTHON_DOCS, ), id="documentation_group", ), Group( AboutAction(application=application), id='about_group', ), name='&Help', id='Help', )) return window
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_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)
def test_unwanted_merge(self): """ Test that we don't have automatic merges due to forgetting to set a schema ID. """ # 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') 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, 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)
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)