Skip to content

Commit

Permalink
Merge pull request #587 from tangkong/mnt_ui_switch
Browse files Browse the repository at this point in the history
MNT: add TyphosDisplaySwitcher to positioner_row.ui
  • Loading branch information
tangkong authored Sep 14, 2023
2 parents 8e9dcdf + 30fd859 commit 8f68987
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
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

0 comments on commit 8f68987

Please sign in to comment.