From c15b0aea20beb136d419c8a1819d41c906921081 Mon Sep 17 00:00:00 2001 From: nstelter-slac Date: Mon, 9 Dec 2024 15:47:49 -0800 Subject: [PATCH 1/3] MNT: qRound not supported by pyside2, python round also to nearest int --- pydm/utilities/iconfont.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydm/utilities/iconfont.py b/pydm/utilities/iconfont.py index 6245e5a36..67112b647 100644 --- a/pydm/utilities/iconfont.py +++ b/pydm/utilities/iconfont.py @@ -9,7 +9,7 @@ from typing import Optional from qtpy import QtGui, QtWidgets -from qtpy.QtCore import QPoint, QRect, Qt, qRound +from qtpy.QtCore import QPoint, QRect, Qt from qtpy.QtGui import QColor, QFont, QFontDatabase, QIcon, QIconEngine, QPainter, QPixmap if sys.version_info[0] == 3: @@ -182,7 +182,7 @@ def paint(self, painter, rect, mode, state): color = self._base_color painter.setPen(color) scale_factor = 1.0 - draw_size = 0.875 * qRound(rect.height() * scale_factor) + draw_size = 0.875 * round(rect.height() * scale_factor) painter.setFont(self.icon_font.font(draw_size)) painter.setOpacity(1.0) painter.drawText(rect, int(Qt.AlignCenter | Qt.AlignVCenter), self.char) From 8b1812369c173dd81e59507d6a1242fad5829ea0 Mon Sep 17 00:00:00 2001 From: nstelter-slac Date: Mon, 9 Dec 2024 15:58:35 -0800 Subject: [PATCH 2/3] MNT: remove use of QVariant QVariant is absent from pyside2 as well as qt6. https://doc.qt.io/qtforpython-6/considerations.html#qvariant --- .../connection_inspector/connection_table_model.py | 10 +++++----- pydm/widgets/axis_table_model.py | 12 ++++++------ pydm/widgets/baseplot_table_model.py | 14 +++++++------- pydm/widgets/enum_combo_box.py | 2 +- pydm/widgets/eventplot_curve_editor.py | 8 ++++---- pydm/widgets/nt_table.py | 8 ++++---- pydm/widgets/scatterplot_curve_editor.py | 6 +++--- pydm/widgets/timeplot_curve_editor.py | 4 ++-- pydm/widgets/waveformplot_curve_editor.py | 6 +++--- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pydm/connection_inspector/connection_table_model.py b/pydm/connection_inspector/connection_table_model.py index 322d25ebc..12d75ec53 100644 --- a/pydm/connection_inspector/connection_table_model.py +++ b/pydm/connection_inspector/connection_table_model.py @@ -1,4 +1,4 @@ -from qtpy.QtCore import QAbstractTableModel, Qt, QVariant, QTimer, Slot +from qtpy.QtCore import QAbstractTableModel, Qt, QTimer, Slot from operator import attrgetter @@ -47,17 +47,17 @@ def columnCount(self, parent=None): def data(self, index, role=Qt.DisplayRole): if not index.isValid(): - return QVariant() + return None if index.row() >= self.rowCount(): - return QVariant() + return None if index.column() >= self.columnCount(): - return QVariant() + return None column_name = self._column_names[index.column()] conn = self.connections[index.row()] if role == Qt.DisplayRole or role == Qt.EditRole: return str(getattr(conn, column_name)) else: - return QVariant() + return None def headerData(self, section, orientation, role=Qt.DisplayRole): if role != Qt.DisplayRole: diff --git a/pydm/widgets/axis_table_model.py b/pydm/widgets/axis_table_model.py index 9358d553c..4c1d8caf4 100644 --- a/pydm/widgets/axis_table_model.py +++ b/pydm/widgets/axis_table_model.py @@ -1,4 +1,4 @@ -from qtpy.QtCore import QAbstractTableModel, Qt, QModelIndex, QVariant +from qtpy.QtCore import QAbstractTableModel, Qt, QModelIndex from .baseplot import BasePlotAxisItem @@ -42,17 +42,17 @@ def columnCount(self, parent=None): def data(self, index, role=Qt.DisplayRole): if not index.isValid(): - return QVariant() + return None if index.row() >= self.rowCount(): - return QVariant() + return None if index.column() >= self.columnCount(): - return QVariant() + return None column_name = self._column_names[index.column()] axis = self.plot._axes[index.row()] if role == Qt.DisplayRole or role == Qt.EditRole: return self.get_data(column_name, axis) else: - return QVariant() + return None def get_data(self, column_name, axis): if column_name == "Y-Axis Name": @@ -80,7 +80,7 @@ def setData(self, index, value, role=Qt.EditRole): column_name = self._column_names[index.column()] axis = self.plot._axes[index.row()] if role == Qt.EditRole: - if isinstance(value, QVariant): + if value is not None: value = value.toString() if not self.set_data(column_name, axis, value): return False diff --git a/pydm/widgets/baseplot_table_model.py b/pydm/widgets/baseplot_table_model.py index 9a0a4ab57..1b4462c76 100644 --- a/pydm/widgets/baseplot_table_model.py +++ b/pydm/widgets/baseplot_table_model.py @@ -1,4 +1,4 @@ -from qtpy.QtCore import QAbstractTableModel, Qt, QVariant +from qtpy.QtCore import QAbstractTableModel, Qt from qtpy.QtGui import QBrush from .baseplot import BasePlotCurveItem @@ -58,11 +58,11 @@ def columnCount(self, parent=None): def data(self, index, role=Qt.DisplayRole): if not index.isValid(): - return QVariant() + return None if index.row() >= self.rowCount(): - return QVariant() + return None if index.column() >= self.columnCount(): - return QVariant() + return None column_name = self._column_names[index.column()] curve = self.plot._curves[index.row()] if role == Qt.DisplayRole or role == Qt.EditRole: @@ -72,12 +72,12 @@ def data(self, index, role=Qt.DisplayRole): elif role == Qt.BackgroundRole and column_name == "Limit Color": return QBrush(curve.threshold_color) else: - return QVariant() + return None def get_data(self, column_name, curve): if column_name == "Label": if curve.name() is None: - return QVariant() + return None return str(curve.name()) elif column_name == "Y-Axis Name": return curve.y_axis_name @@ -110,7 +110,7 @@ def setData(self, index, value, role=Qt.EditRole): column_name = self._column_names[index.column()] curve = self.plot._curves[index.row()] if role == Qt.EditRole: - if isinstance(value, QVariant): + if value is not None: value = value.toString() if not self.set_data(column_name, curve, value): return False diff --git a/pydm/widgets/enum_combo_box.py b/pydm/widgets/enum_combo_box.py index 9101ff8e9..6269d0eed 100644 --- a/pydm/widgets/enum_combo_box.py +++ b/pydm/widgets/enum_combo_box.py @@ -59,7 +59,7 @@ def addItem(self, text, userData=None): ---------- text : str Title of the item - userData : QVariant + userData : object Arbitrary user data that is stored in the Qt.UserRole """ super(PyDMEnumComboBox, self).addItem(text, userData) diff --git a/pydm/widgets/eventplot_curve_editor.py b/pydm/widgets/eventplot_curve_editor.py index 683ace5c6..c4154b66a 100644 --- a/pydm/widgets/eventplot_curve_editor.py +++ b/pydm/widgets/eventplot_curve_editor.py @@ -1,4 +1,4 @@ -from qtpy.QtCore import QModelIndex, QVariant +from qtpy.QtCore import QModelIndex from .baseplot_table_model import BasePlotCurvesModel from .baseplot_curve_editor import BasePlotCurveEditorDialog, PlotStyleColumnDelegate @@ -17,15 +17,15 @@ def __init__(self, plot, parent=None): def get_data(self, column_name, curve): if column_name == "Channel": if curve.address is None: - return QVariant() + return None return str(curve.address) elif column_name == "Y Index": if curve.y_idx is None: - return QVariant() + return None return curve.y_idx elif column_name == "X Index": if curve.x_idx is None: - return QVariant() + return None return curve.x_idx elif column_name == "Buffer Size": return curve.getBufferSize() diff --git a/pydm/widgets/nt_table.py b/pydm/widgets/nt_table.py index 15df9286d..8ece071f6 100644 --- a/pydm/widgets/nt_table.py +++ b/pydm/widgets/nt_table.py @@ -53,11 +53,11 @@ def columnCount(self, parent=None): def data(self, index, role=QtCore.Qt.DisplayRole): if not index.isValid(): - return QtCore.QVariant() + return None if index.row() >= self.rowCount(): - return QtCore.QVariant() + return None if index.column() >= self.columnCount(): - return QtCore.QVariant() + return None if role == QtCore.Qt.DisplayRole: try: item = str(self._list[index.row()][index.column()]) @@ -65,7 +65,7 @@ def data(self, index, role=QtCore.Qt.DisplayRole): item = "" return item else: - return QtCore.QVariant() + return None def setData(self, index, value, role=QtCore.Qt.EditRole): if self.edit_method is None: diff --git a/pydm/widgets/scatterplot_curve_editor.py b/pydm/widgets/scatterplot_curve_editor.py index 92ea0030a..6fab98a91 100644 --- a/pydm/widgets/scatterplot_curve_editor.py +++ b/pydm/widgets/scatterplot_curve_editor.py @@ -1,4 +1,4 @@ -from qtpy.QtCore import QModelIndex, QVariant +from qtpy.QtCore import QModelIndex from .baseplot_table_model import BasePlotCurvesModel from .baseplot_curve_editor import BasePlotCurveEditorDialog, PlotStyleColumnDelegate, RedrawModeColumnDelegate @@ -17,11 +17,11 @@ def __init__(self, plot, parent=None): def get_data(self, column_name, curve): if column_name == "Y Channel": if curve.y_address is None: - return QVariant() + return None return str(curve.y_address) elif column_name == "X Channel": if curve.x_address is None: - return QVariant() + return None return str(curve.x_address) elif column_name == "Redraw Mode": return curve.redraw_mode diff --git a/pydm/widgets/timeplot_curve_editor.py b/pydm/widgets/timeplot_curve_editor.py index dbe10c39b..e502535da 100644 --- a/pydm/widgets/timeplot_curve_editor.py +++ b/pydm/widgets/timeplot_curve_editor.py @@ -1,4 +1,4 @@ -from qtpy.QtCore import QModelIndex, QObject, QVariant +from qtpy.QtCore import QModelIndex, QObject from typing import Optional from .baseplot_table_model import BasePlotCurvesModel from .baseplot_curve_editor import BasePlotCurveEditorDialog, ColorColumnDelegate, PlotStyleColumnDelegate @@ -13,7 +13,7 @@ def __init__(self, plot, parent=None): def get_data(self, column_name, curve): if column_name == "Channel": if curve.address is None: - return QVariant() + return None return str(curve.address) elif column_name == "Style": return curve.plot_style diff --git a/pydm/widgets/waveformplot_curve_editor.py b/pydm/widgets/waveformplot_curve_editor.py index 6b330a977..5379d84dd 100644 --- a/pydm/widgets/waveformplot_curve_editor.py +++ b/pydm/widgets/waveformplot_curve_editor.py @@ -1,4 +1,4 @@ -from qtpy.QtCore import QModelIndex, QObject, QVariant +from qtpy.QtCore import QModelIndex, QObject from .baseplot_table_model import BasePlotCurvesModel from .baseplot_curve_editor import ( BasePlotCurveEditorDialog, @@ -23,11 +23,11 @@ def __init__(self, plot, parent=None): def get_data(self, column_name, curve): if column_name == "Y Channel": if curve.y_address is None: - return QVariant() + return None return str(curve.y_address) elif column_name == "X Channel": if curve.x_address is None: - return QVariant() + return None return str(curve.x_address) elif column_name == "Style": return curve.plot_style From 3a52da74dbc622e048306e0f577c4ab2a2ceb984 Mon Sep 17 00:00:00 2001 From: nstelter-slac Date: Fri, 13 Dec 2024 00:21:06 -0800 Subject: [PATCH 3/3] MNT: get version for both pyqt and pyside bindings, instead of just pyqt --- pydm/about_pydm/about.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pydm/about_pydm/about.py b/pydm/about_pydm/about.py index 292aff1a8..88549320a 100644 --- a/pydm/about_pydm/about.py +++ b/pydm/about_pydm/about.py @@ -1,5 +1,5 @@ from qtpy.QtWidgets import QWidget, QTableWidgetItem -from qtpy.QtCore import Qt, PYQT_VERSION_STR, qVersion +from qtpy.QtCore import Qt, qVersion from .about_ui import Ui_Form from numpy import __version__ as numpyver from pyqtgraph import __version__ as pyqtgraphver @@ -7,6 +7,16 @@ import sys from os import path import inspect +import qtpy + +# get Qt binding and version +PYQT_VERSION = "" +if "PyQt" in qtpy.API_NAME: + PYQT_VERSION = qtpy.QtCore.PYQT_VERSION_STR +elif "PySide" in qtpy.API_NAME: + PYQT_VERSION = qtpy.QtCore.__version__ +else: + PYQT_VERSION = "Unknown version" class AboutWindow(QWidget): @@ -18,7 +28,7 @@ def __init__(self, parent=None): pyver = ".".join([str(v) for v in sys.version_info[0:3]]) self.ui.modulesVersionLabel.setText( str(self.ui.modulesVersionLabel.text()).format( - pyver=pyver, numpyver=numpyver, pyqtgraphver=pyqtgraphver, pyqtver=PYQT_VERSION_STR, qtver=qVersion() + pyver=pyver, numpyver=numpyver, pyqtgraphver=pyqtgraphver, pyqtver=PYQT_VERSION, qtver=qVersion() ) ) self.populate_external_tools_list()