wiki:RaptureApi

How to pass parameters to Rappture tools

This document proposes a method of passing parameters to tools built with Rappture.

Small step: Automatically use parameters to set the default values for string Rappture elements.

Use the current parameter syntax to describe the Rappture element to be set. Example:

file(input.string(indeck).default):/path/to/file.txt

Rappture reads in the parameters.hz file if one exists and sets up an associative array of element paths. The value of each path is the name of a file. In the previous example, the textentry widget in Rappture will check to see if it has a parameter entry for itself (.e.g $path.default) in the global parameters array. If it does, it will open the file and use the contents of the file as the default value (ignoring the specified default value in the tool.xml).

If you use XML paths in parameters, it makes your the tool fragile. If you change your tool.xml, you have to fix all the URLs.

One possible remedy is to create a mapping in the tool.xml. This maps a name to an XML path.

<parameters>
   <parameter>
      <name>indeck</name>
       <variable>input.string(indeck).default</variable>
   </paramater>
</parameters>

Then the parameter would be

file(indeck):/path/to/file.txt

On the other hand, specifying XML paths has the advantage of setting parameters on any Rappture tool on any XML tag, not just ones that the tool author specified by a parameter mapping.

Bigger step: Extend the parameter passing syntax to include "string" parameters.

This will let you inline the values in the URL. Example:

string(input.number(temperature).default):300K
string(input.choice(model).default):boltzman

The real advantage of the inline string is you can then override any tag in Rappture.

number(input.number(temperature).min):3K
number(input.number(temperature).max):10000K

Loader issues

The parameter passing mechanism has to cooperate with the loader. You could override any XML value with a parameter on construction. This makes sure you load the parameters only once. The loader overwrites the parameter value with it's default loader value. This happens after the construction of the widgets. If you set parameters after the widgets initial construction, then you can only set current values, not any tag.

Last modified 10 years ago Last modified on Jan 22, 2014 1:24:16 PM