From 62ab003ca005bdf6d52c5fd0e4c4e7b463311c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Thu, 10 Jun 2021 17:56:47 +0200 Subject: [PATCH] ref: properly decorate pyqtSlots --- CHANGELOG | 1 + pyjibe/fd/main.py | 11 +++++++++++ pyjibe/fd/mpl_qmap.py | 4 +++- pyjibe/fd/rating_iface.py | 4 +++- pyjibe/fd/tab_edelta.py | 4 +++- pyjibe/fd/tab_fit.py | 5 +++++ pyjibe/fd/tab_preprocess.py | 3 ++- pyjibe/fd/tab_qmap.py | 6 +++++- 8 files changed, 33 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3205e85..3f520c7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - ref: make sure there are no duplicate files when loading data (possibly fixes #12) - ref: cleanup - call overloaded processEvents + - ref: properly decorate pyqtSlots - tests: add helper function for setting up datasets 0.8.7 - fix: add workaround for macOS where the non-native PyQt5 dialogs diff --git a/pyjibe/fd/main.py b/pyjibe/fd/main.py index fb219d0..0f3056f 100644 --- a/pyjibe/fd/main.py +++ b/pyjibe/fd/main.py @@ -299,6 +299,7 @@ def info_update(self, fdist=None): fdist = self.current_curve self.tab_info.update_info(fdist) + @QtCore.pyqtSlot() def on_cb_rating_scheme(self): """Switch rating scheme or import a new one""" scheme_id = self.cb_rating_scheme.currentIndex() @@ -318,6 +319,7 @@ def on_cb_rating_scheme(self): else: self.on_params_init() + @QtCore.pyqtSlot() def on_curve_list(self): """Called when a new curve is selected""" fdist = self.current_curve @@ -341,6 +343,7 @@ def on_curve_list(self): # Autosave self.autosave(fdist) + @QtCore.pyqtSlot(QtCore.QModelIndex) def on_curve_list_item_changed(self, item): """An item in the curve list was changed @@ -355,6 +358,7 @@ def on_curve_list_item_changed(self, item): self.tab_qmap.mpl_qmap_update() self.autosave(fdist) + @QtCore.pyqtSlot() def on_export_edelta(self): """Saves all edelta curves""" fname, _e = QtWidgets.QFileDialog.getSaveFileName( @@ -402,6 +406,7 @@ def on_export_edelta(self): with io.open(fname, "ab") as fd: np.savetxt(fd, np.array(res)) + @QtCore.pyqtSlot() def on_export_fit_results(self): """Save metadata and fit results""" fdist_list = [fdist for fdist in self.selected_curves] @@ -444,6 +449,7 @@ def on_fit_all(self): msg, ) + @QtCore.pyqtSlot() def on_model(self): """Called when the fitting model is changed""" # The difference to "on_params_init" is that we @@ -457,10 +463,12 @@ def on_model(self): self.curve_list_update() self.tab_qmap.mpl_qmap_update() + @QtCore.pyqtSlot() def on_mpl_curve_update(self): fdist = self.current_curve self.widget_fdist.mpl_curve_update(fdist) + @QtCore.pyqtSlot() def on_params_init(self): """Called when the initial parameters are changed""" fdist = self.current_curve @@ -472,6 +480,7 @@ def on_params_init(self): self.curve_list_update(item=idx) self.tab_qmap.mpl_qmap_update() + @QtCore.pyqtSlot() def on_rating_threshold(self): """(De)select curves according to threshold rating""" thresh = self.sp_rating_thresh.value() @@ -491,6 +500,7 @@ def on_rating_threshold(self): for fdist in self.data_set: self.autosave(fdist) + @QtCore.pyqtSlot(int) def on_tab_changed(self, index): """Called when the tab on the right hand is changed""" if hasattr(self, "user_tab_selected"): @@ -513,6 +523,7 @@ def on_tab_changed(self, index): self.user_tab_selected = curtab + @QtCore.pyqtSlot() def on_user_rate(self): """Start the curve rater""" cont = QtWidgets.QFileDialog.getSaveFileName( diff --git a/pyjibe/fd/mpl_qmap.py b/pyjibe/fd/mpl_qmap.py index 2fd352f..ee84a0f 100644 --- a/pyjibe/fd/mpl_qmap.py +++ b/pyjibe/fd/mpl_qmap.py @@ -9,6 +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 ..head import custom_widgets @@ -21,7 +22,7 @@ } -class MPLQMap(object): +class MPLQMap: def __init__(self): """Matplotlib plot for 2D quantitative map data""" # Do not use tight_layout (adjust subplot parameters instead) @@ -88,6 +89,7 @@ def connect_curve_selection_event(self, callback): """ self.click_callback = callback + @QtCore.pyqtSlot() def on_click(self, event): if (self.click_callback is not None and self.qmap_coords is not None and diff --git a/pyjibe/fd/rating_iface.py b/pyjibe/fd/rating_iface.py index 21211ed..6b71009 100644 --- a/pyjibe/fd/rating_iface.py +++ b/pyjibe/fd/rating_iface.py @@ -2,7 +2,7 @@ import pkg_resources from nanite.rate import io as nio -from PyQt5 import uic, QtWidgets +from PyQt5 import uic, QtCore, QtWidgets # load QWidget from ui file @@ -54,6 +54,7 @@ def setup_signals(self, enable=True): else: signal.disconnect(slot) + @QtCore.pyqtSlot() def on_change_index(self): index = self.curve_index.value()-1 self.setup_signals(False) @@ -67,6 +68,7 @@ def on_change_index(self): self.sp_rating.selectAll() self.sp_rating.setFocus() + @QtCore.pyqtSlot() def on_change_values(self): index = self.curve_index.value()-1 fdist = self.fdui.data_set[index] diff --git a/pyjibe/fd/tab_edelta.py b/pyjibe/fd/tab_edelta.py index f5cb312..d6bfefd 100644 --- a/pyjibe/fd/tab_edelta.py +++ b/pyjibe/fd/tab_edelta.py @@ -1,7 +1,7 @@ import pkg_resources import numpy as np -from PyQt5 import uic, QtWidgets +from PyQt5 import uic, QtCore, QtWidgets from .. import units from .mpl_edelta import MPLEDelta @@ -65,6 +65,7 @@ def mpl_edelta_update(self): self.fd.tab_fit.fit_approach_retract(fdist) self.mpl_edelta.update(fdist, delta_opt) + @QtCore.pyqtSlot() def on_delta_guess(self): """Guess the optimal indentation depth for the current curve""" fdist = self.current_curve @@ -72,6 +73,7 @@ def on_delta_guess(self): value /= units.scales["µ"] self.delta_spin.setValue(value) + @QtCore.pyqtSlot() def on_delta_change_spin(self, value): """Indentation depth spin control value changed""" # Update all controls diff --git a/pyjibe/fd/tab_fit.py b/pyjibe/fd/tab_fit.py index 0975932..37a58af 100644 --- a/pyjibe/fd/tab_fit.py +++ b/pyjibe/fd/tab_fit.py @@ -374,15 +374,19 @@ def indentation_depth_setup(self): self.cb_delta_select.currentIndexChanged['int'].connect( self.on_delta_select) + @QtCore.pyqtSlot() def on_model(self): self.fd.on_model() + @QtCore.pyqtSlot() def on_params_anc(self): self.fd.on_params_init() + @QtCore.pyqtSlot() def on_params_init(self): self.fd.on_params_init() + @QtCore.pyqtSlot(int) def on_delta_select(self, index): """The user selected a method for indentation depth determination @@ -446,6 +450,7 @@ def on_delta_select(self, index): self.cb_right_individ.setChecked(False) self.on_params_init() + @QtCore.pyqtSlot() def on_update_weights(self, on_params_init=True): """Compute the weight in µm or % for user convenience diff --git a/pyjibe/fd/tab_preprocess.py b/pyjibe/fd/tab_preprocess.py index efe8c67..cb5ddc3 100644 --- a/pyjibe/fd/tab_preprocess.py +++ b/pyjibe/fd/tab_preprocess.py @@ -1,7 +1,7 @@ import pkg_resources import nanite.preproc as npreproc -from PyQt5 import uic, QtWidgets +from PyQt5 import uic, QtCore, QtWidgets class TabPreprocess(QtWidgets.QWidget): @@ -46,6 +46,7 @@ def fit_apply_preprocessing(self, fdist): # Perform preprocessing fdist.apply_preprocessing(preprocessing) + @QtCore.pyqtSlot() def on_preset_changed(self): """Update preselection""" text = self.cb_preproc_presel.currentText() diff --git a/pyjibe/fd/tab_qmap.py b/pyjibe/fd/tab_qmap.py index a8d32fa..56a7fc7 100644 --- a/pyjibe/fd/tab_qmap.py +++ b/pyjibe/fd/tab_qmap.py @@ -1,7 +1,7 @@ import pkg_resources import nanite -from PyQt5 import uic, QtWidgets +from PyQt5 import uic, QtCore, QtWidgets from .mpl_qmap import MPLQMap @@ -48,10 +48,12 @@ def mpl_qmap_update(self): fdist.path) self.update_qmap(fdist_group, fdist) + @QtCore.pyqtSlot() def on_qmap_cmap_changed(self): """colormap selection changed""" self.mpl_qmap_update() + @QtCore.pyqtSlot() def on_qmap_data_changed(self): """data column selection changed""" # set previous spin control values if existent @@ -69,6 +71,7 @@ def on_qmap_data_changed(self): self.qmap_sp_range2.blockSignals(False) self.mpl_qmap_update() + @QtCore.pyqtSlot() def on_qmap_min_max_changed(self): """min or max spin controls changed""" # store spin control values for data column @@ -80,6 +83,7 @@ def on_qmap_min_max_changed(self): self._cache_qmap_spin_ctl[data] = (vmin, vmax) self.mpl_qmap_update() + @QtCore.pyqtSlot() def on_qmap_selection(self, idx): """Show the curve indexed in the current qmap""" # Perform operations on ForceDistance