DocumentTools/Canvas/TestButtonPress - Maple Help

Home : Support : Online Help : DocumentTools/Canvas/TestButtonPress

DocumentTools[Canvas]

 TestButtonPress
 simulate a button press

 Calling Sequence TestButtonPress(canvas) TestButtonPress(canvas, button, options)

Parameters

 canvas - string; URL or XML-based canvas string button - (optional) string; button caption unwrap = - (optional) truefalse stopat = - (optional) list

Description

 • 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.

Examples

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 can not be run using ShowCanvas.  Note that changing where="below" to where="right" in the SetMath call will allow it to be run in Maple.

 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$
 > 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

 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Write An Expression with Variables",x+y,\mathrm{sin}\left({x}^{2}\right)-\mathrm{cos}\left(y\right),\mathrm{ScriptButton}\left("Find Variables and Functions",\mathrm{VarVersusFunc},\mathrm{position}=\left[500,50\right]\right)\right]\right):$
 > $\mathrm{ShareCanvas}\left(\mathrm{cv}\right)$

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.

 > $\mathrm{url}≔\mathrm{ShareCanvas}\left(\mathrm{cv},'\mathrm{showlink}'=\mathrm{false}\right)$

Execute the button press, and examine the generated script

 > $\mathrm{TestButtonPress}\left(\mathrm{url}\right)$

Compatibility

 • The DocumentTools[Canvas][TestButtonPress] command was introduced in Maple 2021.
 • For more information on Maple 2021 changes, see Updates in Maple 2021.