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

[gui][shift] Add ShiftCorrectionDialog

parent b3f9a797
......@@ -26,7 +26,7 @@
__authors__ = ["J. Garriga"]
__license__ = "MIT"
__date__ = "22/12/2020"
__date__ = "05/07/2021"
# import os
import numpy
......@@ -41,13 +41,46 @@ from darfix.core.dataset import Operation
from .operationThread import OperationThread
from .utils import ChooseDimensionDock
class ShiftCorrectionDialog(qt.QDialog):
"""
Dialog with `ShiftCorrectionWidget` as main window and standard buttons.
"""
okSignal = qt.Signal()
def __init__(self, parent=None):
qt.QDialog.__init__(self, parent)
self.setWindowFlags(qt.Qt.Widget)
types = qt.QDialogButtonBox.Ok
self._buttons = qt.QDialogButtonBox(parent=self)
self._buttons.setStandardButtons(types)
self._buttons.setEnabled(False)
resetB = self._buttons.addButton(self._buttons.Reset)
self.mainWindow = ShiftCorrectionWidget(parent=self)
self.mainWindow.setAttribute(qt.Qt.WA_DeleteOnClose)
self.setLayout(qt.QVBoxLayout())
self.layout().addWidget(self.mainWindow)
self.layout().addWidget(self._buttons)
self._buttons.accepted.connect(self.okSignal.emit)
resetB.clicked.connect(self.mainWindow.resetStack)
self.mainWindow.computingSignal.connect(self._toggleButton)
def setDataset(self, dataset, indices=None, bg_indices=None, bg_dataset=None):
if dataset is not None:
self._buttons.setEnabled(True)
self.mainWindow.setDataset(dataset, indices, bg_indices, bg_dataset)
def _toggleButton(self, state):
self._buttons.button(qt.QDialogButtonBox.Ok).setEnabled(not state)
class ShiftCorrectionWidget(qt.QMainWindow):
"""
A widget to apply shift correction to a stack of images
"""
sigComputed = qt.Signal()
sigProgressChanged = qt.Signal(int)
computingSignal = qt.Signal()
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
......@@ -124,11 +157,15 @@ class ShiftCorrectionWidget(qt.QMainWindow):
self._inputDock.widget.correctionB.setEnabled(False)
self._inputDock.widget.abortB.show()
self.thread_correction.start()
self.computingSignal.emit()
def abort(self):
self._inputDock.widget.abortB.setEnabled(False)
self._update_dataset.stop_operation(Operation.SHIFT)
def resetStack(self):
self._update_dataset = self.dataset
self.setStack()
def updateProgress(self, progress):
self.sigProgressChanged.emit(progress)
......@@ -138,11 +175,13 @@ class ShiftCorrectionWidget(qt.QMainWindow):
self.thread_detection.setArgs(self._dimension, indices=self.indices)
self.thread_detection.finished.connect(self._updateShift)
self.thread_detection.start()
self.computingSignal.emit()
def _updateShift(self):
self._inputDock.widget._findShiftB.setEnabled(True)
self.thread_detection.finished.disconnect(self._updateShift)
self.shift = numpy.round(self.thread_detection.data[:, 1], 5)
self.computingSignal.emit()
def _updateData(self):
"""
......@@ -152,13 +191,13 @@ class ShiftCorrectionWidget(qt.QMainWindow):
self._inputDock.widget.abortB.hide()
self._inputDock.widget.abortB.setEnabled(True)
self._inputDock.widget.correctionB.setEnabled(True)
self.computingSignal.emit()
if self.thread_correction.data:
self._update_dataset = self.thread_correction.data
assert self._update_dataset is not None
if self._inputDock.widget.checkbox.isChecked():
self._chooseDimensionDock.widget._checkbox.setChecked(False)
self.setStack(self._update_dataset)
self.sigComputed.emit()
else:
print("\nCorrection aborted")
......
Markdown is supported
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