From 8692048af7d33d8c45d889943a1fd372b81b3db2 Mon Sep 17 00:00:00 2001 From: nstelter-slac Date: Thu, 13 Mar 2025 15:50:16 -0700 Subject: [PATCH] MNT: update enum-button widget's button-group to use proper clicked signal, avoid pyside6 error Calling signal without overloaded int and expecting a button object back, is whats specified in qt5 docs: https://doc.qt.io/qt-5/qbuttongroup.html#buttonClicked. This is the same in the qt6 docs, and pyside6 even throws error if signal is not used in this correct way. Also seems like the newer python in running pyside6 on doesn't like using enums to index into an array, so use a map for 'class_for_type' instead. (using the enum's '.value' should allow for indexing into an array, but imo using the map is more readable.) --- pydm/widgets/enum_button.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/pydm/widgets/enum_button.py b/pydm/widgets/enum_button.py index 617faa8c9..b2e62a038 100644 --- a/pydm/widgets/enum_button.py +++ b/pydm/widgets/enum_button.py @@ -2,7 +2,16 @@ from qtpy.QtCore import Qt, QSize, Property, Slot, QMargins from qtpy.QtGui import QPainter -from qtpy.QtWidgets import QWidget, QButtonGroup, QGridLayout, QPushButton, QRadioButton, QStyleOption, QStyle +from qtpy.QtWidgets import ( + QWidget, + QButtonGroup, + QGridLayout, + QPushButton, + QRadioButton, + QStyleOption, + QStyle, + QAbstractButton, +) from .base import PyDMWritableWidget from .. import data_plugins @@ -25,7 +34,7 @@ class WidgetType(Enum): # noqa: F811 RadioButton = 1 -class_for_type = [QPushButton, QRadioButton] +class_for_type = {WidgetType.PushButton: QPushButton, WidgetType.RadioButton: QRadioButton} logger = logging.getLogger(__name__) @@ -74,7 +83,7 @@ def __init__(self, parent=None, init_channel=None): self._layout_margins = QMargins(9, 9, 9, 9) self._btn_group = QButtonGroup() self._btn_group.setExclusive(True) - self._btn_group.buttonClicked[int].connect(self.handle_button_clicked) + self._btn_group.buttonClicked.connect(self.handle_button_clicked) self._widget_type = WidgetType.PushButton self._orientation = Qt.Vertical self._widgets = [] @@ -379,17 +388,18 @@ def checkable(self, value): for widget in self._widgets: widget.setCheckable(value) - @Slot(int) - def handle_button_clicked(self, id): + @Slot(QAbstractButton) + def handle_button_clicked(self, button): """ Handles the event of a button being clicked. Parameters ---------- - id : int - The clicked button id. + id : QAbstractButton + The clicked button button. """ - self.send_value_signal.emit(id) + button_id = self._btn_group.id(button) # get id of the button in the group + self.send_value_signal.emit(button_id) def clear(self): """