Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
77 changes: 67 additions & 10 deletions typhos/panel.py

@ZLLentz ZLLentz Feb 6, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing here is the pre-release notes docs step, same as how we've done it in pcdsdevices with pre-release-notes.sh

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah derp forgot to commit that, let me fix that after above changes

Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,68 @@ 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 + '<br>' + round(1.75*len(dotted_name))*'-' + '<br>' + tooltip
else:
_tooltip = tooltip
label.setToolTip(_tooltip)
return label

def add_signal(self, signal, name=None, *, tooltip=None):
def _get_long_name(self, device, attr, dotted_name) -> str:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More pettiness: I normally wouldn't ask you to annotate, but this one is half annotated. Can you either finish the annotations or remove them?
device: typing.Any
attr: str
dotted_name: str
-> str | None

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove the annotations to be more consistent with the rest of the script, although it probably wouldn't hurt to add the annotations to all of the funcs one day

"""
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
Comment on lines +277 to +286

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super petty spacing nitpick to match the other docstrings

Suggested change
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
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this ever got committed 👀

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't even remember getting this message on the commit o.O

"""
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
Comment thread
aberges-SLAC marked this conversation as resolved.
Outdated


def add_signal(self, signal, name=None, long_name=None, *, tooltip=None):
"""
Add a signal to the panel.

Expand Down Expand Up @@ -276,8 +328,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.'
)
Expand Down Expand Up @@ -332,8 +384,11 @@ def _add_component(self, device, attr, dotted_name, component):

logger.debug("Adding component %s", dotted_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, 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,
Expand Down Expand Up @@ -662,8 +717,10 @@ 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)
# 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)

return self._add_component(device, attr, dotted_name, component)

Expand Down