Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: add TyphosDisplaySwitcher to positioner_row.ui #587

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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
24 changes: 21 additions & 3 deletions typhos/ui/widgets/positioner_row.ui
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@
</property>
</widget>
</item>
<item>
<widget class="TyphosDisplaySwitcher" name="switcher">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -1258,15 +1271,20 @@ Screen</string>
<header>typhos.alarm</header>
</customwidget>
<customwidget>
<class>TyphosNotesEdit</class>
<extends>QLineEdit</extends>
<header>typhos.notes</header>
<class>TyphosDisplaySwitcher</class>
<extends>QFrame</extends>
<header>typhos.display</header>
</customwidget>
<customwidget>
<class>TyphosRelatedSuiteButton</class>
<extends>QPushButton</extends>
<header>typhos.related_display</header>
</customwidget>
<customwidget>
<class>TyphosNotesEdit</class>
<extends>QLineEdit</extends>
<header>typhos.notes</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down