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 add_actions_and_groups(self, menu_items, location, menu_name, group_name): actions = self.get_actions_wrapper(location, menu_name, group_name) groups = [] group_suffix = "" group_index = 0 current = [] for item in actions: if isinstance(item, Group) or isinstance(item, SMenu): if current: group = Group(*current, id="%s%s" % (group_name, group_suffix)) group_index += 1 group_suffix = str(group_index) groups.append(group) current = [] groups.append(item) else: current.append(item) if current: group = Group(*current, id="%s%s" % (group_name, group_suffix)) groups.append(group) menu_items.append(Separator(id="%sStart" % group_name, separator=False)) for group in groups: menu_items.append(group) menu_items.append(Separator(id="%sEnd" % group_name, separator=False))
def get_actions_Menu_View_FontGroup(self): font_mapping_actions = self.get_font_mapping_actions() font_renderer_actions = [] for r in machine.predefined['font_renderer']: font_renderer_actions.append( va.FontRendererAction(font_renderer=r)) return [ SMenu(Group(va.UseFontAction(font=fonts.A8DefaultFont), va.UseFontAction(font=fonts.A8ComputerFont), va.UseFontAction(font=fonts.A2DefaultFont), va.UseFontAction(font=fonts.A2MouseTextFont), id="a1", separator=True), va.FontChoiceGroup(id="a2", separator=True), Group(va.LoadFontAction(), ba.GetFontFromSelectionAction(), id="a3", separator=True), id='mm5', separator=False, name="Font"), SMenu(Group(*font_renderer_actions, id="a1", separator=True), Group(*font_mapping_actions, id="a2", separator=True), id='mm6', separator=False, name="Character Display"), ]
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 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 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 _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 set_common_menu_29(self): menubar = SMenuBar( SMenu(Separator(id="NewGroup", separator=False), Separator(id="NewGroupEnd", separator=False), Group(OpenAction(), id="OpenGroup"), Separator(id="OpenGroupEnd", separator=False), Separator(id="SaveGroupEnd", separator=False), Group(ExitAction(), id="ExitGroup"), id='File', name='&File'), SMenu(PreferencesAction(), id='Edit', name='&Edit'), SMenu(AboutAction(), id='Help', name='&Help'), ) app = wx.GetApp() # Create a fake task so we can use the menu creation routines window = TaskWindow(application=self.application) log.debug("OSXMenuBarPlugin: minimal menu extra items: %s" % str(self.minimal_menu_actions)) task = OSXMinimalTask(menu_bar=menubar, window=window, extra_actions=self.minimal_menu_actions) t = TaskActionManagerBuilder(task=task) mgr = t.create_menu_bar_manager() control = mgr.create_menu_bar(app) wx.MenuBar.MacSetCommonMenuBar(control) # Prevent wx from exiting when the last window is closed app.SetExitOnFrameDelete(False)
def get_actions_Menu_Segment_ActionGroup(self): return [ ba.GetSegmentFromSelectionAction(), ba.MultipleSegmentsFromSelectionAction(), ba.InterleaveSegmentsAction(), ba.SetSegmentOriginAction(), Separator(), va.AddCommentAction(), va.RemoveCommentAction(), va.AddLabelAction(), va.RemoveLabelAction(), SMenu(Group(ba.ImportSegmentLabelsAction(name="Import"), id="sl1", separator=True), Group(ba.ExportSegmentLabelsAction( name="Export User Defined Labels"), ba.ExportSegmentLabelsAction( name="Export All Labels", include_disassembly_labels=True), id="sl2", separator=True), id='segmentlabels1', separator=False, name="Manage Segment Labels"), Separator(), va.StartTraceAction(), va.AddTraceStartPointAction(), va.ApplyTraceSegmentAction(), va.ClearTraceAction(), ]
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 __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 _create_other_group(self, window): """ Creates a group containing the 'Other...' action. """ group = Group() group.append(ShowViewAction(name="Other...", window=window)) return group
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 _menu_bar_factory(self, menus=None): if not menus: menus = [] edit_menu = SMenu(GenericFindAction(), id='Edit', name='&Edit') # entry_menu = SMenu( # id='entry.menu', # name='&Entry') file_menu = SMenu(SGroup(id='Open'), SGroup(id='New'), SGroup(GenericSaveAsAction(), GenericSaveAction(), id='Save'), SGroup(), id='file.menu', name='File') tools_menu = SMenu(CopyPreferencesAction(), id='tools.menu', name='Tools') window_menu = SMenu( WindowGroup(), Group(CloseAction(), CloseOthersAction(), id='Close'), OpenAdditionalWindow(), Group(MinimizeAction(), ResetLayoutAction(), PositionAction()), # SplitEditorAction(), id='window.menu', name='Window') help_menu = SMenu( IssueAction(), NoteAction(), AboutAction(), DocumentationAction(), ChangeLogAction(), RestartAction(), KeyBindingsAction(), SwitchUserAction(), StartupTestsAction(), # DemoAction(), id='help.menu', name='Help') grps = self._view_groups() view_menu = SMenu(*grps, id='view.menu', name='&View') mb = SMenuBar(file_menu, edit_menu, view_menu, tools_menu, window_menu, help_menu) if menus: for mi in reversed(menus): mb.items.insert(4, mi) return mb
def get_context_menu(self, node): """ Returns the context menu for a node. """ sat = Group(id='SystemActionsTop') nsa = Group(id='NodeSpecificActions') sab = Group(id='SystemActionsBottom') # The 'New' menu. new_actions = self.get_new_actions(node) if new_actions is not None and len(new_actions) > 0: sat.append( MenuManager( name = 'New', *new_actions ), ) # Node-specific actions. actions = self.get_actions(node) if actions is not None and len(actions) > 0: for item in actions: nsa.append(item) # System actions (actions available on ALL nodes). system_actions = self.node_manager.system_actions if len(system_actions) > 0: for item in system_actions: sab.append(item) context_menu = MenuManager(sat, nsa, sab) context_menu.dump() return context_menu
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 = Menu() 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 _window_menu(self): window_menu = SMenu(Group(CloseAction(), CloseOthersAction(), id='Close'), Group(MinimizeAction(), ResetLayoutAction(), PositionAction()), WindowGroup(), id='Window', name='Window') return window_menu
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 _groups_default(self): """ Trait initialiser. """ app = self.window.application editors = [factory() for factory in app.get_extensions(EDITORS)] editors_group = Group(id="editors") for editor in editors: action = OpenWithAction(editor=editor, window=self.window) editors_group.append(action) return [editors_group]
def __label_menu_default(self): """ Trait initialiser. """ size_group = Group(LabelIncrementSizeAction(window=self), LabelDecrementSizeAction(window=self)) normal = LabelNormalFontAction(window=self, id='normal', style='radio', checked=True) bold = LabelBoldFontAction(window=self, id='bold', style='radio') italic = LabelItalicFontAction(window=self, id='italic', style='radio') style_group = Group(normal, bold, italic, id='style') return MenuManager(size_group, style_group, name="&Label")
def get_actions_Menu_View_ColorGroup(self): return [ SMenu(Group(va.ColorStandardAction(name="NTSC", color_standard=0), va.ColorStandardAction(name="PAL", color_standard=1), id="a0", separator=True), Group(va.UseColorsAction(name="ANTIC Powerup Colors", colors=colors.powerup_colors()), id="a1", separator=True), Group(va.AnticColorAction(), id="a2", separator=True), id='mm4', separator=False, name="Colors"), ]
def get_actions_Menu_View_ConfigGroup(self): category_actions = {} for v in self.known_viewers: cat = v.viewer_category if cat not in category_actions: category_actions[cat] = [] category_actions[cat].append(ba.AddViewerAction(viewer=v)) submenus = [] sid = 1 first = True for cat in sorted(category_actions.keys()): submenus.append( SMenu(Group(*category_actions[cat], id="a%d" % sid, separator=True), id='ViewerChoiceSubmenu%d' % sid, separator=first, name="Add %s Viewer" % cat)) sid += 1 first = False submenus.extend([ Separator(), ba.ViewDiffHighlightAction(), va.TextFontAction(), ]) return submenus
def get_actions_Menu_DiskImage_ParserGroup(self): groups = [] for mime, pretty, parsers in iter_known_segment_parsers(): actions = [ ba.SegmentParserAction(segment_parser=s) for s in parsers ] if not pretty: groups.append( Group(ba.CurrentSegmentParserAction(), separator=True)) groups.append(Group(*actions, separator=True)) else: groups.append( SMenu(Group(*actions, separator=True), name=pretty)) return [ SMenu(*groups, id='submenu1', separator=False, name="File Type"), ]
def _create_item_group(self, window): """ Creates a group containing the items. """ group = Group() self._initialize_item_group(window, group) return group
def make_menu(self): self.edit_group = Group( AddSuffixAction(), ChangeSuffixAction(), ) self.menu = MenuManager(self.edit_group)
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_reset_perspective_group(self, window): """ Create the reset perspective actions. """ group = Group(ResetActivePerspectiveAction(window=window), ResetAllPerspectivesAction(window=window)) return group
def _create_view_group(self, window): """ Creates a group containing the view 'togglers'. """ group = Group() self._initialize_view_group(window, group) return group
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 __label_menu_default(self): """ Trait initialiser. """ size_group = Group(CommandAction(command=LabelIncrementSizeCommand), CommandAction(command=LabelDecrementSizeCommand)) normal = CommandAction(id='normal', command=LabelNormalFontCommand, style='radio', checked=True) bold = CommandAction(id='bold', command=LabelBoldFontCommand, style='radio') italic = CommandAction(id='italic', command=LabelItalicFontCommand, style='radio') style_group = Group(normal, bold, italic, id='style') return MenuManager(size_group, style_group, name="&Label")
def get_cell_context_menu(self, row, col): """ Return a MenuManager object that will generate the appropriate context menu for this cell.""" context_menu = MenuManager( Group(_CopyAction(self, row, col, name="Copy"), id="Group")) return context_menu
def _create_menu_manager(self, menu_definition): """ Create a menu manager implementation from a definition. """ menu_manager = MenuManager(id=menu_definition.id) for group_definition in menu_definition.groups: menu_manager.insert(-1, Group(id=group_definition.id)) return menu_manager
def _create_perspective_group(self, window): """ Create the actions that switch to specific perspectives. """ # fixme: Not sure if alphabetic sorting is appropriate in all cases, # but it will do for now! perspectives = window.perspectives[:] perspectives.sort(lambda x, y: cmp(x.name, y.name)) # For each perspective, create an action that sets the active # perspective to it. group = Group() for perspective in perspectives: group.append( SetActivePerspectiveAction( perspective=perspective, window=window ) ) return group
def _groups_default(self): """ Trait initialiser. """ # groups = super(PylonViewMenuManager, self)._groups_default() groups = [] new_group = Group(id="NewGroup") new_group.append(NewWindowAction(window=self.window)) # FIXME: Changing the enabled trait of the NewEditorAction causes barf # new_group.append(NewEditorAction(window=self.window)) # Insert a group for new part actions groups.append(new_group) # Add a group for view and perspective sub menus submenu_group = Group(id="SubMenuGroup") # Add the perspective menu (if requested). if self.show_perspective_menu and len(self.window.perspectives) > 0: perspective_menu = PerspectiveMenuManager(window=self.window) submenu_group.append(perspective_menu) # TODO: Create a ViewMenuManager with a selection of views view_submenu = MenuManager(self._create_other_group(self.window), name="Show View") submenu_group.append(view_submenu) groups.append(submenu_group) # Add a group containing a 'toggler' for all visible views. self._view_group = self._create_view_group(self.window) groups.append(self._view_group) # Add a group containing the preferences action groups.append( Group(PreferencesAction(window=self.window)) ) return groups
def __init__(self, **traits): """Initialise the object.""" pm = get_permissions_manager() # Put them in a group so we can optionally append (because the PyFace # API doesn't do what you expect with append()). group = Group() group.append(LoginAction()) for act in pm.user_manager.user_actions: group.append(act) group.append(LogoutAction()) for act in pm.user_manager.management_actions: group.append(act) for act in pm.policy_manager.management_actions: group.append(act) super(UserMenuManager, self).__init__(group, **traits)