source: trunk/lang/python/Rappture/number.py @ 4346

Last change on this file since 4346 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: 1.7 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: number
3#
4# ======================================================================
5#  AUTHOR:  Michael McLennan, Purdue University
6#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
7#
8#  See the file "license.terms" for information on usage and
9#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10# ======================================================================
11import Rappture
12
13class number:
14    def __init__(self,path,id,**kwargs):
15        """
16        Blah, blah...
17        """
18
19        self.basePath = path
20        self.path = path + ".number(" + id + ")"
21        self.id = id
22        self.attribs = kwargs
23
24    def put(self,lib):
25        lib.put(self.path)
26        for key,val in self.attribs.items():
27            lib.put(self.path+'.'+key, str(val))
28
29    def __coerce__(self,other):
30        attrList = Rappture.driver.children(self.path, "id")
31        attrName = 'default'
32        for attr in attrList:
33            if attr == 'current':
34                attrName = attr
35        s = Rappture.driver.get(self.path+'.'+attrName)
36        # return (float(s),other)
37        #
38        # the following code doesnt work if the <units> tag does not exist
39        # becasue it sends an empty string to convert and it fails there
40        toUnit = Rappture.driver.get(self.path+'.units')
41        if (toUnit != None):
42            val = Rappture.Units.convert(s,to=toUnit,units="off")
43        else :
44            # you have to hope the user didn't put units onto the <default>
45            # value (which is unlikely in most cases, btw)
46            val = float(s)
47        return (val,other)
Note: See TracBrowser for help on using the repository browser.