List Box Component - Maple Help

DocumentTools[Components]

 ListBox
 generate XML for a ListBox Component

 Calling Sequence ListBox(L, opts)

Parameters

 L - (optional) list; list of strings. 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 Select Action Component Code that executes when the ListBox selection is manually adjusted.
 • 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.
 • fillcolor : {list(nonnegint),symbol,string}:=[255,255,255] ; Specifies the background color of the component. The passed value can be either a named color or a list of three integers each between 0 and 255. A list of nonnegative integers is interpreted as RGB values in a 24bit 3-channel color space. The default value is [255,255,255] which corresponds to white.
 • fontcolor : {list(nonnegint),symbol,string}:=[0,0,0] ; Specifies the font color of the component. The passed value can be either a named color or a list of three integers each between 0 and 255. A list of nonnegative integers is interpreted as RGB values in a 24bit 3-channel color space. The default value is [0,0,0] which corresponds to black.
 • identity : {name,string}; The reference name of the component.
 • selected : string; The initially selected item. By default no item is selected.
 • tooltip : string; The text that appears when the mouse pointer hovers over the component.
 • visible : truefalse; Indicates whether the component is visible. The default is true.

Description

 • The ListBox command in the Component Constructors package returns an XML function call which represents a ListBox 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):$
 > $L≔\left["A","B","C"\right]$
 ${L}{≔}\left[{"A"}{,}{"B"}{,}{"C"}\right]$ (1)

Executing the ListBox command produces a function call.

 > $S≔\mathrm{ListBox}\left(L,\mathrm{identity}="ListBox0"\right)$
 ${S}{≔}{\mathrm{_XML_EC-List}}{}\left({"id"}{=}{"ListBox0"}{,}{"enabled"}{=}{"true"}{,}{"visible"}{=}{"true"}{,}{"fillcolor"}{=}{"\left[255,255,255\right]"}{,}{"fontcolor"}{=}{"\left[0,0,0\right]"}{,}{"A,B,C"}\right)$ (2)

By using commands from the DocumentTools:-Layout 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{ListBox}\left(L,\mathrm{identity}="ListBox0",\mathrm{selected}="B",\mathrm{tooltip}="My example ListBox"\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 "ListBox0", which still exists in this worksheet. Inserting additional content whose input contains another component with that same identity "ListBox0" 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[{"ListBox0"}{=}{"ListBox1"}\right]\right)$ (3)

 > $\mathrm{lookup}\left["ListBox0"\right]$
 ${"ListBox1"}$ (4)
 > $\mathrm{GetProperty}\left(\mathrm{lookup}\left["ListBox0"\right],\mathrm{value}\right)$
 ${"B"}$ (5)

The next example makes use of action code for a ListBox. When the selected item is manually altered 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.

 > $p≔\mathrm{plot}\left({x}^{2}\mathrm{sin}\left(x\right),x=-2\mathrm{\pi }..2\mathrm{\pi },\mathrm{color}=\mathrm{blue}\right):$
 > $P≔\mathrm{Components}:-\mathrm{Plot}\left(p,\mathrm{identity}="Plot0"\right):$

The action code consists of multi-line statements supplied as a string.

 > $\mathrm{actioncode}≔"DocumentTools:-SetProperty\left(\text{'}:-Plot0\text{'},value,\n plot\left(x^2*sin\left(x\right), x=-2*Pi..2*Pi,\n color=parse\left(DocumentTools:-GetProperty\left(\text{'}:-ListBox0\text{'},value\right)\right)\right)\right);":$
 > $S≔\mathrm{ListBox}\left(\left["red","black","blue","green","magenta","yellow"\right],\mathrm{identity}="ListBox0",\mathrm{selected}="red",\mathrm{action}=\mathrm{actioncode},\mathrm{tooltip}="The color choice",\mathrm{fillcolor}="LightYellow",\mathrm{fontcolor}="DarkBlue"\right):$
 > $\mathrm{xml}≔\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(P\right)\right)\right),\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(S\right)\right)\right)\right):$

Following insertion an item in the ListBox can be manually selected, which causes the respective action code to execute and the "Plot0" component to be updated.

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

The ListBox component in the previous example is constructed by supplying identity="ListBox0" 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 ListBox in the last example can be replaced at insertion time. Note that literal instances of "ListBox0" are also replaced in all component action code of the inserted content in the last example. In particular the replacement of the literal instance of "ListBox0" in the actioncode string will match the identity replacement. This allows the action code to function as intended, with component identities replaced consistently. This can be confirmed by selecting the inserted ListBox and viewing the component name in the Context Panel and by clicking Edit Select Code... to view the Code Editor for this component.

Compatibility

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