Skip to content

Commit

Permalink
change PrettyStrForSignal class with functions
Browse files Browse the repository at this point in the history
  • Loading branch information
awalter-bnl committed Aug 8, 2024
1 parent 5032f36 commit 2afa046
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 51 deletions.
Binary file modified src/ari_sxn_common/__pycache__/common_ophyd.cpython-312.pyc
Binary file not shown.
98 changes: 47 additions & 51 deletions src/ari_sxn_common/common_ophyd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# noinspection PyUnresolvedReferences,PyProtectedMember

def _pretty__str__for_branches(self):
"""
"""Custom __str__method for use with 'branch' like devices
Updates the __str__() method to provide a custom `__str__()` method that
returns a formatted string that includes the device name as well as
child components grouped by the `component._ophyd_labels_` list.
Expand Down Expand Up @@ -52,7 +53,7 @@ def _pretty__str__for_branches(self):

def _pretty__dir__for_devices(self):
"""
Used to limit the number of options when using tab to complete.
Limits the number of options when using tab to complete on branch devices.
This method is used to give the list of options when using pythons tab
to complete process. It is a custom `__dir__()` method that returns a
Expand All @@ -71,65 +72,47 @@ def _pretty__dir__for_devices(self):
return attribute_list


# noinspection PyUnresolvedReferences
class PrettyStrForSignal:
"""
A class that provides a better string when using `print(PrettyStr)`
def _pretty__str__for_leaves(self):
"""Custom __str__method for use with 'leaf' like devices.
This class has a custom `__str__()` method that returns a formatted string
that includes the device name as well as the `signal._ophyd_labels_` list.
It is designed for use with the `PrettyStrForDevices` class but on the
lowest level signals that should be accessed by users.
This class also has a custom `__dir__()` method that returns a list of
attribute names giving the required options when using tab-to-complete. This
list contains only the `read()` method.
Methods
Returns
-------
__str__() :
Returns a formatted string indicating it's name and it's
`_ophyd_labels_`.
__dir__() :
Returns a list of attribute name strings to be used to define what
options are available when doing tab-to-complete.
output : str
A formatted string that should be printed when using print(self)
"""

def __str__(self):
"""
Updating the __str__ function to return 'name (label)'
Returns
-------
output : str
A formatted string that should be printed when using print(self)
"""
try:
self_label = self._ophyd_labels_
except IndexError:
self_label = {'unknown', }
return f'{self.name} ({str(self_label)[1:-1]})'

try:
self_label = self._ophyd_labels_
except IndexError:
self_label = {'unknown', }
return f'{self.name} ({str(self_label)[1:-1]})'
def _pretty__dir__for_leaves(self):
"""
Limits the number of options when using tab to complete with 'leaf' devices.
def __dir__(self):
"""
Used to limit the number of options when using tab to complete.
This class also has a custom `__dir__()` method that returns a list of
attribute names giving the required options when using tab-to-complete. This
list contains only the `read()` method.
This method is used to give the list of options when using pythons tab
to complete process. It gives only the 'read' method.
Returns
-------
attribute_list : list[str]
A list of attribute names to be included when using tab-to-complete
"""
attribute_list = ['read']
Returns
-------
attribute_list : list[str]
A list of attribute names to be included when using tab-to-complete
"""
attribute_list = ['read']

return attribute_list
return attribute_list


# noinspection PyUnresolvedReferences
class ID29EpicsMotor(PrettyStrForSignal, EpicsMotor):
class ID29EpicsMotor(EpicsMotor):
"""
Updates ophyd.EpicsMotor with a str method from PrettyStrForSignal
Expand Down Expand Up @@ -162,9 +145,11 @@ def __init__(self, *args, **kwargs):
self.user_setpoint.kind = 'normal'
self.user_readback.kind = 'hinted'

__str__ = _pretty__str__for_leaves
__dir__ = _pretty__dir__for_leaves

# noinspection PyUnresolvedReferences
class ID29EpicsSignalRO(PrettyStrForSignal, EpicsSignalRO):
class ID29EpicsSignalRO(EpicsSignalRO):
"""
Updates ophyd.EpicsSignalRO with a str method from PrettyStrForSignal
Expand All @@ -186,9 +171,10 @@ class ID29EpicsSignalRO(PrettyStrForSignal, EpicsSignalRO):
The methods of the parent `PrettyStrForSignal` and `EpicsSignalRO`
classes.
"""
__str__ = _pretty__str__for_leaves
__dir__ = _pretty__dir__for_leaves


class ID29EM(PrettyStrForSignal, NSLS_EM):
class ID29EM(NSLS_EM):
"""
A 29-ID specific version of the NSLS_EM quadEM device.
Expand Down Expand Up @@ -240,15 +226,19 @@ def __init__(self, *args, **kwargs):
elif hasattr(device, 'kind'):
device.kind = 'omitted' # set signal to 'omitted'.

__str__ = _pretty__str__for_leaves
__dir__ = _pretty__dir__for_leaves

class ID29TwoButtonShutter(PrettyStrForSignal, TwoButtonShutter):

class ID29TwoButtonShutter(TwoButtonShutter):
"""
An nslsii.devices.TwoButtonShutter class that adds the `__str__` and
`__dir__` methods from PrettyStrForSignal
"""
__str__ = _pretty__str__for_leaves
__dir__ = _pretty__dir__for_leaves


class Prosilica(PrettyStrForSignal, SingleTrigger, ProsilicaDetector):
class Prosilica(SingleTrigger, ProsilicaDetector):
"""
Adds the `cam1.array_data` attribute required when not image saving.
Expand Down Expand Up @@ -288,6 +278,9 @@ def __init__(self, *args, **kwargs):
self.cam.kind = 'normal'
self.cam.array_data.kind = 'normal'

__str__ = _pretty__str__for_leaves
__dir__ = _pretty__dir__for_leaves

class ProsilicaCam(ProsilicaDetectorCam):
"""
A `ProsillicaDetectorCam` class that adds some extra attributes
Expand Down Expand Up @@ -384,7 +377,7 @@ class DeviceWithLocations(Device):
"""

# noinspection PyUnresolvedReferences
class LocationSignal(PrettyStrForSignal, Signal):
class LocationSignal(Signal):
"""
An InternalSignal class to be used for updating the 'location' signal
Expand Down Expand Up @@ -430,6 +423,9 @@ class LocationSignal(PrettyStrForSignal, Signal):
be set to.
"""

__str__ = _pretty__str__for_leaves
__dir__ = _pretty__dir__for_leaves

def get(self, **kwargs):
"""
Method that returns a list of 'locations' that the device is 'in'
Expand Down

0 comments on commit 2afa046

Please sign in to comment.