diff options
Diffstat (limited to 'silx/gui/plot/Profile.py')
-rw-r--r-- | silx/gui/plot/Profile.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/silx/gui/plot/Profile.py b/silx/gui/plot/Profile.py index 8abddbe..7565155 100644 --- a/silx/gui/plot/Profile.py +++ b/silx/gui/plot/Profile.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2004-2020 European Synchrotron Radiation Facility +# Copyright (c) 2004-2021 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -57,16 +57,43 @@ class _CustomProfileManager(manager.ProfileManager): if it is specified. Else the behavior is the same as the default ProfileManager """ + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.__profileWindow = None + self.__specializedProfileWindows = {} + + def setSpecializedProfileWindow(self, roiClass, profileWindow): + """Set a profile window for a given class or ROI. + + Setting profileWindow to None removes the roiClass from the list. + + :param roiClass: + :param profileWindow: + """ + if profileWindow is None: + self.__specializedProfileWindows.pop(roiClass, None) + else: + self.__specializedProfileWindows[roiClass] = profileWindow + def setProfileWindow(self, profileWindow): self.__profileWindow = profileWindow def createProfileWindow(self, plot, roi): + for roiClass, specializedProfileWindow in self.__specializedProfileWindows.items(): + if isinstance(roi, roiClass): + return specializedProfileWindow + if self.__profileWindow is not None: return self.__profileWindow else: return super(_CustomProfileManager, self).createProfileWindow(plot, roi) def clearProfileWindow(self, profileWindow): + for specializedProfileWindow in self.__specializedProfileWindows.values(): + if profileWindow is specializedProfileWindow: + profileWindow.setProfile(None) + return + if self.__profileWindow is not None: self.__profileWindow.setProfile(None) else: @@ -116,7 +143,7 @@ class ProfileToolBar(qt.QToolBar): # If a profileWindow is defined, # It will be used to display all the profiles - self._manager = _CustomProfileManager(self, plot) + self._manager = self.createProfileManager(self, plot) self._manager.setProfileWindow(profileWindow) self._manager.setDefaultColorFromCursorColor(True) self._manager.setItemType(image=True) @@ -155,6 +182,9 @@ class ProfileToolBar(qt.QToolBar): plot.sigActiveImageChanged.connect(self._activeImageChanged) self._activeImageChanged() + def createProfileManager(self, parent, plot): + return _CustomProfileManager(parent, plot) + def _createProfileActions(self): self.hLineAction = self._manager.createProfileAction(rois.ProfileImageHorizontalLineROI, self) self.vLineAction = self._manager.createProfileAction(rois.ProfileImageVerticalLineROI, self) |