Commit ac532e9e authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[gui][operationThread] Pass parent as self to avoid destoyred QThread

parent 528cd2ab
......@@ -67,7 +67,7 @@ class PCAWidget(qt.QMainWindow):
def _computePCA(self):
self.computeB.setEnabled(False)
try:
self._thread = OperationThread(self.dataset.pca)
self._thread = OperationThread(self, self.dataset.pca)
self._thread.setArgs(return_vals=True)
self._thread.finished.connect(self._updateData)
self._thread.start()
......
......@@ -130,13 +130,13 @@ class BSSWidget(qt.QMainWindow):
method = Method(self.methodCB.currentText())
n_comp = int(self.nComponentsLE.text())
if method == Method.PCA:
self._thread = OperationThread(self.dataset.pca)
self._thread = OperationThread(self, self.dataset.pca)
elif method == Method.NNICA:
self._thread = OperationThread(self.dataset.nica)
self._thread = OperationThread(self, self.dataset.nica)
elif method == Method.NMF:
self._thread = OperationThread(self.dataset.nmf)
self._thread = OperationThread(self, self.dataset.nmf)
elif method == Method.NNICA_NMF:
self._thread = OperationThread(self.dataset.nica_nmf)
self._thread = OperationThread(self, self.dataset.nica_nmf)
else:
raise ValueError('BSS method not managed')
......@@ -171,7 +171,7 @@ class BSSWidget(qt.QMainWindow):
def _detectComp(self):
self.detectButton.setEnabled(False)
self._thread = OperationThread(self.dataset.pca)
self._thread = OperationThread(self, self.dataset.pca)
self._thread.setArgs(return_vals=True)
self._thread.finished.connect(self._setNumComp)
self._thread.start()
......
......@@ -84,7 +84,7 @@ class DataPartitionWidget(qt.QMainWindow):
self.computePartition.setEnabled(False)
self.abortB.show()
try:
self._thread = OperationThread(self._dataset.compute_frames_intensity)
self._thread = OperationThread(self, self._dataset.compute_frames_intensity)
self._thread.finished.connect(self._showHistogram)
self._thread.start()
except Exception as e:
......@@ -96,7 +96,7 @@ class DataPartitionWidget(qt.QMainWindow):
self.computePartition.setEnabled(False)
self.abortB.show()
try:
self._thread = OperationThread(self._dataset.partition_by_intensity)
self._thread = OperationThread(self, self._dataset.partition_by_intensity)
self._thread.setArgs(bins=int(self.bins.text()), num_bins=int(self.binsNumber.text()))
self._thread.finished.connect(self._filterData)
self._thread.start()
......
......@@ -166,7 +166,7 @@ class NoiseRemovalWidget(qt.QMainWindow):
"""
method = self._parametersDock.bsMethodsCB.currentText()
background = self._parametersDock.bsBackgroundCB.currentText()
self._thread = OperationThread(self._update_dataset.apply_background_subtraction)
self._thread = OperationThread(self, self._update_dataset.apply_background_subtraction)
bg = None
if background == "Dark data":
bg = self.bg_dataset
......@@ -188,7 +188,7 @@ class NoiseRemovalWidget(qt.QMainWindow):
removal.
"""
size = self._parametersDock.hpSizeCB.currentText()
self._thread = OperationThread(self._update_dataset.apply_hot_pixel_removal)
self._thread = OperationThread(self, self._update_dataset.apply_hot_pixel_removal)
self._thread.setArgs(int(size), self.indices)
self._thread.finished.connect(self._updateData)
self._parametersDock.abortHP.show()
......
......@@ -37,8 +37,8 @@ class OperationThread(qt.QThread):
Given a function and a set of arguments, it calls it whenever the thread
is started.
"""
def __init__(self, function):
qt.QThread.__init__(self)
def __init__(self, parent, function):
qt.QThread.__init__(self, parent=parent)
self.func = function
self.args = []
self.kwargs = {}
......
......@@ -120,7 +120,7 @@ class ShiftCorrectionWidget(qt.QMainWindow):
self.shift = [dy, dx]
dimension = self.dimension if not self._changeDataShiftFlag else None
frames = numpy.arange(self.dataset.get_data(indices=self.indices, dimension=dimension).shape[0])
self.thread_correction = OperationThread(self._update_dataset.apply_shift)
self.thread_correction = OperationThread(self, self._update_dataset.apply_shift)
self.thread_correction.setArgs(numpy.outer(self.shift, frames), dimension, indices=self.indices)
self.thread_correction.finished.connect(self._updateData)
self._inputDock.widget.correctionB.setEnabled(False)
......@@ -138,7 +138,7 @@ class ShiftCorrectionWidget(qt.QMainWindow):
self._shift2dataset = state
def _findShift(self):
self.thread_detection = OperationThread(self._update_dataset.find_shift)
self.thread_detection = OperationThread(self, self._update_dataset.find_shift)
self._inputDock.widget._findShiftB.setEnabled(False)
self.thread_detection.setArgs(self.dimension, indices=self.indices)
self.thread_detection.finished.connect(self._updateShift)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment