Skip to content

Commit 5306ac3

Browse files
committed
MAINT: added partial support for Qt6 and dropped support for Qt4
(closes #212 - but see the followup at #235 for remaining issues to support Qt6)
1 parent bfcceb7 commit 5306ac3

File tree

9 files changed

+52
-25
lines changed

9 files changed

+52
-25
lines changed

condarecipe/larray-editor/meta.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ requirements:
2424
# requires larray >= 0.32 because of the LArray -> Array rename
2525
- larray >=0.32
2626
- matplotlib
27-
- pyqt >=4.6 # for API v2
28-
- qtpy
27+
- pyqt >=5
28+
- qtpy >=2 # for Qt6 support
2929
# jedi >=0.18 to workaround incompatibility between jedi <0.18 and parso >=0.8 (see #220)
3030
- jedi >=0.18
3131

environment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ channels:
55
dependencies:
66
- pip
77
- larray
8-
- pyqt
9-
- qtpy
8+
- pyqt >=5
9+
- qtpy >=2
1010
- matplotlib
1111
- pytables
1212
- pytest>=3.5

larray_editor/arraymodel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def flags(self, index):
372372
flags = QAbstractTableModel.flags(self, index)
373373
if not self.readonly:
374374
flags |= Qt.ItemIsEditable
375-
return Qt.ItemFlags(flags)
375+
return flags
376376

377377
def data(self, index, role=Qt.DisplayRole):
378378
"""Cell content"""

larray_editor/arraywidget.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ def keyPressEvent(self, event):
373373
# did before because that only seems to work for shortcut
374374
# defined using QKeySequence.StandardKey, which is not the case for
375375
# Ctrl + E
376+
# FIXME: this is no longer supported by PyQt6
377+
# TypeError: unsupported operand type(s) for |: 'KeyboardModifier' and 'int'
376378
keyseq = QKeySequence(event.modifiers() | event.key())
377379
if keyseq == QKeySequence.Copy:
378380
self.copy()

larray_editor/combo.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def __next__(self):
1616
raise StopIteration
1717
next = __next__
1818

19+
def __iter__(self):
20+
return self
21+
1922

2023
class SequenceStandardItemModel(QtGui.QStandardItemModel):
2124
"""
@@ -72,7 +75,11 @@ def __init__(self, parent=None):
7275
self._list_view.setModel(model)
7376
self._model = model
7477
self.addItem("(select all)")
75-
model[0].setTristate(True)
78+
try:
79+
model[0].setTristate(True)
80+
except AttributeError:
81+
# this is the new name for qt6+
82+
model[0].setUserTristate(True)
7683

7784
action = QtWidgets.QWidgetAction(self)
7885
action.setDefaultWidget(self._list_view)

larray_editor/commands.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import logging
22

3-
from qtpy.QtWidgets import QUndoCommand
3+
try:
4+
from qtpy.QtWidgets import QUndoCommand
5+
except ImportError:
6+
# PySide6 provides QUndoCommand in QtGui
7+
# qtpy has been fixed (see https://github.com/spyder-ide/qtpy/pull/366) but the version available via conda as of
8+
# 20/09/2022 (2.2) does not include the fix yet
9+
from qtpy.QtGui import QUndoCommand
10+
411
from larray_editor.utils import logger
512

613

larray_editor/editor.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,24 @@
2828
import larray as la
2929

3030
from larray_editor.traceback_tools import StackSummary
31-
from larray_editor.utils import (PYQT5, _, create_action, show_figure, ima, commonpath, dependencies,
31+
from larray_editor.utils import (_, create_action, show_figure, ima, commonpath, dependencies,
3232
get_versions, get_documentation_url, urls, RecentlyUsedList)
3333
from larray_editor.arraywidget import ArrayEditorWidget
3434
from larray_editor.commands import EditSessionArrayCommand, EditCurrentArrayCommand
3535

3636
from qtpy.QtCore import Qt, QUrl, QSettings
3737
from qtpy.QtGui import QDesktopServices, QKeySequence
3838
from qtpy.QtWidgets import (QMainWindow, QWidget, QListWidget, QListWidgetItem, QSplitter, QFileDialog, QPushButton,
39-
QDialogButtonBox, QShortcut, QVBoxLayout, QGridLayout, QLineEdit, QUndoStack,
39+
QDialogButtonBox, QShortcut, QVBoxLayout, QGridLayout, QLineEdit,
4040
QCheckBox, QComboBox, QMessageBox, QDialog, QInputDialog, QLabel, QGroupBox, QRadioButton)
4141

42+
try:
43+
from qtpy.QtWidgets import QUndoStack
44+
except ImportError:
45+
# PySide6 provides QUndoStack in QtGui
46+
# unsure qtpy has been fixed yet (see https://github.com/spyder-ide/qtpy/pull/366 for the fix for QUndoCommand)
47+
from qtpy.QtGui import QUndoStack
48+
4249
try:
4350
from qtconsole.rich_jupyter_widget import RichJupyterWidget
4451
from qtconsole.inprocess import QtInProcessKernelManager
@@ -230,13 +237,10 @@ def _report_issue(*args, **kwargs):
230237
issue_template = issue_template.format(**versions)
231238

232239
url = QUrl(urls[f'new_issue_{package}'])
233-
if PYQT5:
234-
from qtpy.QtCore import QUrlQuery
235-
query = QUrlQuery()
236-
query.addQueryItem("body", quote(issue_template))
237-
url.setQuery(query)
238-
else:
239-
url.addEncodedQueryItem("body", quote(issue_template))
240+
from qtpy.QtCore import QUrlQuery
241+
query = QUrlQuery()
242+
query.addQueryItem("body", quote(issue_template))
243+
url.setQuery(query)
240244
QDesktopServices.openUrl(url)
241245

242246
return _report_issue
@@ -1049,8 +1053,8 @@ def open_data(self):
10491053
if self._ask_to_save_if_unsaved_modifications():
10501054
filter = "All (*.xls *xlsx *.h5 *.csv);;Excel Files (*.xls *xlsx);;HDF Files (*.h5);;CSV Files (*.csv)"
10511055
res = QFileDialog.getOpenFileNames(self, filter=filter)
1052-
# Qt5 returns a tuple (filepaths, '') instead of a string
1053-
filepaths = res[0] if PYQT5 else res
1056+
# Qt5+ returns a tuple (filepaths, '') instead of a string
1057+
filepaths = res[0]
10541058
if len(filepaths) >= 1:
10551059
if all(['.csv' in filepath for filepath in filepaths]):
10561060
# this means that even a single .csv file will be passed as a list (so that we can add arrays

larray_editor/tests/test_api_larray.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from larray_editor.api import *
99
from larray_editor.utils import logger
1010

11+
import qtpy
12+
13+
print(f"Using {qtpy.API_NAME} as Qt API")
14+
1115
logger.setLevel(logging.DEBUG)
1216

1317
lipro = la.Axis('lipro=P01..P15')

larray_editor/utils.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@
1313
except TypeError:
1414
pass
1515

16-
from qtpy import PYQT5
1716
from qtpy.QtCore import Qt, QSettings
1817
from qtpy.QtGui import QIcon, QColor, QFont, QKeySequence, QLinearGradient
1918
from qtpy.QtWidgets import QAction, QDialog, QVBoxLayout
2019

21-
if PYQT5:
22-
from matplotlib.backends.backend_qt5agg import FigureCanvas
20+
try:
21+
# try the un-versioned backend first (for matplotlib 3.5+)
22+
23+
# this is equivalent to "from matplotlib.backends.backend_qtagg import FigureCanvas" but is easier to statically
24+
# analyze for PyCharm et al.
25+
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas
26+
from matplotlib.backends.backend_qtagg import NavigationToolbar2QT as NavigationToolbar
27+
except ImportError:
28+
# fall back to explicit qt5 backend (for matplotlib < 3.5)
29+
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
2330
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
24-
else:
25-
from matplotlib.backends.backend_qt4agg import FigureCanvas
26-
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
27-
2831

2932
logger = logging.getLogger("editor")
3033

0 commit comments

Comments
 (0)