1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#------------------------------------------------------------------------------
# Copyright (c) 2013-2025, 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'))
|