DocumentTools[Canvas]
ScriptButton
create a button element for a canvas
Calling Sequence
Parameters
Description
Examples
Compatibility
ScriptButton(caption, command)
ScriptButton(caption, command, options)
caption
-
string
command
appliable
color
(optional) string or ColorTools:-Color object
encode
(optional) truefalse
event
(optional) identical(onMoved)
fontsize
(optional) posint
include
(optional) list(name)
parameters
(optional) list
position
(optional) [x,y], or identical(below,right)
size
(optional) [width,height] positive integers
textcolor
visible
The ScriptButton command creates a canvas "button" element, which, when viewed in a canvas, can be clicked to execute the supplied command.
By default, encode = true, which causes the given command to be serialized into an encoded string. This simplifies embedding of the button command in the canvas' XML source code. For simple commands, and as an aid to debugging, setting encode = false can be useful.
The position option can be used to specify absolute coordinates for the location of the button on a canvas, or a relative position below or to the right of the previous component.
Custom independent procedures need to be defined as part of the script button action; otherwise, their definition will not be available to Maple Learn, and will not be available after restart in a Maple session. Dependencies can be added by using the include = [f,g] option to include the definitions of f and g as part of the button declaration.
The parameters option can be used to pass extra arguments to the on-click procedure. For example, if 'parameters'=['mydata','myoption'] then 'command'(canvas,mydata,myoption) will be invoked when the button is pressed.
Set visible = false to hide the button. This can be used in conjunction with the event option, or the onclick option of StaticPlot.
Set event=onMoved to trigger a button press event when any object on the canvas is moved by the user. This can be used to update state when, for example, an image is moved. Note: onMoved events are supported only in the Maple Learn interface, not for documents embedded in Maple via ShowCanvas.
Sets the background color of the button. Can be a string, such as black or #FFFFFF, or a ColorTools:-Color object.
Sets the color of the text on the button. Can be a string, such as black or #FFFFFF, or a ColorTools:-Color object.
Sets the size in pixels of the font used to render the caption.
Sets the size of the button in pixels.
Highlight Example
In this example, when a button is pressed, the action is to scan all of the math in the canvas and highlight variables
with⁡DocumentTools:-Canvas:
LocateVariables := proc( canvas ) local script := Script(':-canvas'=canvas); for local m in GetMath(canvas) do SetActive(script,m); local vars := indets(m:-math); for local v in vars do Highlight(script,v); end do; end do; ToString(script); end proc:
cv≔NewCanvas⁡Write An Expression with Variables,ScriptButton⁡Identify Variables,LocateVariables,position=500,50:
ShareCanvas⁡cv
ShowCanvas⁡cv
onMoved Event Example
In this example, the button is hidden, but when the first group is moved, its action is to fill it in with a random number
Move := proc(canvas) local m := GetElements(canvas,'custom'="msg"); local sc := Script(); SetActive(sc,m[1]); randomize(); SetMath(sc,rand()); ToString(sc); end proc:
cv≔NewCanvas⁡Move Test,Math⁡0,custom=msg,ScriptButton⁡Fire On Move,Move,event=onMoved,visible=false
The DocumentTools[Canvas][ScriptButton] command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
The DocumentTools[Canvas][ScriptButton] command was updated in Maple 2022.
The include, parameters, visible and event options were introduced in Maple 2022.
For more information on Maple 2022 changes, see Updates in Maple 2022.
The color, textcolor, fontsize and size options were introduced in Maple 2023.
For more information on Maple 2023 changes, see Updates in Maple 2023.
See Also
Annotate
GetCanvas
Math
NewCanvas
Script
ShareCanvas
Text
Download Help Document