source: trunk/builder/scripts/templates/python.tl @ 3177

Last change on this file since 3177 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 3.3 KB
RevLine 
[2147]1# ----------------------------------------------------------------------
2#  LANGUAGE:  Python API
3# ======================================================================
4#  AUTHOR:  Michael McLennan, Purdue University
[3177]5#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
[2147]6#
7#  See the file "license.terms" for information on usage and
8#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9# ======================================================================
10language "Python" {
[2153]11  extension ".py"
12  command {python @tool/@@FILENAME@@ @driver}
13
[2147]14  main {# ----------------------------------------------------------------------
15#  MAIN PROGRAM - generated by the Rappture Builder
16# ----------------------------------------------------------------------
17import Rappture
18import sys
19from math import *
20
21# open the XML file containing the run parameters
22io = Rappture.library(sys.argv[1])
23
24#########################################################
25# Get input values from Rappture
26#########################################################
27@@INPUTS@@
28
[2153]29#########################################################
[2147]30#  Add your code here for the main body of your program
[2153]31#########################################################
[2147]32
33# spit out progress messages as you go along...
34Rappture.Utils.progress(0, "Starting...")
35Rappture.Utils.progress(5, "Loading data...")
36Rappture.Utils.progress(50, "Half-way there")
37Rappture.Utils.progress(100, "Done")
38
39#########################################################
40# Save output values back to Rappture
41#########################################################
42@@OUTPUTS@@
43
44Rappture.result(io)
45sys.exit()
46}
47
48  input boolean {
[2153]49    code "\n# get input value for $path"
50    code "# returns value as string \"yes\" or \"no\""
[2162]51    code "$id = io.get('$path.current') == 'yes'"
[2147]52  }
53  input image {
[2153]54    code "\n# get input value for $path"
55    code "# returns base64-encoded image data"
56    code "$id = io.get('$path.current')"
[2147]57  }
[2162]58  input integer {
59    code "\n# get input value for $path"
60    code "$id = int(io.get('$path.current'))"
61  }
[2147]62  input number {
63    set units [attr get units]
64    if {$units ne ""} {
[2153]65      code "\n# get input value for $path and convert to $units"
66      code "str = io.get('$path.current')"
67      code "$id = Rappture.Units.convert(str, to=\"$units\", units=\"off\")"
[2147]68    } else {
[2153]69      code "\n# get input value for $path"
[2162]70      code "$id = float(io.get('$path.current'))"
[2147]71    }
72  }
73  input * {
[2153]74    code "\n# get input value for $path"
75    code "$id = io.get('$path.current')"
[2147]76  }
77
78  output curve {
[2153]79    code "\n# save output value for $path"
80    code "# this shows just one (x,y) point -- modify as needed"
[2196]81    code "line = \"%g %g\n\" % (x, y)"
[2153]82    code "io.put('$path.component.xy', line, append=1)"
[2147]83  }
84  output histogram {
[2153]85    code "\n# save output value for $path"
86    code "# this shows just one point -- modify as needed"
87    code "# (x,h,w) = x-coord, height of bar, and width of bar (optional)"
[2196]88    code "line = \"%g %g %g\n\" % (x, h, w)"
[2153]89    code "io.put('$path.component.xhw', line, append=1)"
[2147]90  }
91  output image {
[2153]92    code "\n# save output value for $path"
93    code "# data should be base64-encoded image data"
94    code "io.put('$path.current', imdata)"
[2147]95  }
96  output * {
[2153]97    code "\n# save output value for $path"
98    code "io.put('$path.current',$id)"
[2147]99  }
100}
Note: See TracBrowser for help on using the repository browser.