DocumentTools[Components]
ToggleButton
generate XML for a ToggleButton Component
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
ToggleButton(caption, opts)
caption
-
(optional) string:="ToggleButton"; the caption on the button
opts
(optional) ; one or more keyword options as described below
action : string:=""; A string which parses to one or more valid statements in 1-D Maple notation. These statements form the Click Action Component Code that executes when the ToggleButton is clicked. The default is the empty string (no action code).
enabled : truefalse; Indicates whether the component is enabled. The default is true. If enabled is false, then the inserted component is grayed out and interaction with it cannot be initiated.
group : string:=""; The name of the group with which this component is associated. The default is the empty string (no group).
height : posint; The height in pixels of the component.
identity : {name,string}; The reference name of the component.
selected : truefalse; Indicates whether the component is initially in the on or the off state. The default value is false (off, unselected).
selectedimage : {string,Matrix,Array}; Image to be displayed on the component when in the on state, specified as either the name of an external image file or a Matrix or Array as recognized by commands in the ImageTools package.
showborders : truefalse; Indicates whether borders will be shown
tooltip : string; The text that appears when the mouse pointer hovers over the component. The default is the empty string (no tooltip).
unselectedimage : {string,Matrix,Array}; Image to be displayed on the component when in the off state, specified as either the name of an external image file or a Matrix or Array as recognized by commands in the ImageTools package.
visible : truefalse; Indicates whether the component is visible. The default is true.
width : posint; The width in pixels of the component.
The ToggleButton command in the Component Constructors package returns an XML function call which represents a ToggleButton Component.
The generated XML can be used with the results of commands in the Layout Constructors package to create an entire Worksheet or Document in XML form. Such a representation of a Worksheet or Document can be inserted into the current document using the InsertContent command.
with⁡DocumentTools:
with⁡DocumentTools:-Components:
with⁡DocumentTools:-Layout:
Executing the ToggleButton command produces a function call.
S≔ToggleButton⁡My ToggleButton,identity=ToggleButton0:
By using commands from the Layout Constructors package a nested function call can be produced which represents a worksheet.
xml≔Worksheet⁡Group⁡Input⁡Textfield⁡S:
That XML representation of a worksheet can be inserted directly.
InsertContent⁡xml:
S≔ToggleButton⁡My ToggleButton,identity=ToggleButton0,tooltip=My example button,selectedimage=none,unselectedimage=none:
The previous example's call to the InsertContent command inserted a component with identity "ToggleButton0", which still exists in this worksheet. Inserting additional content whose input contains another component with that same identity "ToggleButton0" incurs a substitution of the input identity in order to avoid a conflict with the identity of the existing component.
The return value of the following call to InsertContent is a table which can be used to reference the substituted identity of the inserted component.
lookup≔InsertContent⁡xml,output=table
lookup≔table⁡ToggleButton0=ToggleButton1
lookupToggleButton0
ToggleButton1
GetProperty⁡lookupToggleButton0,caption
My ToggleButton
selimg≔cat⁡kernelopts⁡datadir,/images/up_arrow.gif:
unselimg≔cat⁡kernelopts⁡datadir,/images/down_arrow.gif:
B≔ToggleButton⁡selectedimage=selimg,unselectedimage=unselimg,identity=ToggleButton17:
InsertContent⁡Worksheet⁡Group⁡Input⁡Textfield⁡B:
selimg≔Array⁡1..60,1..40,1..3,i,j,k↦`if`⁡k=1,j40,0,datatype=float8,order=C_order:
unselimg≔Array⁡1..60,1..40,1..3,i,j,k↦`if`⁡k=2,j40,0,datatype=float8,order=C_order:
B≔ToggleButton⁡selectedimage=selimg,unselectedimage=unselimg,identity=ToggleButton17,width=70,height=20:
The next example makes use of action code for a toggle button. When the button is toggle the action code is executed.
The action code updates a PlotComponent with identity "Plot0", which will be an additional part of the inserted content. This component will be constructed using the Plot Component constructor.
pinit≔plot⁡sin⁡x2,x=−2⁢π..2⁢π,color=blue,filled=true:
P≔Components:-Plot⁡pinit,identity=Plot0,showborders=false:
codestring≔DocumentTools:-SetProperty(':-Plot0',value,plot(sin(x)^2,x=-2*Pi..2*Pi,color=blue,filled=parse(DocumentTools:-GetProperty(':-ToggleButton0',value))));
B≔ToggleButton⁡selected=true,identity=ToggleButton0,action=codestring,width=35,height=60:
InsertContent⁡Worksheet⁡Group⁡Input⁡Textfield⁡B,P:
The ToggleButton component in the previous example is constructed by supplying identity="ToggleButton0" as an option. But the first example on this page had already inserted content with a component with that identity. Hence the identity of the ToggleButton in the last example can be replaced at insertion time. Note that literal instances of "ToggleButton0" are also replaced in the component action code of the inserted content in the last example. In particular the replacement of the literal instance of "ToggleButton0" in the actioncode string will match the identity replacement. This allows the action code to function as intended, with component identities and references replaced consistently. This can be confirmed by selecting the inserted ToggleButton and viewing the component name in the Context Panel and by clicking Edit Click Code... to view the Code Editor for this component.
The DocumentTools:-Components:-ToggleButton command was introduced in Maple 2015.
For more information on Maple 2015 changes, see Updates in Maple 2015.
See Also
Component Code
Component Constructors
DocumentTools
Embedded Components
Layout Constructors
XMLTools
Download Help Document