Example #1
0
    def __init__(self, parent):
        """
        Initializes the ToolWindow.

        Parameters
        ----------
        parent : Main1DWindow or AbstractParamFrame
            Parent of the toolwindow.
        """
        super(ToolWindow, self).__init__(parent)
        self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.Tool)
        self.father = parent
        self.setWindowTitle(self.NAME)
        self.layout = QtWidgets.QGridLayout(self)
        self.grid = QtWidgets.QGridLayout()
        self.box = QtWidgets.QDialogButtonBox()
        if self.BROWSE:
            self.layout.addLayout(self.grid, 0, 0, 1, 3)
        else:
            self.layout.addLayout(self.grid, 0, 0, 1, 2)
        if self.SINGLESLICE:
            self.singleSlice = QtWidgets.QCheckBox("Single slice")
            self.layout.addWidget(self.singleSlice, 1, 0, 1, 2)
        if self.BROWSE:
            self.browseButton = QtWidgets.QPushButton("&Browse")
            self.browseButton.clicked.connect(self.browse)
            self.box.addButton(self.browseButton,
                               QtWidgets.QDialogButtonBox.ActionRole)
        self.cancelButton = QtWidgets.QPushButton(self.CANCELNAME)
        self.cancelButton.clicked.connect(self.closeEvent)
        self.okButton = QtWidgets.QPushButton(self.OKNAME)
        self.okButton.clicked.connect(self.applyAndClose)
        self.okButton.setFocus()
        self.box.addButton(self.cancelButton,
                           QtWidgets.QDialogButtonBox.RejectRole)
        self.box.addButton(self.okButton,
                           QtWidgets.QDialogButtonBox.AcceptRole)
        self.show()
        self.layout.addWidget(self.box, 3, 0)
        if not self.RESIZABLE:
            self.setFixedSize(self.size())
        if self.MENUDISABLE:
            self.father.menuEnable(False)
        self.setGeometry(self.frameSize().width() - self.geometry().width(),
                         self.frameSize().height(), 0, 0)
Example #2
0
    def __init__(self, father, oldMainWindow):
        """
        Initializes the SaveFigureWindow.

        Parameters
        ----------
        father : MainProgram
            The main program of ssNake.
        oldMainWindow : Main1DWindow
            The figure window that this window replaces.
        """
        super(SaveFigureWindow, self).__init__(father)
        self.father = father
        self.oldMainWindow = oldMainWindow
        self.rename = self.oldMainWindow.rename  # Forward function
        self.get_masterData = self.oldMainWindow.get_masterData  # Forward function
        self.get_current = self.oldMainWindow.get_current  # Forward function
        self.fig = oldMainWindow.current.fig
        self.canvas = FigureCanvas(self.fig)
        self.canvas.mpl_connect('pick_event', self.pickHandler)
        self.ax = oldMainWindow.current.ax
        grid = QtWidgets.QGridLayout(self)
        scroll2 = QtWidgets.QScrollArea()
        grid.addWidget(scroll2, 0, 0)
        scroll2.setWidget(self.canvas)
        self.frame1 = QtWidgets.QGridLayout()
        grid.addLayout(self.frame1, 0, 1)
        scroll = QtWidgets.QScrollArea()
        self.frame1.addWidget(scroll, 0, 0)
        scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        content = QtWidgets.QWidget()
        self.optionFrame = QtWidgets.QGridLayout(content)
        self.optionFrame.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
        self.labelGroup = QtWidgets.QGroupBox('Labels:')
        self.labelFrame = QtWidgets.QGridLayout()
        self.labelFrame.addWidget(wc.QLeftLabel('Title:'), 0, 0)
        self.titleBackup = oldMainWindow.get_masterData().name
        self.titleEntry = wc.QLineEdit(self.titleBackup, self.updatePlot)
        self.labelFrame.addWidget(self.titleEntry, 0, 1)
        self.labelFrame.addWidget(wc.QLeftLabel("x:"), 1, 0)
        self.xlabelBackup = self.ax.get_xlabel()
        self.xlabelEntry = wc.QLineEdit(self.xlabelBackup, self.updatePlot)
        self.labelFrame.addWidget(self.xlabelEntry, 1, 1)
        self.labelFrame.addWidget(wc.QLeftLabel("y:"), 2, 0)
        self.ylabelBackup = self.ax.get_ylabel()
        self.ylabelEntry = wc.QLineEdit(self.ylabelBackup, self.updatePlot)
        self.labelFrame.addWidget(self.ylabelEntry, 2, 1)
        self.labelGroup.setLayout(self.labelFrame)
        self.optionFrame.addWidget(self.labelGroup, 0, 0)
        # limits
        self.limitsGroup = QtWidgets.QGroupBox('Limits:')
        self.limitsFrame = QtWidgets.QGridLayout()
        self.xlimBackup = self.ax.get_xlim()
        self.limitsFrame.addWidget(wc.QLeftLabel("x left:"), 0, 0)
        self.xlimLeftEntry = wc.QLineEdit(self.xlimBackup[0], self.updatePlot)
        self.limitsFrame.addWidget(self.xlimLeftEntry, 0, 1)
        self.limitsFrame.addWidget(wc.QLeftLabel("x right:"), 1, 0)
        self.xlimRightEntry = wc.QLineEdit(self.xlimBackup[1], self.updatePlot)
        self.limitsFrame.addWidget(self.xlimRightEntry, 1, 1)
        self.ylimBackup = self.ax.get_ylim()
        self.limitsFrame.addWidget(wc.QLeftLabel("y down:"), 2, 0)
        self.ylimLeftEntry = wc.QLineEdit(self.ylimBackup[0], self.updatePlot)
        self.limitsFrame.addWidget(self.ylimLeftEntry, 2, 1)
        self.limitsFrame.addWidget(wc.QLeftLabel("y up:"), 3, 0)
        self.ylimRightEntry = wc.QLineEdit(self.ylimBackup[1], self.updatePlot)
        self.limitsFrame.addWidget(self.ylimRightEntry, 3, 1)
        self.limitsGroup.setLayout(self.limitsFrame)
        self.optionFrame.addWidget(self.limitsGroup, 1, 0)
        # Dimensions
        self.dimensionsGroup = QtWidgets.QGroupBox('Dimensions:')
        self.dimensionsFrame = QtWidgets.QGridLayout()
        self.widthBackup, self.heightBackup = self.fig.get_size_inches()
        self.widthBackup = self.widthBackup * 2.54
        self.heightBackup = self.heightBackup * 2.54
        self.dimensionsFrame.addWidget(wc.QLeftLabel("Width [cm]:"), 0, 0)
        self.widthEntry = QtWidgets.QDoubleSpinBox()
        self.widthEntry.setSingleStep(0.1)
        self.widthEntry.setMinimum(0)
        self.widthEntry.setMaximum(1e6)
        self.widthEntry.setValue(self.widthBackup)
        self.widthEntry.valueChanged.connect(self.updatePlot)
        self.dimensionsFrame.addWidget(self.widthEntry, 0, 1)
        self.dimensionsFrame.addWidget(wc.QLeftLabel("Height [cm]:"), 1, 0)
        self.heightEntry = QtWidgets.QDoubleSpinBox()
        self.heightEntry.setSingleStep(0.1)
        self.heightEntry.setMinimum(0)
        self.heightEntry.setMaximum(1e6)
        self.heightEntry.setValue(self.heightBackup)
        self.heightEntry.valueChanged.connect(self.updatePlot)
        self.dimensionsFrame.addWidget(self.heightEntry, 1, 1)
        self.dimensionsFrame.addWidget(wc.QLeftLabel("dpi:"), 2, 0)
        self.dpiEntry = QtWidgets.QSpinBox()
        self.dpiEntry.setSingleStep(1)
        self.dpiEntry.setMinimum(0)
        self.dpiEntry.setMaximum(1e6)
        self.dpiEntry.setValue(self.fig.dpi)
        self.dpiEntry.valueChanged.connect(self.updatePlot)
        self.dimensionsFrame.addWidget(self.dpiEntry, 2, 1)
        self.dimensionsGroup.setLayout(self.dimensionsFrame)
        self.optionFrame.addWidget(self.dimensionsGroup, 2, 0)
        # Font size
        self.fontGroup = QtWidgets.QGroupBox('Font sizes:')
        self.fontFrame = QtWidgets.QGridLayout()
        self.mainFontLabel = wc.QLeftLabel("Main:")
        self.fontFrame.addWidget(self.mainFontLabel, 0, 0)
        self.mainFontSizeEntry = QtWidgets.QDoubleSpinBox()
        self.mainFontSizeEntry.setSingleStep(0.1)
        self.mainFontSizeEntry.setMinimum(0)
        self.mainFontSizeEntry.setValue(
            self.ax.xaxis.get_label().get_fontsize())
        self.mainFontSizeEntry.valueChanged.connect(self.updatePlot)
        self.fontFrame.addWidget(self.mainFontSizeEntry, 0, 1)
        self.fontDetailsCheck = QtWidgets.QCheckBox('Details')
        self.fontDetailsCheck.stateChanged.connect(self.fontCheckChanged)
        self.fontFrame.addWidget(self.fontDetailsCheck, 1, 0)
        self.titleFontSizeBackup = self.ax.title.get_fontsize()
        self.titleFontLabel = wc.QLeftLabel("Title:")
        self.titleFontLabel.hide()
        self.fontFrame.addWidget(self.titleFontLabel, 2, 0)
        self.titleFontSizeEntry = QtWidgets.QDoubleSpinBox()
        self.titleFontSizeEntry.setSingleStep(0.1)
        self.titleFontSizeEntry.setMinimum(0)
        self.titleFontSizeEntry.setValue(self.titleFontSizeBackup)
        self.titleFontSizeEntry.valueChanged.connect(self.updatePlot)
        self.titleFontSizeEntry.hide()
        self.fontFrame.addWidget(self.titleFontSizeEntry, 2, 1)
        self.xlabelFontSizeBackup = self.ax.xaxis.get_label().get_fontsize()
        self.xlabelFontLabel = wc.QLeftLabel("X-label:")
        self.xlabelFontLabel.hide()
        self.fontFrame.addWidget(self.xlabelFontLabel, 3, 0)
        self.xlabelFontSizeEntry = QtWidgets.QDoubleSpinBox()
        self.xlabelFontSizeEntry.setSingleStep(0.1)
        self.xlabelFontSizeEntry.setMinimum(0)
        self.xlabelFontSizeEntry.setValue(self.xlabelFontSizeBackup)
        self.xlabelFontSizeEntry.valueChanged.connect(self.updatePlot)
        self.xlabelFontSizeEntry.hide()
        self.fontFrame.addWidget(self.xlabelFontSizeEntry, 3, 1)
        self.ylabelFontSizeBackup = self.ax.yaxis.get_label().get_fontsize()
        self.ylabelFontLabel = wc.QLeftLabel("Y-label:")
        self.ylabelFontLabel.hide()
        self.fontFrame.addWidget(self.ylabelFontLabel, 4, 0)
        self.ylabelFontSizeEntry = QtWidgets.QDoubleSpinBox()
        self.ylabelFontSizeEntry.setSingleStep(0.1)
        self.ylabelFontSizeEntry.setMinimum(0)
        self.ylabelFontSizeEntry.setValue(self.ylabelFontSizeBackup)
        self.ylabelFontSizeEntry.valueChanged.connect(self.updatePlot)
        self.ylabelFontSizeEntry.hide()
        self.fontFrame.addWidget(self.ylabelFontSizeEntry, 4, 1)
        self.xtickFontSizeBackup = self.ax.xaxis.get_ticklabels(
        )[0].get_fontsize()
        self.xtickFontLabel = wc.QLeftLabel("X-ticks:")
        self.xtickFontLabel.hide()
        self.fontFrame.addWidget(self.xtickFontLabel, 5, 0)
        self.xtickFontSizeEntry = QtWidgets.QDoubleSpinBox()
        self.xtickFontSizeEntry.setSingleStep(0.1)
        self.xtickFontSizeEntry.setMinimum(0)
        self.xtickFontSizeEntry.setValue(self.xtickFontSizeBackup)
        self.xtickFontSizeEntry.valueChanged.connect(self.updatePlot)
        self.xtickFontSizeEntry.hide()
        self.fontFrame.addWidget(self.xtickFontSizeEntry, 5, 1)
        self.ytickFontSizeBackup = self.ax.yaxis.get_ticklabels(
        )[0].get_fontsize()
        self.ytickFontLabel = wc.QLeftLabel("Y-ticks:")
        self.ytickFontLabel.hide()
        self.fontFrame.addWidget(self.ytickFontLabel, 6, 0)
        self.ytickFontSizeEntry = QtWidgets.QDoubleSpinBox()
        self.ytickFontSizeEntry.setSingleStep(0.1)
        self.ytickFontSizeEntry.setMinimum(0)
        self.ytickFontSizeEntry.setValue(self.ytickFontSizeBackup)
        self.ytickFontSizeEntry.valueChanged.connect(self.updatePlot)
        self.ytickFontSizeEntry.hide()
        self.fontFrame.addWidget(self.ytickFontSizeEntry, 6, 1)
        self.legend = self.ax.legend()
        if self.legend is not None:  # Fix for matplotlib 2.0, were for contour self.legend becomes None
            if not self.legend.get_texts():
                self.legend.set_visible(False)
                self.legend = None
            else:
                self.legendFontSizeBackup = self.legend.get_texts(
                )[0].get_fontsize()
                self.legendFontLabel = wc.QLeftLabel("Legend:")
                self.legendFontLabel.hide()
                self.fontFrame.addWidget(self.legendFontLabel, 7, 0)
                self.legendFontSizeEntry = QtWidgets.QDoubleSpinBox()
                self.legendFontSizeEntry.setSingleStep(0.1)
                self.legendFontSizeEntry.setMinimum(0)
                self.legendFontSizeEntry.setValue(self.legendFontSizeBackup)
                self.legendFontSizeEntry.valueChanged.connect(self.updatePlot)
                self.legendFontSizeEntry.hide()
                self.fontFrame.addWidget(self.legendFontSizeEntry, 7, 1)
        self.fontGroup.setLayout(self.fontFrame)
        self.optionFrame.addWidget(self.fontGroup, 3, 0)
        # Legend
        if self.legend is not None:
            if self.oldMainWindow.current.__class__.__name__ == 'CurrentMulti':  # If from multiplot
                order = list(
                    self.oldMainWindow.current.viewSettings['extraOffset'])
                order.append(0)
                self.legendOrder = list(np.argsort(order))[::-1]
            elif self.oldMainWindow.current.__class__.__name__ == 'CurrentStacked':
                self.legendOrder = list(
                    np.arange(0, len(self.legend.get_texts())))[::-1]
            else:
                self.legendOrder = list(
                    np.arange(0, len(self.legend.get_texts())))
            try:
                self.legend.set_draggable(True)
            except AttributeError:
                self.legend.draggable(True)  # For older Matplotlib versions
            self.legendPos = 'best'
            self.legendTextList = []
            for line in self.legend.get_texts():
                self.legendTextList.append(line.get_text())
            self.legend.set_visible(False)
            self.legendGroup = QtWidgets.QGroupBox('Legend:')
            self.legendGroup.setCheckable(True)
            self.legendGroup.setChecked(False)
            self.legendGroup.toggled.connect(self.updatePlot)
            self.legendFrame = QtWidgets.QGridLayout()
            legendButton = QtWidgets.QPushButton('Legend settings')
            legendButton.clicked.connect(lambda: LegendWindow(self))
            self.legendFrame.addWidget(legendButton, 0, 0)
            self.legendGroup.setLayout(self.legendFrame)
            self.optionFrame.addWidget(self.legendGroup, 4, 0)
        self.xticksToggle = QtWidgets.QCheckBox('X-ticks')
        self.xticksToggle.setChecked(True)
        self.xticksToggle.stateChanged.connect(self.updatePlot)
        self.optionFrame.addWidget(self.xticksToggle, 5, 0)
        self.yticksToggle = QtWidgets.QCheckBox('Y-ticks')
        self.yticksToggle.setChecked(True)
        self.yticksToggle.stateChanged.connect(self.updatePlot)
        self.optionFrame.addWidget(self.yticksToggle, 6, 0)
        self.frameToggle = QtWidgets.QCheckBox('Box')
        self.frameToggle.setChecked(True)
        self.frameToggle.stateChanged.connect(self.updatePlot)
        self.optionFrame.addWidget(self.frameToggle, 7, 0)
        self.inFrame = QtWidgets.QGridLayout()
        self.frame1.addLayout(self.inFrame, 1, 0)
        self.inFrame.addWidget(wc.QLabel("File type:"), 0, 0, 1, 2)
        self.filetypeEntry = QtWidgets.QComboBox()
        self.fileOptions = ['svg', 'png', 'eps', 'jpg', 'pdf']
        self.filetypeEntry.addItems(self.fileOptions)
        self.inFrame.addWidget(self.filetypeEntry, 1, 0, 1, 2)
        cancelButton = QtWidgets.QPushButton("&Close")
        cancelButton.clicked.connect(self.cancel)
        okButton = QtWidgets.QPushButton("&Save")
        okButton.clicked.connect(self.save)
        box = QtWidgets.QDialogButtonBox()
        box.setOrientation(QtCore.Qt.Horizontal)
        box.addButton(cancelButton, QtWidgets.QDialogButtonBox.RejectRole)
        box.addButton(okButton, QtWidgets.QDialogButtonBox.AcceptRole)
        self.inFrame.addWidget(box, 2, 0)
        grid.setColumnStretch(0, 1)
        grid.setRowStretch(0, 1)
        self.optionFrame.setAlignment(QtCore.Qt.AlignTop)
        self.grid = grid
        scroll.setWidget(content)
        scroll.setMinimumWidth(content.sizeHint().width() +
                               scroll.verticalScrollBar().sizeHint().width())
        self.updatePlot()