Difference: DpHipeTools (105 vs. 106)

Revision 1062013-08-14 - JavierDiaz

Line: 1 to 1
 
META TOPICPARENT name="WritingTasks"
<-- ANALYTICS CODE - DO NOT EDIT -->
<-- Google Analytics script BEGIN -->
<-- Google Analytics script END -->
Line: 253 to 253
 Warning, important * To fully support editing modifiers, that is, task parameter GUI elements that allow to generate-edit values (vs just pass variables) full support for generating Jython values must be provided. Most basic and usual types are supported but if this is not the case then you need to provide a Jython converter that supports your type. * The mechanism for showing defaults does not rely on toString() working for all types, so it generates safe Jython to avoid unwanted errors.
Changed:
<
<
* For composite types (arrays, collections ...), the system may fall back to using toString for the elements which may produce a bad default string. In this case, you have to provide a Jython Converter for the element type.
>
>
  • For composite types (arrays, collections ...), the system may fall back to using toString for the elements which may produce a bad default string. In this case, you have to provide a proper __repr__ or a Jython Converter for the element type.
 

Defining Jython converters
Changed:
<
<
If the type of parameter you use does not have a good way to be written as valid Jython code (it falls back to using toString() on the value from the selection) you may need to register a JythonConverter.
>
>
If the type of parameter you use does not have a good way to be written as valid Jython code (it does not implement __repr__ and it falls back to using toString() on the value from the selection) you may need to register a JythonConverter.
 For example, you have a parameter of type X and a modifier for X that has an editor. If you edit the value, when you press Accept the framework will try to generate a Jython string expression that creates that value to be assigned to the parameter in the task call.
Changed:
<
<
If there is no JythonConverter for class X or x.toString() does not generate a valid (syntactically or type-wise) Jython expression, the generated command will not execute due to syntax errors or incompatibility with the type the parameter expects. In many cases, you can define a parameter of a simple type (Object or List) and do the conversion yourself to the proper type in the execute of your method.
>
>
If there is no JythonConverter for class X, nor does it define __repr__ and x.toString() does not generate a valid (syntactically or type-wise) Jython expression, the generated command will not execute due to syntax errors or incompatibility with the type the parameter expects. In many cases, you can define a parameter of a simple type (Object or List) and do the conversion yourself to the proper type in the execute of your method. In others, you can just add a public PyString __repr__() method to the class. For example:
     // Java 
    public class WithRepr {
        String value;
        public WithRepr(String val) {
            value = val;
        }

        // this should return a PyString that when executed in Jython creates or gives access to an object like this one
       // in this case we construct a new WithRepr (check the use of escape for embedded strings)
        public PyString __repr__() {
            return new PyString("WithRepr(\"" + StringUtil.escape(value, "\"\\") +"\")");
        }

       // Typically for human consumption, so this cannot be properly parsed by Jython   
        @Override
        public String toString() {
            return value;
        }
    }
  So, if your task has a parameter with an editable (that generates values, vs only using already defined variables) modifier the system may not generate the expected values for this type from the modifier. If that is the case, then the module that defines the type (class) of the modifier can:
  • Implement a JythonConverter
 
This site is powered by the TWiki collaboration platform Powered by Perl