Commit 151f88e2 authored by Damien Naudet's avatar Damien Naudet

Locking some widgets when the fit is running.

parent 729f59b6
...@@ -153,6 +153,11 @@ class FitWidget(Qt.QWidget): ...@@ -153,6 +153,11 @@ class FitWidget(Qt.QWidget):
containing the results. containing the results.
""" """
sigProcessStarted = Qt.Signal()
""" Signal emitted when a fit is started. Argument is the name of the file
containing the results.
"""
FitTypes = OrderedDict([('LEASTSQ', FitTypes.LEASTSQ), FitTypes = OrderedDict([('LEASTSQ', FitTypes.LEASTSQ),
('CENTROID', FitTypes.CENTROID)]) ('CENTROID', FitTypes.CENTROID)])
...@@ -282,6 +287,7 @@ class FitWidget(Qt.QWidget): ...@@ -282,6 +287,7 @@ class FitWidget(Qt.QWidget):
timer.timeout.connect(self.__slotProgTimer) timer.timeout.connect(self.__slotProgTimer)
try: try:
self.sigProcessStarted.emit()
fitter.peak_fit(blocking=False, callback=self.__sigFitDone.emit) fitter.peak_fit(blocking=False, callback=self.__sigFitDone.emit)
timer.start(self.__progressDelay) timer.start(self.__progressDelay)
except Exception as ex: except Exception as ex:
...@@ -289,6 +295,7 @@ class FitWidget(Qt.QWidget): ...@@ -289,6 +295,7 @@ class FitWidget(Qt.QWidget):
self.__statusLabel.setText('ERROR') self.__statusLabel.setText('ERROR')
print('ERROR : {0}.'.format(ex)) print('ERROR : {0}.'.format(ex))
self.__lock(False) self.__lock(False)
self.sigProcessDone.emit(None)
def __slotProgTimer(self): def __slotProgTimer(self):
if self.__fitter: if self.__fitter:
......
...@@ -209,6 +209,10 @@ class CutPlanePlotWindow(PlotWidget): ...@@ -209,6 +209,10 @@ class CutPlanePlotWindow(PlotWidget):
class QSpaceView(Qt.QMainWindow): class QSpaceView(Qt.QMainWindow):
"""
Window displaying the 3D q space isosurfaces.
"""
sigFitDone = Qt.Signal(object, object) sigFitDone = Qt.Signal(object, object)
plot = property(lambda self: self.__plotWindow) plot = property(lambda self: self.__plotWindow)
...@@ -216,8 +220,13 @@ class QSpaceView(Qt.QMainWindow): ...@@ -216,8 +220,13 @@ class QSpaceView(Qt.QMainWindow):
def __init__(self, def __init__(self,
parent, parent,
model, model,
node, node):
**kwargs): """
:param parent: parent widget
:param model: XsocsModel
:param node: QspaceItem node
"""
super(QSpaceView, self).__init__(parent) super(QSpaceView, self).__init__(parent)
...@@ -277,6 +286,7 @@ class QSpaceView(Qt.QMainWindow): ...@@ -277,6 +286,7 @@ class QSpaceView(Qt.QMainWindow):
self.__fitWidget = fitWidget = FitWidget(self.__qspaceH5.filename) self.__fitWidget = fitWidget = FitWidget(self.__qspaceH5.filename)
fitWidget.roiWidget().sigRoiChanged.connect(self.__slotRoiChanged) fitWidget.roiWidget().sigRoiChanged.connect(self.__slotRoiChanged)
fitWidget.roiWidget().sigRoiToggled.connect(self.__slotRoiToggled) fitWidget.roiWidget().sigRoiToggled.connect(self.__slotRoiToggled)
fitWidget.sigProcessStarted.connect(self.__slotFitProcessStarted)
fitWidget.sigProcessDone.connect(self.__slotFitProcessDone) fitWidget.sigProcessDone.connect(self.__slotFitProcessDone)
self.__nextFitFile() self.__nextFitFile()
fitDock = Qt.QDockWidget() fitDock = Qt.QDockWidget()
...@@ -286,23 +296,16 @@ class QSpaceView(Qt.QMainWindow): ...@@ -286,23 +296,16 @@ class QSpaceView(Qt.QMainWindow):
fitDock.setFeatures(features) fitDock.setFeatures(features)
view3d.addDockWidget(Qt.Qt.RightDockWidgetArea, fitDock) view3d.addDockWidget(Qt.Qt.RightDockWidgetArea, fitDock)
# widget that are to be disabled when the fit is running
self.__lockWidgets = lockWidgets = []
sfDock = Qt.QDockWidget() sfDock = Qt.QDockWidget()
sfDock.setWindowTitle('Isosurface options') sfDock.setWindowTitle('Isosurface options')
sfDock.setWidget(sfTree) sfDock.setWidget(sfTree)
features = sfDock.features() ^ Qt.QDockWidget.DockWidgetClosable features = sfDock.features() ^ Qt.QDockWidget.DockWidgetClosable
sfDock.setFeatures(features) sfDock.setFeatures(features)
# view3d.addDockWidget(Qt.Qt.RightDockWidgetArea, sfDock)
self.addDockWidget(Qt.Qt.LeftDockWidgetArea, sfDock) self.addDockWidget(Qt.Qt.LeftDockWidgetArea, sfDock)
# view3d.splitDockWidget(fitDock, sfDock, Qt.Qt.Vertical) lockWidgets.append(sfDock)
# treeDock = Qt.QDockWidget(self)
# tree = QSpaceTree(self, model=model)
# index = node.index()
# tree.setRootIndex(index)
# treeDock.setWidget(tree)
# features = treeDock.features() ^ Qt.QDockWidget.DockWidgetClosable
# treeDock.setFeatures(features)
# self.addDockWidget(Qt.Qt.LeftDockWidgetArea, treeDock)
planePlotDock = Qt.QDockWidget('Cut Plane', self) planePlotDock = Qt.QDockWidget('Cut Plane', self)
planePlotDock.setWidget(planePlotWindow) planePlotDock.setWidget(planePlotWindow)
...@@ -311,6 +314,7 @@ class QSpaceView(Qt.QMainWindow): ...@@ -311,6 +314,7 @@ class QSpaceView(Qt.QMainWindow):
planePlotDock.visibilityChanged.connect( planePlotDock.visibilityChanged.connect(
self.__planePlotDockVisibilityChanged) self.__planePlotDockVisibilityChanged)
self.splitDockWidget(sfDock, planePlotDock, Qt.Qt.Vertical) self.splitDockWidget(sfDock, planePlotDock, Qt.Qt.Vertical)
lockWidgets.append(planePlotDock)
roiPlotDock = Qt.QDockWidget('ROI Intensity', self) roiPlotDock = Qt.QDockWidget('ROI Intensity', self)
roiPlotDock.setWidget(roiPlotWindow) roiPlotDock.setWidget(roiPlotWindow)
...@@ -318,26 +322,46 @@ class QSpaceView(Qt.QMainWindow): ...@@ -318,26 +322,46 @@ class QSpaceView(Qt.QMainWindow):
roiPlotDock.setFeatures(features) roiPlotDock.setFeatures(features)
self.splitDockWidget(sfDock, roiPlotDock, Qt.Qt.Vertical) self.splitDockWidget(sfDock, roiPlotDock, Qt.Qt.Vertical)
self.tabifyDockWidget(planePlotDock, roiPlotDock) self.tabifyDockWidget(planePlotDock, roiPlotDock)
lockWidgets.append(roiPlotDock)
plotDock = Qt.QDockWidget('Intensity', self) plotDock = Qt.QDockWidget('Intensity', self)
plotDock.setWidget(plotWindow) plotDock.setWidget(plotWindow)
features = plotDock.features() ^ Qt.QDockWidget.DockWidgetClosable features = plotDock.features() ^ Qt.QDockWidget.DockWidgetClosable
plotDock.setFeatures(features) plotDock.setFeatures(features)
self.tabifyDockWidget(roiPlotDock, plotDock) self.tabifyDockWidget(roiPlotDock, plotDock)
lockWidgets.append(plotDock)
self.__showIsoView(firstX, firstY) self.__showIsoView(firstX, firstY)
# TODO : refactor this in a common base with RealSpaceViewWidget
def __setPlotData(self, x, y, data): def __setPlotData(self, x, y, data):
"""
Sets the intensity maps data.
:param x:
:param y:
:param data:
:return:
"""
self.__plotWindow.setPlotData(x, y, data) self.__plotWindow.setPlotData(x, y, data)
self.__plotWindow.resetZoom() self.__plotWindow.resetZoom()
self.__roiPlotWindow.setPlotData(x, y, data) self.__roiPlotWindow.setPlotData(x, y, data)
self.__roiPlotWindow.resetZoom() self.__roiPlotWindow.resetZoom()
def selectPoint(self, x, y): def selectPoint(self, x, y):
"""
Displays the q space closest to sample coordinates x and y.
:param x:
:param y:
:return:
"""
self.__showIsoView(x, y) self.__showIsoView(x, y)
def __pointSelected(self, point): def __pointSelected(self, point):
"""
Slot called each time a point is selected on one of the intensity maps.
Displays the corresponding q space cube.
:param point:
:return:
"""
xIdx = point.xIdx xIdx = point.xIdx
x = point.x x = point.x
y = point.y y = point.y
...@@ -345,6 +369,16 @@ class QSpaceView(Qt.QMainWindow): ...@@ -345,6 +369,16 @@ class QSpaceView(Qt.QMainWindow):
self.__showIsoView(x, y, xIdx) self.__showIsoView(x, y, xIdx)
def __showIsoView(self, x, y, idx=None): def __showIsoView(self, x, y, idx=None):
"""
Displays the q space closest to sample coordinates x and y.
If idx is provided, x and y are ignored. If idx is not provided, the
closest point to x and y is selected.
:param x: sample x coordinate of the point to select
:param y: sample y coordinate of the point to select
:param idx: index of the point to select in the array of sample
coordinates.
:return:
"""
isoView = self.__view3d isoView = self.__view3d
if self.sender() == self.__roiPlotWindow: if self.sender() == self.__roiPlotWindow:
...@@ -395,6 +429,10 @@ class QSpaceView(Qt.QMainWindow): ...@@ -395,6 +429,10 @@ class QSpaceView(Qt.QMainWindow):
roiWidget.zSlider().setSliderProfile(z_sum, colormap=cmap) roiWidget.zSlider().setSliderProfile(z_sum, colormap=cmap)
def __nextFitFile(self): def __nextFitFile(self):
"""
Temporary method that generated a new file name for the Fit results.
:return:
"""
project = self.__projectItem.projectRoot() project = self.__projectItem.projectRoot()
xsocsFile = os.path.basename(project.xsocsFile) xsocsFile = os.path.basename(project.xsocsFile)
xsocsPrefix = xsocsFile.rpartition('.')[0] xsocsPrefix = xsocsFile.rpartition('.')[0]
...@@ -402,11 +440,38 @@ class QSpaceView(Qt.QMainWindow): ...@@ -402,11 +440,38 @@ class QSpaceView(Qt.QMainWindow):
output_f = nextFileName(project.workdir, template) output_f = nextFileName(project.workdir, template)
self.__fitWidget.setOutputFile(output_f) self.__fitWidget.setOutputFile(output_f)
def __slotFitProcessStarted(self):
"""
Slot called when a fit is started. Locks all widgets that reads
the XsocsProject file. This is necessary because that file is
is opened in write mode when the fit is done, to write the fit result.
:return:
"""
for widget in self.__lockWidgets:
widget.setEnabled(False)
def __slotFitProcessDone(self, event): def __slotFitProcessDone(self, event):
self.sigFitDone.emit(self.__node, event) """
self.__nextFitFile() Slot called when the fit is done. Event is the name of the FitH5 file
that has been created.
Unlocks the widgets locked in __slotFitProcessStarted.
Emits QSpaceView.sigFitDone.
:param event:
:return:
"""
if event is not None:
self.sigFitDone.emit(self.__node, event)
self.__nextFitFile()
for widget in self.__lockWidgets:
widget.setEnabled(True)
def __slotRoiToggled(self, on): def __slotRoiToggled(self, on):
"""
Slot called when the Roi selection is enabled.
:param on:
:return:
"""
view3d = self.__view3d view3d = self.__view3d
region = view3d.getSelectedRegion() region = view3d.getSelectedRegion()
...@@ -439,6 +504,11 @@ class QSpaceView(Qt.QMainWindow): ...@@ -439,6 +504,11 @@ class QSpaceView(Qt.QMainWindow):
roiWidget.zSlider().setSliderValues(zLeft, zRight) roiWidget.zSlider().setSliderValues(zLeft, zRight)
def __slotRoiChanged(self, event): def __slotRoiChanged(self, event):
"""
Slot called each time the ROI is modified
:param event:
:return:
"""
region = self.__view3d.getSelectedRegion() region = self.__view3d.getSelectedRegion()
if region is None: if region is None:
......
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