source: trunk/python/Rappture/number.py @ 539

Last change on this file since 539 was 115, checked in by mmc, 19 years ago

Updated all copyright notices.

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