Examples

Input Style Cell Group Closer

This button opens and closes cell groups that are headed by an Input style cell. In uses NotebookFind to track down all cells of a given style.  After the cells are located, a command token is issued to perform the equivalent of Cell -> Cell Grouping -> Open All Subgroups.

[Graphics:../Images/Buttons19991022_gr_57.gif]

To make this button available to all notebooks, drag select it and then use the front end menu command File -> Generate Palette from Selection.

Version Stamp

This button is designed for providing a date/version stamp for notebooks with bug reports.  It uses MathLink packet trips to request information from the front end and then writes the results in new cell.  Because the ouput is generated by assembling a cell expression, the kernel must play the role of evaluator.

We make use of undocumented front end packets here.

[Graphics:../Images/Buttons19991022_gr_58.gif] Purpose
[Graphics:../Images/Buttons19991022_gr_59.gif] [Graphics:../Images/Buttons19991022_gr_60.gif]
[Graphics:../Images/Buttons19991022_gr_61.gif] [Graphics:../Images/Buttons19991022_gr_62.gif]

Here is an example of how one can use FrontEnd`ToFileName to resolve paths used by the front end.

[Graphics:../Images/Buttons19991022_gr_63.gif]

The philosophy of FrontEnd`FileName objects are discussed in Glynn and Gray, Chapter

Here is a means by which one can get the date from the front end.

[Graphics:../Images/Buttons19991022_gr_64.gif]

You can find the names of values that may be plugged into a FrontEnd`Value packet in the menu that is summoned via the menu command Input -> Create Value Display Object...  Packet trips can resolve only those setttings which are meaningful at the global level.

[Graphics:../Images/Buttons19991022_gr_65.gif]

Toggling Button

In this example, we create a button that toggles between two states.  The state of the button is recorded in the button cell's CellTags option.  The button function as a separate kernel function.  The cell acts as a container for the button­specific options through the aggregate option ButtonBoxOptions.

The button function ToggleColor first locates the target cell and obtains the value of ButtonBoxOptions.  It then swaps red for green (and vice versa) in the cell tag list, updates the cell tags, and reverts the button's color according to the state.

Evaluate both cells below and then click on the resulting button to see the toggling effect.

[Graphics:../Images/Buttons19991022_gr_66.gif]

[Graphics:../Images/Buttons19991022_gr_67.gif]

Form­Based Assignment

In the next example, we demonstrate how to use ButtonSource and TagBox to make a form for assigning values to symbols.  Interfaces such as this are useful in the development of courseware.

To create the button, evaluate this cell.  Enter a value in the selection placeholder and click on the "do assignment."

[Graphics:../Images/Buttons19991022_gr_68.gif]

Now let's be clever about it and create a button style and generator function.  Here is the style definition prototype cell for the button.

[Graphics:../Images/Buttons19991022_gr_69.gif]

The resulting prototype can be pasted into a notebook's style sheet.  Now we write a function to make the creation of these buttons a single­step process.

[Graphics:../Images/Buttons19991022_gr_70.gif]

Paste this expression in a notebook whose style sheet has been modified and evaluate it to create a bank of buttons.

[Graphics:../Images/Buttons19991022_gr_71.gif]

Style Selector Palette

The following example shows how to create a button that changes the style setting for a cell or a block of text.  In this case, we are using the style token to wrap a StyleBox around some selected text.

[Graphics:../Images/Buttons19991022_gr_72.gif]

Here is some text for testing the button.  Select a portion of the text and then click on the button.  The selected text should now be shown in the InlineInput cell style.

We can be really clever and generalize this into a button style as shown below.

[Graphics:../Images/Buttons19991022_gr_73.gif]

Using the approach described eariler, we can copy the formatted cell and paste the cell into a private style sheet.

We can now create a vertical grid of buttons that use this style.  To do this, open a new notebook, paste the following expression in an Input cell and evaluate it.

[Graphics:../Images/Buttons19991022_gr_74.gif]

Copy the prototype style generated above and paste it into the new notebook's style sheet.

Note that if you try to turn this grid of buttons into a palette using the front end menu command File -> Generate Palette from Selection, the buttons on the palette will not work the same way.  The palette knows only about button styles defined in the Default style sheet.  It does not share any information about styles defined in the target notebook.  Getting around this problem is discussed in greater detail below.

Addendum -- Adding Button Style to Palette Notebook

You can correct the missing style problem above by adding your custom button styles to the palette's style sheet.  Here is one way to do this:

1) Click on the front end menu command sequence Edit -> Preferences... to summon the Option Inspector dialog.

2) Change the drop down list indicator for Window to reflect the name of the palette and the indicator for Scope to be notebook.

3) Make sure that you are viewing options by category.

4) Open up the expandable menu for Editing Options so that the setting for Editable is visible.  Change this value from False to True.

5) Open up the expandable menu for Window Properties so that the setting for WindowClickSelect is visible.  Change this value from False to True.

6) Open up the expandable menu for Window Properties so that the setting for WindowClickSelect is visible.  Change this value from False to True.

7) Close the Option Inspector dialog window.

8) With the palette window as the selected notebook, click on the front end menu command sequence Format -> Edit Style Sheet...  This will present you with a dialog box.  Click on the button that reads Import Private Copy or Import and Edit Styles.

9) Paste the cell prototype for the custom button style into the notebook in an appropriate location, such as the Palette Styles section.

10) Close the style sheet notebook window.

11) Click on the front end menu command sequence Edit -> Preferences... to summon the Option Inspector dialog once again.

12) Change the drop down list indicator for Window to reflect the name of the palette and the indicator for Scope to be notebook.

13) Make sure that you are viewing options by category.

14) Open up the expandable menu for Editing Options so that the setting for Editable is visible.  Change this value from True to False.

15) Open up the expandable menu for Window Properties so that the setting for WindowClickSelect is visible.  Change this value from True to False.

16) Close the Option Inspector dialog window.



 © 2009 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: