Enaml
latest
  • Getting Started
  • Developer Guides
  • Architecture Reference
  • FAQs
  • Examples
    • Tutorial Examples
    • Widgets Examples
      • Buttons Example
      • Context Menu Example
      • Dates Example
      • Dock Area Example
      • Dock Pane Example
      • Drag And Drop Example
      • Dual Slider Example
      • Field Example
      • File Dialog Example
      • Flow Area Example
      • Focus Traversal Example
      • Form Spacing Example
      • Form Example
      • Group Box Example
      • H Group Example
      • Image View Example
      • Ipython Console Example
      • Main Window Example
      • Menu Bar Example
      • Mdi Area Example
      • Mpl Canvas Example
      • Notebook Example
      • Popup Menu Example
      • Popup View Example
      • Progress Bar Example
      • Scroll Area Example
      • Slider Example
      • Spin Box Example
      • Splitter Example
      • Tool Bar Example
      • Tool Buttons Example
      • V Group Example
      • Vtk Canvas Example
      • Window Example
      • Window Children Example
    • Layout Examples
    • Stdlib Examples
    • Dynamic Examples
    • Aliases Examples
    • Functions Examples
    • Styling Examples
    • Templates Examples
    • Applib Examples
    • Workbench Examples
  • API Reference
  • Command Reference
  • Developer Notes
Enaml
  • Examples
  • Menu Bar Example
  • Edit on GitHub

Menu Bar Example

An example of the MenuBar widget.

This example demonstrates the use of the MenuBar widget. A MenuBar can have an arbitrary number of children, which must be Menu widgets. A Menu can have an arbitrary number of children which must be Menu widgets or Action widgets. An Menu child becomes a submenu, and an Action is represented as a clickable menu item. A MenuBar must be used as the child of a MainWindow.

This example also demonstrates the ActionGroup widget. An ActionGroup is used logically group multiple Action widgets together. Changes to the enabled or visible state of the ActionGroup apply to all of the Action widgets in that group. Additionally, the ActionGroup is the primary means of making Action widgets exclusive. The default behavior of the group is to make all child Action widgets mutually exclusive. This can be disabled by setting exclusive = False on the ActionGroup.

Tip

To see this example in action, download it from menu_bar and run:

$ enaml-run menu_bar.enaml

Screenshot

../_images/ex_menu_bar.png

Example Enaml Code

#------------------------------------------------------------------------------
# Copyright (c) 2013, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
""" An example of the `MenuBar` widget.

This example demonstrates the use of the `MenuBar` widget. A `MenuBar`
can have an arbitrary number of children, which must be `Menu` widgets.
A `Menu` can have an arbitrary number of children which must be `Menu`
widgets or `Action` widgets. An `Menu` child becomes a submenu, and an
`Action` is represented as a clickable menu item. A `MenuBar` must be
used as the child of a `MainWindow`.

This example also demonstrates the `ActionGroup` widget. An `ActionGroup`
is used logically group multiple `Action` widgets together. Changes to
the `enabled` or `visible` state of the `ActionGroup` apply to all of the
`Action` widgets in that group. Additionally, the `ActionGroup` is the
primary means of making `Action` widgets exclusive. The default behavior
of the group is to make all child `Action` widgets mutually exclusive.
This can be disabled by setting `exclusive = False` on the `ActionGroup`.

<< autodoc-me >>
"""
from __future__ import print_function
from enaml.widgets.api import MainWindow, MenuBar, Menu, Action, ActionGroup


enamldef Main(MainWindow):
    MenuBar:
        Menu:
            title = '&File'
            Action:
                text = 'New File\tCtrl+N'
                triggered :: print('New File triggered')
            Action:
                text = 'Open File\tCtrl+O'
                triggered :: print('Open File triggered')
            Action:
                text = 'Open Folder...'
                triggered :: print('Open Folder triggered')
        Menu:
            title = '&Edit'
            Action:
                text = 'Undo\tCtrl+Z'
                triggered :: print('Undo triggered')
            Action:
                text = 'Redo\tCtrl+R'
                triggered :: print('Redo triggered')
            Menu:
                title = 'Undo Selection'
                Action:
                    text = 'Undo Insert\tCtrl+U'
                    triggered :: print('Undo Insert triggered')
                Action:
                    text = 'Redo Insert\tCtrl+Shift+U'
                    enabled = False
                    triggered :: print('Redo Insert triggered')
            Action:
                separator = True
            Action:
                text = 'Cut\tCtrl+X'
                triggered :: print("Cut triggered")
            Action:
                text = 'Copy\tCtrl+C'
                triggered :: print('Copy triggered')
            Action:
                text = 'Paste\tCtrl+V'
                triggered :: print('Paste triggered')
        Menu:
            title = '&View'
            ActionGroup:
                Action:
                    checkable = True
                    text = 'Center'
                    toggled :: print('%s toggled %s' % (text, 'on' if checked else 'off'))
                Action:
                    checkable = True
                    text = 'Left'
                    toggled :: print('%s toggled %s' % (text, 'on' if checked else 'off'))
                Action:
                    checkable = True
                    text = 'Right'
                    toggled :: print('%s toggled %s' % (text, 'on' if checked else 'off'))
                Action:
                    checkable = True
                    text = 'Justify'
                    toggled :: print('%s toggled %s' % (text, 'on' if checked else 'off'))
Previous Next

© Copyright 2013-2021, Nucleic Development Team. Revision 052cd81f. Last updated on Jan 26, 2023.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: latest
Versions
latest
stable
Downloads
epub
On Read the Docs
Project Home
Builds