def __init__(self, plotWindow, profileWindow=None, title='Profile Selection', parent=None): """ :param plotWindow: :class:`PlotWindow` instance on which to operate. :param profileWindow: :class:`ProfileScanWidget` instance where to display the profile curve or None to create one. :param str title: See :class:`QToolBar`. :param parent: See :class:`QToolBar`. """ super(ProfileToolBar, self).__init__(title, parent) assert plotWindow is not None self.plotWindow = plotWindow self.plotWindow.sigPlotSignal.connect(self._plotWindowSlot) self._overlayColor = None self._roiInfo = None if profileWindow is None: self.profileWindow = ProfileScanWidget(actions=False) else: self.profileWindow = profileWindow # Actions self.browseAction = qt.QAction( qt.QIcon(qt.QPixmap(IconDict["normal"])), 'Browsing Mode', None) self.browseAction.setToolTip('Enables zooming interaction mode') self.browseAction.setCheckable(True) self.hLineAction = qt.QAction( qt.QIcon(qt.QPixmap(IconDict["horizontal"])), 'Horizontal Profile Mode', None) self.hLineAction.setToolTip( 'Enables horizontal profile selection mode') self.hLineAction.setCheckable(True) self.vLineAction = qt.QAction( qt.QIcon(qt.QPixmap(IconDict["vertical"])), 'Vertical Profile Mode', None) self.vLineAction.setToolTip('Enables vertical profile selection mode') self.vLineAction.setCheckable(True) self.lineAction = qt.QAction( qt.QIcon(qt.QPixmap(IconDict["diagonal"])), 'Fee Line Profile Mode', None) self.lineAction.setToolTip('Enables line profile selection mode') self.lineAction.setCheckable(True) self.clearAction = qt.QAction(qt.QIcon(qt.QPixmap(IconDict["image"])), 'Clear Profile', None) self.clearAction.setToolTip('Clear the profile Region of interest') self.clearAction.setCheckable(False) self.clearAction.triggered.connect(self.clearProfile) # ActionGroup self.actionGroup = qt.QActionGroup(self) self.actionGroup.addAction(self.browseAction) self.actionGroup.addAction(self.hLineAction) self.actionGroup.addAction(self.vLineAction) self.actionGroup.addAction(self.lineAction) self.actionGroup.triggered.connect(self._actionGroupTriggeredSlot) self.browseAction.setChecked(True) # Add actions to ToolBar self.addAction(self.browseAction) self.addAction(self.hLineAction) self.addAction(self.vLineAction) self.addAction(self.lineAction) self.addAction(self.clearAction) # Add width spin box to toolbar self.addWidget(qt.QLabel('W:')) self.lineWidthSpinBox = qt.QSpinBox(self) self.lineWidthSpinBox.setRange(0, 1000) self.lineWidthSpinBox.setValue(1) self.lineWidthSpinBox.valueChanged[int].connect( self._lineWidthSpinBoxValueChangedSlot) self.addWidget(self.lineWidthSpinBox)
def __init__(self, parent=None): qt.QMainWindow.__init__(self, parent=parent) if parent is not None: # behave as a widget self.setWindowFlags(qt.Qt.Widget) else: self.setWindowTitle("PyMca - Image Selection Tool") centralWidget = qt.QWidget(self) layout = qt.QVBoxLayout(centralWidget) centralWidget.setLayout(layout) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) # Plot self.plot = PlotWidget(parent=centralWidget) self.plot.setWindowFlags(qt.Qt.Widget) self.plot.setDefaultColormap({ 'name': 'temperature', 'normalization': 'linear', 'autoscale': True, 'vmin': 0., 'vmax': 1. }) layout.addWidget(self.plot) # Mask Widget self._maskToolsDockWidget = None # Image selection slider self.slider = qt.QSlider(self.centralWidget()) self.slider.setOrientation(qt.Qt.Horizontal) self.slider.setMinimum(0) self.slider.setMaximum(0) layout.addWidget(self.slider) self.slider.valueChanged[int].connect(self.showImage) # ADD/REMOVE/REPLACE IMAGE buttons buttonBox = qt.QWidget(self) buttonBoxLayout = qt.QHBoxLayout(buttonBox) buttonBoxLayout.setContentsMargins(0, 0, 0, 0) buttonBoxLayout.setSpacing(0) self.addImageButton = qt.QPushButton(buttonBox) icon = qt.QIcon(qt.QPixmap(IconDict["rgb16"])) self.addImageButton.setIcon(icon) self.addImageButton.setText("ADD IMAGE") self.addImageButton.setToolTip("Add image to RGB correlator") buttonBoxLayout.addWidget(self.addImageButton) self.removeImageButton = qt.QPushButton(buttonBox) self.removeImageButton.setIcon(icon) self.removeImageButton.setText("REMOVE IMAGE") self.removeImageButton.setToolTip("Remove image from RGB correlator") buttonBoxLayout.addWidget(self.removeImageButton) self.replaceImageButton = qt.QPushButton(buttonBox) self.replaceImageButton.setIcon(icon) self.replaceImageButton.setText("REPLACE IMAGE") self.replaceImageButton.setToolTip( "Replace all images in RGB correlator with this one") buttonBoxLayout.addWidget(self.replaceImageButton) self.addImageButton.clicked.connect(self._addImageClicked) self.removeImageButton.clicked.connect(self._removeImageClicked) self.replaceImageButton.clicked.connect(self._replaceImageClicked) layout.addWidget(buttonBox) # median filter widget self._medianParameters = {'row_width': 1, 'column_width': 1} self._medianParametersWidget = MedianParameters(self) self._medianParametersWidget.widthSpin.setValue(1) self._medianParametersWidget.widthSpin.valueChanged[int].connect( self._setMedianKernelWidth) layout.addWidget(self._medianParametersWidget) self.setCentralWidget(centralWidget) # Init actions self.group = qt.QActionGroup(self) self.group.setExclusive(False) self.resetZoomAction = self.group.addAction( PlotActions.ResetZoomAction(plot=self.plot, parent=self)) self.addAction(self.resetZoomAction) self.zoomInAction = PlotActions.ZoomInAction(plot=self.plot, parent=self) self.addAction(self.zoomInAction) self.zoomOutAction = PlotActions.ZoomOutAction(plot=self.plot, parent=self) self.addAction(self.zoomOutAction) self.xAxisAutoScaleAction = self.group.addAction( PlotActions.XAxisAutoScaleAction(plot=self.plot, parent=self)) self.addAction(self.xAxisAutoScaleAction) self.yAxisAutoScaleAction = self.group.addAction( PlotActions.YAxisAutoScaleAction(plot=self.plot, parent=self)) self.addAction(self.yAxisAutoScaleAction) self.colormapAction = self.group.addAction( PlotActions.ColormapAction(plot=self.plot, parent=self)) self.addAction(self.colormapAction) self.copyAction = self.group.addAction( PlotActions.CopyAction(plot=self.plot, parent=self)) self.addAction(self.copyAction) self.group.addAction(self.getMaskAction()) # Init toolbuttons self.saveToolbutton = SaveToolButton(parent=self, maskImageWidget=self) self.yAxisInvertedButton = PlotToolButtons.YAxisOriginToolButton( parent=self, plot=self.plot) self.keepDataAspectRatioButton = PlotToolButtons.AspectToolButton( parent=self, plot=self.plot) self.backgroundButton = qt.QToolButton(self) self.backgroundButton.setCheckable(True) self.backgroundButton.setIcon( qt.QIcon(qt.QPixmap(IconDict["subtract"]))) self.backgroundButton.setToolTip( 'Toggle background image subtraction from current image\n' + 'No action if no background image available.') self.backgroundButton.clicked.connect(self._subtractBackground) # Creating the toolbar also create actions for toolbuttons self._toolbar = self._createToolBar(title='Plot', parent=None) self.addToolBar(self._toolbar) self._profile = ProfileToolBar(plot=self.plot) self.addToolBar(self._profile) self.setProfileToolbarVisible(False) # add a transparency slider for the stack data self._alphaSliderToolbar = qt.QToolBar("Alpha slider", parent=self) self._alphaSlider = NamedImageAlphaSlider( parent=self._alphaSliderToolbar, plot=self.plot, legend="current") self._alphaSlider.setOrientation(qt.Qt.Vertical) self._alphaSlider.setToolTip("Adjust opacity of stack image overlay") self._alphaSliderToolbar.addWidget(self._alphaSlider) self.addToolBar(qt.Qt.RightToolBarArea, self._alphaSliderToolbar) # hide optional tools and actions self.setAlphaSliderVisible(False) self.setBackgroundActionVisible(False) self.setMedianFilterWidgetVisible(False) self.setProfileToolbarVisible(False) self._images = [] """List of images, as 2D numpy arrays or 3D numpy arrays (RGB(A)). """ self._labels = [] """List of image labels. """ self._bg_images = [] """List of background images, as 2D numpy arrays or 3D numpy arrays (RGB(A)). These images are not active, their colormap cannot be changed and they cannot be the base image used for drawing a mask. """ self._bg_labels = [] self._deltaXY = ( 1.0, 1.0) # TODO: allow different scale and origin for each image """Current image scale (Xscale, Yscale) (in axis units per image pixel). The scale is adjusted to keep constant width and height for the image when a crop operation is applied.""" self._origin = (0., 0.) """Current image origin: coordinate (x, y) of sample located at (row, column) = (0, 0)""" # scales and origins for background images self._bg_deltaXY = [] self._bg_origins = []