Changeset 5410
- Timestamp:
- May 4, 2015, 5:12:06 AM (9 years ago)
- Location:
- branches/uq/lang/python
- Files:
-
- 5 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/uq/lang/python/README
r3177 r5410 38 38 Python scripts. 39 39 40 Rappture applications load their data from a library object. You can 41 load a library as follows: 40 Rappture applications load their data from a an XML driver file. 41 In the tool.xml file, you should have something like 42 43 <command> @tool/path/to/executable @driver </command> 44 45 The "@driver" pattern is replaced by the driver xml file generated by 46 Rappture. This driver file will contain the values to use for the 47 parameters in your application. See 48 https://nanohub.org/infrastructure/rappture/wiki/rappture_xml_elements 49 for more information. 50 51 The first thing your application should do is load the driver file. 42 52 43 53 import Rappture 44 lib = Rappture.library('example.xml') 45 print lib.xml() 46 54 rx = Rappture.PyXml('example.xml') 55 56 You can see the xml contents by doing 57 print rx.xml() 58 47 59 The "import" statement loads the Rappture toolkit into your Python 48 60 application. The next line creates a library object representing … … 54 66 55 67 import Rappture 56 lib = Rappture. library('example.xml')68 lib = Rappture.PyXml('example.xml') 57 69 tval = lib.get('group(ambient).number(temp).current') 70 or alternatively 71 tval = lib['group(ambient).number(temp).current'].value 58 72 59 73 The get() method follows a path through the XML. In this example, … … 68 82 69 83 tval += 10 70 lib.put('group(ambient).number(temp).current',str(tval)) 84 lib.put('group(ambient).number(temp).current', tval) 85 or 86 lib[group(ambient).number(temp).current'] = tval 71 87 72 88 This changes the text within the <current>...</current> tag, 73 replacing it with the new value. Note that the value must be a 74 string, so we use str(tval), rather than tval itself, when inserting 75 a value. 89 replacing it with the new value, converted to a string if necessary. 76 90 77 91 You can also append to an existing value. For example, … … 79 93 lib.put('group(ambient).number(temp).current', 'more text', append=1) 80 94 81 This adds the string 'more text' after the value (tval) within the 82 <current>...</current> tag. 95 This adds the string 'more text' after the value (tval) within the 96 <current>...</current> tag. Use of append in a loop is not 97 recommended because it can be very slow. It is faster to collect 98 data in python and put it all at once. 83 99 84 Suppose we wanted to add another number to the "ambient" group.85 We could do that by requesting "number#". The # sign indicates86 that you'd like to create a new number element (number1, number2,87 etc.). For example, we could add a number for a damping factor:88 89 lib.put('group(ambient).number#(damping).current','0.25')90 91 This creates a new element <number id="damping"> within92 <group id="ambient">, positioned just after the existing93 <number id="temp">. -
branches/uq/lang/python/Rappture/__init__.py
r790 r5410 1 1 # Rappture package 2 2 from library import library 3 from pyxml import PyXml 3 4 from interface import interface 4 5 from number import number -
branches/uq/lang/python/setup.py.in
r1584 r5410 41 41 'Rappture.signalHandler', 42 42 'Rappture.tools', 43 'Rappture.result'], 43 'Rappture.result', 44 'Rappture.pyxml'], 44 45 ext_modules=[ encode_module, 45 46 library_module,
Note: See TracChangeset
for help on using the changeset viewer.