Contents Previous Next Index
10 Embedded Components and Maplets
These graphical components help you to create documents to use and share with colleagues or students, that interact with Maple code within the document without needing the reader to understand that Maple code. Other methods of interaction with Maple are described throughout this guide.
10.1 In This Chapter
Section
Topics
Using Embedded Components - Basic interacting with Maple documents containing embedded components
Interacting with Components
Printing and Exporting
Creating Embedded Components - Methods for creating embedded components that work together and with your document
Inserting Components
Editing Components
Removing Components
Integrating into a Document
Using Maplets - Methods for launching a Maplet
Maplet File
Maple Document
Authoring Maplets - Methods for authoring and saving a Maplet
Simple Maplet
Maplet Builder
Maplets Package
Saving
10.2 Using Embedded Components
Interacting
Embedded components allow readers to interact with Maple code through graphical components, rather than commands. They can be used alone, as with a button that you click to execute code, or together, such as a drop-down menu where you select an item, and a change takes place in a plot component.
Component Descriptions
Component Name and Description
Inserted Image
Button - Click to perform an action; that is, execute code.
Check Box - Select or de-select. Change the caption, and enter code to execute when the value changes.
Combo Box - Select one of the listed options from the drop-down menu. Change the items listed, and enter code to execute when the value changes.
Data Table - Link this embedded component to a Matrix, Vector, or Array in your worksheet.
Dial - Select or display an integer or floating-point value. Change the display, and enter code to execute when the value changes.
Label - Display a label. The value can be updated based on code in the document or another embedded component.
List Box - Display a list of items. Change the items listed, and enter code to execute when an item is selected.
Math Expression - Enter or display a mathematical expression. The value can be updated based on code in the document or another embedded component.
Meter - Select or display an integer or floating-point value. Change the display, and enter code to execute when the value changes.
Microphone Component - Capture sound from a recording device. Change setting options from properties, and enter code for start and stop recording actions.
Plot - Display a 2-D or 3-D plot or animation. This plot or animation can be interacted with in the same way as other plots (see Plots and Animations). The value can be updated based on code in the document or another embedded component. You can also enter code to be executed when the Click and Drag pointer is used to click or drag in the plot region.
Radio Button - Use with other radio buttons to select one in a group. Enter code to execute when the value changes.
Rotary Gauge - Select or display an integer or floating-point value. Change the display, and enter code to execute when the value changes.
Slider - Select or display an integer or floating-point value. Change the display, and enter code to execute when the value changes.
Text Area - Enter or display plain text. The value can be updated based on code in the document or another embedded component, and you can enter code to execute when the value changes.
Toggle Button - Select or display one of two options. Change the images displayed, and enter to code to execute when the value changes.
Video Player - Play a video. Enter code that specifies an action to perform when the video player reaches a marker during playback.
Volume Gauge - Select or display an integer or floating-point value. Change the display, and enter code to execute when the value changes.
Shortcut Component - Use to hyperlink various types of content, including help pages, MapleCloud documents, and URLs.
Speaker Component - Play a sound. Customize component by modifying setting options under properties.
Example 1 - Using Embedded Components
This example demonstrates several components working together to perform a task. The user inputs an expression, which is plotted when the button is clicked. Plot options are controlled by text areas, a combo box, a math expression, and radio buttons.
Enter an expression in the variable x: Then click the Plot button.
Change the axis ranges:
x = to
y = to
Change the color:
BlueRedMagentaYellowGreenBlack
Scaling:
Printing and Exporting a Document with Embedded Components
Printing: When printing a document, embedded components are rendered as they appear on screen.
Exporting: Exporting a document with embedded components to other formats produces the following results.
HTML format - components are exported as .gif files.
RTF format - components are rendered as bitmap images in the .rtf document.
LaTeX - components are exported as .eps files.
PDF - components are rendered as static images.
10.3 Creating Embedded Components
Embedded Components are graphical components that you can add to your document. They provide interactive access to Maple code without requiring the user to know Maple commands, and include buttons, sliders, math and text input areas, plot display, and shortcut components.
The graphical interface components can be inserted by using the Components palette (Figure 10.1) or by cutting/copying and pasting existing components to another area of the document. Although copied components have most of the same characteristics, they are distinct.
If the Components palette is not visible, see Palettes for instructions on viewing palettes.
Figure 10.1: Components Palette
Editing Component Properties: General Process
To edit properties of components embedded in the document:
Click the component to display the context panel.
In the context panel, enter values and contents in the fields as necessary.
To define an action, such as an action to perform when the slider is moved, click the component, and then select Edit Value Changed Code... from the Context Panel. A Code Edit Region opens allowing you to enter Maple code that is executed when the event occurs. For details, refer to the DocumentTools help page.
Note: You can also edit embedded component properties and actions that are performed when a value changes by using Maple worksheet Edit menu options, Edit > Component Properties, and Edit > Component Code, respectively. For more information on options available in the Edit menu, see Edit menu options.
Removing Graphical Interface Components
You can remove an embedded component by:
Using the Delete key
Using the Backspace key
Placing the cursor at the component and selecting from the document menu, Edit→Delete Element
Integrating Components into a Document
Use embedded components to display information from calculations, obtain input from a reader, or perform calculations at the click of a button, all without your readers having an understanding of Maple commands. They can be entered in any part of a Maple document, including a document block or table. For details on each component, see its help page.
This simple example inserts a slider with a label that indicates the current value of the slider.
Place the cursor in the location where the embedded component is to be inserted.
In the Components palette, click the Slider item. A slider is inserted into the document.
In the Components palette, click the Label item. A label is inserted next to the slider.
Click the label component. The Label context panel opens. See Figure 10.2.
Figure 10.2: Label Properties Dialog
Figure 10.3: Slider Properties Dialog
Name the component SliderLabel and click OK.
Click the slider component. The Slider context panel opens. See Figure 10.3.
Name the component Slider1.
Enter the value at the lowest position as 0 and the highest as 100.
Enter major tick marks at 20 and minor tick marks at 10.
Make sure that the Continuous Update On Drag check box is selected.
Click OK.
To define an action, click the slider component, and then select Edit Value Changed Code... from the context panel. This launches a dialog that allows you to program the action of displaying the slider value in the label component. The dialog includes information on how to program actions between embedded components. The use...in/end use; statement allows you to specify routines using the short form of accessing a package command without invoking the package. For details on this command, refer to the use help page.
Before the end use; statement at the bottom of the dialog, enter the following command.
Do(%SliderLabel(caption)=%Slider0(value));
Save the code, and exit the code editor.
As you move the arrow indicator, the value from the slider populates the Label caption field.
For details on this command, refer to the DocumentTools[Do] help page.
Example 2 - Creating Embedded Components
In chapter 7 (see Embedded Components), you created a document that included embedded components, imported from a task template. Here, we re-create that configuration of components. This example takes two parameters, a and b,as inputs, then plots the function y=b x+a and calculates ab.
Create the components.
The table layout is best done after the components are finished, in case the configuration of the components changes as you are working.
Create two DialComponents to set the parameters, a and b, one RotaryGaugeComponent to display the result, ab, one PlotComponent to display the plot, and one MathContainerComponent to display the function. Note that you do not have to use the dial and rotary gauge components here, you can also use the slider instead.
Figure 10.4: The Inserted Components
Edit the display of the components.
Open the context panel for the first DialComponent, and notice that it already has a name. This name is used to reference the component from other components, and is unique. Change the display of each of the components as follows:
Dial0: no changes.
Dial1: change the Value at Lowest Position to 1, the Value at Highest Position to 10, the Spacing of Major Tick Marks to 1, and the Spacing of Minor Tick Marks to 1.
RotaryGauge0: change the Value at Highest Position to 40, the Spacing of Major Tick Marks to 5, and the Spacing of Minor Tick Marks to 1.
Plot0: no changes.
MathContainer0: change the Width in Pixels to 200, and the Height in Pixels to 45.
Note the names of all of the components, and close each dialog before moving on.
Create actions for the components.
Components can perform actions when their values are changed, so the code to execute needs to be in the dials. That way, whenever one of them is changed, the other components are updated to reflect that change.
The following Maple commands retrieve the values of the parameters and display them in the other three components:
parameter1:=Do(%Dial0):
parameter2:=Do(%Dial1):
Do(%RotaryGauge0=parameter1/parameter2);
Do(%Plot0=plot((parameter2*x+parameter1), x=-50..50, y=-50..50));
Do(%MathContainer0=(y=parameter2*x+parameter1));
Test the actions.
To test these commands, first load the DocumentTools package with the following command.
with(DocumentTools):
After loading the package, execute the commands in the document, and verify that the components you inserted are updated: the gauge should change to the computed value, a plot should appear in the plot component, and the function should display in the math container.
Troubleshooting.
The first Do command gives an error, because the second parameter is 0. One way to avoid this problem is to change the range of the second dial. In the Component Properties dialog for the second DialComponent, change the Value at Lowest Position from 0 to 1. Alternatively, you could change the code to compensate, with an if statement.
Copy the actions to the components.
After the commands work as expected, you can copy them into the components.
Click the first DialComponent and select Edit Value Changed Code from the context panel. Copy and paste the commands into the space between the use statements.
Figure 10.5: DialComponent Action Code Editor
Do the same for the second DialComponent. Now, moving either dial will update the rotary gauge, plot, and formula displayed in the math component.
Create the layout for the components.
Create a table, and then cut and paste the components into it, along with explanatory text. Important: you must cut, not copy, the components, or their names will be changed to avoid duplication. For information on creating and modifying tables, refer to Tables.
Parameters: a and b
Plot Window
Use the Dials to set parameters
Parameter 1: a
Parameter 2: b
Result: ab
Plot of
10.4 Using Maplets
A Maplet is a popup graphical user interface that provides interactive access to the Maple engine through buttons, text regions, slider bars, and other visual interfaces. You can create your own Maplets, and you can take advantage of the built-in Maplets that cover numerous academic and specialized topics. Built-in Maplets include some assistants and tutors, such as the ODE Analyzer. For more information on this assistant, see Ordinary Differential Equations (ODEs).
Maplet applications are launched by executing Maplet code. Maplet code can be saved in a Maplet (.maplet) file or Maple document (.mw).
To launch a Maplet application saved as a Maplet file:
In Windows, double-click the file from a Windows file browser.
In UNIX and on Macintosh, use the command-line interface. At the command-line, enter maple -q <maplet_filename>.
To view and edit the Maplet code contained within the .maplet file:
Start Maple.
From the File menu, select Open. Maple displays the Open dialog.
In the Files of Type drop-down list, select .maplet.
Navigate to the location of the .maplet file and select the file.
Click Open.
To launch a Maplet application for which the Maple code is contained in a Maple document, you need to execute the Maplet code. To display the Maplet application, you must use the Maplets[Display] command. Note: The Maplet code may be quite large if the Maplet application is complex. In this case, execute the document to ensure user-defined procedures that are referenced in the Maplet application are also defined.
Typical procedure:
If present, evaluate user-defined procedures.
Myproc:=proc..
Load the Maplets[Elements] package.
with( Maplets[Elements] );
Evaluate the Maplet definition.
Maplet_name:=Maplet( Maplet_definition );
Display the Maplet application.
Maplets[Display]( Maplet_name );
Important: When a Maplet application is running, you cannot interact with the Maple document.
10.5 Authoring Maplets
To author Maplets, you can use the Maplet Builder (GUI-based) or the Maplets package (syntax-based). The Maplet Builder allows you to drag and drop buttons, sliders, text regions, and other elements to define the Maplet application and set the element properties to perform an action on selection or update of the element. The Maplet Builder is designed to create simple Maplets. The Maplets package offers more capabilities, control, and options when designing complicated Maplet applications.
Designing a Maplet application is similar to constructing a house. When building a house, you first construct the skeletal structure (that is, foundation, floors, and walls) and then proceed to add the windows and doors. Constructing a Maplet is no different. First define the rows and columns of the Maplet application and then proceed to add the body elements (such as buttons, text fields, and plot regions).
A Maplet application can be defined using the commands in the Maplets[Elements] package and then launched using the Maplets[Display] command. The following commands define and run a very simple Maplet application that contains the text string "Hello World".
with(Maplets[Elements]):
MySimpleMaplet:= Maplet([["Hello World"]]):
Maplets[Display](MySimpleMaplet):
Figure 10.6: A Simple Maplet
To start the Maplet Builder:
From the Tools menu, select Assistants → Maplet Builder.
Figure 10.7: Maplet Builder Interface
The Maplet Builder is divided into four different panes.
The Palette pane displays palettes, which contain Maplet elements, organized by category. For a description of the elements, see the MapletBuilder/Palette help page. The Body palette contains the most popular elements.
The Layout pane displays the visual elements of the Maplet.
The Command pane displays the commands and corresponding actions defined in the Maplet.
The Properties pane displays the properties of an instance of a defined element in the Maplet.
Example 3 - Design a Maplet Using the Maplet Builder
In this example, shown in Figure 10.8, the Maplet user enters a function and plots the result.
Figure 10.8: Image of the Maplet
Button element
Label element
Plot element
TextField element
Figure 10.9: Body Elements Used to Define This Maplet
Action
Result in MapletBuilder
Define the number of rows in the Maplet:
In the Properties pane:
In the drop-down list, select BoxColumn1.
Change the numrows field to 2.
Add a plot region to row 1:
From the Body palette, drag the Plotter element to the first row in the Layout pane.
Add columns to row 2:
In the drop-down list, select BoxRow2.
Change the numcolumns field to 3.
Add a label to row 2:
From the Body palette, drag the Label element to the left column in the Layout pane.
In the drop-down list, select Label1.
Change the caption field to Enter a function of x.
Add a text region to row 2:
From the Body palette, drag the TextField element to the middle column. The TextField element allows the Maplet user to enter input that can be retrieved in an action.
If necessary, resize the Maplet Builder to display the entire Layout pane.
Add a button to row 2:
From the Body palette, drag the Button element to the right column in the Layout pane.
In the drop-down list, select Button1.
Change the caption field to Plot.
In the onclick property drop-down list, select <Evaluate>.
In the Evaluate Expression dialog that displays, the Target drop-down list contains the defined elements to which you can send information, in this case, Plotter1 and TextField1. The List group box, located below the Expression group box, displays the defined elements to which you can retrieve information, in this case, TextField1.
In the Target drop-down list, select Plotter1.
In the Command Form tab, enter plot(TextField1, x=-10..10) in the Expression group box. (Note: Do not include a semicolon (;) at the end of the plot command.) You can also double-click TextField1 in the List group box to insert this element in the command syntax.
Click Ok.
Run the Maplet:
From the File menu, select Run. You are prompted to save the Maplet. Maplets created with the Maplet Builder are saved as .maplet files.
Click Yes and navigate to a location to save this Maplet.
For further information on the Maplet Builder, see the MapletBuilder help page. For more examples of designing Maplets using the Maplet Builder, see examples/MapletBuilder.
When designing a complicated Maplet, the Maplets package offers greater control. The Maplets[Elements] subpackage contains the elements available when designing a Maplet application. After you define the Maplet, use the Maplets[Display] command to launch the Maplet.
For more information on the Maplets package, refer to the MapletsPackage help page. For more examples of designing Maplets using the Maplets package, see the Maplets/Roadmap help page.
Example 4 - Design a Maplet Using the Maplets Package
To introduce the structure of designing Maplets using the Maplets package, this example illustrates the equivalent syntax for the Example 3 - Design a Maplet Using the Maplet Builder.
Define the Maplet application. To suppress the display of the data structure associated with the Maplet application, end the definition with a colon.
PlottingMaplet:=Maplet( BoxLayout( BoxColumn( # First Box Row BoxRow( # Define a Plot region Plotter('reference' = Plotter1) # End of first Box Row ), # Second Box Row BoxRow( # Define a Label Label("Enter a function of x "), # Define a Text Field TextField('reference' = TextField1), # Define a Button Button(caption="Plot", Evaluate(value = 'plot(TextField1, x = -10..10)', 'target' = Plotter1)) # End of second Box Row ) # End of BoxColumn ) # End of BoxLayout ) # End of Maplet ):
Launch the Maplet.
Maplets[Display](PlottingMaplet);
For further examples using both the MapletBuilder and Maplets package commands, see the Maplets example worksheets. For a listing, refer to the examples/index help page.
When saving a Maplet, you can save the document as an .mw file or you can export the document as a .maplet file.
To save the Maplet code as an .mw file:
From the File menu, select Save.
Navigate to the save location.
Enter a filename.
Click Save.
If the document contains only Maplet code, it is recommended that you export the document as a .maplet file.
To export the Maplet code as a .maplet file:
From the File menu, select Export As.
In the Files of Type drop-down list, select Maplet.
Navigate to the export location.
Enter the filename.
Download Help Document