Popup Menu Button Object

Radio buttons work well when there are only a few options. When you get past a dozen or so options, you’ll probably want to use a pop-up menu or Text List Object instead.

#### Creating a Basic Popup Menu

Start by dragging a pop-up menu object from the Object Library to the form. Then enter the name of the field or variable that will be linked to the pop-up menu. Finally, switch to the Formula panel and enter the menu choices, separated by commas (you can optionally include spaces, as shown below). To save time, I preloaded the menu choices into the clipboard.

For a basic pop-up menu, that’s it … you’re done!

#### Separator Lines

If you want separator lines in the menu, just use `(-` in any spot where you want a separator line.

#### Dynamic Popup Menus

The examples shown so far have been fixed menus – menus that never change. If you need a pop-up menu that can change dynamically, switch the object to Formula mode.

In this mode, the Formula panel actually contains a formula, instead of a comma separated list. Here is the revised formula for our National Park example. Notice that now each national park is on a separate line, and also note the quote characters at the beginning and end, which are necessary to make this a valid formula.

One minor advantage of this mode is that it allows menu choices to contain commas, which isn’t allowed in the Comma Separated Values mode. But the real power of Formula mode is unleashed when you use a variable or field in the formula. Since the variable or field may be changed at any time with a procedure (or even with standard data entry), the pop-up menu can change at any time. For example, suppose you want to make the national park menu user editable. I can create a Text Editor Object linked to a variable named NationalParkNames, like this:

Then I can change the pop-up menu formula to this same variable name.

Now the pop-up menu name can be edited on-the-fly.

In this example, the formula is very simple, just a single variable, but you can use as complex a formula as you need.

#### Custom Formulas

If you want to go the full Monty, you can create a fully custom menu with the menu( and menuitem( functions (see Custom Menus. With these, you have full control over the menu, including styles, colors, images, icons, checkmarks, submenus, etc, like this:

Here is the formula for this menu.

To learn how to design complex menus with these functions, see Custom Menus.

#### Diagnosing Formula Problems

If your formula has a problem it can be a bit tricky to figure out what’s wrong since you can’t directly see the text produced by the formula. In that situation you can use the Object Value dialog to display the entire formula result. See Diagnosing a Formula embedded in a Form Object to learn how to use this dialog.

#### Popup Menu Options

Click on the magic panel to see and modify the pop-up menu options:

Data – This is the field or variable that is linked to the pop-up menu. You can either type in the name of a field or variable, or you can choose a field name from the pop-up menu (on the right). Panorama will also auto-complete field names as you type.

When you select a choice from a pop-up menu, that choice will be be placed into the linked field or variable. Of course the value of a field or variable can also be set other ways, for example with an assignment statement in a procedure. This code will work with the pop-up menu shown in earlier examples to change the displayed national park to Grand Canyon.

    parkName = "Grand Canyon"
    showvariables parkName

There is a problem however, if the new value is not one of the available choices in the menu.

    parkName = "Petite Canyon"
    showvariables parkName

If the value is not a menu choice, the value will not be displayed. Instead, the pop-up menu will be blank.

The reason the pop-up menu is blank is that Panorama uses standard Apple pop-up menu code, and Apple’s code will only display values that are included in the menu. See Cocoa Objects for more information about why Panorama uses standard Apple code, in spite of some restrictions like this.

Note: If you specify a variable that has not already been created with a procedure, Panorama will automatically create a global, fileglobal or windowglobal variable with this name the first time the form is displayed. The type of variable created depends on the Form Preferences.

Data Source The data source is usually a field or variable, but you can also use a formula. See Using a Formula as the Popup Menu Data Source below to learn more about this option.

Size – Popup menu buttons may be one of three fixed heights: Regular, Small and Mini.

These are the only sizes available – see Cocoa Objects for more detail about the reasons for this limitation.

System Font – If this option is checked, the popup menu will always be displayed using the standard system font and font size. Uncheck this option if you want to use a non-standard font or size (in which case you select the font and size from the Text panel, see Fonts).

Transparent – If this option is checked, the button will be completely transparent (the title will also be hidden). This is handy if you want to put the button on top of other graphics, however, see Using Any Type of Object as a Pop-up Menu below for an alternate method for doing this.

Disabled – This option disables the button. When the button is disabled it is dimmed and it can’t be clicked on.

Of course there is no point in a button that is permanently disabled. So normally you would enable/disable a button with a procedure. See {Push Button Objects for an explanation of how a procedure can enable/disable a button.

#### Using Any Type of Object as a Pop-up Menu

Using the popupclick statement and a few lines of code, Panorama X allows any type of object to be converted into a pop-up menu. In this example, the button was created with the Font Awesome Icons wizard.

When the icon is clicked on, it runs the code which pops up the menu.

In older versions of Panorama (6 and earlier), a custom pop-up menu like this would have to be created by layering two objects on top of each other – an image and a transparent button. Now only a single object is needed.

#### Using a Formula as the Popup Menu Data Source

Panorama usually automatically links the pop-up menu to a database field or a variable. The pop-up menu automatically displays the contents of the field or variable in the pop-up menu, and automatically updates the value of the field or variable when a selection is made from the popup menu. In some cases, however, the value may not be in a field or variable. For example, the value might be in a preference value (see getpreferencevalue(), in a file on disk, or might need to be calculated on-the-fly somehow. To do this, change the Data Source to Formula and type in the formula into the Data box. (Note: This formula, which is used for the data value, is separate from the formula described above for creating the menu choices. In other words, a popup menu object can have two different formulas – one for the menu choices, and another for the data value.)

Here is an example that uses the preference value PXErrorDisplay as the data source. (If this preference value hasn’t been set yet, the formula defaults to displaying Alert in the popup menu.)

When the user makes a selection with this popup menu, Panorama doesn’t have a field or variable to put the selected value into. So instead, it puts the selected value into a fileglobal variable named PopupMenuResult (if this variable doesn’t already exist, Panorama creates it). It’s up to you to write code that takes this value and stores it somewhere. Here’s code that stores that value into the PXErrorDisplay preference value:

In addition to storing the value, this code needs to make sure that the display of the popup menu is refreshed with the new value. In this example, this is done with the variable exFresh. The second line of the code above tells Panorama to refresh any object that contains this variable. Looking back to the data formula for this object, you’ll notice that it contains this variable inside a catcherror( function.

    catcherror("",exFresh)+catcherror("Alert",getpreferencevalue("PXErrorDisplay"))

This variable doesn’t contain anything, in fact it doesn’t even exist! So that part of the formula doesn’t display anything. But even though the variable doesn’t exist, Panorama will still update the display when you use the showvariables statement in your code.

    showvariables exFresh

You could of course set up an actual variable in advance, then you wouldn’t have to use the catcherror( function. But since the variable isn’t actually needed for anything else, you may find the technique shown here simpler to use. (You could use any variable name you want, it doesn’t have to be exFresh, just make sure that you consistently use the same name in the data formula and the code.)

See Also

- Adjusting Object Spacing -- adjust the spacing between multiple selected objects so that the same amount of space is in between each pair of objects.
- adjustobjectspacing -- adjusts the spacing of selected objects in a form.
- adjustobjectspacingdialog -- opens a dialog sheet to adjust the spacing of the currently selected objects.
- Aligning Objects -- so that two or more object edges are made even with each other.
- Automatic Form Construction -- creates a column of form elements for editing data fields (or variables).
- Automatic Mailing Label Construction -- creates a mailing label.
- Automatic Report Construction -- creates a tabular report with columns of data.
- Cocoa Objects -- discussion of how objects are implemented in Panorama X compared to earlier versions
- Creating a New Form Object -- with the Object Library.
- Data Button Object -- is used to create checkboxes and radio buttons.
- Diagnosing a Formula embedded in a Form Object -- diagnosing problems with formulas embedded in form objects.
- Displaying Data in a Grid -- fundamentals of displaying data in a grid (Text List/Matrix).
- Duplicating Objects -- to make copies of one or more objects.
- Fixed Image Object -- is used for fixed images (images that never change).
- Fonts -- setting the font and text size of form text objects.
- Form Object Appearance -- changing the color, fill, stroke, opacity and drop shadow attributes of selected objects.
- Form Object Blueprint -- display and edit raw object specifications
- Form Object Code -- associating programming code with an object
- Grouping Objects -- allows you to manipulate multiple objects as if they were a single object.
- Image Display Animations -- animated images.
- Image Display Colors and Gradients -- displaying pure colors and gradients
- Image Display Data Buttons -- checkboxes and radio buttons created from custom images.
- Image Display Object -- is used for dynamic images (images that change depending on the data).
- Image Display Push Buttons -- push buttons created from custom images.
- info("clickedobjectname") -- returns the name of the button that was just clicked.
- Line Item Grid Constructor -- creates a grid of form elements for displaying and editing line item fields.
- Line Object -- draws a line within a form.
- Matrix Clicking -- handling clicks in a Matrix Object.
- Matrix Constructor -- quickly creating a Matrix Object from a template.
- Matrix Database Integration -- synchronizing a Matrix Object with a database.
- Matrix Geometry -- customizing the size and geometry of Matrix Object elements.
- Matrix Header and Horizontal Scrolling -- setting up a custom header for a Matrix Object grid.
- Matrix Object -- displaying a grid of items with a custom arrangement.
- Matrix Object Frame -- setting up the arrangement of items within a Matrix Object.
- Matrix Programming -- programming a Matrix object.
- Object Inspector Panel -- is used to view and modify the attributes of selected objects in a form.
- Object Library -- is used to create new objects in a form.
- Object Names -- can be used to identify an object in a program.
- Oval Object -- draws an oval or circle within a form.
- Polygon Object -- draws a polygon within a form.
- popup -- makes a pop-up menu appear anywhere on the screen.
- popupatmouse -- displays a pop-up menu at the current mouse location.
- popupbelowbutton -- displays a pop-up menu in response to clicking on a button.
- popupbynumber -- makes a pop-up menu appear anywhere on the screen.
- popupclick -- displays a pop-up menu at the current mouse location.
- popupdoublefieldchoices -- displays a pop-up menu listing values in a specified field, with submenus containing values from a second field.
- popupfieldchoices -- displays a pop-up menu listing values in a specified field.
- Progress Indicator Object -- is used to create progress indicators
- Push Button Object -- triggers a procedure when it is pushed.
- Rectangle Object -- draws a rectangle or square within a form.
- Report Tile Object -- component for assembling a custom report.
- Rounded Rectangle Object -- draws a rectangle with round corners within a form.
- Scroll Bar Object -- is used to create scroll bars.
- Segmented Button Object -- is used to created segmented buttons.
- Selecting Form Objects -- so that they can be modified.
- Slider Object -- is used to create sliders and knobs.
- Smart Resize -- adjusts the sizes and locations of the other selected objects to match the change of one object.
- Star Object -- draws a star within a form.
- Stepper Object -- is used to create numeric steppers for use with Text Editor objects.
- Tab Panel Appearance -- appearance options for a Tab Panel Object.
- Tab Panel Buttons and Selection -- button options for a Tab Panel Object.
- Tab Panel Constructor -- quickly creating a Tab Panel Object from a template.
- Tab Panel Content -- setting up the content for a Tab Panel Object.
- Tab Panel Forms -- setting up the forms for a Tab Panel Object.
- Tab Panel Object -- switchable tab panels.
- Text Display Object -- is used to display text using a formula.
- Text Editor Object -- is used to edit text in a field or variable.
- Text Label Object -- displays a short, fixed, text item within a form.
- Text List Appearance -- customizing the appearance of a Text List Object.
- Text List Constructor -- quickly creating a Text List Object from a template.
- Text List Database Integration -- synchronizing a Text List Object with a database.
- Text List Multiple Columns -- displaying multiple columns in a Text List Object
- Text List Object -- displaying a grid of text.
- Text List Programming -- programming a Text List Object.
- Text List Searching -- searching within a Text List Object.
- Text List Selection -- selecting items in a Text List Object.
- Text Object Background Color/Gradient -- text object background colors and gradients.
- Web Browser Object -- is used to display web pages from within a Panorama form.

History

Version | Status | Notes
10.2 | Updated | Now allows the data value to be determined by a formula (as an alternative to being linked to a database field or variable).
10.0 | Updated | Carried over from Panorama 6.0 from Popup Menu SuperObjects, but with some new features. This version of Panorama only supports standard system button styles, so some button styles that were available in previous versions of Panorama are no longer available.