Choice Input Example
Location: examples/rappture2/choice/
This example demonstrates the <choice> input type – a dropdown selector
for mutually exclusive options.
tool.xml
<?xml version="1.0"?>
<run xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../rappture2web/contract.xsd">
<tool>
<title>choice (rappture2web)</title>
<about>Example of a Rappture <choice> object.
Choices are a set of mutually exclusive options. When you click Simulate, the selected choice is echoed in the output.
</about>
<command>python3 @tool/choice.py @driver</command>
<contract>
<input>
<choice id="stats">
<about>
<label>Carrier Statistics</label>
<description>Determines the model for carrier statistics used in bandgap narrowing calculations.</description>
</about>
<option>
<about>
<label>Boltzmann</label>
<description>From the Boltzmann transport equation</description>
</about>
<value>bte</value>
</option>
<option>
<about>
<label>Fermi</label>
<description>Fermi-Dirac statistics</description>
</about>
<value>fermi</value>
</option>
<option>
<about>
<label>2D Gas</label>
<description>Includes confinement at material interface</description>
</about>
<value>2deg</value>
</option>
<default>Boltzmann</default>
</choice>
</input>
<output>
<string id="out">
<about><label>Selected carrier statistics</label><description>Reports the selected carrier statistics model.</description></about>
</string>
</output>
</contract>
</tool>
<input>
<choice id="stats">
<about>
<label>Carrier Statistics</label>
<description>Determines the model for carrier statistics used in bandgap narrowing calculations.</description>
</about>
<option>
<about>
<label>Boltzmann</label>
<description>From the Boltzmann transport equation</description>
</about>
<value>bte</value>
</option>
<option>
<about>
<label>Fermi</label>
<description>Fermi-Dirac statistics</description>
</about>
<value>fermi</value>
</option>
<option>
<about>
<label>2D Gas</label>
<description>Includes confinement at material interface</description>
</about>
<value>2deg</value>
</option>
<default>Boltzmann</default>
</choice>
</input>
</run>
Script
import sys
import rappture2web.rp_library as Rappture
rx = Rappture.PyXml(sys.argv[1])
stats = rx['input.choice(stats).current'].value
rx['output.string(out).about.label'] = 'Selected carrier statistics'
rx['output.string(out).current'] = 'Carrier Statistics: %s' % stats
rx.close()
Key concepts
Each
<option>has an optional<value>child. If omitted, the label text is used as the value.<default>matches against the option label, not the value.The script receives the value (e.g.
bte), not the label.
Running
rappture2web examples/rappture2/choice/