示例#1
0
    def divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize):
        ''' Reimplements qwt.QwtLinearScaleEngine.divideScale

        :return: (qwt.QwtScaleDiv) a scale division whose ticks are aligned with
                 the natural delta time units '''
        interval = qwt.QwtInterval(x1, x2).normalized()
        if interval.width() <= 0:
            return qwt.QwtScaleDiv()
        d_range = interval.width()
        if d_range < 2:  # 2s
            return qwt.QwtLinearScaleEngine.divideScale(
                self, x1, x2, maxMajSteps, maxMinSteps, stepSize)
        elif d_range < 20:  # 20 s
            s = 1
        elif d_range < 120:  # =60s*2 = 2 minutes
            s = 10
        elif d_range < 1200:  # 60s*20 =20 minutes
            s = 60
        elif d_range < 7200:  # 3600s*2 = 2 hours
            s = 600
        elif d_range < 172800:  # 3600s24*2 = 2 days
            s = 3600
        else:
            s = 86400  # 1 day
        # calculate a step size that respects the base step (s) and also
        # enforces the maxMajSteps
        stepSize = s * int(numpy.ceil(float(d_range // s) / maxMajSteps))
        return qwt.QwtLinearScaleEngine.divideScale(self, x1, x2, maxMajSteps,
                                                    maxMinSteps, stepSize)
示例#2
0
 def label(self, val):
     if str(self._labelFormat) == "":
         return qwt.QwtText()
     if self._labelFormat is None:
         return qwt.QwtScaleDraw.label(self, val)
     else:
         return qwt.QwtText(self._labelFormat % val)
示例#3
0
 def label(self, val):
     try:
         index = self._positions.index(val)  # try to find an exact match
     except:
         index = None  # It won't show any label
         # use the index of the closest position
         #index = (numpy.abs(self._positionsarray - val)).argmin()
     if index is not None:
         return qwt.QwtText(self._labels[index])
     else:
         qwt.QwtText()
示例#4
0
 def label(self, val):
     if str(self._labelFormat) == "":
         return qwt.QwtText()
     # From val to a string with time
     t = datetime.fromtimestamp(val)
     try:  # If the scaleDiv was created by a DateTimeScaleEngine it has a _datetimeLabelFormat
         s = t.strftime(self._datetimeLabelFormat)
     except AttributeError as e:
         print(
             "Warning: cannot get the datetime label format (Are you using a DateTimeScaleEngine?)"
         )
         s = t.isoformat(' ')
     return qwt.QwtText(s)
示例#5
0
    def disableInAxis(plot, axis, scaleDraw=None, scaleEngine=None):
        '''convenience method that will disable this engine in the given
        axis. Note that it changes the ScaleDraw as well.

        :param plot: (qwt.QwtPlot) the plot to change
        :param axis: (qwt.QwtPlot.Axis) the id of the axis
        :param scaleDraw: (qwt.QwtScaleDraw) Scale draw to use. If None given,
                          a :class:`FancyScaleDraw` will be set
        :param scaleEngine: (qwt.QwtScaleEngine) Scale draw to use. If None given,
                          a :class:`qwt.QwtLinearScaleEngine` will be set
        '''
        if scaleDraw is None:
            scaleDraw = FancyScaleDraw()
        if scaleEngine is None:
            scaleEngine = qwt.QwtLinearScaleEngine()
        plot.setAxisScaleEngine(axis, scaleEngine)
        plot.setAxisScaleDraw(axis, scaleDraw)
示例#6
0
class TaurusTimeScaleDraw(FancyScaleDraw):
    def __init__(self, *args):
        FancyScaleDraw.__init__(self, *args)

    def setDatetimeLabelFormat(self, format):
        self._datetimeLabelFormat = format

    def datetimeLabelFormat(self):
        return self._datetimeLabelFormat

    def label(self, val):
        if str(self._labelFormat) == "":
            return qwt.QwtText()
        # From val to a string with time
        t = datetime.fromtimestamp(val)
        try:  # If the scaleDiv was created by a DateTimeScaleEngine it has a _datetimeLabelFormat
            s = t.strftime(self._datetimeLabelFormat)
        except AttributeError, e:
            print "Warning: cannot get the datetime label format (Are you using a DateTimeScaleEngine?)"
            s = t.isoformat(' ')
        return qwt.QwtText(s)
示例#7
0
    def __init__(self, parent=None):
        Qt.QWidget.__init__(self, parent)
        self.loadUi()

        self._controllers = []

        # construct the layout for controllers container
        self.ctrlLayout = Qt.QHBoxLayout(self.controllersContainer)
        self.ctrlLayout.setContentsMargins(5, 0, 5, 0)
        self.ctrlLayout.setSpacing(1)

        # implement scroll bars for the controllers container
        self.scrollArea = Qt.QScrollArea(self)
        self.scrollArea.setWidget(self.controllersContainer)
        self.scrollArea.setVerticalScrollBarPolicy(Qt.Qt.ScrollBarAlwaysOff)
        self.scrollArea.setWidgetResizable(True)
        self.cpointsGroupBox.layout().insertWidget(0, self.scrollArea)

        # initialize data
        cpoints = 2
        self.x = numpy.arange(256, dtype='double')
        self.y = numpy.zeros(256, dtype='double')
        self.xp = numpy.linspace(self.x[0], self.x[-1], cpoints)
        self.corrp = numpy.zeros(cpoints)
        self.yp = numpy.interp(self.xp, self.x, self.y)
        self.corr = numpy.zeros(self.x.size)

        # markers
        self.markerPos = self.xp[0]
        self.marker1 = Qwt5.QwtPlotMarker()
        self.marker1.setSymbol(
            Qwt5.QwtSymbol(Qwt5.QwtSymbol.Rect, Qt.QBrush(Qt.Qt.NoBrush),
                           Qt.QPen(Qt.Qt.green), Qt.QSize(8, 8)))
        self.marker1.attach(self.plot1)
        self.marker2 = Qwt5.QwtPlotMarker()
        self.marker2.setSymbol(
            Qwt5.QwtSymbol(Qwt5.QwtSymbol.Rect, Qt.QBrush(Qt.Qt.NoBrush),
                           Qt.QPen(Qt.Qt.green), Qt.QSize(8, 8)))
        self.marker2.attach(self.plot2)

        # cpointsPickers
        self._cpointMovingIndex = None
        self._cpointsPicker1 = Qwt5.QwtPicker(self.plot1.canvas())
        self._cpointsPicker1.setSelectionFlags(Qwt5.QwtPicker.PointSelection)
        self._cpointsPicker2 = Qwt5.QwtPicker(self.plot2.canvas())
        self._cpointsPicker2.setSelectionFlags(Qwt5.QwtPicker.PointSelection)
        self._cpointsPicker1.widgetMousePressEvent = self.plot1MousePressEvent
        self._cpointsPicker1.widgetMouseReleaseEvent = self.plot1MouseReleaseEvent
        self._cpointsPicker2.widgetMousePressEvent = self.plot2MousePressEvent
        self._cpointsPicker2.widgetMouseReleaseEvent = self.plot2MouseReleaseEvent
        self._cpointsPicker1.widgetMouseDoubleClickEvent = self.plot1MouseDoubleClickEvent
        self._cpointsPicker2.widgetMouseDoubleClickEvent = self.plot2MouseDoubleClickEvent
        self._populatePlots()
        self.resetCorrection()
        self._selectedController = self._controllers[0]

        self._addCPointsDialog = AddCPointsDialog(self)

        # Launch low-priority initializations (to speed up load time)
        # Qt.QTimer.singleShot(0, <method>)

        # connections
        self.addCPointsBT.clicked.connect(self._addCPointsDialog.show)
        self._addCPointsDialog.editBT.clicked.connect(
            self.showEditCPointsDialog)
        self._addCPointsDialog.cleanBT.clicked.connect(self.resetCorrection)
        self._addCPointsDialog.addSingleCPointBT.clicked.connect(
            self.onAddSingleCPointBT)
        self._addCPointsDialog.addRegEspCPointsBT.clicked.connect(
            self.onAddRegEspCPointsBT)
示例#8
0
    def __init__(self, parent=None):
        super(CurveStatsDialog, self).__init__(parent)
        self.loadUi()

        plot = parent
        xIsTime = plot.getXIsTime()
        self.ui.minDTE.setVisible(xIsTime)
        self.ui.maxDTE.setVisible(xIsTime)
        self.ui.minSB.setVisible(not xIsTime)
        self.ui.maxSB.setVisible(not xIsTime)

        self.ui.minSB.setMinimum(float('-inf'))
        self.ui.minSB.setMaximum(float('inf'))
        self.ui.maxSB.setMinimum(float('-inf'))
        self.ui.maxSB.setMaximum(float('inf'))

        icon = getIcon(':/actions/system-search.svg')
        self.ui.selectMinPB.setIcon(icon)
        self.ui.selectMaxPB.setIcon(icon)

        self.refreshCurves()

        cbs = (self.ui.npointsStatCB, self.ui.minStatCB, self.ui.maxStatCB,
               self.ui.meanStatCB, self.ui.stdStatCB, self.ui.rmsStatCB)
        self._checkboxToColMap = dict(zip(cbs, xrange(len(self.statColumns))))

        self.minPicker = Qwt5.QwtPlotPicker(Qwt5.QwtPlot.xBottom,
                                            Qwt5.QwtPlot.yLeft,
                                            Qwt5.QwtPicker.PointSelection,
                                            Qwt5.QwtPicker.VLineRubberBand,
                                            Qwt5.QwtPicker.AlwaysOn, plot.canvas())

        self.maxPicker = Qwt5.QwtPlotPicker(Qwt5.QwtPlot.xBottom,
                                            Qwt5.QwtPlot.yLeft,
                                            Qwt5.QwtPicker.PointSelection,
                                            Qwt5.QwtPicker.VLineRubberBand,
                                            Qwt5.QwtPicker.AlwaysOn, plot.canvas())

        self.minPicker.setEnabled(False)
        self.maxPicker.setEnabled(False)

        # initialize min and max display
        xmin = plot.axisScaleDiv(Qwt5.QwtPlot.xBottom).lowerBound()
        xmax = plot.axisScaleDiv(Qwt5.QwtPlot.xBottom).upperBound()

        self.minMarker = Qwt5.QwtPlotMarker()
        self.minMarker.setLineStyle(Qwt5.QwtPlotMarker.VLine)
        self.minMarker.setLinePen(Qt.QPen(Qt.Qt.green, 3))
        self.minMarker.setXValue(xmin)
        self.minMarker.attach(plot)
        self.minMarker.hide()

        self.maxMarker = Qwt5.QwtPlotMarker()
        self.maxMarker.setLineStyle(Qwt5.QwtPlotMarker.VLine)
        self.maxMarker.setLinePen(Qt.QPen(Qt.Qt.red, 3))
        self.maxMarker.setXValue(xmax)
        self.maxMarker.attach(plot)
        self.maxMarker.hide()

        if xIsTime:
            self.ui.minDTE.setDateTime(self._timestamptToQDateTime(xmin))
            self.ui.maxDTE.setDateTime(self._timestamptToQDateTime(xmax))
        else:
            self.ui.minSB.setValue(xmin)
            self.ui.maxSB.setValue(xmax)

        refreshAction = Qt.QAction(getThemeIcon(
            'view-refresh'), "Refresh available curves", self.ui.statsTW)
        refreshAction.setShortcut(Qt.Qt.Key_F5)
        self.connect(refreshAction, Qt.SIGNAL(
            "triggered()"), self.refreshCurves)
        self.ui.statsTW.addAction(refreshAction)

        # connections
        for cb in cbs:
            self.connect(cb, Qt.SIGNAL('toggled(bool)'), self.onStatToggled)
        self.connect(self.ui.calculatePB, Qt.SIGNAL(
            'clicked()'), self.onCalculate)
        self.connect(self.ui.selectMinPB, Qt.SIGNAL(
            'clicked()'), self.onSelectMin)
        self.connect(self.ui.selectMaxPB, Qt.SIGNAL(
            'clicked()'), self.onSelectMax)
        self.connect(self.minPicker, Qt.SIGNAL(
            'selected(QwtDoublePoint)'), self.minSelected)
        self.connect(self.maxPicker, Qt.SIGNAL(
            'selected(QwtDoublePoint)'), self.maxSelected)
        self.connect(self.ui.minSB, Qt.SIGNAL(
            'valueChanged(double)'), self.onMinChanged)
        self.connect(self.ui.minDTE, Qt.SIGNAL(
            'dateTimeChanged(QDateTime)'), self.onMinChanged)
        self.connect(self.ui.maxSB, Qt.SIGNAL(
            'valueChanged(double)'), self.onMaxChanged)
        self.connect(self.ui.maxDTE, Qt.SIGNAL(
            'dateTimeChanged(QDateTime)'), self.onMaxChanged)
        self.connect(self.ui.minCB, Qt.SIGNAL(
            'toggled(bool)'), self.onMinChanged)
        self.connect(self.ui.maxCB, Qt.SIGNAL(
            'toggled(bool)'), self.onMaxChanged)
示例#9
0
 def divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize=0.0):
     div = qwt.QwtScaleDiv(x1, x2, self._positions, [], [])
     div.setTicks(qwt.QwtScaleDiv.MajorTick, self._positions)
     return div
示例#10
0
 def label(self, val):
     if val >= 0:
         s = "+%s" % str(timedelta(seconds=val))
     else:
         s = "-%s" % str(timedelta(seconds=-val))
     return qwt.QwtText(s)
示例#11
0
    def divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize):
        ''' Reimplements qwt.QwtLinearScaleEngine.divideScale

        **Important**: The stepSize parameter is **ignored**.

        :return: (qwt.QwtScaleDiv) a scale division whose ticks are aligned with
                 the natural time units '''

        # if stepSize != 0:
        #    scaleDiv = qwt.QwtLinearScaleEngine.divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize)
        #    scaleDiv.datetimeLabelFormat = "%Y/%m/%d %H:%M%S.%f"
        #    return scaleDiv

        interval = qwt.QwtInterval(x1, x2).normalized()
        if interval.width() <= 0:
            return qwt.QwtScaleDiv()

        dt1 = datetime.fromtimestamp(interval.minValue())
        dt2 = datetime.fromtimestamp(interval.maxValue())

        if dt1.year < 1900 or dt2.year > 9999:  # limits in time.mktime and datetime
            return qwt.QwtScaleDiv()

        majticks = []
        medticks = []
        minticks = []

        dx = interval.width()

        # = 3600s*24*(365+366) = 2 years (counting a leap year)
        if dx > 63072001:
            format = "%Y"
            for y in range(dt1.year + 1, dt2.year):
                dt = datetime(year=y, month=1, day=1)
                majticks.append(mktime(dt.timetuple()))

        elif dx > 5270400:  # = 3600s*24*61 = 61 days
            format = "%Y %b"
            d = timedelta(days=31)
            dt = dt1.replace(day=1, hour=0, minute=0, second=0,
                             microsecond=0) + d
            while (dt < dt2):
                # make sure that we are on day 1 (even if always sum 31 days)
                dt = dt.replace(day=1)
                majticks.append(mktime(dt.timetuple()))
                dt += d

        elif dx > 172800:  # 3600s24*2 = 2 days
            format = "%b/%d"
            d = timedelta(days=1)
            dt = dt1.replace(hour=0, minute=0, second=0, microsecond=0) + d
            while (dt < dt2):
                majticks.append(mktime(dt.timetuple()))
                dt += d

        elif dx > 7200:  # 3600s*2 = 2hours
            format = "%b/%d-%Hh"
            d = timedelta(hours=1)
            dt = dt1.replace(minute=0, second=0, microsecond=0) + d
            while (dt < dt2):
                majticks.append(mktime(dt.timetuple()))
                dt += d

        elif dx > 1200:  # 60s*20 =20 minutes
            format = "%H:%M"
            d = timedelta(minutes=10)
            dt = dt1.replace(
                minute=(dt1.minute // 10) * 10, second=0, microsecond=0) + d
            while (dt < dt2):
                majticks.append(mktime(dt.timetuple()))
                dt += d

        elif dx > 120:  # =60s*2 = 2 minutes
            format = "%H:%M"
            d = timedelta(minutes=1)
            dt = dt1.replace(second=0, microsecond=0) + d
            while (dt < dt2):
                majticks.append(mktime(dt.timetuple()))
                dt += d

        elif dx > 20:  # 20 s
            format = "%H:%M:%S"
            d = timedelta(seconds=10)
            dt = dt1.replace(second=(dt1.second // 10) * 10, microsecond=0) + d
            while (dt < dt2):
                majticks.append(mktime(dt.timetuple()))
                dt += d

        elif dx > 2:  # 2s
            format = "%H:%M:%S"
            majticks = list(range(int(x1) + 1, int(x2)))

        else:  # less than 2s (show microseconds)
            scaleDiv = qwt.QwtLinearScaleEngine.divideScale(
                self, x1, x2, maxMajSteps, maxMinSteps, stepSize)
            self.scaleDraw().setDatetimeLabelFormat("%S.%f")
            return scaleDiv

        # make sure to comply with maxMajTicks
        L = len(majticks)
        if L > maxMajSteps:
            majticks = majticks[::int(numpy.ceil(float(L) / maxMajSteps))]

        scaleDiv = qwt.QwtScaleDiv(interval, minticks, medticks, majticks)
        self.scaleDraw().setDatetimeLabelFormat(format)
        if x1 > x2:
            scaleDiv.invert()

        # START DEBUG
        # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        # for tk in  scaleDiv.ticks(scaleDiv.MajorTick):
        #    print datetime.fromtimestamp(tk).isoformat()
        # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        # END DEBUG

        return scaleDiv