ScriptButton - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


DocumentTools[Canvas]

  

ScriptButton

  

create a button element for a canvas

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

ScriptButton(caption, command)

ScriptButton(caption, command, options)

Parameters

caption

-

string

command

-

appliable

Options

• 

color -  string or ColorTools:-Color object

• 

encode - truefalse

• 

event - identical(onMoved)

• 

fontsize - posint

• 

include - list(name)

• 

parameters - list

• 

position - [x,y], or identical(below,right)

• 

size - [width,height] positive integers

• 

textcolor - string or ColorTools:-Color object

• 

visible - truefalse

Description

• 

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.

• 

The color option sets the background color of the button.  Can be a string, such as "black" or #FFFFFF", or a ColorTools:-Color object.

• 

The textcolor option sets the color of the text on the button.  Can be a string, such as "black" or "#FFFFFF", or a ColorTools:-Color object.

• 

The fontsize option sets the size in pixels of the font used to render the caption.

• 

The size option sets the size of the button in pixels.

• 

The option defineproc=false will prevent the procedure definition from being written into the canvas.  This should only be used for commands that are part of the default Maple library.

Examples

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.

withDocumentTools:-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:

cvNewCanvasWrite An Expression with Variables,ScriptButtonIdentify Variables,LocateVariables,position=500,50:

ShareCanvascv

ShowCanvascv

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.

withDocumentTools:-Canvas:

Move := proc(canvas)
   local m := GetElements(canvas,'custom'="msg");
   local sc := Script();
   SetActive(sc,m[1]);
   randomize();
   SetMath(sc,rand());
   ToString(sc);
end proc:

cvNewCanvasMove Test,Math0,custom=msg,ScriptButtonFire On Move,Move,event=onMoved,visible=false

ShareCanvascv

Compatibility

• 

The DocumentTools[Canvas][ScriptButton] command was introduced in Maple 2021.

• 

For more information on Maple 2021 changes, see Updates in Maple 2021.

• 

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.

• 

The DocumentTools[Canvas][ScriptButton] command was updated in Maple 2025.

• 

The defineproc option was introduced in Maple 2025.

• 

For more information on Maple 2025 changes, see Updates in Maple 2025.

See Also

Annotate

GetCanvas

Math

NewCanvas

Script

ShareCanvas

Text

 


Download Help Document