Skip to content

Commit 8692048

Browse files
committed
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.)
1 parent 0c4f0c9 commit 8692048

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

pydm/widgets/enum_button.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22

33
from qtpy.QtCore import Qt, QSize, Property, Slot, QMargins
44
from qtpy.QtGui import QPainter
5-
from qtpy.QtWidgets import QWidget, QButtonGroup, QGridLayout, QPushButton, QRadioButton, QStyleOption, QStyle
5+
from qtpy.QtWidgets import (
6+
QWidget,
7+
QButtonGroup,
8+
QGridLayout,
9+
QPushButton,
10+
QRadioButton,
11+
QStyleOption,
12+
QStyle,
13+
QAbstractButton,
14+
)
615

716
from .base import PyDMWritableWidget
817
from .. import data_plugins
@@ -25,7 +34,7 @@ class WidgetType(Enum): # noqa: F811
2534
RadioButton = 1
2635

2736

28-
class_for_type = [QPushButton, QRadioButton]
37+
class_for_type = {WidgetType.PushButton: QPushButton, WidgetType.RadioButton: QRadioButton}
2938

3039
logger = logging.getLogger(__name__)
3140

@@ -74,7 +83,7 @@ def __init__(self, parent=None, init_channel=None):
7483
self._layout_margins = QMargins(9, 9, 9, 9)
7584
self._btn_group = QButtonGroup()
7685
self._btn_group.setExclusive(True)
77-
self._btn_group.buttonClicked[int].connect(self.handle_button_clicked)
86+
self._btn_group.buttonClicked.connect(self.handle_button_clicked)
7887
self._widget_type = WidgetType.PushButton
7988
self._orientation = Qt.Vertical
8089
self._widgets = []
@@ -379,17 +388,18 @@ def checkable(self, value):
379388
for widget in self._widgets:
380389
widget.setCheckable(value)
381390

382-
@Slot(int)
383-
def handle_button_clicked(self, id):
391+
@Slot(QAbstractButton)
392+
def handle_button_clicked(self, button):
384393
"""
385394
Handles the event of a button being clicked.
386395
387396
Parameters
388397
----------
389-
id : int
390-
The clicked button id.
398+
id : QAbstractButton
399+
The clicked button button.
391400
"""
392-
self.send_value_signal.emit(id)
401+
button_id = self._btn_group.id(button) # get id of the button in the group
402+
self.send_value_signal.emit(button_id)
393403

394404
def clear(self):
395405
"""

0 commit comments

Comments
 (0)