Example #1
0
    def __init__(self, manager, parent, controller):
        """ Creates a new tree. """

        # Base class constructor.
        MenuBar.__init__(self, parent)

        # The parent of the menu.
        self._parent = parent

        # The manager that the menu is a view of.
        self._manager = manager

        # The controller.
        self._controller = controller

        # List of menu items
        self.menu_items = []

        # Create the menu structure.
        self.refresh()

        # Listen to the manager being updated.
        self._manager.on_trait_change(self.refresh, 'changed')
        self._manager.on_trait_change(self._on_enabled_changed, 'enabled')

        return
class MenuBarHiddenItemsExample(VerticalLayout):

    def __init__(self):
        super(MenuBarHiddenItemsExample, self).__init__()

        self._menubar = MenuBar()

        menuCommand = MenuCommand(self)

        # Save reference to individual items so we can add sub-menu
        # items to them
        f = self._menubar.addItem('File', None)
        newItem = f.addItem('New', None)
        f.addItem('Open f...', menuCommand)
        f.addSeparator()
        newItem.addItem('File', menuCommand)
        newItem.addItem('Folder', menuCommand)
        newItem.addItem('Project...', menuCommand)
        f.addItem('Close', menuCommand)
        f.addItem('Close All', menuCommand)
        f.addSeparator()
        f.addItem('Save', menuCommand)
        f.addItem('Save As...', menuCommand)
        f.addItem('Save All', menuCommand)

        edit = self._menubar.addItem('Edit', None)
        edit.addItem('Undo', menuCommand)

        redo = edit.addItem('Redo', menuCommand)
        redo.setEnabled(False)

        edit.addSeparator()
        edit.addItem('Cut', menuCommand)
        edit.addItem('Copy', menuCommand)
        edit.addItem('Paste', menuCommand)
        edit.addSeparator()

        find = edit.addItem('Find/Replace', menuCommand)

        # Actions can be added inline as well, of course
        find.addItem('Google Search', SearchCommand(self))
        find.addSeparator()
        find.addItem('Find/Replace...', menuCommand)
        find.addItem('Find Next', menuCommand)
        find.addItem('Find Previous', menuCommand)

        view = self._menubar.addItem('View', None)
        view.addItem('Show/Hide Status Bar', menuCommand)
        view.addItem('Customize Toolbar...', menuCommand)
        view.addSeparator()
        view.addItem('Actual Size', menuCommand)
        view.addItem('Zoom In', menuCommand)
        view.addItem('Zoom Out', menuCommand)

        self.addComponent(self._menubar)
        self.addComponent( Button('Hide File menu', HideListener(f)) )

        l = RedoListener(redo)
        self.addComponent( Button('Enable Edit -> Redo action', l) )
        self.setSpacing(True)
class MenuBarWithIconsExample(VerticalLayout):

    def __init__(self):
        super(MenuBarWithIconsExample, self).__init__()

        self._menubar = MenuBar()

        menuCommand = MenuCommand(self)

        # Save reference to individual items so we can add sub-menu items to
        # them
        f = self._menubar.addItem('File', None)
        newItem = f.addItem('New', None)
        f.addItem('Open file...',
                ThemeResource('../runo/icons/16/folder.png'), menuCommand)
        f.addSeparator()
        newItem.addItem('File',
                ThemeResource('../runo/icons/16/document.png'), menuCommand)
        newItem.addItem('Folder',
                ThemeResource('../runo/icons/16/folder.png'), menuCommand)
        newItem.addItem('Project...',
                ThemeResource('../runo/icons/16/globe.png'), menuCommand)
        f.addItem('Close', menuCommand)
        f.addItem('Close All', menuCommand)
        f.addSeparator()
        f.addItem('Save', menuCommand)
        f.addItem('Save As...', menuCommand)
        f.addItem('Save All', menuCommand)

        edit = self._menubar.addItem('Edit', None)
        edit.addItem('Undo', menuCommand)
        edit.addItem('Redo', menuCommand).setEnabled(False)
        edit.addSeparator()
        edit.addItem('Cut', menuCommand)
        edit.addItem('Copy', menuCommand)
        edit.addItem('Paste', menuCommand)

        edit.addSeparator()
        find = edit.addItem('Find/Replace', menuCommand)

        # Actions can be added inline as well, of course
        find.addItem('Google Search', SearchCommand(self))
        find.addSeparator()
        find.addItem('Find/Replace...', menuCommand)
        find.addItem('Find Next', menuCommand)
        find.addItem('Find Previous', menuCommand)

        view = self._menubar.addItem('View',
                ThemeResource('../runo/icons/16/user.png'), None)
        view.addItem('Show/Hide Status Bar', menuCommand)
        view.addItem('Customize Toolbar...', menuCommand)
        view.addSeparator()
        view.addItem('Actual Size', menuCommand)
        view.addItem('Zoom In', menuCommand)
        view.addItem('Zoom Out', menuCommand)

        self.addComponent(self._menubar)
Example #4
0
    def __init__(self):
        super(BasicMenuBarExample, self).__init__()

        self._menubar = MenuBar()

        menuCommand = MenuCommand(self)

        # Save reference to individual items so we can add sub-menu
        # items to them
        f = self._menubar.addItem('File', None)
        newItem = f.addItem('New', None)
        f.addItem('Open f...', menuCommand)
        f.addSeparator()
        newItem.addItem('File', menuCommand)
        newItem.addItem('Folder', menuCommand)
        newItem.addItem('Project...', menuCommand)
        f.addItem('Close', menuCommand)
        f.addItem('Close All', menuCommand)
        f.addSeparator()
        f.addItem('Save', menuCommand)
        f.addItem('Save As...', menuCommand)
        f.addItem('Save All', menuCommand)

        edit = self._menubar.addItem('Edit', None)
        edit.addItem('Undo', menuCommand)
        edit.addItem('Redo', menuCommand).setEnabled(False)
        edit.addSeparator()
        edit.addItem('Cut', menuCommand)
        edit.addItem('Copy', menuCommand)
        edit.addItem('Paste', menuCommand)

        edit.addSeparator()
        find = edit.addItem('Find/Replace', menuCommand)

        # Actions can be added inline as well, of course
        find.addItem('Google Search', SearchCommand(self))
        find.addSeparator()
        find.addItem('Find/Replace...', menuCommand)
        find.addItem('Find Next', menuCommand)
        find.addItem('Find Previous', menuCommand)

        view = self._menubar.addItem('View', None)
        view.addItem('Show/Hide Status Bar', menuCommand)
        view.addItem('Customize Toolbar...', menuCommand)
        view.addSeparator()
        view.addItem('Actual Size', menuCommand)
        view.addItem('Zoom In', menuCommand)
        view.addItem('Zoom Out', menuCommand)

        self.addComponent(self._menubar)
class MenuBarCheckableItemsExample(VerticalLayout):

    def __init__(self):
        super(MenuBarCheckableItemsExample, self).__init__()

        self._menubar = MenuBar()

        menuCommand = MenuCommand(self)

        f = self._menubar.addItem('File', None)
        f.addItem('New...', menuCommand)
        f.addItem('Open...', menuCommand)
        f.addSeparator()
        f.addItem('Save', menuCommand)
        f.addSeparator()
        # Save on exit is checkable but we do not want any listener to be
        # called when its state changes
        saveOnExit = f.addItem('Save on exit', None)
        saveOnExit.setCheckable(True)
        saveOnExit.setChecked(True)
        f.addSeparator()
        f.addItem('Exit', menuCommand)

        settings = self._menubar.addItem('Settings', None)
        # These settings are checkable and the listener is called when their
        # state changes
        setting1 = settings.addItem('Allow settings to be changed by all users',
                menuCommand)
        setting1.setCheckable(True)
        setting1.setChecked(True)

        setting2 = settings.addItem('Convert XML files automatically',
                menuCommand)
        setting2.setCheckable(True)

        setting3 = settings.addItem('Convert files automatically',
                menuCommand)
        setting3.setCheckable(True)
        settings.addSeparator()

        # This could be used to show a popup with all the settings for the
        # application
        settings.addItem('More settings...', menuCommand)
        self.addComponent(self._menubar)
Example #6
0
class MenuBarCheckableItemsExample(VerticalLayout):
    def __init__(self):
        super(MenuBarCheckableItemsExample, self).__init__()

        self._menubar = MenuBar()

        menuCommand = MenuCommand(self)

        f = self._menubar.addItem('File', None)
        f.addItem('New...', menuCommand)
        f.addItem('Open...', menuCommand)
        f.addSeparator()
        f.addItem('Save', menuCommand)
        f.addSeparator()
        # Save on exit is checkable but we do not want any listener to be
        # called when its state changes
        saveOnExit = f.addItem('Save on exit', menuCommand)
        saveOnExit.setCheckable(True)
        saveOnExit.setChecked(True)
        f.addSeparator()
        f.addItem('Exit', menuCommand)

        settings = self._menubar.addItem('Settings', None)
        # These settings are checkable and the listener is called when their
        # state changes
        setting1 = settings.addItem(
            'Allow settings to be changed by all users', menuCommand)
        setting1.setCheckable(True)
        setting1.setChecked(True)

        setting2 = settings.addItem('Convert XML files automatically',
                                    menuCommand)
        setting2.setCheckable(True)

        setting3 = settings.addItem('Convert files automatically', menuCommand)
        setting3.setCheckable(True)
        settings.addSeparator()

        # This could be used to show a popup with all the settings for the
        # application
        settings.addItem('More settings...', menuCommand)
        self.addComponent(self._menubar)
Example #7
0
    def create_menu_bar(self, parent, controller=None):
        """ Creates a menu bar representation of the manager. """

        # If a controller is required it can either be set as a trait on the
        # menu bar manager (the trait is part of the 'ActionManager' API), or
        # passed in here (if one is passed in here it takes precedence over the
        # trait).
        if controller is None:
            controller = self.controller

        # Create the menu bar.
        menu_bar = MenuBar(parent)

        # Every item in every group must be a menu manager.
        for group in self.groups:
            for item in group.items:
                menu = item.create_menu(parent, controller)
                menu.menuAction().setText(item.name)
                menu_bar.addMenu(menu)

        return menu_bar
Example #8
0
    def __init__(self):
        super(BasicMenuBarExample, self).__init__()

        self._menubar = MenuBar()

        menuCommand = MenuCommand(self)

        # Save reference to individual items so we can add sub-menu
        # items to them
        f = self._menubar.addItem('File', None)
        newItem = f.addItem('New', None)
        f.addItem('Open f...', menuCommand)
        f.addSeparator()
        newItem.addItem('File', menuCommand)
        newItem.addItem('Folder', menuCommand)
        newItem.addItem('Project...', menuCommand)
        f.addItem('Close', menuCommand)
        f.addItem('Close All', menuCommand)
        f.addSeparator()
        f.addItem('Save', menuCommand)
        f.addItem('Save As...', menuCommand)
        f.addItem('Save All', menuCommand)

        edit = self._menubar.addItem('Edit', None)
        edit.addItem('Undo', menuCommand)
        edit.addItem('Redo', menuCommand).setEnabled(False)
        edit.addSeparator()
        edit.addItem('Cut', menuCommand)
        edit.addItem('Copy', menuCommand)
        edit.addItem('Paste', menuCommand)

        edit.addSeparator()
        find = edit.addItem('Find/Replace', menuCommand)

        # Actions can be added inline as well, of course
        find.addItem('Google Search', SearchCommand(self))
        find.addSeparator()
        find.addItem('Find/Replace...', menuCommand)
        find.addItem('Find Next', menuCommand)
        find.addItem('Find Previous', menuCommand)

        view = self._menubar.addItem('View', None)
        view.addItem('Show/Hide Status Bar', menuCommand)
        view.addItem('Customize Toolbar...', menuCommand)
        view.addSeparator()
        view.addItem('Actual Size', menuCommand)
        view.addItem('Zoom In', menuCommand)
        view.addItem('Zoom Out', menuCommand)

        self.addComponent(self._menubar)
Example #9
0
    def __init__(self):
        super(MenuBarTooltipsExample, self).__init__()

        self._menubar = MenuBar()

        menuCommand = MenuCommand(self)

        # Add tooltip to the menubar itself
        self._menubar.setDescription('Perform some actions by selecting '
                'them from the menus')

        # Save reference to individual items so we can add sub-menu
        # items to them
        f = self._menubar.addItem('File', None)
        f.setDescription('File menu')
        newItem = f.addItem('New', None)
        newItem.setDescription('Add a new..')
        opn = f.addItem('Open file...', menuCommand)
        opn.setDescription('Retrieve a file from the filesystem')
        f.addSeparator()

        item = newItem.addItem('File', menuCommand)
        item.setDescription('Open a file')
        item = newItem.addItem('Folder', menuCommand)
        item.setDescription('Open a folder')
        item = newItem.addItem('Project...', menuCommand)
        item.setDescription('Open a project')
        item = f.addItem('Close', menuCommand)
        item.setDescription('Closes the selected file')
        item = f.addItem('Close All', menuCommand)
        item.setDescription('Closes all files')

        f.addSeparator()
        item = f.addItem('Save', menuCommand)
        item.setDescription('Saves the file')
        item = f.addItem('Save As...', menuCommand)
        item.setDescription('Saves the file with a different name')
        item = f.addItem('Save All', menuCommand)
        item.setDescription('Saves all files')

        edit = self._menubar.addItem('Edit', None)
        edit.setDescription('Edit menu')
        item = edit.addItem('Undo', menuCommand)
        item.setDescription('Reverses recent changes')
        item = edit.addItem('Redo', menuCommand)
        item.setEnabled(False)
        item.setDescription('Redoes undone changed')

        edit.addSeparator()
        item = edit.addItem('Cut', menuCommand)
        item.setDescription('Copies the text to the clipboard and removes it')
        item = edit.addItem('Copy', menuCommand)
        item.setDescription('Copies the text to the clipboard')
        item = edit.addItem('Paste', menuCommand)
        item.setDescription('Copies the contents of the clipboard on to the document')

        edit.addSeparator()
        find = edit.addItem('Find/Replace', menuCommand)
        find.setDescription('Find or Replace text')

        # Actions can be added inline as well, of course
        item = find.addItem('Google Search', SearchCommand(self))
        item.setDescription('Search with Google')

        find.addSeparator()
        item = find.addItem('Find/Replace...', menuCommand)
        item.setDescription('Finds or replaces text')
        item = find.addItem('Find Next', menuCommand)
        item.setDescription('Find the next occurrence')
        item = find.addItem('Find Previous', menuCommand)
        item.setDescription('Find the previous occurrence')

        view = self._menubar.addItem('View', None)
        view.setDescription('View menu')
        item = view.addItem('Show/Hide Status Bar', menuCommand)
        item.setDescription('Toggles the visibility of the Status Bar')
        item = view.addItem('Customize Toolbar...', menuCommand)
        item.setDescription('Add or remove items in the toolbar')

        view.addSeparator()
        item = view.addItem('Actual Size', menuCommand)
        item.setDescription('Resize view to the original size')
        item = view.addItem('Zoom In', menuCommand)
        item.setDescription('Zoom the document in by 10%')
        item = view.addItem('Zoom Out', menuCommand)
        item.setDescription('Zoom the doucment out by 10%')

        self.addComponent(self._menubar)
    def __init__(self):
        super(MenuBarTooltipsExample, self).__init__()

        self._menubar = MenuBar()

        menuCommand = MenuCommand(self)

        # Add tooltip to the menubar itself
        self._menubar.setDescription('Perform some actions by selecting '
                                     'them from the menus')

        # Save reference to individual items so we can add sub-menu
        # items to them
        f = self._menubar.addItem('File', None)
        f.setDescription('File menu')
        newItem = f.addItem('New', None)
        newItem.setDescription('Add a new..')
        opn = f.addItem('Open file...', menuCommand)
        opn.setDescription('Retrieve a file from the filesystem')
        f.addSeparator()

        item = newItem.addItem('File', menuCommand)
        item.setDescription('Open a file')
        item = newItem.addItem('Folder', menuCommand)
        item.setDescription('Open a folder')
        item = newItem.addItem('Project...', menuCommand)
        item.setDescription('Open a project')
        item = f.addItem('Close', menuCommand)
        item.setDescription('Closes the selected file')
        item = f.addItem('Close All', menuCommand)
        item.setDescription('Closes all files')

        f.addSeparator()
        item = f.addItem('Save', menuCommand)
        item.setDescription('Saves the file')
        item = f.addItem('Save As...', menuCommand)
        item.setDescription('Saves the file with a different name')
        item = f.addItem('Save All', menuCommand)
        item.setDescription('Saves all files')

        edit = self._menubar.addItem('Edit', None)
        edit.setDescription('Edit menu')
        item = edit.addItem('Undo', menuCommand)
        item.setDescription('Reverses recent changes')
        item = edit.addItem('Redo', menuCommand)
        item.setEnabled(False)
        item.setDescription('Redoes undone changed')

        edit.addSeparator()
        item = edit.addItem('Cut', menuCommand)
        item.setDescription('Copies the text to the clipboard and removes it')
        item = edit.addItem('Copy', menuCommand)
        item.setDescription('Copies the text to the clipboard')
        item = edit.addItem('Paste', menuCommand)
        item.setDescription(
            'Copies the contents of the clipboard on to the document')

        edit.addSeparator()
        find = edit.addItem('Find/Replace', menuCommand)
        find.setDescription('Find or Replace text')

        # Actions can be added inline as well, of course
        item = find.addItem('Google Search', SearchCommand(self))
        item.setDescription('Search with Google')

        find.addSeparator()
        item = find.addItem('Find/Replace...', menuCommand)
        item.setDescription('Finds or replaces text')
        item = find.addItem('Find Next', menuCommand)
        item.setDescription('Find the next occurrence')
        item = find.addItem('Find Previous', menuCommand)
        item.setDescription('Find the previous occurrence')

        view = self._menubar.addItem('View', None)
        view.setDescription('View menu')
        item = view.addItem('Show/Hide Status Bar', menuCommand)
        item.setDescription('Toggles the visibility of the Status Bar')
        item = view.addItem('Customize Toolbar...', menuCommand)
        item.setDescription('Add or remove items in the toolbar')

        view.addSeparator()
        item = view.addItem('Actual Size', menuCommand)
        item.setDescription('Resize view to the original size')
        item = view.addItem('Zoom In', menuCommand)
        item.setDescription('Zoom the document in by 10%')
        item = view.addItem('Zoom Out', menuCommand)
        item.setDescription('Zoom the doucment out by 10%')

        self.addComponent(self._menubar)