Skip to content
yeealex93 edited this page Jul 26, 2012 · 2 revisions

Directory paths will depend on the instrument that the module is defined for. This will walk you through module creation for a generic "instrument".

Although not required, it is advised to create your module in a separate python file dedicated to the module. In /dataflow/dataflow/your_instrument/modules create your module file and name it appropriately. For instance, here is the shell of one called tempMod.py.

tempMod.py:

from ... import config
from ...core import Module

def tempMod_module(id=None, datatype=None, action=None, version='0.0', fields={},
              description="default description here!!!", **kwargs):
 """
 Return a module to do.... #Write a useful comment!
 """

 icon = {
    'URI': config.IMAGES + 'your_instrument/module_icon.png', #Link to your module's icon in toolbar
    'image': config.IMAGES + 'your_instrument/module_image.png', #Link to your module's image in canvas
    'width': 'auto', 
    'terminals': {
        'input': (-12, 16, -1, 0),
        'output': (48, 16, 1, 0),
    }
 }
 #wire terminal locations may be defined in the icon.
 #(xoffset, yoffset, wire_curvature (-1 or 1 is good), 0)

 terminals = [
    dict(id='input',
         datatype=datatype,
         use='in',
         description='', #describe your input
         required=False, #specify if the wire is required
         ),
    dict(id='output',
         datatype=datatype,
         use='out',
         description='', #describe your output
         ),
 ]

 fields = {
    'your_field': {
        "type": "string", 
        "label": "This is a string field:",
        "name": "your_field", 
        "value": 'Hello!',  
    }, 
 }

 # Combine everything into a module.
 module = Module(id=id,
              name='Module_name',  # name your module
              version=version,
              description=description,
              icon=icon,
              terminals=terminals,
              fields=fields,
              action=action,
              **kwargs
              )

 return module

All supported types for your fields are:

  • 'files'
  • 'Array' or 'Object'
  • 'list' or 'List'
  • 'string'
  • 'number'
  • 'boolean' Leaving type undefined will revert to a default type based on the value provided. More details can be found within the createItem() function of dataflow/static/wireit_test/moduleSimpleConfigForm.js.

After creating your module, find your /dataflow/dataflow/your_instrument/instruments.py file. Here you must:

  • code the action that the module will perform
  • instantiate the module
  • add your module to your instrument object. To modify the javascript appearance for the module, such as adding a button, define an xtype for your module or use a preexisting xtype. Examples of xtypes are available at /dataflow/static/wireit_test/lang_common.js.

For example, to add your module to the TripleAxis instrument:

def tempMod_action(input, **kwargs):
    #do whatever this module should do. Can call other functions if needed.

tempMod = tempMod_module(id='tas.tempMod', datatype=TAS_DATA,
               version='1.0', action=tempMod_action, filterModule=tempModFunction)
#tempMod.xtype = 'ConfigContainer' #optional... see above comments!

# ==== Instrument definitions ====
INS = Instrument(id='ncnr.',
             name='tas',
             archive=config.NCNR_DATA + '/tas',
             menu=[('Input', [load, save]),
                   ('Reduction', [join, subtract, normalizemonitor, detailedbalance,
                                  monitorcorrection, volumecorrection, tempMod]) #add your module
                   ],
             datatypes=[data1d],
             )

Clone this wiki locally