Skip to content

Commit

Permalink
MNT: add tooltip to switcher help button
Browse files Browse the repository at this point in the history
  • Loading branch information
tangkong committed Sep 14, 2023
1 parent 7685170 commit 30fd859
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions typhos/positioner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import inspect
import logging
import os.path
import threading
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion typhos/ui/widgets/positioner_row.ui
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
</widget>
</item>
<item>
<widget class="TyphosDisplaySwitcher" name="TyphosDisplaySwitcher">
<widget class="TyphosDisplaySwitcher" name="switcher">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
Expand Down

0 comments on commit 30fd859

Please sign in to comment.