Exemplo n.º 1
0
    def onOffset(self, value):
        """Executed when axes offsets have been modified."""
        # Ensure that we can work
        plt = Plot.getPlot()
        if not plt:
            self.updateUI()
            return
        # Get again all the subwidgets (to avoid PySide Pitfalls)
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.all = self.widget(QtGui.QCheckBox, "allAxes")
        form.xOffset = self.widget(QtGui.QSpinBox, "xOffset")
        form.yOffset = self.widget(QtGui.QSpinBox, "yOffset")

        axesList = [plt.axes]
        if form.all.isChecked():
            axesList = plt.axesList
        # Set new offset
        for axes in axesList:
            # For some reason, modify spines offset erase axes labels, so we
            # need store it in order to regenerate later
            x = axes.get_xlabel()
            y = axes.get_ylabel()
            for loc, spine in axes.spines.iteritems():
                if loc in ['bottom', 'top']:
                    spine.set_position(('outward', form.xOffset.value()))
                if loc in ['left', 'right']:
                    spine.set_position(('outward', form.yOffset.value()))
            # Now we can restore axes labels
            Plot.xlabel(unicode(x))
            Plot.ylabel(unicode(y))
        plt.update()
Exemplo n.º 2
0
 def onData(self, value):
     """ Executed when selected item data is modified. """
     plt = Plot.getPlot()
     if not plt:
         self.updateUI()
         return
     mw = self.getMainWindow()
     form = mw.findChild(QtGui.QWidget, "TaskPanel")
     form.items = self.widget(QtGui.QListWidget, "items")
     form.x = self.widget(QtGui.QDoubleSpinBox, "x")
     form.y = self.widget(QtGui.QDoubleSpinBox, "y")
     form.s = self.widget(QtGui.QDoubleSpinBox, "size")
     if not self.skip:
         self.skip = True
         name = self.names[self.item]
         obj = self.objs[self.item]
         x = form.x.value()
         y = form.y.value()
         s = form.s.value()
         # x/y labels only have one position control
         if name.find('x label') >= 0:
             form.y.setValue(x)
         elif name.find('y label') >= 0:
             form.x.setValue(y)
         # title and labels only have one size control
         if name.find('title') >= 0 or name.find('label') >= 0:
             obj.set_position((x, y))
             obj.set_size(s)
         # legend have all controls
         else:
             Plot.legend(plt.legend, (x, y), s)
         plt.update()
         self.skip = False
Exemplo n.º 3
0
    def onDims(self, value):
        """Executed when axes dims have been modified."""
        # Ensure that we can work
        plt = Plot.getPlot()
        if not plt:
            self.updateUI()
            return
        # Get again all the subwidgets (to avoid PySide Pitfalls)
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.all = self.widget(QtGui.QCheckBox, "allAxes")
        form.xMin = self.widget(QtGui.QSlider, "posXMin")
        form.xMax = self.widget(QtGui.QSlider, "posXMax")
        form.yMin = self.widget(QtGui.QSlider, "posYMin")
        form.yMax = self.widget(QtGui.QSlider, "posYMax")

        axesList = [plt.axes]
        if form.all.isChecked():
            axesList = plt.axesList
        # Set new dimensions
        xmin = form.xMin.value() / 100.0
        xmax = form.xMax.value() / 100.0
        ymin = form.yMin.value() / 100.0
        ymax = form.yMax.value() / 100.0
        for axes in axesList:
            axes.set_position([xmin, ymin, xmax - xmin, ymax - ymin])
        plt.update()
Exemplo n.º 4
0
    def create(self, title, function, xlength, xname, xunit, xscale, yname,
               yunit, yscale, numxpoints):
        # Initialize
        from freecad.plot import Plot
        self.title = title
        self.function = function  # This is assumed to be always a SegmentFunction
        self.xlength = xlength
        self.xname = xname
        self.xunit = xunit
        self.xscale = xscale
        self.yname = yname
        self.yunit = yunit
        self.yscale = yscale
        self.numxpoints = numxpoints

        # Create a plot window
        self.win = Plot.figure(title)
        # Get the plot object from the window
        self.thePlot = Plot.getPlot()
        # Format the plot object
        Plot.xlabel("$%s$ [%s]" % (xname, xunit))
        Plot.ylabel("$%s$ [%s]" % (yname, yunit))
        Plot.grid(True)

        # Calculate points
        (self.xpoints,
         self.ypoints) = self.function.evaluate(self.xlength, self.numxpoints)
        # Create plot
        self.plot()
Exemplo n.º 5
0
    def onRemove(self):
        """Executed when axes must be deleted."""
        # Ensure that we can work
        plt = Plot.getPlot()
        if not plt:
            self.updateUI()
            return
        # Get again all the subwidgets (to avoid PySide Pitfalls)
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.axId = self.widget(QtGui.QSpinBox, "axesIndex")

        # Don't remove first axes
        if not form.axId.value():
            msg = QtGui.QApplication.translate("plot_console",
                                               "Axes 0 can not be deleted",
                                               None)
            App.Console.PrintError(msg + "\n")
            return
        # Remove axes
        ax = plt.axes
        ax.set_axis_off()
        plt.axesList.pop(form.axId.value())
        # Ensure that active axes is correct
        index = min(form.axId.value(), len(plt.axesList) - 1)
        form.axId.setValue(index)
        plt.update()
Exemplo n.º 6
0
    def onMdiArea(self, subWin):
        """Executed when a new window is selected on the mdi area.

        Keyword arguments:
        subWin -- Selected window.
        """
        plt = Plot.getPlot()
        if plt != subWin:
            self.updateUI()
Exemplo n.º 7
0
 def Activated(self):
     from freecad.plot import Plot
     plt = Plot.getPlot()
     if not plt:
         msg = QtGui.QApplication.translate(
             "plot_console",
             "The legend must be activated on top of a plot document", None)
         FreeCAD.Console.PrintError(msg + "\n")
         return
     flag = plt.isLegend()
     Plot.legend(not flag)
Exemplo n.º 8
0
    def onNew(self):
        """Executed when new axes must be created."""
        # Ensure that we can work
        plt = Plot.getPlot()
        if not plt:
            self.updateUI()
            return
        # Get again all the subwidgets (to avoid PySide Pitfalls)
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.axId = self.widget(QtGui.QSpinBox, "axesIndex")

        Plot.addNewAxes()
        form.axId.setValue(len(plt.axesList) - 1)
        plt.update()
Exemplo n.º 9
0
 def onRemove(self):
     """Executed when the data serie must be removed."""
     plt = Plot.getPlot()
     if not plt:
         self.updateUI()
         return
     # Ensure that selected serie exist
     if self.item >= len(Plot.series()):
         self.updateUI()
         return
     # Remove serie
     Plot.removeSerie(self.item)
     self.setList()
     self.updateUI()
     plt.update()
Exemplo n.º 10
0
 def setupUi(self):
     mw = self.getMainWindow()
     form = mw.findChild(QtGui.QWidget, "TaskPanel")
     form.axId = self.widget(QtGui.QSpinBox, "axesIndex")
     form.title = self.widget(QtGui.QLineEdit, "title")
     form.titleSize = self.widget(QtGui.QSpinBox, "titleSize")
     form.xLabel = self.widget(QtGui.QLineEdit, "titleX")
     form.xSize = self.widget(QtGui.QSpinBox, "xSize")
     form.yLabel = self.widget(QtGui.QLineEdit, "titleY")
     form.ySize = self.widget(QtGui.QSpinBox, "ySize")
     self.form = form
     self.retranslateUi()
     # Look for active axes if can
     axId = 0
     plt = Plot.getPlot()
     if plt:
         while plt.axes != plt.axesList[axId]:
             axId = axId + 1
         form.axId.setValue(axId)
     self.updateUI()
     QtCore.QObject.connect(form.axId,
                            QtCore.SIGNAL('valueChanged(int)'),
                            self.onAxesId)
     QtCore.QObject.connect(form.title,
                            QtCore.SIGNAL("editingFinished()"),
                            self.onLabels)
     QtCore.QObject.connect(form.xLabel,
                            QtCore.SIGNAL("editingFinished()"),
                            self.onLabels)
     QtCore.QObject.connect(form.yLabel,
                            QtCore.SIGNAL("editingFinished()"),
                            self.onLabels)
     QtCore.QObject.connect(form.titleSize,
                            QtCore.SIGNAL("valueChanged(int)"),
                            self.onFontSizes)
     QtCore.QObject.connect(form.xSize,
                            QtCore.SIGNAL("valueChanged(int)"),
                            self.onFontSizes)
     QtCore.QObject.connect(form.ySize,
                            QtCore.SIGNAL("valueChanged(int)"),
                            self.onFontSizes)
     QtCore.QObject.connect(
         Plot.getMdiArea(),
         QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"),
         self.onMdiArea)
     return False
Exemplo n.º 11
0
    def onLabels(self):
        """ Executed when labels have been modified. """
        plt = Plot.getPlot()
        if not plt:
            self.updateUI()
            return
        # Get again all the subwidgets (to avoid PySide Pitfalls)
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.title = self.widget(QtGui.QLineEdit, "title")
        form.xLabel = self.widget(QtGui.QLineEdit, "titleX")
        form.yLabel = self.widget(QtGui.QLineEdit, "titleY")

        Plot.title(unicode(form.title.text()))
        Plot.xlabel(unicode(form.xLabel.text()))
        Plot.ylabel(unicode(form.yLabel.text()))
        plt.update()
Exemplo n.º 12
0
    def onAlign(self, value):
        """Executed when axes align have been modified."""
        # Ensure that we can work
        plt = Plot.getPlot()
        if not plt:
            self.updateUI()
            return
        # Get again all the subwidgets (to avoid PySide Pitfalls)
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.all = self.widget(QtGui.QCheckBox, "allAxes")
        form.xAlign = self.widget(QtGui.QComboBox, "xAlign")
        form.yAlign = self.widget(QtGui.QComboBox, "yAlign")

        axesList = [plt.axes]
        if form.all.isChecked():
            axesList = plt.axesList
        # Set new alignment
        for axes in axesList:
            if form.xAlign.currentIndex() == 0:
                axes.xaxis.tick_bottom()
                axes.spines['bottom'].set_color((0.0, 0.0, 0.0))
                axes.spines['top'].set_color('none')
                axes.xaxis.set_ticks_position('bottom')
                axes.xaxis.set_label_position('bottom')
            else:
                axes.xaxis.tick_top()
                axes.spines['top'].set_color((0.0, 0.0, 0.0))
                axes.spines['bottom'].set_color('none')
                axes.xaxis.set_ticks_position('top')
                axes.xaxis.set_label_position('top')
            if form.yAlign.currentIndex() == 0:
                axes.yaxis.tick_left()
                axes.spines['left'].set_color((0.0, 0.0, 0.0))
                axes.spines['right'].set_color('none')
                axes.yaxis.set_ticks_position('left')
                axes.yaxis.set_label_position('left')
            else:
                axes.yaxis.tick_right()
                axes.spines['right'].set_color((0.0, 0.0, 0.0))
                axes.spines['left'].set_color('none')
                axes.yaxis.set_ticks_position('right')
                axes.yaxis.set_label_position('right')
        plt.update()
Exemplo n.º 13
0
 def updateUI(self):
     """Setup the UI control values if it is possible."""
     mw = self.getMainWindow()
     form = mw.findChild(QtGui.QWidget, "TaskPanel")
     form.items = self.widget(QtGui.QListWidget, "items")
     form.x = self.widget(QtGui.QDoubleSpinBox, "x")
     form.y = self.widget(QtGui.QDoubleSpinBox, "y")
     form.s = self.widget(QtGui.QDoubleSpinBox, "size")
     plt = Plot.getPlot()
     form.items.setEnabled(bool(plt))
     form.x.setEnabled(bool(plt))
     form.y.setEnabled(bool(plt))
     form.s.setEnabled(bool(plt))
     if not plt:
         self.plt = plt
         form.items.clear()
         return
     # Refill items list only if Plot instance have been changed
     if self.plt != plt:
         self.plt = plt
         self.plt.update()
         self.setList()
     # Get data for controls
     name = self.names[self.item]
     obj = self.objs[self.item]
     if name.find('title') >= 0 or name.find('label') >= 0:
         p = obj.get_position()
         x = p[0]
         y = p[1]
         s = obj.get_size()
         if name.find('x label') >= 0:
             form.y.setEnabled(False)
             form.y.setValue(x)
         elif name.find('y label') >= 0:
             form.x.setEnabled(False)
             form.x.setValue(y)
     else:
         x = plt.legPos[0]
         y = plt.legPos[1]
         s = obj.get_texts()[-1].get_fontsize()
     # Send it to controls
     form.x.setValue(x)
     form.y.setValue(y)
     form.s.setValue(s)
Exemplo n.º 14
0
    def onFontSizes(self, value):
        """ Executed when font sizes have been modified. """
        # Get apply environment
        plt = Plot.getPlot()
        if not plt:
            self.updateUI()
            return
        # Get again all the subwidgets (to avoid PySide Pitfalls)
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.titleSize = self.widget(QtGui.QSpinBox, "titleSize")
        form.xSize = self.widget(QtGui.QSpinBox, "xSize")
        form.ySize = self.widget(QtGui.QSpinBox, "ySize")

        ax = plt.axes
        ax.title.set_fontsize(form.titleSize.value())
        ax.xaxis.label.set_fontsize(form.xSize.value())
        ax.yaxis.label.set_fontsize(form.ySize.value())
        plt.update()
Exemplo n.º 15
0
    def updateUI(self):
        """ Setup UI controls values if possible """
        # Get again all the subwidgets (to avoid PySide Pitfalls)
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.axId = self.widget(QtGui.QSpinBox, "axesIndex")
        form.title = self.widget(QtGui.QLineEdit, "title")
        form.titleSize = self.widget(QtGui.QSpinBox, "titleSize")
        form.xLabel = self.widget(QtGui.QLineEdit, "titleX")
        form.xSize = self.widget(QtGui.QSpinBox, "xSize")
        form.yLabel = self.widget(QtGui.QLineEdit, "titleY")
        form.ySize = self.widget(QtGui.QSpinBox, "ySize")

        plt = Plot.getPlot()
        form.axId.setEnabled(bool(plt))
        form.title.setEnabled(bool(plt))
        form.titleSize.setEnabled(bool(plt))
        form.xLabel.setEnabled(bool(plt))
        form.xSize.setEnabled(bool(plt))
        form.yLabel.setEnabled(bool(plt))
        form.ySize.setEnabled(bool(plt))
        if not plt:
            return
        # Ensure that active axes is correct
        index = min(form.axId.value(), len(plt.axesList) - 1)
        form.axId.setValue(index)
        # Store data before starting changing it.

        ax = plt.axes
        t = ax.get_title()
        x = ax.get_xlabel()
        y = ax.get_ylabel()
        tt = ax.title.get_fontsize()
        xx = ax.xaxis.label.get_fontsize()
        yy = ax.yaxis.label.get_fontsize()
        # Set labels
        form.title.setText(t)
        form.xLabel.setText(x)
        form.yLabel.setText(y)
        # Set font sizes
        form.titleSize.setValue(tt)
        form.xSize.setValue(xx)
        form.ySize.setValue(yy)
Exemplo n.º 16
0
 def onData(self):
     """Executed when the selected item data is modified."""
     if not self.skip:
         self.skip = True
         plt = Plot.getPlot()
         if not plt:
             self.updateUI()
             return
         mw = self.getMainWindow()
         form = mw.findChild(QtGui.QWidget, "TaskPanel")
         form.label = self.widget(QtGui.QLineEdit, "label")
         form.isLabel = self.widget(QtGui.QCheckBox, "isLabel")
         form.style = self.widget(QtGui.QComboBox, "lineStyle")
         form.marker = self.widget(QtGui.QComboBox, "markers")
         form.width = self.widget(QtGui.QDoubleSpinBox, "lineWidth")
         form.size = self.widget(QtGui.QSpinBox, "markerSize")
         # Ensure that selected serie exist
         if self.item >= len(Plot.series()):
             self.updateUI()
             return
         # Set label
         serie = Plot.series()[self.item]
         if (form.isLabel.isChecked()):
             serie.name = None
             form.label.setEnabled(False)
         else:
             serie.name = form.label.text()
             form.label.setEnabled(True)
         # Set line style and marker
         style = form.style.currentIndex()
         linestyles = list(Line2D.lineStyles.keys())
         serie.line.set_linestyle(linestyles[style])
         marker = form.marker.currentIndex()
         markers = list(Line2D.markers.keys())
         serie.line.set_marker(markers[marker])
         # Set line width and marker size
         serie.line.set_linewidth(form.width.value())
         serie.line.set_markersize(form.size.value())
         plt.update()
         # Regenerate series labels
         self.setList()
         self.skip = False
Exemplo n.º 17
0
 def accept(self):
     plt = Plot.getPlot()
     if not plt:
         msg = QtGui.QApplication.translate(
             "plot_console",
             "Plot document must be selected in order to save it", None)
         App.Console.PrintError(msg + "\n")
         return False
     mw = self.getMainWindow()
     form = mw.findChild(QtGui.QWidget, "TaskPanel")
     form.path = self.widget(QtGui.QLineEdit, "path")
     form.sizeX = self.widget(QtGui.QDoubleSpinBox, "sizeX")
     form.sizeY = self.widget(QtGui.QDoubleSpinBox, "sizeY")
     form.dpi = self.widget(QtGui.QSpinBox, "dpi")
     try:
         path = unicode(form.path.text())
     except NameError:
         path = str(form.path.text())
     size = (form.sizeX.value(), form.sizeY.value())
     dpi = form.dpi.value()
     Plot.save(path, size, dpi)
     return True
Exemplo n.º 18
0
    def onAxesId(self, value):
        """ Executed when axes index is modified. """
        if not self.skip:
            self.skip = True
            # No active plot case
            plt = Plot.getPlot()
            if not plt:
                self.updateUI()
                self.skip = False
                return
            # Get again all the subwidgets (to avoid PySide Pitfalls)
            mw = self.getMainWindow()
            form = mw.findChild(QtGui.QWidget, "TaskPanel")
            form.axId = self.widget(QtGui.QSpinBox, "axesIndex")

            form.axId.setMaximum(len(plt.axesList))
            if form.axId.value() >= len(plt.axesList):
                form.axId.setValue(len(plt.axesList) - 1)
            # Send new control to Plot instance
            plt.setActiveAxes(form.axId.value())
            self.updateUI()
            self.skip = False
Exemplo n.º 19
0
 def updateUI(self):
     """ Setup UI controls values if possible """
     mw = self.getMainWindow()
     form = mw.findChild(QtGui.QWidget, "TaskPanel")
     form.path = self.widget(QtGui.QLineEdit, "path")
     form.pathButton = self.widget(QtGui.QPushButton, "pathButton")
     form.sizeX = self.widget(QtGui.QDoubleSpinBox, "sizeX")
     form.sizeY = self.widget(QtGui.QDoubleSpinBox, "sizeY")
     form.dpi = self.widget(QtGui.QSpinBox, "dpi")
     plt = Plot.getPlot()
     form.path.setEnabled(bool(plt))
     form.pathButton.setEnabled(bool(plt))
     form.sizeX.setEnabled(bool(plt))
     form.sizeY.setEnabled(bool(plt))
     form.dpi.setEnabled(bool(plt))
     if not plt:
         return
     fig = plt.fig
     size = fig.get_size_inches()
     dpi = fig.get_dpi()
     form.sizeX.setValue(size[0])
     form.sizeY.setValue(size[1])
     form.dpi.setValue(dpi)
Exemplo n.º 20
0
    def onColor(self):
        """ Executed when color palette is requested. """
        plt = Plot.getPlot()
        if not plt:
            self.updateUI()
            return
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.color = self.widget(QtGui.QPushButton, "color")

        # Ensure that selected serie exist
        if self.item >= len(Plot.series()):
            self.updateUI()
            return
        # Show widget to select color
        col = QtGui.QColorDialog.getColor()
        # Send color to widget and serie
        if col.isValid():
            serie = plt.series[self.item]
            form.color.setStyleSheet(
                "background-color: rgb({}, {}, {});".format(
                    col.red(), col.green(), col.blue()))
            serie.line.set_color((col.redF(), col.greenF(), col.blueF()))
            plt.update()
Exemplo n.º 21
0
 def setupUi(self):
     mw = self.getMainWindow()
     form = mw.findChild(QtGui.QWidget, "TaskPanel")
     self.form = form
     form.axId = self.widget(QtGui.QSpinBox, "axesIndex")
     form.new = self.widget(QtGui.QPushButton, "newAxesButton")
     form.remove = self.widget(QtGui.QPushButton, "delAxesButton")
     form.all = self.widget(QtGui.QCheckBox, "allAxes")
     form.xMin = self.widget(QtGui.QSlider, "posXMin")
     form.xMax = self.widget(QtGui.QSlider, "posXMax")
     form.yMin = self.widget(QtGui.QSlider, "posYMin")
     form.yMax = self.widget(QtGui.QSlider, "posYMax")
     form.xAlign = self.widget(QtGui.QComboBox, "xAlign")
     form.yAlign = self.widget(QtGui.QComboBox, "yAlign")
     form.xOffset = self.widget(QtGui.QSpinBox, "xOffset")
     form.yOffset = self.widget(QtGui.QSpinBox, "yOffset")
     form.xAuto = self.widget(QtGui.QCheckBox, "xAuto")
     form.yAuto = self.widget(QtGui.QCheckBox, "yAuto")
     form.xSMin = self.widget(QtGui.QLineEdit, "xMin")
     form.xSMax = self.widget(QtGui.QLineEdit, "xMax")
     form.ySMin = self.widget(QtGui.QLineEdit, "yMin")
     form.ySMax = self.widget(QtGui.QLineEdit, "yMax")
     self.retranslateUi()
     # Look for active axes if can
     axId = 0
     plt = Plot.getPlot()
     if plt:
         while plt.axes != plt.axesList[axId]:
             axId = axId + 1
         form.axId.setValue(axId)
     self.updateUI()
     QtCore.QObject.connect(form.axId, QtCore.SIGNAL('valueChanged(int)'),
                            self.onAxesId)
     QtCore.QObject.connect(form.new, QtCore.SIGNAL("pressed()"),
                            self.onNew)
     QtCore.QObject.connect(form.remove, QtCore.SIGNAL("pressed()"),
                            self.onRemove)
     QtCore.QObject.connect(form.xMin, QtCore.SIGNAL("valueChanged(int)"),
                            self.onDims)
     QtCore.QObject.connect(form.xMax, QtCore.SIGNAL("valueChanged(int)"),
                            self.onDims)
     QtCore.QObject.connect(form.yMin, QtCore.SIGNAL("valueChanged(int)"),
                            self.onDims)
     QtCore.QObject.connect(form.yMax, QtCore.SIGNAL("valueChanged(int)"),
                            self.onDims)
     QtCore.QObject.connect(form.xAlign,
                            QtCore.SIGNAL("currentIndexChanged(int)"),
                            self.onAlign)
     QtCore.QObject.connect(form.yAlign,
                            QtCore.SIGNAL("currentIndexChanged(int)"),
                            self.onAlign)
     QtCore.QObject.connect(form.xOffset,
                            QtCore.SIGNAL("valueChanged(int)"),
                            self.onOffset)
     QtCore.QObject.connect(form.yOffset,
                            QtCore.SIGNAL("valueChanged(int)"),
                            self.onOffset)
     QtCore.QObject.connect(form.xAuto, QtCore.SIGNAL("stateChanged(int)"),
                            self.onScales)
     QtCore.QObject.connect(form.yAuto, QtCore.SIGNAL("stateChanged(int)"),
                            self.onScales)
     QtCore.QObject.connect(form.xSMin, QtCore.SIGNAL("editingFinished()"),
                            self.onScales)
     QtCore.QObject.connect(form.xSMax, QtCore.SIGNAL("editingFinished()"),
                            self.onScales)
     QtCore.QObject.connect(form.ySMin, QtCore.SIGNAL("editingFinished()"),
                            self.onScales)
     QtCore.QObject.connect(form.ySMax, QtCore.SIGNAL("editingFinished()"),
                            self.onScales)
     QtCore.QObject.connect(
         Plot.getMdiArea(),
         QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"),
         self.onMdiArea)
     return False
Exemplo n.º 22
0
 def updateUI(self):
     """ Setup UI controls values if possible """
     mw = self.getMainWindow()
     form = mw.findChild(QtGui.QWidget, "TaskPanel")
     form.items = self.widget(QtGui.QListWidget, "items")
     form.label = self.widget(QtGui.QLineEdit, "label")
     form.isLabel = self.widget(QtGui.QCheckBox, "isLabel")
     form.style = self.widget(QtGui.QComboBox, "lineStyle")
     form.marker = self.widget(QtGui.QComboBox, "markers")
     form.width = self.widget(QtGui.QDoubleSpinBox, "lineWidth")
     form.size = self.widget(QtGui.QSpinBox, "markerSize")
     form.color = self.widget(QtGui.QPushButton, "color")
     form.remove = self.widget(QtGui.QPushButton, "remove")
     plt = Plot.getPlot()
     form.items.setEnabled(bool(plt))
     form.label.setEnabled(bool(plt))
     form.isLabel.setEnabled(bool(plt))
     form.style.setEnabled(bool(plt))
     form.marker.setEnabled(bool(plt))
     form.width.setEnabled(bool(plt))
     form.size.setEnabled(bool(plt))
     form.color.setEnabled(bool(plt))
     form.remove.setEnabled(bool(plt))
     if not plt:
         self.plt = plt
         form.items.clear()
         return
     self.skip = True
     # Refill list
     if self.plt != plt or len(Plot.series()) != form.items.count():
         self.plt = plt
         self.setList()
     # Ensure that have series
     if not len(Plot.series()):
         form.label.setEnabled(False)
         form.isLabel.setEnabled(False)
         form.style.setEnabled(False)
         form.marker.setEnabled(False)
         form.width.setEnabled(False)
         form.size.setEnabled(False)
         form.color.setEnabled(False)
         form.remove.setEnabled(False)
         return
     # Set label
     serie = Plot.series()[self.item]
     if serie.name is None:
         form.isLabel.setChecked(True)
         form.label.setEnabled(False)
         form.label.setText("")
     else:
         form.isLabel.setChecked(False)
         form.label.setText(serie.name)
     # Set line style and marker
     form.style.setCurrentIndex(0)
     linestyles = list(Line2D.lineStyles.keys())
     for i in range(0, len(linestyles)):
         style = linestyles[i]
         if style == serie.line.get_linestyle():
             form.style.setCurrentIndex(i)
     form.marker.setCurrentIndex(0)
     markers = list(Line2D.markers.keys())
     for i in range(0, len(markers)):
         marker = markers[i]
         if marker == serie.line.get_marker():
             form.marker.setCurrentIndex(i)
     # Set line width and marker size
     form.width.setValue(serie.line.get_linewidth())
     form.size.setValue(serie.line.get_markersize())
     # Set color
     color = Colors.colorConverter.to_rgb(serie.line.get_color())
     form.color.setStyleSheet("background-color: rgb({}, {}, {});".format(
         int(color[0] * 255), int(color[1] * 255), int(color[2] * 255)))
     self.skip = False
Exemplo n.º 23
0
    def onScales(self):
        """Executed when axes scales have been modified."""
        # Ensure that we can work
        plt = Plot.getPlot()
        if not plt:
            self.updateUI()
            return
        # Get again all the subwidgets (to avoid PySide Pitfalls)
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.all = self.widget(QtGui.QCheckBox, "allAxes")
        form.xAuto = self.widget(QtGui.QCheckBox, "xAuto")
        form.yAuto = self.widget(QtGui.QCheckBox, "yAuto")
        form.xSMin = self.widget(QtGui.QLineEdit, "xMin")
        form.xSMax = self.widget(QtGui.QLineEdit, "xMax")
        form.ySMin = self.widget(QtGui.QLineEdit, "yMin")
        form.ySMax = self.widget(QtGui.QLineEdit, "yMax")

        axesList = [plt.axes]
        if form.all.isChecked():
            axesList = plt.axesList
        if not self.skip:
            self.skip = True
            # X axis
            if form.xAuto.isChecked():
                for ax in axesList:
                    ax.set_autoscalex_on(True)
                form.xSMin.setEnabled(False)
                form.xSMax.setEnabled(False)
                lim = plt.axes.get_xlim()
                form.xSMin.setText(str(lim[0]))
                form.xSMax.setText(str(lim[1]))
            else:
                form.xSMin.setEnabled(True)
                form.xSMax.setEnabled(True)
                try:
                    xMin = float(form.xSMin.text())
                except:
                    xMin = plt.axes.get_xlim()[0]
                    form.xSMin.setText(str(xMin))
                try:
                    xMax = float(form.xSMax.text())
                except:
                    xMax = plt.axes.get_xlim()[1]
                    form.xSMax.setText(str(xMax))
                for ax in axesList:
                    ax.set_xlim((xMin, xMax))
            # Y axis
            if form.yAuto.isChecked():
                for ax in axesList:
                    ax.set_autoscaley_on(True)
                form.ySMin.setEnabled(False)
                form.ySMax.setEnabled(False)
                lim = plt.axes.get_ylim()
                form.ySMin.setText(str(lim[0]))
                form.ySMax.setText(str(lim[1]))
            else:
                form.ySMin.setEnabled(True)
                form.ySMax.setEnabled(True)
                try:
                    yMin = float(form.ySMin.text())
                except:
                    yMin = plt.axes.get_ylim()[0]
                    form.ySMin.setText(str(yMin))
                try:
                    yMax = float(form.ySMax.text())
                except:
                    yMax = plt.axes.get_ylim()[1]
                    form.ySMax.setText(str(yMax))
                for ax in axesList:
                    ax.set_ylim((yMin, yMax))
            plt.update()
            self.skip = False
Exemplo n.º 24
0
 def updateUI(self):
     """Setup UI controls values if possible"""
     plt = Plot.getPlot()
     # Get again all the subwidgets (to avoid PySide Pitfalls)
     mw = self.getMainWindow()
     form = mw.findChild(QtGui.QWidget, "TaskPanel")
     form.axId = self.widget(QtGui.QSpinBox, "axesIndex")
     form.new = self.widget(QtGui.QPushButton, "newAxesButton")
     form.remove = self.widget(QtGui.QPushButton, "delAxesButton")
     form.all = self.widget(QtGui.QCheckBox, "allAxes")
     form.xMin = self.widget(QtGui.QSlider, "posXMin")
     form.xMax = self.widget(QtGui.QSlider, "posXMax")
     form.yMin = self.widget(QtGui.QSlider, "posYMin")
     form.yMax = self.widget(QtGui.QSlider, "posYMax")
     form.xAlign = self.widget(QtGui.QComboBox, "xAlign")
     form.yAlign = self.widget(QtGui.QComboBox, "yAlign")
     form.xOffset = self.widget(QtGui.QSpinBox, "xOffset")
     form.yOffset = self.widget(QtGui.QSpinBox, "yOffset")
     form.xAuto = self.widget(QtGui.QCheckBox, "xAuto")
     form.yAuto = self.widget(QtGui.QCheckBox, "yAuto")
     form.xSMin = self.widget(QtGui.QLineEdit, "xMin")
     form.xSMax = self.widget(QtGui.QLineEdit, "xMax")
     form.ySMin = self.widget(QtGui.QLineEdit, "yMin")
     form.ySMax = self.widget(QtGui.QLineEdit, "yMax")
     # Enable/disable them
     form.axId.setEnabled(bool(plt))
     form.new.setEnabled(bool(plt))
     form.remove.setEnabled(bool(plt))
     form.all.setEnabled(bool(plt))
     form.xMin.setEnabled(bool(plt))
     form.xMax.setEnabled(bool(plt))
     form.yMin.setEnabled(bool(plt))
     form.yMax.setEnabled(bool(plt))
     form.xAlign.setEnabled(bool(plt))
     form.yAlign.setEnabled(bool(plt))
     form.xOffset.setEnabled(bool(plt))
     form.yOffset.setEnabled(bool(plt))
     form.xAuto.setEnabled(bool(plt))
     form.yAuto.setEnabled(bool(plt))
     form.xSMin.setEnabled(bool(plt))
     form.xSMax.setEnabled(bool(plt))
     form.ySMin.setEnabled(bool(plt))
     form.ySMax.setEnabled(bool(plt))
     if not plt:
         form.axId.setValue(0)
         return
     # Ensure that active axes is correct
     index = min(form.axId.value(), len(plt.axesList) - 1)
     form.axId.setValue(index)
     # Set dimensions
     ax = plt.axes
     bb = ax.get_position()
     form.xMin.setValue(int(100 * bb.min[0]))
     form.xMax.setValue(int(100 * bb.max[0]))
     form.yMin.setValue(int(100 * bb.min[1]))
     form.yMax.setValue(int(100 * bb.max[1]))
     # Set alignment and offset
     xPos = ax.xaxis.get_ticks_position()
     yPos = ax.yaxis.get_ticks_position()
     xOffset = ax.spines['bottom'].get_position()[1]
     yOffset = ax.spines['left'].get_position()[1]
     if xPos == 'bottom' or xPos == 'default':
         form.xAlign.setCurrentIndex(0)
     else:
         form.xAlign.setCurrentIndex(1)
     form.xOffset.setValue(xOffset)
     if yPos == 'left' or yPos == 'default':
         form.yAlign.setCurrentIndex(0)
     else:
         form.yAlign.setCurrentIndex(1)
     form.yOffset.setValue(yOffset)
     # Set scales
     if ax.get_autoscalex_on():
         form.xAuto.setChecked(True)
         form.xSMin.setEnabled(False)
         form.xSMax.setEnabled(False)
     else:
         form.xAuto.setChecked(False)
         form.xSMin.setEnabled(True)
         form.xSMax.setEnabled(True)
     lim = ax.get_xlim()
     form.xSMin.setText(str(lim[0]))
     form.xSMax.setText(str(lim[1]))
     if ax.get_autoscaley_on():
         form.yAuto.setChecked(True)
         form.ySMin.setEnabled(False)
         form.ySMax.setEnabled(False)
     else:
         form.yAuto.setChecked(False)
         form.ySMin.setEnabled(True)
         form.ySMax.setEnabled(True)
     lim = ax.get_ylim()
     form.ySMin.setText(str(lim[0]))
     form.ySMax.setText(str(lim[1]))