|
From: Marc J. R. S. <mro...@ce...> - 2015-08-20 11:30:06
|
Move Tango specific attributes and methods from TaurusAttribute
to TangoAttribute. Mark deprecated methods using decorator and
give alternative method names.
---
lib/taurus/core/tango/tangoattribute.py | 108 +++++++++++++++++++++++-
lib/taurus/core/taurusattribute.py | 140 +-------------------------------
2 files changed, 105 insertions(+), 143 deletions(-)
diff --git a/lib/taurus/core/tango/tangoattribute.py b/lib/taurus/core/tango/tangoattribute.py
index bf219c2..218e347 100755
--- a/lib/taurus/core/tango/tangoattribute.py
+++ b/lib/taurus/core/tango/tangoattribute.py
@@ -254,6 +254,7 @@ class TangoAttribute(TaurusAttribute):
attr_info = None
self._decodeAttrInfoEx(attr_info)
+ self.format = '%s'
def cleanUp(self):
self.trace("[TangoAttribute] cleanUp")
@@ -299,6 +300,28 @@ class TangoAttribute(TaurusAttribute):
tgtype = self._tango_data_type
return tgtype == PyTango.CmdArgType.DevState
+ @tep14_deprecation(dbg_msg='Deprecated method')
+ def displayValue(self,value):
+ if value is None:
+ return None
+ ret = None
+ try:
+ if self.isScalar():
+ fmt = self.getFormat()
+ if self.isNumeric() and fmt is not None:
+ ret = fmt % value
+ else:
+ ret = str(value)
+ elif self.isSpectrum():
+ ret = str(value)
+ else:
+ ret = str(value)
+ except:
+ # if cannot calculate value based on the format just return the value
+ ret = str(value)
+ return ret
+
+ @tep14_deprecation(alt='getLabel')
def getDisplayValue(self, cache=True):
attrvalue = self.getValueObj(cache=cache)
if not attrvalue:
@@ -307,6 +330,33 @@ class TangoAttribute(TaurusAttribute):
return self.displayValue(v)
+ @tep14_deprecation(alt='.rvalue.units')
+ def getUnit(self, cache=True):
+ try:
+ return str(self.getValueObj(cache).rvalue.units)
+ except:
+ return None
+
+ @tep14_deprecation(alt='.rvalue.units')
+ def getStandardUnit(self, cache=True):
+ try:
+ return str(self.getValueObj(cache).rvalue.units)
+ except:
+ return None
+
+ @tep14_deprecation(alt='.rvalue.units')
+ def getDisplayUnit(self, cache=True):
+ try:
+ return str(self.getValueObj(cache).rvalue.units)
+ except:
+ return None
+
+ def getFormat(self, cache=True):
+ return self.format
+
+ def setFormat(self, fmt):
+ self.format = fmt
+
@tep14_deprecation(dbg_msg='Do not use')
def getDisplayWriteValue(self,cache=True):
raise NotImplementedError("Not available since Taurus4")
@@ -711,6 +761,10 @@ class TangoAttribute(TaurusAttribute):
###########################################################################
# TangoConfiguration
+ @tep14_deprecation(alt='isWritable')
+ def getWritable(self, cache=True):
+ return self.isWritable(cache)
+
def isWrite(self, cache=True):
return self.getTangoWritable(cache) == PyTango.AttrWriteType.WRITE
@@ -744,6 +798,46 @@ class TangoAttribute(TaurusAttribute):
# def getType(self, cache=True):
# return self.data_type
+ @tep14_deprecation(alt='self.data_format')
+ def isScalar(self):
+ return self.data_format == DataFormat._0D
+
+ @tep14_deprecation(alt='self.data_format')
+ def isSpectrum(self):
+ return self.data_format == DataFormat._1D
+
+ @tep14_deprecation(alt='self.data_format')
+ def isImage(self):
+ return self.data_format == DataFormat._2D
+
+ def getMaxDim(self, cache=True):
+ return self.max_dim
+
+ @tep14_deprecation(alt='getMaxDim')
+ def getMaxDimX(self, cache=True):
+ dim = self.getMaxDim(cache)
+ if dim:
+ return dim[0]
+ else:
+ return None
+
+ @tep14_deprecation(alt='getMaxDim')
+ def getMaxDimY(self, cache=True):
+ dim = self.getMaxDim(cache)
+ if dim:
+ return dim[1]
+ else:
+ return None
+
+ @tep14_deprecation(dbg_msg='Deprecated method')
+ def getShape(self, cache=True):
+ if self.isScalar(cache):
+ return ()
+ elif self.isSpectrum():
+ return (self.getMaxDimX(),)
+ else:
+ return self.getMaxDim()
+
def getRange(self, cache=True):
return self.getLimits(cache=cache)
@@ -771,8 +865,9 @@ class TangoAttribute(TaurusAttribute):
def getWarnings(self, cache=True):
return list(self.cwarnings)
+ @tep14_deprecation(alt='getattr')
def getParam(self, param_name):
- # TODO mal implementado
+ # TODO not well implemented
if param_name.endswith('warning') or param_name.endswith('alarm'):
attr = self.alarms
try:
@@ -780,8 +875,9 @@ class TangoAttribute(TaurusAttribute):
except:
return None
+ @tep14_deprecation(alt='setattr')
def setParam(self, param_name, value):
- # TODO mal implementado
+ # TODO not well implemented
if param_name.endswith('warning') or param_name.endswith('alarm'):
attr = self.alarms
setattr(attr, param_name, value)
@@ -836,6 +932,11 @@ class TangoAttribute(TaurusAttribute):
config = self._pytango_attrinfoex
self.setConfigEx(config)
+ @tep14_deprecation(alt='self')
+ def getConfig(self):
+ """ Returns the current configuration of the attribute."""
+ return weakref.proxy(self)
+
###########################################################################
# TangoConfValue methods
# it is the old constructor
@@ -891,7 +992,6 @@ class TangoAttribute(TaurusAttribute):
self.tango_writable = i.writable
#################################################
-
self.format = standard_display_format_from_tango(i.data_type,
i.format)
@@ -913,6 +1013,7 @@ class TangoAttribute(TaurusAttribute):
'''returns the *tango* (not Taurus) data type'''
return self._pytango_attrinfoex.data_type
+
class TangoStateAttribute(TangoAttribute, TaurusStateAttribute):
def __init__(self, name, parent, **kwargs):
self.call__init__(TangoAttribute, name, parent, **kwargs)
@@ -937,7 +1038,6 @@ class TangoAttributeEventListener(EventListener):
self.fireEvent(v.value)
-
def test1():
import numpy
from taurus import Attribute
diff --git a/lib/taurus/core/taurusattribute.py b/lib/taurus/core/taurusattribute.py
index d31fa34..85c6ea7 100644
--- a/lib/taurus/core/taurusattribute.py
+++ b/lib/taurus/core/taurusattribute.py
@@ -92,8 +92,6 @@ class TaurusAttribute(TaurusModel):
self.range = float('-inf'), float('inf')
self.alarm = float('-inf'), float('inf')
self.warning = float('-inf'), float('inf')
- # TODO decide what to do with self.format and its get and set methods
- self.format = '%s'
def cleanUp(self):
self.trace("[TaurusAttribute] cleanUp")
@@ -153,9 +151,6 @@ class TaurusAttribute(TaurusModel):
raise NotImplementedError("Not allowed to call AbstractClass" \
" TaurusAttribute.isState")
-# def getDisplayValue(self,cache=True):
-# raise NotImplementedError("Not allowed to call AbstractClass TaurusAttribute.getDisplayValue")
-
def encode(self, value):
raise NotImplementedError("Not allowed to call AbstractClass" \
" TaurusAttribute.encode")
@@ -205,26 +200,6 @@ class TaurusAttribute(TaurusModel):
except:
return False
- def displayValue(self,value):
- if value is None:
- return None
- ret = None
- try:
- if self.isScalar():
- fmt = self.getFormat()
- if self.isNumeric() and fmt is not None:
- ret = fmt % value
- else:
- ret = str(value)
- elif self.isSpectrum():
- ret = str(value)
- else:
- ret = str(value)
- except:
- # if cannot calculate value based on the format just return the value
- ret = str(value)
- return ret
-
#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
# API for listeners
#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
@@ -309,24 +284,12 @@ class TaurusAttribute(TaurusModel):
self.deprecated("use disablePolling()")
self.disablePolling()
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
- # API for attribute configuration
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
-
- @tep14_deprecation(alt='self')
- def getConfig(self):
- """ Returns the current configuration of the attribute."""
- return weakref.proxy(self)
-
##########################################################################
# TaurusConfiguration Methods
def __str__(self):
return self.getFullName()
- def getDisplayValue(self,cache=True):
- return self.getLabel(cache)
-
def getDisplayDescription(self,cache=True):
return self.getDescription(cache)
@@ -363,91 +326,27 @@ class TaurusAttribute(TaurusModel):
def isWritable(self, cache=True):
return self.writable
- @tep14_deprecation(alt='isWritable')
- def getWritable(self, cache=True):
- return self.isWritable(cache)
-
def getType(self, cache=True):
return self.type
def getDataFormat(self, cache=True):
return self.data_format
- def getMaxDim(self, cache=True):
- return self.max_dim
-
- @tep14_deprecation(alt='getMaxDim')
- def getMaxDimX(self, cache=True):
- dim = self.getMaxDim(cache)
- if dim:
- return dim[0]
- else:
- return None
-
- @tep14_deprecation(alt='getMaxDim')
- def getMaxDimY(self, cache=True):
- dim = self.getMaxDim(cache)
- if dim:
- return dim[1]
- else:
- return None
-
- def getShape(self, cache=True):
- if self.isScalar(cache):
- return ()
- elif self.isSpectrum():
- return (self.getMaxDimX(),)
- else:
- return self.getMaxDim()
-
def getDescription(self, cache=True):
return self.description
def getLabel(self, cache=True):
return self.label
- @tep14_deprecation(alt='.rvalue.units')
- def getUnit(self, cache=True):
- try:
- return str(self.getValueObj(cache).rvalue.units)
- except:
- return None
-
- @tep14_deprecation(alt='.rvalue.units')
- def getStandardUnit(self, cache=True):
- try:
- return str(self.getValueObj(cache).rvalue.units)
- except:
- return None
-
- @tep14_deprecation(alt='.rvalue.units')
- def getDisplayUnit(self, cache=True):
- try:
- return str(self.getValueObj(cache).rvalue.units)
- except:
- return None
-
- def getFormat(self, cache=True):
- return self.format
-
def getMinValue(self, cache=True):
return self.range[0]
def getMaxValue(self, cache=True):
return self.range[1]
- @tep14_deprecation(alt='getRange')
- def getLimits(self, cache=True):
- return self.getRange(cache=cache)
-
def getRange(self, cache=True):
return self.range
- @tep14_deprecation(alt='getRange')
- def getRanges(self, cache=True):
- return [self.range[0], self.alarm[0], self.warning[0],
- self.warning[1], self.alarm[1], self.range[1]]
-
def getMinAlarm(self, cache=True):
return self.alarm[0]
@@ -466,26 +365,12 @@ class TaurusAttribute(TaurusModel):
def getWarnings(self, cache=True):
return self.warning
- def getParam(self, param_name):
- return getattr(self, param_name)
-
- def setParam(self, param_name, value):
- if self.getParam(param_name):
- setattr(self, param_name, value)
-
- def setFormat(self, fmt):
- self.format = fmt
-
def setDescription(self, descr):
self.description = descr
def setLabel(self, lbl):
self.label = lbl
- @tep14_deprecation(alt='getRange')
- def setLimits(self, low, high):
- self.setRange(low, high)
-
def setRange(self, low, high):
self.range = [low, high]
@@ -499,30 +384,6 @@ class TaurusAttribute(TaurusModel):
v = self.read(cache)
return isinstance(v.rvalue, bool)
- @tep14_deprecation(alt='isWritable')
- def isReadOnly(self, cache=True):
- return not self.isWritable(cache)
-
- @tep14_deprecation(alt='isWritable')
- def isReadWrite(self, cache=True):
- return self.isWritable(cache)
-
- @tep14_deprecation(alt='isWritable')
- def isWrite(self, cache=True):
- return self.isWritable(cache)
-
- @tep14_deprecation(alt='self.data_format')
- def isScalar(self):
- return self.data_format == DataFormat._0D
-
- @tep14_deprecation(alt='self.data_format')
- def isSpectrum(self):
- return self.data_format == DataFormat._1D
-
- @tep14_deprecation(alt='self.data_format')
- def isImage(self):
- return self.data_format == DataFormat._2D
-
def _get_unit(self):
'''for backwards compat with taurus < 4'''
return self.getUnit(True)
@@ -536,6 +397,7 @@ class TaurusAttribute(TaurusModel):
unit = property(_get_unit, _set_unit)
+
class TaurusStateAttribute(TaurusAttribute):
""" """
--
1.8.1.4
|