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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#------------------------------------------------------------------------------
# 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 `MainWindow` widget.
This example demonstrates the use of the `MainWindow` widget. This is a
subclass of the `Window` widget which adds support for dock panes, tool
bars and a menu bar. The children of a `MainWindow` can be defined in
any order. Like `Window`, a `MainWindow` has at most one central widget
which is an instance of `Container`. A `MainWindow` can have any number
of `DockPane` and `ToolBar` children, and at most one `MenuBar`.
Support for a `StatusBar` will be added in the future.
<< autodoc-me >>
"""
from __future__ import print_function
from enaml.layout.api import vbox
from enaml.widgets.api import (
MainWindow, ToolBar, DockPane, MenuBar, Menu, Action, ActionGroup,
StatusBar, StatusItem, Container, Html, PushButton, Label,
)
enamldef MyMenuBar(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'))
enamldef MyStatusBar(StatusBar):
StatusItem:
Label:
text = "Status"
enamldef MyToolBar(ToolBar):
Action:
text = 'Button'
tool_tip = text
ActionGroup:
Action:
separator = True
Action:
checkable = True
text = 'Exclusive'
triggered :: print('triggered')
toggled :: print('toggled')
Action:
checkable = True
text = 'ToolBar'
Action:
checkable = True
text = 'Buttons'
Action:
separator = True
Action:
checkable = True
text = 'Checkable'
Action:
checkable = True
text = 'ToolBar'
Action:
checkable = True
text = 'Buttons'
enamldef MyDockPane(DockPane):
title << 'Dock Area %s | %s' % (dock_area, 'floating' if floating else 'docked')
Container:
PushButton:
text = 'Foo'
PushButton:
text = 'Bar'
PushButton:
text = 'Baz'
enamldef Main(MainWindow):
MyMenuBar:
pass
MyStatusBar:
pass
MyToolBar:
pass
MyToolBar:
dock_area = 'left'
MyToolBar:
dock_area = 'bottom'
MyDockPane:
dock_area = 'left'
allowed_dock_areas = ['left', 'right']
MyDockPane:
dock_area = 'right'
MyDockPane:
dock_area = 'right'
movable = False
Container:
constraints = [vbox(html, tbar, spacing=0)]
Html: html:
source = '<h1><center>Hello World!</center></h1>'
MyToolBar: tbar:
pass
MyDockPane:
dock_area = 'bottom'
floating = True
|