From 5b94a78e099e461fcb9da2ce7c299ec2d6de03e2 Mon Sep 17 00:00:00 2001 From: aberges-SLAC Date: Wed, 5 Feb 2025 17:52:04 -0800 Subject: [PATCH 1/6] ENH: Add support for "long_names" on signal panels --- typhos/panel.py | 61 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/typhos/panel.py b/typhos/panel.py index 92240ff5..ee26a695 100644 --- a/typhos/panel.py +++ b/typhos/panel.py @@ -235,16 +235,38 @@ def _got_signal_widget_info(self, obj, info): for _, sig_info in signal_pairs): self.loading_complete.emit([name for name, _ in signal_pairs]) - def _create_row_label(self, attr, dotted_name, tooltip): - """Create a row label (i.e., the one used to display the name).""" - label_text = self.label_text_from_attribute(attr, dotted_name) + def _create_row_label(self, attr, dotted_name, tooltip, long_name=None): + """ + Create a row label (i.e., the one used to display the name). + If an alternative (human-readable) long name is defined, use that instead + and add the dotted_name to the tooltip for hutch python ease of use. + + Parameters + ----------- + attr: any + Name of the signal + dotted_name: any + Full dotted name of the signal + tooltip: str + Doc string to add to signal + long_name: str, optional + Long form (human readable) name to use for the signal row label text. + """ + if long_name: + label_text = long_name + else: + label_text = self.label_text_from_attribute(attr, dotted_name) label = SignalPanelRowLabel(label_text) label.setObjectName(dotted_name) if tooltip is not None: - label.setToolTip(tooltip) + if long_name: + _tooltip = dotted_name + '
' + round(1.75*len(dotted_name))*'-' + '
' + tooltip + else: + _tooltip = tooltip + label.setToolTip(_tooltip) return label - def add_signal(self, signal, name=None, *, tooltip=None): + def add_signal(self, signal, name=None, long_name=None, *, tooltip=None): """ Add a signal to the panel. @@ -276,8 +298,8 @@ def add_signal(self, signal, name=None, *, tooltip=None): return logger.debug("Adding signal %s (%s)", signal.name, name) - - label = self._create_row_label(name, name, tooltip) + + label = self._create_row_label(attr=name, dotted_name=name, long_name=long_name, tooltip=tooltip) loading = utils.TyphosLoading( timeout_message='Connection timed out.' ) @@ -332,8 +354,18 @@ def _add_component(self, device, attr, dotted_name, component): logger.debug("Adding component %s", dotted_name) + # Hacky workaround until Ophyd.Component.long_name PR comes through + long_name = None + try: + if hasattr(getattr(device, attr), 'long_name'): + long_name = getattr(device, attr).long_name + except AttributeError: + # Then maybe we have a nested component and can't touch the signal + if hasattr(getattr(device, dotted_name), 'long_name'): + long_name = getattr(device, dotted_name).long_name label = self._create_row_label( - attr, dotted_name, tooltip=component.doc or '') + attr=attr, dotted_name=dotted_name, long_name=long_name, + tooltip=component.doc or '') row = self.add_row(label, None) # utils.TyphosLoading()) self.signal_name_to_info[dotted_name] = dict( row=row, @@ -662,8 +694,17 @@ def _maybe_add_signal(self, device, attr, dotted_name, component): logger.warning('Failed to get signal %r from device %s: %s', dotted_name, device.name, ex, exc_info=True) return - - return self.add_signal(signal, name=attr, tooltip=component.doc) + # Hacky workaround until Ophyd.Component.long_name PR comes through + long_name = None + try: + if hasattr(getattr(device, attr), 'long_name'): + long_name = getattr(device, attr).long_name + except AttributeError as ex: + # Then we must have a component signal, so try the dotted_name + if hasattr(getattr(device, dotted_name), 'long_name'): + long_name = getattr(device, dotted_name).long_name + return self.add_signal(signal=signal, name=attr, long_name=long_name, + tooltip=component.doc) return self._add_component(device, attr, dotted_name, component) From 03d69aa77123fea399eff54317a3a7dc46124de4 Mon Sep 17 00:00:00 2001 From: aberges-SLAC Date: Thu, 6 Feb 2025 14:47:03 -0800 Subject: [PATCH 2/6] ENH: Repackage hacky long_name checks into a func --- typhos/panel.py | 52 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/typhos/panel.py b/typhos/panel.py index ee26a695..cd923102 100644 --- a/typhos/panel.py +++ b/typhos/panel.py @@ -266,6 +266,36 @@ def _create_row_label(self, attr, dotted_name, tooltip, long_name=None): label.setToolTip(_tooltip) return label + def _get_long_name(self, device, attr, dotted_name) -> str: + """ + Check the signal for its long_name, if it exists. + Until Ophyd makes it a standard signal, need to manually check + the device and its components for the name. + + Parameters + ----------- + device: (any) + The Ophyd.Device with component signals + attr: (str) + The str name of the signal attribute + dotted_name: (str) + The full dotted name to the signal + + Returns + -------- + str or None + """ + long_name = None + try: + if hasattr(getattr(device, attr), 'long_name'): + long_name = getattr(device, attr).long_name + except AttributeError: + # Then maybe we have a nested component and can't touch the signal + if hasattr(getattr(device, dotted_name), 'long_name'): + long_name = getattr(device, dotted_name).long_name + return long_name + + def add_signal(self, signal, name=None, long_name=None, *, tooltip=None): """ Add a signal to the panel. @@ -354,15 +384,8 @@ def _add_component(self, device, attr, dotted_name, component): logger.debug("Adding component %s", dotted_name) - # Hacky workaround until Ophyd.Component.long_name PR comes through - long_name = None - try: - if hasattr(getattr(device, attr), 'long_name'): - long_name = getattr(device, attr).long_name - except AttributeError: - # Then maybe we have a nested component and can't touch the signal - if hasattr(getattr(device, dotted_name), 'long_name'): - long_name = getattr(device, dotted_name).long_name + # Workaround until Ophyd.Component.long_name PR comes through + long_name = self._get_long_name(device, attr, dotted_name) label = self._create_row_label( attr=attr, dotted_name=dotted_name, long_name=long_name, tooltip=component.doc or '') @@ -694,15 +717,8 @@ def _maybe_add_signal(self, device, attr, dotted_name, component): logger.warning('Failed to get signal %r from device %s: %s', dotted_name, device.name, ex, exc_info=True) return - # Hacky workaround until Ophyd.Component.long_name PR comes through - long_name = None - try: - if hasattr(getattr(device, attr), 'long_name'): - long_name = getattr(device, attr).long_name - except AttributeError as ex: - # Then we must have a component signal, so try the dotted_name - if hasattr(getattr(device, dotted_name), 'long_name'): - long_name = getattr(device, dotted_name).long_name + # Workaround until Ophyd.Component.long_name PR comes through + long_name = self._get_long_name(device, attr, dotted_name) return self.add_signal(signal=signal, name=attr, long_name=long_name, tooltip=component.doc) From c17aa283e6d50ae0dc173f1a4954403fc8e53ea4 Mon Sep 17 00:00:00 2001 From: aberges-SLAC Date: Thu, 6 Feb 2025 14:51:13 -0800 Subject: [PATCH 3/6] DOC: Add release notes --- .../627-Add_long_name_for_SignalPanel.rst | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/source/upcoming_release_notes/627-Add_long_name_for_SignalPanel.rst diff --git a/docs/source/upcoming_release_notes/627-Add_long_name_for_SignalPanel.rst b/docs/source/upcoming_release_notes/627-Add_long_name_for_SignalPanel.rst new file mode 100644 index 00000000..5953b420 --- /dev/null +++ b/docs/source/upcoming_release_notes/627-Add_long_name_for_SignalPanel.rst @@ -0,0 +1,22 @@ +627 Add long_name for SignalPanel +################# + +API Breaks +---------- +- N/A + +Features +-------- +- Add `long_name` support for `device.signal` or `device.component.signal` that replace `label_text` for rows in `SignalPanel` + +Bugfixes +-------- +- N/A + +Maintenance +----------- +- N/A + +Contributors +------------ +- aberges-SLAC From a47a75120ccf227e0f8f842be80ea88beb239c14 Mon Sep 17 00:00:00 2001 From: aberges-SLAC Date: Thu, 6 Feb 2025 15:08:30 -0800 Subject: [PATCH 4/6] MNT: Fix white space --- typhos/panel.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/typhos/panel.py b/typhos/panel.py index cd923102..3a077390 100644 --- a/typhos/panel.py +++ b/typhos/panel.py @@ -250,7 +250,7 @@ def _create_row_label(self, attr, dotted_name, tooltip, long_name=None): tooltip: str Doc string to add to signal long_name: str, optional - Long form (human readable) name to use for the signal row label text. + Long form (human readable) name to use for the signal row label text. """ if long_name: label_text = long_name @@ -268,7 +268,7 @@ def _create_row_label(self, attr, dotted_name, tooltip, long_name=None): def _get_long_name(self, device, attr, dotted_name) -> str: """ - Check the signal for its long_name, if it exists. + Check the signal for its long_name, if it exists. Until Ophyd makes it a standard signal, need to manually check the device and its components for the name. @@ -295,7 +295,6 @@ def _get_long_name(self, device, attr, dotted_name) -> str: long_name = getattr(device, dotted_name).long_name return long_name - def add_signal(self, signal, name=None, long_name=None, *, tooltip=None): """ Add a signal to the panel. @@ -328,7 +327,7 @@ def add_signal(self, signal, name=None, long_name=None, *, tooltip=None): return logger.debug("Adding signal %s (%s)", signal.name, name) - + label = self._create_row_label(attr=name, dotted_name=name, long_name=long_name, tooltip=tooltip) loading = utils.TyphosLoading( timeout_message='Connection timed out.' From 63832eb53c6a9a4ad9f9ad6465c2c4062df6d9ed Mon Sep 17 00:00:00 2001 From: Adam Berges <149725219+aberges-SLAC@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:10:50 -0800 Subject: [PATCH 5/6] ENH: fix allocation in _get_long_name Co-authored-by: Zachary Lentz --- typhos/panel.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/typhos/panel.py b/typhos/panel.py index 3a077390..77954167 100644 --- a/typhos/panel.py +++ b/typhos/panel.py @@ -285,15 +285,13 @@ def _get_long_name(self, device, attr, dotted_name) -> str: -------- str or None """ - long_name = None try: if hasattr(getattr(device, attr), 'long_name'): - long_name = getattr(device, attr).long_name + return getattr(device, attr).long_name except AttributeError: # Then maybe we have a nested component and can't touch the signal if hasattr(getattr(device, dotted_name), 'long_name'): - long_name = getattr(device, dotted_name).long_name - return long_name + return getattr(device, dotted_name).long_name def add_signal(self, signal, name=None, long_name=None, *, tooltip=None): """ From 902449158d441b6861d9590ce5bd67ce7f574741 Mon Sep 17 00:00:00 2001 From: aberges-SLAC Date: Thu, 6 Feb 2025 15:13:29 -0800 Subject: [PATCH 6/6] MNT: Be consistent with annotations --- typhos/panel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typhos/panel.py b/typhos/panel.py index 77954167..62463ce3 100644 --- a/typhos/panel.py +++ b/typhos/panel.py @@ -266,7 +266,7 @@ def _create_row_label(self, attr, dotted_name, tooltip, long_name=None): label.setToolTip(_tooltip) return label - def _get_long_name(self, device, attr, dotted_name) -> str: + def _get_long_name(self, device, attr, dotted_name): """ Check the signal for its long_name, if it exists. Until Ophyd makes it a standard signal, need to manually check