Sample Maplet Application: Question
This worksheet demonstrates how to write Maplet applications that function similarly to the Question Maplet application available in the Maplets[Examples] package. It is designed for experienced Maple authors.
Simple Example
restart:
# Invoke the Maplets Elements subpackage. with(Maplets[Elements]): # Define the question Maplet application. maplet1 := Maplet( 'abnormalshutdown' = "false", QuestionDialog( # The text that appears in the Maplet application. "Is x > 0 ?", # The Maplet application title. 'title' = "Warning: Contradiction", # The value returned. Click "OK", true. # Click "Cancel", false. 'onapprove' = Shutdown( "true" ), 'ondecline' = Shutdown( "false" ) ) ):
# Assign result to the value returned by the Maplet application. result := parse(Maplets[Display](maplet1));
Complex Example
The following example does not use any of the simplifications that have been included to make writing Maplet applications easier which leads to longer code but faster execution and for more complex Maplet applications, greater control of the Maplet application appearance and behavior. The required changes are:
1. An onstartup action must be specified. This action must be referenced and contain a RunDialog element which starts the QuestionDialog element.
2. Actions associated with onapprove and ondecline must be given by a reference and located outside the QuestionDialog element. The command elements must be wrapped in Action elements.
3. All option names must be specified, including caption, reference, and value.
with(Maplets[Elements]): # Define abnormalshutdown and the "onstartup" option. maplet2 := Maplet( 'abnormalshutdown' = "FAIL", 'onstartup' = 'A0', QuestionDialog( 'reference' = 'QD1', 'caption' = "Is x > 0 ?", 'title' = "Warning: Contradiction", 'onapprove' = 'A1', 'ondecline' = 'A2' ), # Start the QuestionDialog. Action( 'reference' = 'A0', RunDialog( 'dialog' = 'QD1' ) ), # When "OK" is clicked, return true. Action( 'reference' = 'A1', Shutdown( 'value' = "true" ) ), # When "Cancel" is clicked, return FAIL. Action( 'reference' = 'A2', Shutdown( 'value' = "FAIL" ) ) ):
result := parse(Maplets[Display](maplet2));
Comparison
Maplet applications can be viewed by using the Maplets[Tools][Print] function. This function prints the XML data structure of the Maplet application.
Compare the resulting output of the two example Maplet applications. Note that the only major difference is that the first example replaces the name references with "_Maplets_reference_#", where # is a unique number, and the second example leaves the string references unchanged.
Maplets[Tools][Print](maplet1);
Maplets[Tools][Print](maplet2);
Maplets[Examples][Question]
The Maplets[Examples][Question] function displays a Maplet application similar to that of the previous examples. The function, however, allows the user to modify the caption and title options.
For help on this Maplet application, see:
?Maplets[Examples][Question]
To view the source code, enter:
print( Maplets[Examples][Question] );
See Also
Maplets[Examples], Maplets[Examples][Question], Maplets[Elements][QuestionDialog]
Return to Index for Example Worksheets
Download Help Document