Skip to content

Commit

Permalink
ref: properly decorate pyqtSlots
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jun 10, 2021
1 parent 4aa6a5e commit 62ab003
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions pyjibe/fd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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"):
Expand All @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion pyjibe/fd/mpl_qmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pyjibe/fd/rating_iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion pyjibe/fd/tab_edelta.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -65,13 +65,15 @@ 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
value = fdist.estimate_optimal_mindelta()
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
Expand Down
5 changes: 5 additions & 0 deletions pyjibe/fd/tab_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pyjibe/fd/tab_preprocess.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion pyjibe/fd/tab_qmap.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 62ab003

Please sign in to comment.