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

popup_menu

This example demonstrates how to popup a menu.

A menu can be popped up in 2-ways. The first is by declaring the menu as
a child of a widget and setting the 'context_menu' attribute to True. The
second method is by creating the menu on-demand, and then invoking it's
'popup()' method to show the menu at the current mouse location.
$ enaml-run popup_menu
../_images/ex_popup_menu.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 example demonstrates how to popup a menu.

A menu can be popped up in 2-ways. The first is by declaring the menu as
a child of a widget and setting the 'context_menu' attribute to True. The
second method is by creating the menu on-demand, and then invoking it's
'popup()' method to show the menu at the current mouse location.

<< autodoc-me >>
"""
from enaml.widgets.api import (
    Window, Container, PushButton, Menu, Action, Field
)


enamldef PopupMenu(Menu):
    Action:
        text = 'foo'
        triggered :: print text + ' triggered'
    Action:
        text = 'bar'
        triggered :: print text + ' triggered'
    Action:
        text = 'baz'
        triggered :: print text + ' triggered'
    Action:
        text = 'spam'
        triggered :: print text + ' triggered'
    Action:
        text = 'ham'
        triggered :: print text + ' triggered'


enamldef Main(Window):
    Container:
        PushButton:
            text = 'Popup Menu'
            clicked :: PopupMenu().popup()
        Field:
            text = 'Context Menu'
            read_only = True
            PopupMenu:
                context_menu = True

Back to top

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