### Install Atom Framework from Source
Source: https://github.com/nucleic/enaml/blob/main/docs/source/get_started/installation.md
Clones the latest development version of the 'atom' framework from its Git repository and installs it using pip. This allows for the newest, potentially unstable, features.
```bash
git clone https://github.com/nucleic/atom.git
cd atom
pip install .
```
--------------------------------
### Install Enaml from Source
Source: https://github.com/nucleic/enaml/blob/main/docs/source/get_started/installation.md
Clones the latest development version of Enaml from its Git repository and installs it using pip. This method provides access to the most recent, potentially unstable, features of the Enaml framework.
```bash
git clone https://github.com/nucleic/enaml.git
cd enaml
pip install .
```
--------------------------------
### Install Enaml with Multiple Extras via Pip
Source: https://github.com/nucleic/enaml/blob/main/docs/source/get_started/installation.md
Installs Enaml along with multiple optional extras, such as specific widget support or rendering backends, using a single pip command. Extras are separated by commas.
```bash
$ pip install enaml[qt5-pyqt,ipython-qt]
```
--------------------------------
### Install Enaml with Specific Qt Backend via Pip
Source: https://github.com/nucleic/enaml/blob/main/docs/source/get_started/installation.md
Installs Enaml with a specific Qt rendering backend using pip's extra_requires feature. This allows users to choose between Qt5/Qt6 and PyQt/PySide.
```bash
$ pip install enaml[qt5-pyqt]
```
```bash
$ pip install enaml[qt5-pyside]
```
```bash
$ pip install enaml[qt6-pyqt]
```
```bash
$ pip install enaml[qt6-pyside]
```
--------------------------------
### Install Atom Framework using Pip
Source: https://github.com/nucleic/enaml/blob/main/docs/source/get_started/installation.md
Installs the 'atom' Python framework, which provides the foundational object model for Enaml. Atom is known for its lightweight, fast performance and Observer Pattern implementation.
```bash
$ pip install atom
```
--------------------------------
### Install Enaml with Qt Backend Support
Source: https://context7.com/nucleic/enaml/llms.txt
Installs Enaml with various Qt backends (PyQt5, PyQt6, PySide2) and optional extras like IPython support. Also shows installation via conda-forge.
```bash
# Install with PyQt5 backend (recommended)
pip install enaml[qt5-pyqt]
# Install with PyQt6 backend
pip install enaml[qt6-pyqt]
# Install with PySide2 backend
pip install enaml[qt5-pyside]
# Install with multiple extras (e.g., IPython console support)
pip install enaml[qt5-pyqt,ipython-qt]
# Install from conda-forge
conda install enaml -c conda-forge
```
--------------------------------
### Install QtPy Compatibility Layer with Pip
Source: https://github.com/nucleic/enaml/blob/main/docs/source/get_started/installation.md
Installs the QtPy library, which acts as a compatibility shim between different Qt rendering libraries (Qt5/Qt6, PyQt/PySide). This is a dependency for Enaml's toolkit rendering.
```bash
$ pip install QtPy
```
--------------------------------
### Install Enaml with Pip
Source: https://github.com/nucleic/enaml/blob/main/docs/source/get_started/installation.md
Installs Enaml and its core dependencies using pip. This method is suitable for users not utilizing the Anaconda distribution.
```bash
$ pip install enaml
```
--------------------------------
### Install Bytecode Library using Pip
Source: https://github.com/nucleic/enaml/blob/main/docs/source/get_started/installation.md
Installs the 'bytecode' Python library, which is used for generating and modifying bytecode. This is a key dependency for the Enaml compiler.
```bash
$ pip install bytecode
```
--------------------------------
### Install Kiwisolver for Layout Engine with Pip
Source: https://github.com/nucleic/enaml/blob/main/docs/source/get_started/installation.md
Installs the Kiwisolver library, which provides Python bindings to a C++ implementation of the Cassowary linear constraint optimizer. This is the core of Enaml's layout engine.
```bash
$ pip install kiwisolver
```
--------------------------------
### Enaml MainWindow Widget Example
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_main_window.md
This Enaml code snippet demonstrates the basic structure and usage of the `MainWindow` widget. It highlights how to define children like dock panes, toolbars, and a menu bar within the main window. This example is intended for users familiar with the Enaml declarative UI framework.
```enaml
#------------------------------------------------------------------------------
# Copyright (c) 2013-2025, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
```
--------------------------------
### Enaml Notebook Widget Example
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_notebook.md
Demonstrates the Enaml Notebook widget, which displays children as a tabbed control. It shows how to create pages, add widgets within pages, and control tab properties like closability and movability. The example also includes buttons to navigate between tabs and change tab styles.
```enaml
#------------------------------------------------------------------------------
# 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 `Notebook` widget.
This example demonstrates the use of the `Notebook` widget. A `Notebook`
displays its children as a tabbed control, where one child is visible
at a time. The children of a `Notebook` must be instances of `Page` and
parent of a `Page` must be a `Notebook`. A `Page` can have at most one
child which must be an instance of `Container`. This `Container` is
expanded to fill the available space in the page. A `Notebook` is layed
out using constraints just like normal constraints enabled widgets.
Implementation Notes:
Changing the tab style of the `Notebook` dynamically is not
supported on Wx. Close buttons on tabs is not supported on
Wx when using the 'preferences' tab style.
<< autodoc-me >>
"""
from enaml.widgets.api import (
Window, Notebook, Page, Container, PushButton, Field, Html, CheckBox
)
enamldef Main(Window):
Container:
Notebook: nbook:
tab_style = 'preferences'
Page:
title = 'Foo Page'
closable = False
tool_tip = 'Foo Page here'
Container:
PushButton:
text = 'Open Bar Page'
enabled << not bar.visible
clicked :: bar.open()
PushButton:
text = 'Open Baz Page'
enabled << not baz.visible
clicked :: baz.open()
PushButton:
text = 'Go to Bar Page'
enabled << bar.visible
clicked ::
nbook.selected_tab = 'bar_page'
PushButton:
text = 'Go to Baz Page'
enabled << baz.visible
clicked ::
nbook.selected_tab = 'baz_page'
CheckBox:
text = 'Tabs Closable'
checked := nbook.tabs_closable
CheckBox:
text = 'Tabs Movable'
checked := nbook.tabs_movable
CheckBox:
text = 'Document Style Tabs'
checked << nbook.tab_style == 'document'
toggled ::
if checked:
nbook.tab_style = 'document'
else:
nbook.tab_style = 'preferences'
Page: bar:
title = 'Bar Page'
name = 'bar_page'
Container:
Field:
pass
Field:
pass
Field:
pass
Page: baz:
title = 'Baz Page'
name = 'baz_page'
Container:
padding = 0
Html:
source = '
Hello World!
'
```
--------------------------------
### Vbox Layout Helper Example in Enaml
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_vbox.md
This Enaml code demonstrates how to use the `vbox` layout helper to arrange multiple `PushButton` widgets vertically within a `Container`. The `vbox` function handles the layout and spacing, ensuring proper alignment.
```enaml
#------------------------------------------------------------------------------
# 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 which demonstrates the use of the `vbox` layout helper.
In this example, we use the `vbox` layout helper to layout the children
of the Container in a vertical group. The `vbox` function is a fairly
sophisticated layout helper which automatically takes into account the
content boundaries of its parent. It also provides the necessary layout
spacers in the horizontal direction to allow for children of various
widths.
<< autodoc-me >>
"""
from enaml.layout.api import vbox
from enaml.widgets.api import Window, Container, PushButton
enamldef Main(Window):
Container:
constraints = [
vbox(pb1, pb2, pb3)
]
PushButton: pb1:
text = 'Spam'
PushButton: pb2:
text = 'Long Name Foo'
PushButton: pb3:
text = 'Bar'
```
--------------------------------
### Container Basic Attributes Example (Enaml)
Source: https://github.com/nucleic/enaml/blob/main/docs/source/api_ref/widgets/container.md
An Enaml example showcasing common attributes of a Container, including background, enabled state, font, foreground, and tooltips.
```enaml
Container:
background = 'lightblue'
enabled = True
font = '10pt Arial'
foreground = 'black'
tool_tip = 'This is a container widget.'
```
--------------------------------
### Python List Initialization Example
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_flow_area.md
A Python code snippet initializing a list of strings. This is a basic data structure example, likely used in conjunction with UI elements for selection or display.
```python
items = ['leading', 'center', 'trailing']
index = 0
```
--------------------------------
### Enaml ProgressBar Widget Example
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_progress_bar.md
Demonstrates the Enaml ProgressBar widget. It hooks up a PushButton to simulate work updates, showing progress percentage and value. Dependencies include enaml.layout.api and enaml.widgets.api.
```enaml
#------------------------------------------------------------------------------
# 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 'ProgressBar' widget.
This example demonstrates the use the `ProgressBar` widget by hooking
it up to a `PushButton` widgets which simulates a work update.
<< autodoc-me >>
"""
import random
from enaml.layout.api import hbox, align
from enaml.widgets.api import (
Window, Container, ProgressBar, Label, PushButton
)
enamldef Main(Window):
title = 'Progress Bar'
Container:
constraints = [
hbox(work_button, progress, label),
align('v_center', work_button, progress, label),
]
ProgressBar: progress:
pass
Label:
text << '{0}% ({1}/{2})'.format(progress.percentage, progress.value, progress.maximum)
PushButton: work_button:
text << "Do Some Work" if progress.percentage < 100 else "Reset"
clicked ::
if progress.percentage < 100:
val = progress.value + random.randint(0, 10)
progress.value = min(val, 100)
else:
progress.value = 0
```
--------------------------------
### Enaml MenuBar Widget Example
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_menu_bar.md
This snippet demonstrates the creation and structure of a MenuBar widget in Enaml. It shows how to add menus, submenus, and actions, and how to handle action triggers. The MenuBar must be a child of a MainWindow.
```enaml
#------------------------------------------------------------------------------
# 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'))
```
--------------------------------
### Python Workbench Entry Point
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/wb_sample.md
This Python script serves as the main entry point for the Enaml Workbench example. It initializes the UIWorkbench, registers a sample plugin manifest, and runs the workbench application. Dependencies include the 'enaml' library and its UI components.
```python
#------------------------------------------------------------------------------
# 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.
#------------------------------------------------------------------------------
""" A simple example plugin application.
This example serves to demonstrate the concepts described the accompanying
developer crash source document.
"""
import enaml
from enaml.workbench.ui.api import UIWorkbench
import sys, os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
def main():
with enaml.imports():
from sample_plugin import SampleManifest
workbench = UIWorkbench()
workbench.register(SampleManifest())
workbench.run()
if __name__ == '__main__':
main()
```
--------------------------------
### Run Enaml Application from Command Line
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/tut_hello_world.md
This command demonstrates how to execute an Enaml file directly from the terminal using the 'enaml-run' utility. It assumes the Enaml file defines a component named 'Main' or 'main'.
```bash
$ enaml-run hello_world_view.enaml
```
--------------------------------
### Install Enaml with Conda
Source: https://github.com/nucleic/enaml/blob/main/docs/source/get_started/installation.md
Installs the latest release of Enaml using the conda package manager from the conda-forge channel. This is the recommended method for Anaconda users.
```bash
$ conda install enaml -c conda-forge
```
--------------------------------
### Launch Enaml Application with Atom Object
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/tut_person.md
This Python script demonstrates how to launch an Enaml application. It imports the necessary components, creates a Person object, sets up a QtApplication, instantiates the PersonView with the Person object, and starts the application event loop.
```python
import enaml
from enaml.qt.qt_application import QtApplication
if __name__ == '__main__':
with enaml.imports():
from person_view import PersonView
john = Person(first_name='John', last_name='Doe', age=42)
john.debug = True
app = QtApplication()
view = PersonView(person=john)
view.show()
app.start()
```
--------------------------------
### Use Enaml View in Python Application
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/tut_hello_world.md
This Python code snippet shows how to import and instantiate an Enaml view, then display it. It utilizes 'enaml.imports()' as a context manager and requires a toolkit-specific application instance (like QtApplication) to run the event loop.
```python
import enaml
with enaml.imports():
from hello_world_view import Main
from enaml.qt.qt_application import QtApplication
app = QtApplication()
view = Main(message="Hello World, from Python!")
view.show()
# Start the application event loop
app.start()
```
--------------------------------
### Install Ply Parsing Tools with Pip
Source: https://github.com/nucleic/enaml/blob/main/docs/source/get_started/installation.md
Installs the PLY parsing tools, which are used by Enaml to extend Python's grammar with new declarative syntax constructs. This is a dependency for building Enaml from source.
```bash
$ pip install ply
```
--------------------------------
### Using hbox and vbox for Layouts in Enaml
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/tut_employee.md
Shows an alternative way to define constraints using the hbox and vbox layout functions for simpler, more direct layouts. These functions are advantageous for nesting and creating structured arrangements.
```enaml
Container:
constraints = [
vbox(btm_box, btm_box.when(btm_box.visible)),
align('midline', top_form, btm_form)
]
```
--------------------------------
### Assemble Drag and Drop Widgets in an Enaml Window
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_drag_and_drop.md
The `Main` window orchestrates the drag and drop example. It includes the `ExampleStyleSheet` and a `Container` holding two `DragLabel` widgets and one `DropField` target. Layout is managed using `hbox` and `vbox` constraints, demonstrating how draggable items are positioned relative to the drop target.
```enaml
from enaml.layout.api import hbox, vbox
from enaml.widgets.api import Window, Container
# Assuming DragLabel, DropField, and ExampleStyleSheet are defined elsewhere
enamldef Main(Window):
ExampleStyleSheet:
pass
Container:
constraints = [
hbox(vbox(lbl1, lbl2), target),
]
DragLabel: lbl1:
text = 'Drag Me 1'
data = b'small\ndata'
DragLabel: lbl2:
text = 'Drag Me 2'
data = b'\n'.join([bytes(str(i), 'utf-8') for i in range(100)])
DropField: target:
hug_width = 'strong'
read_only = True
```
--------------------------------
### IPythonConsole Widget Example in Enaml
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_ipython_console.md
This Enaml code defines a simple window containing an IPythonConsole widget. It demonstrates the basic integration of the console into an Enaml application. Ensure 'qtconsole' is installed for this widget to function correctly.
```enaml
#------------------------------------------------------------------------------
# Copyright (c) 2017-2024, 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 `IPythonConsole` widget.
Requires qtconsole to be installed.
<< autodoc-me >>
"""
from enaml.widgets.api import Window, Container, IPythonConsole
enamldef Main(Window):
title = 'IPython console'
Container:
padding = 0
IPythonConsole:
pass
```
--------------------------------
### WebView Widget Initialization and Properties
Source: https://github.com/nucleic/enaml/blob/main/docs/source/api_ref/widgets/web_view.md
Demonstrates the initialization of the WebView widget and setting its core properties like url and html. The url and html properties are mutually exclusive.
```python
from enaml.widgets.web_view import WebView
# Create a WebView instance
web_view = WebView()
# Set the URL to load
web_view.url = "https://www.example.com"
# Alternatively, set HTML content (mutually exclusive with url)
# web_view.html = "Hello, World!
"
# Set other properties
web_view.base_url = "/path/to/local/files"
web_view.hug_width = True
web_view.hug_height = False
web_view.background = "#FFFFFF"
web_view.enabled = True
web_view.style_class = "my-webview-style"
```
--------------------------------
### Enaml VTKCanvas Widget Example
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_vtk_canvas.md
This Enaml code defines a `Window` containing a `VTKCanvas` widget. The canvas is configured with a VTK renderer created by the `create_renderer` function, which visualizes a quadric function using contour and outline filters. Requires `enaml` and `vtk` to be installed.
```enaml
#------------------------------------------------------------------------------
# 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 `VTKCanvas` widget.
Requires vtk to be installed.
<< autodoc-me >>
"""
from enaml.widgets.api import Window, Container, VTKCanvas
import vtk
def create_renderer():
quadric = vtk.vtkQuadric()
quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0)
sample = vtk.vtkSampleFunction()
sample.SetSampleDimensions(50, 50, 50)
sample.SetImplicitFunction(quadric)
contours = vtk.vtkContourFilter()
contours.SetInputConnection(sample.GetOutputPort())
contours.GenerateValues(5, 0.0, 1.2)
contour_mapper = vtk.vtkPolyDataMapper()
contour_mapper.SetInputConnection(contours.GetOutputPort())
contour_mapper.SetScalarRange(0.0, 1.2)
contour_actor = vtk.vtkActor()
contour_actor.SetMapper(contour_mapper)
outline = vtk.vtkOutlineFilter()
outline.SetInputConnection(sample.GetOutputPort())
outline_mapper = vtk.vtkPolyDataMapper()
outline_mapper.SetInputConnection(outline.GetOutputPort())
outline_actor = vtk.vtkActor()
outline_actor.SetMapper(outline_mapper)
outline_actor.GetProperty().SetColor(0, 0, 0)
renderer = vtk.vtkRenderer()
renderer.AddActor(contour_actor)
renderer.AddActor(outline_actor)
renderer.SetBackground(.75, .75, .75)
return renderer
enamldef Main(Window):
title = 'VTK Canvas'
Container:
padding = 0
VTKCanvas:
renderer = create_renderer()
```
--------------------------------
### AutoFormBody Template for Model Structure
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_advanced.md
A template that constructs the body of an AutoForm by generating form items for each member of a given Atom model type. It uses `form_spec` to get the model's members and `ForEach` to iterate and create `FormItem`s.
```enaml
template AutoFormBody(ModelType):
""" A template which builds the body for an AutoForm.
Parameters
----------
ModelType : type
The type of the model. This should be an Atom subclass.
"""
const Spec: tuple = form_spec(ModelType)
ForEach(Spec, FormItem):
pass
```
--------------------------------
### Enaml Drag and Drop Functionality
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_drag_and_drop.md
This Enaml code snippet demonstrates the declarative functions for implementing drag and drop behavior. It includes functions for handling the start and end of a drag operation, as well as events for when a drag enters, moves within, leaves, or is dropped onto a widget. These functions are available on widgets with the DragEnabled and DropEnabled Feature flags.
```enaml
#------------------------------------------------------------------------------
# Copyright (c) 2014-2024,, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
```
--------------------------------
### MenuBar Widget
Source: https://github.com/nucleic/enaml/blob/main/docs/source/api_ref/widgets/menu_bar.md
Provides documentation for the MenuBar widget, which is used as a menu bar in a MainWindow. It includes details on its proxy object and how to retrieve its menus.
```APIDOC
## enaml.widgets.menu_bar.MenuBar
### Description
A widget used as a menu bar in a MainWindow.
### Method
N/A (Class Definition)
### Endpoint
N/A (Class Definition)
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
N/A
### Response
#### Success Response (200)
N/A
#### Response Example
N/A
### Methods
#### menus()
##### Description
Get the menus defined as children on the menu bar.
##### Method
N/A (Method within a class)
##### Endpoint
N/A (Method within a class)
##### Parameters
N/A
##### Request Example
N/A
##### Response
N/A
### Proxy
#### proxy
##### Description
A reference to the ProxyMenuBar object.
##### Method
N/A (Attribute within a class)
##### Endpoint
N/A (Attribute within a class)
##### Parameters
N/A
##### Request Example
N/A
##### Response
N/A
```
--------------------------------
### Window Show Method
Source: https://github.com/nucleic/enaml/blob/main/docs/source/api_ref/widgets/window.md
Shows the Enaml window on the screen. Initializes and builds the window hierarchy if necessary.
```APIDOC
## show()
### Description
Show the window to the screen. This is a reimplemented parent class method which will init and build the window hierarchy if needed.
### Method
POST
### Endpoint
/nucleic/enaml/show
### Parameters
#### Query Parameters
None
#### Request Body
None
### Request Example
```json
{
"message": "Show window request"
}
```
### Response
#### Success Response (200)
- **status** (string) - Indicates the success of the operation.
#### Response Example
```json
{
"status": "Window shown successfully"
}
```
```
--------------------------------
### Enaml DockArea Widget Example
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_dock_area.md
This Enaml code snippet showcases the usage of the DockArea widget. It provides a canvas for DockItems and supports saving/restoring layout configurations. No external dependencies are explicitly mentioned for this basic example.
```enaml
#------------------------------------------------------------------------------
# Copyright (c) 2013-2025, Nucleic Development Team
#
# Distributed under the terms of the Modified BSD License.
#
```
--------------------------------
### Create and Display Person GUI in Python
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/tut_person.md
This Python script defines a 'Person' class using Atom and demonstrates how to create a GUI using Enaml. It imports the 'PersonView' from an Enaml file, creates a 'Person' object, and displays it in a Qt application window. The 'debug_print' method shows how to observe changes to the 'age' attribute.
```python
#------------------------------------------------------------------------------
# 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.
#------------------------------------------------------------------------------
from __future__ import unicode_literals, print_function
from atom.api import Atom, Str, Range, Bool, observe
import enaml
from enaml.qt.qt_application import QtApplication
import sys, os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
class Person(Atom):
""" A simple class representing a person object.
"""
last_name = Str()
first_name = Str()
age = Range(low=0)
debug = Bool(False)
@observe('age')
def debug_print(self, change):
""" Prints out a debug message whenever the person's age changes.
"""
if self.debug:
templ = "{first} {last} is {age} years old."
s = templ.format(
first=self.first_name, last=self.last_name, age=self.age,
)
print(s)
def main():
with enaml.imports():
from person_view import PersonView
john = Person(first_name='John', last_name='Doe', age=42)
john.debug = True
app = QtApplication()
view = PersonView(person=john)
view.show()
app.start()
if __name__ == '__main__':
main()
```
--------------------------------
### Enaml Focus Traversal Example
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_focus_traversal.md
Demonstrates custom focus traversal logic in Enaml. It defines how widgets receive focus using Tab and Shift+Tab keys by specifying next and previous focusable widgets. This example uses a double-linked list approach for navigation.
```enaml
#------------------------------------------------------------------------------
# Copyright (c) 2014-2024,; 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 using the FocusTraversal advanced widget feature.
The FocusTraversal is an advanced widget feature for controlling the
order in which widgets receive focus during Tab and Shift+Tab keyboard
events. It enables two methods which can be implemented as declarative
Enaml functions which will compute the next/previous focus widgets on
demand.
In this example, the traversal handlers simply return the next or
previous field from a double-linked list of fields. However, there
is no restriction on how the handlers actually compute the focus
widgets.
<< autodoc-me >>
"""
from enaml.widgets.api import Window, GroupBox, Field, FocusTracker, Container, Feature
enamldef LinkField(Field):
attr next_field
attr prev_field
enamldef Main(Window):
title = 'Focus Traversal'
Container:
features = Feature.FocusTraversal
next_focus_child => (current): # triggered on Tab
return getattr(current, 'next_field', None)
previous_focus_child => (current): # triggered on Shift+Tab
return getattr(current, 'prev_field', None)
FocusTracker:
focused_widget::
print(change["value"])
GroupBox:
title = 'First Group'
LinkField: f1:
placeholder = '1'
next_field = f4
prev_field = f5
LinkField: f2:
placeholder = '5'
next_field = f7
prev_field = f6
LinkField: f3:
placeholder = '3'
next_field = f6
prev_field = f4
LinkField: f4:
placeholder = '2'
next_field = f3
prev_field = f1
GroupBox:
title = 'Second Group'
LinkField: f5:
placeholder = '7'
next_field = f1
prev_field = f7
LinkField: f6:
placeholder = '4'
next_field = f2
prev_field = f3
LinkField: f7:
placeholder = '6'
next_field = f5
prev_field = f2
```
--------------------------------
### Creating Nested Layouts with EmployerForm in Enaml
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/tut_employee.md
Illustrates how to create a custom component, EmployerForm, by inheriting from Container and defining nested hbox and vbox layouts. This example demonstrates setting constraints for child widget widths to ensure proper alignment.
```enaml
enamldef EmployerForm(Container):
attr employer
constraints = [
vbox(
hbox(cmp_lbl, mng_lbl, edit_lbl),
hbox(cmp_fld, mng_fld, en_cb),
),
cmp_lbl.width == cmp_fld.width,
mng_lbl.width == mng_fld.width,
edit_lbl.width == en_cb.width,
]
Label: cmp_lbl:
text = "Company:"
Field: cmp_fld:
text << employer.company_name
enabled << en_cb.checked
Label: mng_lbl:
text = "Reporting Manager:"
Field: mng_fld:
text << "%s %s" % (employer.first_name, employer.last_name)
enabled << en_cb.checked
Label: edit_lbl:
text = "Allow Editing:"
CheckBox: en_cb:
checked = True
```
--------------------------------
### PopupView Widget Initialization and Usage (Enaml)
Source: https://github.com/nucleic/enaml/blob/main/docs/source/api_ref/widgets/popup_view.md
Demonstrates how to create and display a PopupView widget in Enaml. This includes setting basic properties like window type and content, and then showing the popup. It highlights the transient nature of PopupView and its automatic destruction upon closing.
```enaml
from enaml.widgets.popup_view import PopupView
popup = PopupView(
window_type='popup',
# Add other properties as needed
)
# Assuming 'popup' is part of a layout or context where it can be shown
# popup.show()
# To close the popup:
# popup.close()
```
--------------------------------
### Applying Weighted Constraints in Enaml
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/tut_employee.md
Demonstrates how to apply constraints to a Container, including setting a specific width with a 'weak' weight for flexibility. It utilizes Enaml's constraint system and exposes content-related attributes for layout control.
```enaml
Container:
constraints << [
vertical(
top, top_box, btm_box.when(btm_box.visible), spacer, bottom
),
horizontal(left, spacer.flex(), top_box, spacer.flex(), right),
horizontal(left, spacer.flex(), btm_box, spacer.flex(), right),
align('midline', top_form, btm_form),
(width == 233) | 'weak'
]
```
--------------------------------
### Enaml Form Widget Layout Example
Source: https://github.com/nucleic/enaml/blob/main/docs/source/examples/ex_form.md
Demonstrates the Enaml Form widget's ability to automatically arrange children in two columns. It shows how the Form handles an odd number of children by spanning the last one across both columns and includes an example with nested containers and dynamic label updates.
```enaml
#------------------------------------------------------------------------------
# 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 `Form` widget.
A `Form` is a simple subclass of `Container` which automatically lays
out it children in two columns, neatly aligning the widget edges. If
a `Form` has an odd number of children, the last child will span both
columns. The typical use case of a `Form` alternates `Label` and `Field`
instances, but there is not restriction on the types of children used
with a form, except that they be constrainable.
<< autodoc-me >>
"""
from enaml.layout.api import hbox
from enaml.widgets.api import Window, Form, Container, Label, Slider, Field
enamldef Main(Window):
Form:
Label:
text = 'First Name'
Field:
pass
Label:
text = 'Last Name'
Field:
pass
Label:
text = 'Age'
Container:
padding = 0
constraints = [
hbox(lbl, sldr),
lbl.v_center == sldr.v_center,
]
Label: lbl:
text << '%d' % sldr.value
constraints = [width == 25]
Slider: sldr:
pass
Field:
placeholder = 'Odd Number Child'
```