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: update enum-button widget's button-group to use proper clicked signal, avoid pyside6 error #1196

Merged
merged 1 commit into from
Mar 27, 2025
Merged
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
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.)
nstelter-slac committed Mar 14, 2025

Verified

This commit was signed with the committer’s verified signature.
karinathomasbbc Karina Thomas
commit 8692048af7d33d8c45d889943a1fd372b81b3db2
26 changes: 18 additions & 8 deletions pydm/widgets/enum_button.py
Original file line number Diff line number Diff line change
@@ -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):
"""