Toggle Button Component - Maple Help

Home : Support : Online Help : Programming : Document Tools : Components : Toggle Button Component

DocumentTools[Components]

 ToggleButton
 generate XML for a ToggleButton Component

 Calling Sequence ToggleButton(caption, opts)

Parameters

 caption - (optional) string:="ToggleButton"; the caption on the button opts - (optional) ; one or more keyword options as described below

Options

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

Description

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

Examples

 > $\mathrm{with}\left(\mathrm{DocumentTools}\right):$
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Components}\right):$
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Layout}\right):$

Executing the ToggleButton command produces a function call.

 > $S≔\mathrm{ToggleButton}\left("My ToggleButton",\mathrm{identity}="ToggleButton0"\right):$

By using commands from the Layout Constructors package a nested function call can be produced which represents a worksheet.

 > $\mathrm{xml}≔\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(S\right)\right)\right)\right):$

That XML representation of a worksheet can be inserted directly.

 > $\mathrm{InsertContent}\left(\mathrm{xml}\right):$

 > $S≔\mathrm{ToggleButton}\left("My ToggleButton",\mathrm{identity}="ToggleButton0",\mathrm{tooltip}="My example button",\mathrm{selectedimage}=\mathrm{none},\mathrm{unselectedimage}=\mathrm{none}\right):$
 > $\mathrm{xml}≔\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(S\right)\right)\right)\right):$

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.

 > $\mathrm{lookup}≔\mathrm{InsertContent}\left(\mathrm{xml},\mathrm{output}=\mathrm{table}\right)$
 ${\mathrm{lookup}}{≔}{table}{}\left(\left[{"ToggleButton0"}{=}{"ToggleButton1"}\right]\right)$ (1)

 > $\mathrm{lookup}\left["ToggleButton0"\right]$
 ${"ToggleButton1"}$ (2)
 > $\mathrm{GetProperty}\left(\mathrm{lookup}\left["ToggleButton0"\right],\mathrm{caption}\right)$
 ${"My ToggleButton"}$ (3)
 > $\mathrm{selimg}≔\mathrm{cat}\left(\mathrm{kernelopts}\left(\mathrm{datadir}\right),"/images/up_arrow.gif"\right):$
 > $\mathrm{unselimg}≔\mathrm{cat}\left(\mathrm{kernelopts}\left(\mathrm{datadir}\right),"/images/down_arrow.gif"\right):$
 > $B≔\mathrm{ToggleButton}\left(\mathrm{selectedimage}=\mathrm{selimg},\mathrm{unselectedimage}=\mathrm{unselimg},\mathrm{identity}="ToggleButton17"\right):$
 > $\mathrm{InsertContent}\left(\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(B\right)\right)\right)\right)\right):$

 > $\mathrm{selimg}≔\mathrm{Array}\left(1..60,1..40,1..3,\left(i,j,k\right)↦\mathrm{if}\left(k=1,\frac{j}{40},0\right),\mathrm{datatype}=\mathrm{float}\left[8\right],\mathrm{order}=\mathrm{C_order}\right):$
 > $\mathrm{unselimg}≔\mathrm{Array}\left(1..60,1..40,1..3,\left(i,j,k\right)↦\mathrm{if}\left(k=2,\frac{j}{40},0\right),\mathrm{datatype}=\mathrm{float}\left[8\right],\mathrm{order}=\mathrm{C_order}\right):$
 > $B≔\mathrm{ToggleButton}\left(\mathrm{selectedimage}=\mathrm{selimg},\mathrm{unselectedimage}=\mathrm{unselimg},\mathrm{identity}="ToggleButton17"\right):$
 > $\mathrm{InsertContent}\left(\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(B\right)\right)\right)\right)\right):$

 > $B≔\mathrm{ToggleButton}\left(\mathrm{selectedimage}=\mathrm{selimg},\mathrm{unselectedimage}=\mathrm{unselimg},\mathrm{identity}="ToggleButton17",\mathrm{width}=70,\mathrm{height}=20\right):$
 > $\mathrm{InsertContent}\left(\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(B\right)\right)\right)\right)\right):$

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.

 > $\mathrm{pinit}≔\mathrm{plot}\left({\mathrm{sin}\left(x\right)}^{2},x=-2\mathrm{\pi }..2\mathrm{\pi },\mathrm{color}=\mathrm{blue},\mathrm{filled}=\mathrm{true}\right):$
 > $P≔\mathrm{Components}:-\mathrm{Plot}\left(\mathrm{pinit},\mathrm{identity}="Plot0",\mathrm{showborders}=\mathrm{false}\right):$
 > $\mathrm{codestring}≔"DocumentTools:-SetProperty\left(\text{'}:-Plot0\text{'},value,plot\left(sin\left(x\right)^2,x=-2*Pi..2*Pi,color=blue,filled=parse\left(DocumentTools:-GetProperty\left(\text{'}:-ToggleButton0\text{'},value\right)\right)\right)\right);"$
 ${\mathrm{codestring}}{≔}{"DocumentTools:-SetProperty\left(\text{'}:-Plot0\text{'},value,plot\left(sin\left(x\right)^2,x=-2*Pi..2*Pi,color=blue,filled=parse\left(DocumentTools:-GetProperty\left(\text{'}:-ToggleButton0\text{'},value\right)\right)\right)\right);"}$ (4)
 > $B≔\mathrm{ToggleButton}\left(\mathrm{selected}=\mathrm{true},\mathrm{identity}="ToggleButton0",\mathrm{action}=\mathrm{codestring},\mathrm{width}=35,\mathrm{height}=60\right):$
 > $\mathrm{InsertContent}\left(\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(B,P\right)\right)\right)\right)\right):$

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.

Compatibility

 • The DocumentTools:-Components:-ToggleButton command was introduced in Maple 2015.