Skip to content

Commit

Permalink
Pyqt5 to pyqt6 migration (#37) (close #35)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
RaghavaAlajangi and paulmueller authored Dec 16, 2024
1 parent d4bbded commit 96f38cd
Show file tree
Hide file tree
Showing 38 changed files with 169 additions and 162 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.16.0
- ref: migrate from pyqt5 to pyqt6 (#35)
0.15.10
- ref: migrate from pkg_resources to importlib.resources (#33)
0.15.9
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ h5py
matplotlib
nanite
numpy
pyqt5
PyQt6
scipy
sphinx
sphinxcontrib.bibtex
Expand Down
6 changes: 3 additions & 3 deletions docs/scrots/make_scrots_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
import pathlib
import sys

from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication
from PyQt6 import QtCore
from PyQt6.QtWidgets import QApplication
from pyjibe.head.main import PyJibe
from pyjibe.head import preferences

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

app = QApplication(sys.argv)

QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.C))
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.Language.C))

mw = PyJibe()
mw.settings.setValue("check for updates", 0)
Expand Down
6 changes: 3 additions & 3 deletions docs/scrots/make_scrots_qg_import_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import sys
import time

from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication
from PyQt6 import QtCore
from PyQt6.QtWidgets import QApplication
from pyjibe.head.main import PyJibe

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


app = QApplication(sys.argv)
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.C))
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.Language.C))
mw = PyJibe()
mw.settings.setValue("check for updates", 0)
mw.settings.setValue("advanced/developer mode", 0)
Expand Down
6 changes: 3 additions & 3 deletions docs/scrots/make_scrots_ui_fd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pathlib
import sys

from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication
from PyQt6 import QtCore
from PyQt6.QtWidgets import QApplication
from pyjibe.head.main import PyJibe

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


app = QApplication(sys.argv)
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.C))
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.Language.C))
mw = PyJibe()
mw.settings.setValue("check for updates", 0)
mw.settings.setValue("advanced/developer mode", "0")
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorials/t01_make_figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import numpy as np
import pandas
import seaborn as sns
from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication
from PyQt6 import QtCore
from PyQt6.QtWidgets import QApplication
from pyjibe.head.main import PyJibe


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

app = QApplication(sys.argv)
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.C))
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.Language.C))
mw = PyJibe()


Expand Down Expand Up @@ -50,7 +50,7 @@
war.tab_fit.cb_model.setCurrentIndex(idm)
war.tab_fit.sp_range_2.setValue(2)
war.tab_fit.table_parameters_initial.item(1, 1).setText("5")
war.tab_fit.cb_weight_cp.setCheckState(QtCore.Qt.Unchecked)
war.tab_fit.cb_weight_cp.setCheckState(QtCore.Qt.CheckState.Unchecked)
war.btn_fitall.clicked.emit()

QApplication.processEvents()
Expand Down
16 changes: 8 additions & 8 deletions pyjibe/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ def main(splash=True):
import importlib.resources
import sys

from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QEventLoop
from PyQt6.QtWidgets import QApplication
from PyQt6.QtCore import QEventLoop

app = QApplication(sys.argv)

if splash:
from PyQt5.QtWidgets import QSplashScreen
from PyQt5.QtGui import QPixmap
from PyQt6.QtWidgets import QSplashScreen
from PyQt6.QtGui import QPixmap
ref = importlib.resources.files("pyjibe.img") / "splash.png"
with importlib.resources.as_file(ref) as splash_path:
splash_pix = QPixmap(str(splash_path))
splash = QSplashScreen(splash_pix)
splash.setMask(splash_pix.mask())
splash.show()
# make sure Qt really displays the splash screen
app.processEvents(QEventLoop.AllEvents, 300)
app.processEvents(QEventLoop.ProcessEventsFlag.AllEvents, 300)

from PyQt5 import QtCore, QtGui
from PyQt6 import QtCore, QtGui
from .head import PyJibe

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

# Use dots as decimal separators
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.C))
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.Language.C))

window = PyJibe()

if splash:
splash.finish(window)

sys.exit(app.exec_())
sys.exit(app.exec())


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion pyjibe/fd/dlg_export_vals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import importlib.resources

from PyQt5 import uic, QtWidgets
from PyQt6 import uic, QtWidgets

from . import export

Expand Down
3 changes: 1 addition & 2 deletions pyjibe/fd/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from afmformats import meta
import nanite.model as nmodel
from PyQt5 import QtCore
from PyQt6 import QtCore

from .. import units

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

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

size = len(fdist_list)
Expand Down
35 changes: 18 additions & 17 deletions pyjibe/fd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import nanite
import nanite.fit as nfit
import numpy as np
from PyQt5 import uic, QtCore, QtGui, QtWidgets
from PyQt6 import uic, QtCore, QtGui, QtWidgets

from .. import colormap
from ..head.custom_widgets import show_wait_cursor
Expand Down Expand Up @@ -38,10 +38,9 @@ def __init__(self, *args, **kwargs):
uic.loadUi(path_ui, self)

self.settings = QtCore.QSettings()
self.settings.setIniCodec("utf-8")
if not self.settings.value("force-distance/rate ts path", ""):
dataloc = pathlib.Path(QtCore.QStandardPaths.writableLocation(
QtCore.QStandardPaths.AppDataLocation))
QtCore.QStandardPaths.StandardLocation.AppDataLocation))
ts_import_path = dataloc / "force-distance_rate-ts-user"
self.settings.setValue("force-distance/rate ts path",
str(ts_import_path))
Expand Down Expand Up @@ -175,7 +174,7 @@ def selected_curves(self):
for ar in self.data_set:
idx = self.data_set.index(ar)
item = self.list_curves.topLevelItem(idx)
if item.checkState(3) == QtCore.Qt.Checked:
if item.checkState(3) == QtCore.Qt.CheckState.Checked:
curves.append(ar)
return curves

Expand Down Expand Up @@ -213,7 +212,7 @@ def callback(partial):
"""
bar.setValue(int((ii+partial)*mult))
QtCore.QCoreApplication.instance().processEvents(
QtCore.QEventLoop.AllEvents, 300)
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 300)
if bar.wasCanceled():
# Raise a custom `AbortProgress` error, such that
# we can exit the parent for-loop.
Expand All @@ -237,7 +236,7 @@ def callback(partial):

def autosave(self, fdist):
"""Performs autosaving for all files"""
if (self.cb_autosave.checkState() == QtCore.Qt.Checked
if (self.cb_autosave.checkState() == QtCore.Qt.CheckState.Checked
and fdist.fit_properties.get("success", False)):
# Determine the directory of the current curve
adir = os.path.dirname(fdist.path)
Expand All @@ -256,7 +255,7 @@ def autosave(self, fdist):
# fdist was fitted with same model
ar.fit_properties["model_key"] == model_key and
# user selected curve for export ("use")
it.checkState(3) == QtCore.Qt.Checked
it.checkState(3) == QtCore.Qt.CheckState.Checked
):
exp_curv.append(ar)
# The file to export
Expand All @@ -271,10 +270,11 @@ def autosave(self, fdist):
if oride == -1:
# Ask user what to do
dlgwin = QtWidgets.QDialog(self)
dlgwin.setWindowModality(QtCore.Qt.ApplicationModal)
dlgwin.setWindowModality(
QtCore.Qt.WindowModality.ApplicationModal)
dlgui = DlgAutosave()
dlgui.setupUi(dlgwin)
if dlgwin.exec_():
if dlgwin.exec():
if dlgui.btn_nothing.isChecked():
oride = 0
elif dlgui.btn_override.isChecked():
Expand Down Expand Up @@ -310,7 +310,8 @@ def curve_list_setup(self):
"""Add items to the tree widget"""
header = self.list_curves.header()
header.setStretchLastSection(False)
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
header.setSectionResizeMode(0,
QtWidgets.QHeaderView.ResizeMode.Stretch)
self.list_curves.setColumnWidth(1, 70)
self.list_curves.setColumnWidth(2, 70)
self.list_curves.setColumnWidth(3, 40)
Expand All @@ -320,7 +321,7 @@ def curve_list_setup(self):
str(ar.enum),
"{:.1f}".format(-1)])
self.list_curves.addTopLevelItem(it)
it.setCheckState(3, QtCore.Qt.Checked)
it.setCheckState(3, QtCore.Qt.CheckState.Checked)
# Connect signals:
# Selection of curves
self.list_curves.itemSelectionChanged.connect(self.on_curve_list)
Expand Down Expand Up @@ -462,7 +463,7 @@ def on_export_edelta(self):
else:
res += [d, e]
QtCore.QCoreApplication.instance().processEvents(
QtCore.QEventLoop.AllEvents, 300)
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 300)
bar.setValue(ii+1)

# export curves with numpy
Expand Down Expand Up @@ -496,7 +497,7 @@ def on_fit_all(self):
errored = []
for ii, fdist in enumerate(self.data_set):
QtCore.QCoreApplication.instance().processEvents(
QtCore.QEventLoop.AllEvents, 300)
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 300)
if bar.wasCanceled():
break
try:
Expand Down Expand Up @@ -562,9 +563,9 @@ def on_rating_threshold(self):
it = self.list_curves.topLevelItem(ii)
if not np.isnan(rating):
if rating >= thresh:
it.setCheckState(3, QtCore.Qt.Checked)
it.setCheckState(3, QtCore.Qt.CheckState.Checked)
else:
it.setCheckState(3, QtCore.Qt.Unchecked)
it.setCheckState(3, QtCore.Qt.CheckState.Unchecked)
self.list_curves.blockSignals(False)
# TODO:
# - make this more efficient. There is a lot written to disk here.
Expand Down Expand Up @@ -614,8 +615,8 @@ def on_user_rate(self):
caption="Please select a rating container",
directory="",
filter="Rating containers (*.h5)",
options=QtWidgets.QFileDialog.DontConfirmOverwrite
| QtWidgets.QFileDialog.DontUseNativeDialog)
options=QtWidgets.QFileDialog.Option.DontConfirmOverwrite
| QtWidgets.QFileDialog.Option.DontUseNativeDialog)

path = cont[0]
if path:
Expand Down
9 changes: 5 additions & 4 deletions pyjibe/fd/mpl_edelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import nanite.fit as nfit
import numpy as np
from PyQt5.QtWidgets import QApplication
from PyQt5 import QtCore
from PyQt6.QtWidgets import QApplication
from PyQt6 import QtCore


from .. import units
Expand Down Expand Up @@ -76,7 +76,7 @@ def update(self, fdist, delta_opt=None):
self._update_in_progress_active = fdist
if fdist in self._update_in_progress_locks:
QApplication.instance().processEvents(
QtCore.QEventLoop.AllEvents, 300)
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 300)
else:
self._update_in_progress_locks[fdist] = True
def cbfdist(e, d): return self.update_plot(e, d, fdist=fdist)
Expand Down Expand Up @@ -123,4 +123,5 @@ def update_plot(self, emoduli, indentations,
self.plot_data[:, 0] = indentations
self.plot_data[:, 1] = emoduli

QApplication.processEvents(QtCore.QEventLoop.AllEvents, 300)
QApplication.processEvents(
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 300)
2 changes: 1 addition & 1 deletion pyjibe/fd/mpl_qmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import matplotlib.patches as mpatches
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
from PyQt5 import QtCore
from PyQt6 import QtCore


from ..head import custom_widgets
Expand Down
2 changes: 1 addition & 1 deletion pyjibe/fd/rating_iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import importlib.resources

from nanite.rate import io as nio
from PyQt5 import uic, QtCore, QtWidgets
from PyQt6 import uic, QtCore, QtWidgets


# load QWidget from ui file
Expand Down
2 changes: 1 addition & 1 deletion pyjibe/fd/tab_edelta.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import importlib.resources

import numpy as np
from PyQt5 import uic, QtCore, QtWidgets
from PyQt6 import uic, QtCore, QtWidgets

from .. import units
from .mpl_edelta import MPLEDelta
Expand Down
Loading

0 comments on commit 96f38cd

Please sign in to comment.