Enaml 0.9.1
  • Site
      • Getting Started
      • Developer Guides
      • Architecture Reference
      • FAQs
      • Examples
      • API Reference
  • Page
      • Popup View 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

Popup View ExampleΒΆ

popup_view

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.
$ enaml-run popup_view
../_images/ex_popup_view.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.
#------------------------------------------------------------------------------
""" 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 << arrow_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: arrow_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()

Back to top

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