DocumentTools[Canvas]
TestButtonPress
simulate a button press
Calling Sequence
Parameters
Description
Examples
Compatibility
TestButtonPress(canvas)
TestButtonPress(canvas, button, options)
canvas
-
string; URL or XML-based canvas string
button
(optional) string; button caption
unwrap =
(optional) truefalse
stopat =
(optional) list
The TestButtonPress command simulates a button press action in a given canvas. This is useful when developing a Maple Learn application. After deploying a canvas, you can interact with it, then share the new document including the interaction, and use the share-link as the canvas argument to this command. This allows you to debug the button press action inside Maple.
When more than one button is present in the canvas, the second argument, button, can be used to specify which button-press event to actuate.
By default, commands behind a button action are wrapped inside a procedure. The unwrap option allows you to remove the procedure wrapper before executing the script commands.
A button event typically includes an entire procedure definition. When developing a canvas application in Maple, you may have the same procedure already defined inside your worksheet. Executing TestButtonPress will cause that procedure to be redefined to the unpacked version in the canvas. In order to set breakpoints in the unpacked version, it is useful to specify the name of the procedure using the 'stopat'=[YourProcName] option. Multiple breakpoints can be specified in the list.
This example defines a procedure that highlights parts of a math expression and provides information about variables and functions. Because it inserts new math between existing math boxes, it cannot be run using ShowCanvas. Note that changing where="below" to where="right" in the SetMath call will allow it to be run in Maple.
with⁡DocumentTools:-Canvas:
VarVersusFunc := proc(canvas) local m := GetMath(canvas): local sc := Script(':-canvas'=canvas): for local mi in m do SetActive(sc,mi); local vars := indets(mi:-math,symbol): for local v in vars do Highlight(sc,v); end do: Annotate(sc,`if`(vars={},"no variables present","variables highlighted")); SetMath(sc,mi:-math,where="below"); local funs := indets(mi:-math,function): for local F in funs do Highlight(sc,op(0,F)); end do: Annotate(sc,`if`(funs={},"no functions present","functions highlighted")); end do; sc:-ToString(sc); end proc:
For demonstration purposes, we will create a canvas with some math expressions already in it. Normally you would insert these yourself in Maple Learn
cv≔NewCanvas⁡Write An Expression with Variables,x+y,sin⁡x2−cos⁡y,ScriptButton⁡Find Variables and Functions,VarVersusFunc,position=500,50:
ShareCanvas⁡cv
After editing the deployed canvas from the link above, you can share that canvas and assign the pasted string to the url variable below. Here we will use the canvas as deployed.
url≔ShareCanvas⁡cv,showlink=false
Execute the button press, and examine the generated script
TestButtonPress⁡url
The DocumentTools[Canvas][TestButtonPress] command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
See Also
Annotate
GetCanvas
Math
NewCanvas
Script
ShareCanvas
Text
Download Help Document