Skip to content

Commit

Permalink
Merge pull request #7 from klauer/fix_attribute_signal
Browse files Browse the repository at this point in the history
FIX: attributesignal describe from ophyd PR
  • Loading branch information
tacaswell committed May 16, 2016
2 parents 12c4bb8 + 9de1442 commit 4a08c21
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions hkl/diffract.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,25 @@ class AttributeSignal(Signal):
def __init__(self, attr, *, name=None, parent=None):
super().__init__(name=name, parent=parent)

self.attr_base, self.attr = attr.rsplit('.', 1)
if '.' in attr:
self.attr_base, self.attr = attr.rsplit('.', 1)
else:
self.attr_base, self.attr = None, attr

@property
def full_attr(self):
'''The full attribute name'''
if not self.attr_base:
return self.attr
else:
return '.'.join((self.attr_base, self.attr))

@property
def base(self):
'''The parent instance which has the final attribute'''
if self.attr_base is None:
return self.parent

obj = self.parent
for i, part in enumerate(self.attr_base.split('.')):
try:
Expand All @@ -48,10 +62,11 @@ def put(self, value, **kwargs):

def describe(self):
value = self.value
return {'source': 'PY:{}.{}'.format(self.parent.name, self.attr),
desc = {'source': 'PY:{}.{}'.format(self.parent.name, self.full_attr),
'dtype': data_type(value),
'shape': data_shape(value),
}
return {self.name: desc}


class ArrayAttributeSignal(AttributeSignal):
Expand Down

0 comments on commit 4a08c21

Please sign in to comment.