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
  • Popup View Example
  • Edit on GitHub

Popup View Example

This is an example of a fully dynamic PopupView widget.

The PopupView is useful for displaying transient configuration dialogs and notification windows. The widget supports a transparent background.

Tip

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

$ enaml-run popup_view.enaml

Screenshot

../_images/ex_popup_view.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.
#------------------------------------------------------------------------------
""" This is an example of a fully dynamic PopupView widget.

The PopupView is useful for displaying transient configuration dialogs
and notification windows. The widget supports a transparent background.

<< autodoc-me >>
"""
from enaml.core.api import Include
from enaml.widgets.api import (
    Window, Container, PopupView, Form, Label, PushButton, ComboBox, Slider,
    Field, SpinBox
)


POSITIONS = {
    'Top Left': (0.0, 0.0),
    'Top Center': (0.5, 0.0),
    'Top Right': (1.0, 0.0),
    'Left': (0.0, 0.5),
    'Center': (0.5, 0.5),
    'Right': (1.0, 0.5),
    'Bottom Left': (0.0, 1.0),
    'Bottom Center': (0.5, 1.0),
    'Bottom Right': (1.0, 1.0),
}


enamldef ConfigPopup(PopupView): popup:
    foreground = 'white'
    background = 'rgba(30, 30, 30, 0.85)'
    parent_anchor << POSITIONS[parent_box.selected_item]
    anchor << POSITIONS[view_box.selected_item]
    arrow_size << sizer.value
    arrow_edge << edge.selected_item
    offset << (offset_x.value, offset_y.value)
    Form:
        padding = 20
        Label:
            foreground = 'white'
            text = 'Arrow Size'
        Slider: sizer:
            minimum = 5
            maximum = 30
            value = 20
        Label:
            foreground = 'white'
            text = 'Arrow Edge'
        ComboBox: edge:
            items = ['top', 'bottom', 'left', 'right']
            index = 0
        Label:
            foreground = 'white'
            text = 'Parent Anchor'
        ComboBox: parent_box:
            items = sorted(POSITIONS.keys())
            index = items.index('Center')
        Label:
            foreground = 'white'
            text = 'View Anchor'
        ComboBox: view_box:
            items = sorted(POSITIONS.keys())
            index = items.index('Top Center')
        Label:
            foreground = 'white'
            text = 'Offset X'
        SpinBox: offset_x:
            minimum = -30
            maximum = 30
        Label:
            foreground = 'white'
            text = 'Offset Y'
        SpinBox: offset_y:
            minimum = -30
            maximum = 30
        Include: inc:
            pass
        PushButton:
            text = 'Add Row'
            clicked ::
                items = [Label(text='Label', foreground='white'), Field()]
                inc.objects.extend(items)
        PushButton:
            text = 'Close'
            clicked :: popup.close()


enamldef NotificationPopup(PopupView):
    foreground = 'white'
    background = 'rgba(30, 30, 30, 0.85)'
    window_type = 'tool_tip'
    parent_anchor = (1.0, 1.0)
    anchor = (1.0, 1.0)
    offset = (-10, -10)
    timeout = 5
    fade_in_duration = 500
    fade_out_duration = 500
    Container:
        Label:
            foreground = 'white'
            text = 'Hello Enaml Notifications'
            align = 'center'


enamldef Main(Window): win:
    initial_size = (400, 400)
    Container:
        PushButton:
            text = 'Show Config Popup'
            clicked :: ConfigPopup(self).show()
        PushButton:
            text = 'Show Window Notification'
            clicked :: NotificationPopup(win, window_type='window').show()
        PushButton:
            text = 'Show Desktop Notification'
            clicked :: NotificationPopup().show()
        PushButton:
            text = 'Show Mouse Notification'
            clicked ::
                popup = NotificationPopup()
                popup.anchor_mode = 'cursor'
                popup.anchor = (0.0, 0.0)
                popup.offset = (0, 0)
                popup.timeout = 1
                popup.show()
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