Sample Maplet Application: Alert
This worksheet demonstrates how to write Maplet applications that function similarly to the Alert Maplet application available in the Maplets[Examples] package. It is designed for experienced Maple authors.
Simple Example
restart
Invoke the Maplets Elements subpackage
withMapletsElements:
Define the alert Maplet application; define an abnormal shutdown as one that returns FAIL.
maplet1≔Maplet'abnormalshutdown'=FAIL, AlertDialog# The text that appears as the alert Maplet application's message and titleAssuming x > 0 leads to a contradiction, 'title'=Warning: Contradiction, #The value returned. Click "OK", true. Click "Cancel", fail. 'onapprove'=Shutdowntrue, 'oncancel'=ShutdownFAIL :
Assign result to the value returned by the Maplet application.
result ≔ parseMapletsDisplaymaplet1;
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 AlertDialog element.
2. Actions associated with onapprove and oncancel must be given by a reference, and located outside the AlertDialog element. The command elements must be wrapped in Action elements.
3. All option names must be specified, including caption, reference, and value.
withMapletsElements:# Define the "onstartup" option referenced by A0. maplet2 ≔ Maplet 'abnormalshutdown' = FAIL, 'onstartup' = 'A0', AlertDialog 'reference' = 'AD1', 'caption' = Assuming x > 0 leads to a contradiction, 'title' = Warning: Contradiction, 'onapprove' = 'A1', 'oncancel' = 'A2' , # Start the AlertDialog. Action 'reference' = 'A0', RunDialog 'dialog' = 'AD1' , # Define the resulting action if "OK" is clicked. Action 'reference' = 'A1', Shutdown 'value' = 'true' , # Define the resulting action if "Cancel" is clicked. Action 'reference' = 'A2', Shutdown 'value' = FAIL :
result ≔ parseMapletsDisplaymaplet2;
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_# strings where # is a unique number and the second example leaves the string references unchanged.
MapletsToolsPrintmaplet1
<Maplet abnormalshutdown='FAIL' locale='English_United States.1252' onstartup='Maplets_reference_12'> <AlertDialog caption='Assuming x > 0 leads to a contradiction' enabled='true' onapprove='Maplets_reference_9' oncancel='Maplets_reference_10' reference='Maplets_reference_11' resizable='false' title='Warning: Contradiction' visible='true'/> <Action reference='Maplets_reference_10' run='false'> <Shutdown value='FAIL'/> </Action> <Action reference='Maplets_reference_9' run='false'> <Shutdown value='true'/> </Action> <Action reference='Maplets_reference_12' run='false'> <RunDialog dialog='Maplets_reference_11'/> </Action> </Maplet>
MapletsToolsPrintmaplet2
<Maplet abnormalshutdown='FAIL' locale='English_United States.1252' onstartup='A0'> <AlertDialog caption='Assuming x > 0 leads to a contradiction' enabled='true' onapprove='A1' oncancel='A2' reference='AD1' resizable='false' title='Warning: Contradiction' visible='true'/> <Action reference='A0' run='false'> <RunDialog dialog='AD1'/> </Action> <Action reference='A1' run='false'> <Shutdown value='true'/> </Action> <Action reference='A2' run='false'> <Shutdown value='FAIL'/> </Action> </Maplet>
Maplets[Examples][Alert]
The Maplets[Examples][Alert] 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][Alert]
To view the source code, enter:
print MapletsExamplesAlert ;
procs::string,symbol,title::string,symbol:=Alert, $localresult,maplet;maplet:=Maplets:-Elements:-Maplet⁡'onstartup'=A0,Maplets:-Elements:-AlertDialog⁡'reference'=AD1,'onapprove'=A1,'oncancel'=A2,'caption'=s,':-title'=title,Maplets:-Elements:-Action⁡'reference'=A0,Maplets:-Elements:-RunDialog⁡'dialog'=AD1,Maplets:-Elements:-Action⁡'reference'=A1,Maplets:-Elements:-Shutdown⁡'value'=true,Maplets:-Elements:-Action⁡'reference'=A2,Maplets:-Elements:-Shutdown⁡'value'=FAIL;result:=Maplets:-Display⁡maplet;iftype⁡result,'string'thenparse⁡resultelseFAILend ifend proc
See Also
Maplets[Examples], Maplets[Examples][Alert], Maplets[Elements][AlertDialog]
Return to Index for Example Worksheets
Download Help Document