String Input Example
Location: examples/rappture2/string/
This example demonstrates the <string> input type for both single-line
and multi-line text entry. The <size> element controls textarea
dimensions.
tool.xml
<?xml version="1.0"?>
<run xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../rappture2web/contract.xsd">
<tool>
<title>string (rappture2web)</title>
<about>Example of a Rappture <string> object.
Strings are bits of text--single line or multiple lines. When you click Simulate, the input strings are echoed to the output.
</about>
<command>python3 @tool/run_string.py @driver</command>
<contract>
<input>
<string id="title">
<about>
<label>Title</label>
<description>This text will be used as the title for all plots.</description>
</about>
<default>untitled</default>
</string>
<string id="indeck">
<about>
<label>Input</label>
<description>This is the control file for the program.</description>
</about>
<default>Enter your SPICE commands
in this area.</default>
</string>
</input>
<output>
<string id="outt"><about><label>Echo of title</label><description>Echoes the title string.</description></about></string>
<string id="outi"><about><label>Echo of input</label><description>Echoes the multiline input text.</description></about></string>
</output>
</contract>
</tool>
<input>
<string id="title">
<about>
<label>Title</label>
<description>This text will be used as the title for all plots.</description>
</about>
<default>untitled</default>
</string>
<separator/>
<string id="indeck">
<about>
<label>Input</label>
<description>This is the control file for the program.</description>
<hints>EXAMPLE: .print ac vm(11) mag(i(vcc))</hints>
</about>
<size>40x10</size>
<default>Enter your SPICE commands
in this area.</default>
</string>
</input>
</run>
Script
import sys
import rappture2web.rp_library as Rappture
rx = Rappture.PyXml(sys.argv[1])
title = rx['input.(title).current'].value
indeck = rx['input.(indeck).current'].value
rx['output.string(outt).about.label'] = 'Echo of title'
rx['output.string(outt).current'] = title
rx['output.string(outi).about.label'] = 'Echo of input'
rx['output.string(outi).current'] = indeck
rx.close()
Key concepts
<size>40x10</size>creates a multi-line textarea (40 cols x 10 rows).Without
<size>, the string renders as a single-line input.<separator/>draws a horizontal divider between inputs.<hints>provides a help tooltip for the input.
Running
rappture2web examples/rappture2/string/