Skip to content

Commit

Permalink
Merge pull request #1903 from vallsv/calibrant-widget
Browse files Browse the repository at this point in the history
New calibrant widget
  • Loading branch information
kif committed Jul 4, 2023
2 parents d4995da + ed45723 commit 629e6cd
Show file tree
Hide file tree
Showing 17 changed files with 878 additions and 114 deletions.
12 changes: 11 additions & 1 deletion pyFAI/gui/CalibrationContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def __init__(self, settings=None):
self.__scatteringVectorUnit.setValue(units.Unit.INV_ANGSTROM)
self.__markerColors = {}
self.__cacheStyles = {}
self.__recentCalibrants = DataModel()
self.__recentCalibrants.setValue([])

self.sigStyleChanged = self.__rawColormap.sigChanged

Expand Down Expand Up @@ -142,6 +144,9 @@ def restoreSettings(self):
self.__restoreUnit(self.__scatteringVectorUnit, settings, "scattering-vector-unit", units.Unit.INV_ANGSTROM)
settings.endGroup()

recentCalibrants = settings.value("recent-calibrations", [], type=list)
self.__recentCalibrants.setValue(recentCalibrants)

def saveSettings(self):
"""Save the settings of all the application"""
settings = self.__settings
Expand All @@ -157,6 +162,8 @@ def saveSettings(self):
settings.setValue("scattering-vector-unit", self.__scatteringVectorUnit.value().name)
settings.endGroup()

settings.setValue("recent-calibrations", self.__recentCalibrants.value())

# Synchronize the file storage
super(CalibrationContext, self).saveSettings()

Expand Down Expand Up @@ -286,7 +293,10 @@ def getCurrentStyle(self):
def getHtmlMarkerColor(self, index):
colors = self.markerColorList()
color = colors[index % len(colors)]
"#%02X%02X%02X" % (color.red(), color.green(), color.blue())
return "#%02X%02X%02X" % (color.red(), color.green(), color.blue())

def getRecentCalibrants(self) -> DataModel:
return self.__recentCalibrants

def disabledMarkerColor(self):
style = self.getCurrentStyle()
Expand Down
10 changes: 5 additions & 5 deletions pyFAI/gui/dialog/DetectorSelectorDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

import pyFAI.utils
import pyFAI.detectors
from ..widgets.DetectorModel import AllDetectorModel
from ..widgets.DetectorModel import DetectorFilter
from ..widgets.model.AllDetectorItemModel import AllDetectorItemModel
from ..widgets.model.DetectorFilterProxyModel import DetectorFilterProxyModel
from ..model.DataModel import DataModel
from ..utils import validators
from ..ApplicationContext import ApplicationContext
Expand All @@ -62,8 +62,8 @@ def __init__(self, parent=None):
selection = self._manufacturerList.selectionModel()
selection.selectionChanged.connect(self.__manufacturerChanged)

model = AllDetectorModel(self)
modelFilter = DetectorFilter(self)
model = AllDetectorItemModel(self)
modelFilter = DetectorFilterProxyModel(self)
modelFilter.setSourceModel(model)

self._detectorView.setModel(modelFilter)
Expand Down Expand Up @@ -512,7 +512,7 @@ def currentDetectorClass(self):
return None
index = indexes[0]
model = self._detectorView.model()
return model.data(index, role=AllDetectorModel.CLASS_ROLE)
return model.data(index, role=AllDetectorItemModel.CLASS_ROLE)

def __modelChanged(self, selected, deselected):
model = self.currentDetectorClass()
Expand Down
11 changes: 9 additions & 2 deletions pyFAI/gui/tasks/ExperimentTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ def _initGui(self):

self._detectorFileDescription.setElideMode(qt.Qt.ElideMiddle)

self._calibrant.setFileLoadable(True)
#self._calibrant.setFileLoadable(True)
self._calibrant.sigLoadFileRequested.connect(self.loadCalibrant)
recentCalibrants = CalibrationContext.instance().getRecentCalibrants().value()
self._calibrant.setRecentCalibrants(recentCalibrants)

self.__synchronizeRawView = SynchronizeRawView()
self.__synchronizeRawView.registerTask(self)
Expand All @@ -93,6 +95,11 @@ def _initGui(self):
self._wavelength.setValidator(validator)
super()._initGui()

def aboutToClose(self):
super(ExperimentTask, self).aboutToClose()
recentCalibrants = self._calibrant.recentCalibrants()
CalibrationContext.instance().getRecentCalibrants().setValue(recentCalibrants)

def __createPlot(self, parent):
plot = silx.gui.plot.PlotWidget(parent=parent)
plot.setKeepDataAspectRatio(True)
Expand Down Expand Up @@ -141,7 +148,7 @@ def _updateModel(self, model):

settings = model.experimentSettingsModel()

self._calibrant.setModel(settings.calibrantModel())
self._calibrant.setCalibrantModel(settings.calibrantModel())
self._detectorLabel.setDetectorModel(settings.detectorModel())
self._image.setModel(settings.image())
self._imageLoader.setModel(settings.image())
Expand Down
20 changes: 15 additions & 5 deletions pyFAI/gui/widgets/CalibrantSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
from silx.gui import icons
import pyFAI.calibrant
from ..model.CalibrantModel import CalibrantModel
from ...utils.decorators import deprecated


class CalibrantSelector(qt.QComboBox):
"""Dropdown widget to select a calibrant.
It is a view on top of a calibrant model (see :meth:`setModel`, :meth:`model`)
It is a view on top of a calibrant model (see :meth:`setCalibrantModel`,
:meth:`calibrantModel`)
The calibrant can be selected from a list of calibrant known by pyFAI.
Expand All @@ -67,11 +69,11 @@ def __init__(self, parent=None):
self.__isFileLoadable = False

self.__model: CalibrantModel = None
self.setModel(CalibrantModel())
self.setCalibrantModel(CalibrantModel())
self.currentIndexChanged[int].connect(self.__currentIndexChanged)

def __currentIndexChanged(self, index):
model = self.model()
model = self.calibrantModel()
if model is None:
return
if self.__isFileLoadable:
Expand Down Expand Up @@ -108,14 +110,18 @@ def setFileLoadable(self, isFileLoadable):
def __loadFileRequested(self):
self.sigLoadFileRequested.emit()

def setModel(self, model: CalibrantModel):
def setCalibrantModel(self, model: CalibrantModel):
if self.__model is not None:
self.__model.changed.disconnect(self.__modelChanged)
self.__model = model
if self.__model is not None:
self.__model.changed.connect(self.__modelChanged)
self.__modelChanged()

@deprecated(replacement="setCalibrantModel")
def setModel(self, model: CalibrantModel):
self.setCalibrantModel(model)

def findCalibrant(self, calibrant):
"""Returns the first index containing the requested calibrant.
Else return -1"""
Expand Down Expand Up @@ -154,5 +160,9 @@ def __modelChanged(self):
self.__calibrantCount += 1
self.setCurrentIndex(index)

def model(self) -> CalibrantModel:
def calibrantModel(self) -> CalibrantModel:
return self.__model

@deprecated(replacement="calibrantModel")
def model(self) -> CalibrantModel:
return self.model()
Loading

0 comments on commit 629e6cd

Please sign in to comment.