source: trunk/python/Rappture/interface.py @ 55

Last change on this file since 55 was 55, checked in by dkearney, 19 years ago

python/Rappture/number.py

  • added ability for number to choose between default and current tags
  • changed structure of init so the basePath and the id are separate arguments to keep compatibility with how the driver program expects a number xml structure

python/Rappture/interface.py

  • included a more complete xml structure including tool and command i structures, for writing the xml to the file when the -g option is used
  • adjusted the finish() function to utilize the new Rappture.result() function

examples/app-fermi/fermi_io.py

  • adjusted the Rappture.number() fxn call to split the path and id.
  • commented out the result = [] because we now write the result to xml

examples/app-fermi/fermi.py

  • added output section with curve xml details for writing to xml
  • directly write the results to xml instead of to a result[] array

gui/apps/rerun

  • added script to re-visualize output from previously created run.xml file
File size: 3.0 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: interface - used in the main program of a simulator
3#
4#  Rappture.interface() is called at the start of a simulator.  You pass
5#  in arguments and one or more interface packages.  If the -gui flag
6#  is included, then the interfaces are loaded and interrogated, and
7#  interface() writes out a tool.xml file, then invokes the Rappture GUI
8#  to collect input.  The Rappture GUI writes out a driver.xml file,
9#  and then invokes this tool again with the -driver flag to process
10#  the input.
11
12# ======================================================================
13#  AUTHOR:  Michael McLennan, Purdue University
14#  Copyright (c) 2005  Purdue Research Foundation, West Lafayette, IN
15# ======================================================================
16import getopt, sys
17import atexit
18import Rappture
19
20def interface(argv,*args):
21    """
22    Clients call this near the top of their simulator.  It looks
23    at command line arguments and decides whether the Rappture GUI
24    should be invoked, or perhaps the GUI has already been invoked
25    and the simulator should process a driver file.
26
27    The argv is a list of command-line arguments.  All remaining
28    arguments represent packages that should be imported and
29    interrogated for Rappture components, to feed the GUI.
30    """
31
32    try:
33        opts,rest = getopt.getopt(argv[1:],'d:g',["driver","gui"])
34    except getopt.GetoptError:
35        print 'usage:'
36        print '  %s --gui (launch the graphical interface)' % argv[0]
37        print '  %s --driver file (use the input stored in file)' % argv[0]
38        sys.exit(2)
39
40    for opt,val in opts:
41        if opt in ('-g','--gui'):
42            #
43            # Launch the GUI.  Start by loading the various modules
44            # and interrogating them for symbols.
45            #
46            lib = Rappture.library('<?xml version="1.0"?><run><tool>' +
47                    '<about>Press Simulate to view results.</about>' +
48                    '<command>' +argv[0]+ ' -d @driver</command></tool></run>')
49
50            for module in args:
51                for symbol in dir(module):
52                    s = module.__dict__[symbol]
53                    if isinstance(s, Rappture.number):
54                        s.put(lib)
55
56            f = open("driver.xml","w")
57            f.write( lib.xml() )
58            f.close()
59
60            print 'launch the gui...'
61            sys.exit(0)
62
63        elif opt in ('-d','--driver'):
64            #
65            # Continue, using input from the driver file.
66            # Register a hook to write out results upon exit.
67            #
68            Rappture.driver = Rappture.library(val)
69
70            atexit.register(finish)
71            return
72
73
74def finish():
75    """
76    Called automatically whenever the program exits.  Writes out
77    any results in the global driver to the "run.xml" file
78    representing the entire run.
79    """
80#    f = open("run.xml","w")
81#    f.write( Rappture.driver.xml() )
82#    f.close()
83
84    Rappture.result(Rappture.driver)
Note: See TracBrowser for help on using the repository browser.