Skip to content

Commit 96f38cd

Browse files
Pyqt5 to pyqt6 migration (#37) (close #35)
* ref: migration from pyqt5 to pyqt6 * update changelog * uncomment assertion * ref: replace pyqt5 objects with pyqt6 * tests: handle unstable fit --------- Co-authored-by: Paul Müller <[email protected]>
1 parent d4bbded commit 96f38cd

38 files changed

+169
-162
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
0.16.0
2+
- ref: migrate from pyqt5 to pyqt6 (#35)
13
0.15.10
24
- ref: migrate from pkg_resources to importlib.resources (#33)
35
0.15.9

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ h5py
22
matplotlib
33
nanite
44
numpy
5-
pyqt5
5+
PyQt6
66
scipy
77
sphinx
88
sphinxcontrib.bibtex

docs/scrots/make_scrots_extensions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
import pathlib
33
import sys
44

5-
from PyQt5 import QtCore
6-
from PyQt5.QtWidgets import QApplication
5+
from PyQt6 import QtCore
6+
from PyQt6.QtWidgets import QApplication
77
from pyjibe.head.main import PyJibe
88
from pyjibe.head import preferences
99

1010
data_path = pathlib.Path(__file__).resolve().parent / ".." / "data"
1111

1212
app = QApplication(sys.argv)
1313

14-
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.C))
14+
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.Language.C))
1515

1616
mw = PyJibe()
1717
mw.settings.setValue("check for updates", 0)

docs/scrots/make_scrots_qg_import_ts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import sys
44
import time
55

6-
from PyQt5 import QtCore
7-
from PyQt5.QtWidgets import QApplication
6+
from PyQt6 import QtCore
7+
from PyQt6.QtWidgets import QApplication
88
from pyjibe.head.main import PyJibe
99

1010
jpkfile = pathlib.Path("PAAm_Compliant_ROI1_force-save-"
@@ -20,7 +20,7 @@ def cleanup_autosave(jpkfile):
2020

2121

2222
app = QApplication(sys.argv)
23-
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.C))
23+
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.Language.C))
2424
mw = PyJibe()
2525
mw.settings.setValue("check for updates", 0)
2626
mw.settings.setValue("advanced/developer mode", 0)

docs/scrots/make_scrots_ui_fd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import pathlib
33
import sys
44

5-
from PyQt5 import QtCore
6-
from PyQt5.QtWidgets import QApplication
5+
from PyQt6 import QtCore
6+
from PyQt6.QtWidgets import QApplication
77
from pyjibe.head.main import PyJibe
88

99
jpkfiles = [pathlib.Path("map-data-2015.05.21-18.16.49.170.jpk-force-map")]
@@ -18,7 +18,7 @@ def cleanup_autosave(jpkfile):
1818

1919

2020
app = QApplication(sys.argv)
21-
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.C))
21+
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.Language.C))
2222
mw = PyJibe()
2323
mw.settings.setValue("check for updates", 0)
2424
mw.settings.setValue("advanced/developer mode", "0")

docs/tutorials/t01_make_figures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
import numpy as np
99
import pandas
1010
import seaborn as sns
11-
from PyQt5 import QtCore
12-
from PyQt5.QtWidgets import QApplication
11+
from PyQt6 import QtCore
12+
from PyQt6.QtWidgets import QApplication
1313
from pyjibe.head.main import PyJibe
1414

1515

1616
datapath = pathlib.Path("figshare_AFM-PAAm-gels_11637675.v3")
1717

1818
app = QApplication(sys.argv)
19-
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.C))
19+
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.Language.C))
2020
mw = PyJibe()
2121

2222

@@ -50,7 +50,7 @@
5050
war.tab_fit.cb_model.setCurrentIndex(idm)
5151
war.tab_fit.sp_range_2.setValue(2)
5252
war.tab_fit.table_parameters_initial.item(1, 1).setText("5")
53-
war.tab_fit.cb_weight_cp.setCheckState(QtCore.Qt.Unchecked)
53+
war.tab_fit.cb_weight_cp.setCheckState(QtCore.Qt.CheckState.Unchecked)
5454
war.btn_fitall.clicked.emit()
5555

5656
QApplication.processEvents()

pyjibe/__main__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ def main(splash=True):
22
import importlib.resources
33
import sys
44

5-
from PyQt5.QtWidgets import QApplication
6-
from PyQt5.QtCore import QEventLoop
5+
from PyQt6.QtWidgets import QApplication
6+
from PyQt6.QtCore import QEventLoop
77

88
app = QApplication(sys.argv)
99

1010
if splash:
11-
from PyQt5.QtWidgets import QSplashScreen
12-
from PyQt5.QtGui import QPixmap
11+
from PyQt6.QtWidgets import QSplashScreen
12+
from PyQt6.QtGui import QPixmap
1313
ref = importlib.resources.files("pyjibe.img") / "splash.png"
1414
with importlib.resources.as_file(ref) as splash_path:
1515
splash_pix = QPixmap(str(splash_path))
1616
splash = QSplashScreen(splash_pix)
1717
splash.setMask(splash_pix.mask())
1818
splash.show()
1919
# make sure Qt really displays the splash screen
20-
app.processEvents(QEventLoop.AllEvents, 300)
20+
app.processEvents(QEventLoop.ProcessEventsFlag.AllEvents, 300)
2121

22-
from PyQt5 import QtCore, QtGui
22+
from PyQt6 import QtCore, QtGui
2323
from .head import PyJibe
2424

2525
# Set Application Icon
@@ -28,14 +28,14 @@ def main(splash=True):
2828
app.setWindowIcon(QtGui.QIcon(str(icon_path)))
2929

3030
# Use dots as decimal separators
31-
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.C))
31+
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.Language.C))
3232

3333
window = PyJibe()
3434

3535
if splash:
3636
splash.finish(window)
3737

38-
sys.exit(app.exec_())
38+
sys.exit(app.exec())
3939

4040

4141
if __name__ == "__main__":

pyjibe/fd/dlg_export_vals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import importlib.resources
22

3-
from PyQt5 import uic, QtWidgets
3+
from PyQt6 import uic, QtWidgets
44

55
from . import export
66

pyjibe/fd/export.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from afmformats import meta
88
import nanite.model as nmodel
9-
from PyQt5 import QtCore
9+
from PyQt6 import QtCore
1010

1111
from .. import units
1212

@@ -34,7 +34,6 @@ def save_tsv_metadata_results(filename, fdist_list, which=EXPORT_CHOICES):
3434
raise ValueError("Found invalid export choices.")
3535

3636
settings = QtCore.QSettings()
37-
settings.setIniCodec("utf-8")
3837
dev_mode = bool(int(settings.value("advanced/developer mode", "0")))
3938

4039
size = len(fdist_list)

pyjibe/fd/main.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import nanite
1010
import nanite.fit as nfit
1111
import numpy as np
12-
from PyQt5 import uic, QtCore, QtGui, QtWidgets
12+
from PyQt6 import uic, QtCore, QtGui, QtWidgets
1313

1414
from .. import colormap
1515
from ..head.custom_widgets import show_wait_cursor
@@ -38,10 +38,9 @@ def __init__(self, *args, **kwargs):
3838
uic.loadUi(path_ui, self)
3939

4040
self.settings = QtCore.QSettings()
41-
self.settings.setIniCodec("utf-8")
4241
if not self.settings.value("force-distance/rate ts path", ""):
4342
dataloc = pathlib.Path(QtCore.QStandardPaths.writableLocation(
44-
QtCore.QStandardPaths.AppDataLocation))
43+
QtCore.QStandardPaths.StandardLocation.AppDataLocation))
4544
ts_import_path = dataloc / "force-distance_rate-ts-user"
4645
self.settings.setValue("force-distance/rate ts path",
4746
str(ts_import_path))
@@ -175,7 +174,7 @@ def selected_curves(self):
175174
for ar in self.data_set:
176175
idx = self.data_set.index(ar)
177176
item = self.list_curves.topLevelItem(idx)
178-
if item.checkState(3) == QtCore.Qt.Checked:
177+
if item.checkState(3) == QtCore.Qt.CheckState.Checked:
179178
curves.append(ar)
180179
return curves
181180

@@ -213,7 +212,7 @@ def callback(partial):
213212
"""
214213
bar.setValue(int((ii+partial)*mult))
215214
QtCore.QCoreApplication.instance().processEvents(
216-
QtCore.QEventLoop.AllEvents, 300)
215+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 300)
217216
if bar.wasCanceled():
218217
# Raise a custom `AbortProgress` error, such that
219218
# we can exit the parent for-loop.
@@ -237,7 +236,7 @@ def callback(partial):
237236

238237
def autosave(self, fdist):
239238
"""Performs autosaving for all files"""
240-
if (self.cb_autosave.checkState() == QtCore.Qt.Checked
239+
if (self.cb_autosave.checkState() == QtCore.Qt.CheckState.Checked
241240
and fdist.fit_properties.get("success", False)):
242241
# Determine the directory of the current curve
243242
adir = os.path.dirname(fdist.path)
@@ -256,7 +255,7 @@ def autosave(self, fdist):
256255
# fdist was fitted with same model
257256
ar.fit_properties["model_key"] == model_key and
258257
# user selected curve for export ("use")
259-
it.checkState(3) == QtCore.Qt.Checked
258+
it.checkState(3) == QtCore.Qt.CheckState.Checked
260259
):
261260
exp_curv.append(ar)
262261
# The file to export
@@ -271,10 +270,11 @@ def autosave(self, fdist):
271270
if oride == -1:
272271
# Ask user what to do
273272
dlgwin = QtWidgets.QDialog(self)
274-
dlgwin.setWindowModality(QtCore.Qt.ApplicationModal)
273+
dlgwin.setWindowModality(
274+
QtCore.Qt.WindowModality.ApplicationModal)
275275
dlgui = DlgAutosave()
276276
dlgui.setupUi(dlgwin)
277-
if dlgwin.exec_():
277+
if dlgwin.exec():
278278
if dlgui.btn_nothing.isChecked():
279279
oride = 0
280280
elif dlgui.btn_override.isChecked():
@@ -310,7 +310,8 @@ def curve_list_setup(self):
310310
"""Add items to the tree widget"""
311311
header = self.list_curves.header()
312312
header.setStretchLastSection(False)
313-
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
313+
header.setSectionResizeMode(0,
314+
QtWidgets.QHeaderView.ResizeMode.Stretch)
314315
self.list_curves.setColumnWidth(1, 70)
315316
self.list_curves.setColumnWidth(2, 70)
316317
self.list_curves.setColumnWidth(3, 40)
@@ -320,7 +321,7 @@ def curve_list_setup(self):
320321
str(ar.enum),
321322
"{:.1f}".format(-1)])
322323
self.list_curves.addTopLevelItem(it)
323-
it.setCheckState(3, QtCore.Qt.Checked)
324+
it.setCheckState(3, QtCore.Qt.CheckState.Checked)
324325
# Connect signals:
325326
# Selection of curves
326327
self.list_curves.itemSelectionChanged.connect(self.on_curve_list)
@@ -462,7 +463,7 @@ def on_export_edelta(self):
462463
else:
463464
res += [d, e]
464465
QtCore.QCoreApplication.instance().processEvents(
465-
QtCore.QEventLoop.AllEvents, 300)
466+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 300)
466467
bar.setValue(ii+1)
467468

468469
# export curves with numpy
@@ -496,7 +497,7 @@ def on_fit_all(self):
496497
errored = []
497498
for ii, fdist in enumerate(self.data_set):
498499
QtCore.QCoreApplication.instance().processEvents(
499-
QtCore.QEventLoop.AllEvents, 300)
500+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 300)
500501
if bar.wasCanceled():
501502
break
502503
try:
@@ -562,9 +563,9 @@ def on_rating_threshold(self):
562563
it = self.list_curves.topLevelItem(ii)
563564
if not np.isnan(rating):
564565
if rating >= thresh:
565-
it.setCheckState(3, QtCore.Qt.Checked)
566+
it.setCheckState(3, QtCore.Qt.CheckState.Checked)
566567
else:
567-
it.setCheckState(3, QtCore.Qt.Unchecked)
568+
it.setCheckState(3, QtCore.Qt.CheckState.Unchecked)
568569
self.list_curves.blockSignals(False)
569570
# TODO:
570571
# - make this more efficient. There is a lot written to disk here.
@@ -614,8 +615,8 @@ def on_user_rate(self):
614615
caption="Please select a rating container",
615616
directory="",
616617
filter="Rating containers (*.h5)",
617-
options=QtWidgets.QFileDialog.DontConfirmOverwrite
618-
| QtWidgets.QFileDialog.DontUseNativeDialog)
618+
options=QtWidgets.QFileDialog.Option.DontConfirmOverwrite
619+
| QtWidgets.QFileDialog.Option.DontUseNativeDialog)
619620

620621
path = cont[0]
621622
if path:

0 commit comments

Comments
 (0)