Skip to content

Commit

Permalink
Merge pull request #1044 from nstelter-slac/multistate_widget_base
Browse files Browse the repository at this point in the history
Basic version of multi-state LED indicator widget
  • Loading branch information
jbellister-slac authored Dec 12, 2023
2 parents 56502c5 + c0b56d2 commit ed63318
Show file tree
Hide file tree
Showing 7 changed files with 666 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/source/widgets/PyDMWidget.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ API Documentation
:show-inheritance:

PyDMToolTip Instructions
=================
========================
The PyDMToolTip property field takes a string. In the PyDMToolTip property field, the user can include the tag $(pv_value) to get the value of the
channel displayed on the tool tip.

Expand Down
2 changes: 1 addition & 1 deletion docs/source/widgets/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Display Widgets
:maxdepth: 1

byte.rst
multistate.rst
datetime_label.rst
image.rst
label.rst
Expand Down Expand Up @@ -74,7 +75,6 @@ Base Widgets

Utilities
---------

.. toctree::
:maxdepth: 1

Expand Down
11 changes: 11 additions & 0 deletions docs/source/widgets/multistate.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#######################
PyDMMultiStateIndicator
#######################

.. autoclass:: pydm.widgets.byte.PyDMMultiStateIndicator
:members:
:show-inheritance:


.. note::
See `QWidget Documentation <https://doc.qt.io/qtforpython-5/PySide2/QtWidgets/QWidget.html>`_ for all inherited properties and methods.
157 changes: 157 additions & 0 deletions examples/byte_indicator/multi_state_indicator.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>325</width>
<height>264</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="PyDMMultiStateIndicator" name="PyDMMultiStateIndicator">
<property name="toolTip">
<string/>
</property>
<property name="channel" stdset="0">
<string>ca://MTEST:Float</string>
</property>
<property name="renderAsRectangle" stdset="0">
<bool>false</bool>
</property>
<property name="state0Color" stdset="0">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="state1Color" stdset="0">
<color>
<red>170</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="state2Color" stdset="0">
<color>
<red>0</red>
<green>85</green>
<blue>0</blue>
</color>
</property>
<property name="state3Color" stdset="0">
<color>
<red>170</red>
<green>85</green>
<blue>0</blue>
</color>
</property>
<property name="state4Color" stdset="0">
<color>
<red>0</red>
<green>170</green>
<blue>0</blue>
</color>
</property>
<property name="state5Color" stdset="0">
<color>
<red>170</red>
<green>170</green>
<blue>0</blue>
</color>
</property>
<property name="state6Color" stdset="0">
<color>
<red>0</red>
<green>255</green>
<blue>0</blue>
</color>
</property>
<property name="state7Color" stdset="0">
<color>
<red>170</red>
<green>255</green>
<blue>0</blue>
</color>
</property>
<property name="state8Color" stdset="0">
<color>
<red>0</red>
<green>0</green>
<blue>127</blue>
</color>
</property>
<property name="state9Color" stdset="0">
<color>
<red>170</red>
<green>0</green>
<blue>127</blue>
</color>
</property>
<property name="state10Color" stdset="0">
<color>
<red>0</red>
<green>85</green>
<blue>127</blue>
</color>
</property>
<property name="state11Color" stdset="0">
<color>
<red>170</red>
<green>85</green>
<blue>127</blue>
</color>
</property>
<property name="state12Color" stdset="0">
<color>
<red>0</red>
<green>170</green>
<blue>127</blue>
</color>
</property>
<property name="state13Color" stdset="0">
<color>
<red>170</red>
<green>170</green>
<blue>127</blue>
</color>
</property>
<property name="state14Color" stdset="0">
<color>
<red>0</red>
<green>255</green>
<blue>127</blue>
</color>
</property>
<property name="state15Color" stdset="0">
<color>
<red>170</red>
<green>255</green>
<blue>127</blue>
</color>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>PyDMMultiStateIndicator</class>
<extends>QWidget</extends>
<header>pydm.widgets.byte</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
48 changes: 48 additions & 0 deletions pydm/tests/widgets/test_multistate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest

from qtpy.QtGui import QColor
from qtpy.QtCore import Qt
from ...widgets.byte import PyDMMultiStateIndicator


@pytest.mark.parametrize(
"value, expectedColor",
[
(0, QColor(Qt.black)),
(4, QColor(Qt.red)),
(7, QColor(Qt.darkGreen)),
(15, QColor(Qt.yellow)),
],
)
def test_state_change(qtbot, signals, value, expectedColor):
"""
Test the widget's handling of the value changed event.
Expectations:
1. Widget state is update to reflect incoming signal value
2. Widgets color after state-update is the correct color set for the new state
Parameters
----------
qtbot : fixture
pytest-qt window for widget testing
signals : fixture
The signals fixture, which provides access signals to be bound to the appropriate slots
expected : int
Expected resulting color after state-update
"""
pydm_multistate = PyDMMultiStateIndicator()
qtbot.addWidget(pydm_multistate)
pydm_multistate.show()

pydm_multistate.state4Color = QColor(Qt.red)
pydm_multistate.state7Color = QColor(Qt.darkGreen)
pydm_multistate.state15Color = QColor(Qt.yellow)

pydm_multistate._connected = True

signals.new_value_signal[type(value)].connect(pydm_multistate.channelValueChanged)
signals.new_value_signal[type(value)].emit(value)

assert pydm_multistate._curr_state == value
assert pydm_multistate._curr_color == expectedColor
Loading

0 comments on commit ed63318

Please sign in to comment.