diff --git a/typhos/positioner.py b/typhos/positioner.py index c218a4af..78ec85c5 100644 --- a/typhos/positioner.py +++ b/typhos/positioner.py @@ -1,5 +1,6 @@ from __future__ import annotations +import inspect import logging import os.path import threading @@ -10,6 +11,8 @@ from pydm.widgets.channel import PyDMChannel from qtpy import QtCore, QtWidgets, uic +from typhos.display import TyphosDisplaySwitcher + from . import dynamic_font, utils, widgets from .alarm import AlarmLevel, KindLevel, _KindLevel from .panel import SignalOrder, TyphosSignalPanel @@ -828,6 +831,7 @@ class _TyphosPositionerRowUI(_TyphosPositionerUI): status_container_widget: QtWidgets.QFrame extended_signal_panel: Optional[TyphosSignalPanel] error_prefix: QtWidgets.QLabel + switcher: TyphosDisplaySwitcher class TyphosPositionerRowWidget(TyphosPositionerWidget): @@ -964,6 +968,33 @@ def add_device(self, device: ophyd.Device) -> None: self.ui.device_name_label.setText(device.name) self.ui.notes_edit.add_device(device) + self.ui.switcher.help_toggle_button.setToolTip(self._get_tooltip()) + self.ui.switcher.help_toggle_button.setEnabled(False) + + def _get_tooltip(self): + """Update the tooltip based on device information.""" + # Lifted from TyphosHelpFrame + tooltip = [] + # BUG: I'm seeing two devices in `self.devices` for + # $ typhos --fake-device 'ophyd.EpicsMotor[{"prefix":"b"}]' + for device in sorted( + set(self.devices), + key=lambda dev: self.devices.index(dev) + ): + heading = device.name or type(device).__name__ + tooltip.extend([ + heading, + "-" * len(heading), + "" + ]) + + tooltip.append( + inspect.getdoc(device) or + inspect.getdoc(type(device)) or + "No docstring" + ) + tooltip.append("") + return "\n".join(tooltip) @utils.linked_attribute('error_message_attribute', 'ui.error_label', True) def _link_error_message(self, signal, widget): diff --git a/typhos/ui/widgets/positioner_row.ui b/typhos/ui/widgets/positioner_row.ui index 3b8fbaa6..85ce5e47 100644 --- a/typhos/ui/widgets/positioner_row.ui +++ b/typhos/ui/widgets/positioner_row.ui @@ -116,7 +116,7 @@ - + 0