Enaml 0.9.1
  • Site
      • Getting Started
      • Developer Guides
      • Architecture Reference
      • FAQs
      • Examples
      • API Reference
  • Page
      • Menu Bar Example
  • Index
  • Getting Started
  • Developer Guides
  • Architecture Reference
  • FAQs
  • Examples
    • Tutorial Examples
    • Widgets Examples
      • Buttons Example
      • Context Menu Example
      • Dock Area Example
      • Dock Pane Example
      • Dual Slider Example
      • File Dialog Example
      • Flow Area Example
      • Form Example
      • Group Box Example
      • Image View Example
      • Main Window Example
      • Menu Bar 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
      • Vtk Canvas Example
      • Window Example
      • Window Children Example
      • Window Closing Example
    • Layout Examples
    • Stdlib Examples
    • Dynamic Examples
    • Aliases Examples
    • Styling Examples
    • Templates Examples
    • Applib Examples
    • Workbench Examples
  • API Reference

Menu Bar ExampleΒΆ

menu_bar

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`.
$ enaml-run menu_bar
../_images/ex_menu_bar.png
#------------------------------------------------------------------------------
# Copyright (c) 2013, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, 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 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')

Back to top

© Copyright 2013, Nucleic Development Team.
Last updated on Feb 18, 2014.
Created using Sphinx 1.1.3.