Example #1
0
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)
        DlgUtils.__init__(self, 'Live data')
        self.panel = parent
        layout1 = QVBoxLayout()
        self.plot = QwtPlot(self)
        layout1.addWidget(self.plot)
        self.curve = QwtPlotCurve()
        self.curve.setRenderHint(QwtPlotCurve.RenderAntialiased)
        self.curve.attach(self.plot)
        self.marker = QwtPlotMarker()
        self.marker.attach(self.plot)
        self.markerpen = QPen(Qt.red)
        self.marker.setSymbol(
            QwtSymbol(QwtSymbol.Ellipse, QBrush(), self.markerpen, QSize(7,
                                                                         7)))
        self.zoomer = QwtPlotZoomer(self.plot.canvas())
        self.zoomer.setMousePattern(QwtPlotZoomer.MouseSelect3, Qt.NoButton)
        self.picker = QwtPlotPicker(self.plot.canvas())
        self.picker.setSelectionFlags(QwtPlotPicker.PointSelection
                                      | QwtPlotPicker.ClickSelection)
        self.picker.setMousePattern(QwtPlotPicker.MouseSelect1, Qt.MidButton)
        self.picker.selected.connect(self.pickerSelected)
        layout2 = QHBoxLayout()
        layout2.addWidget(QLabel('Scale:', self))
        self.scale = QComboBox(self)
        self.scale.addItems([
            'Single detectors, sorted by angle',
            'Scattering angle 2theta (deg)', 'Q value (A-1)'
        ])
        self.scale.currentIndexChanged[int].connect(self.scaleChanged)
        layout2.addWidget(self.scale)
        layout2.addStretch()
        self.scaleframe = QFrame(self)
        self.scaleframe.setLayout(layout2)
        self.scaleframe.setVisible(False)
        layout1.addWidget(self.scaleframe)
        mainframe = QFrame(self)
        mainframe.setLayout(layout1)
        self.setCentralWidget(mainframe)
        self.setContentsMargins(6, 6, 6, 6)
        plotfont = scaledFont(self.font(), 0.7)
        self.plot.setAxisFont(QwtPlot.xBottom, plotfont)
        self.plot.setAxisFont(QwtPlot.yLeft, plotfont)
        self.plot.setCanvasBackground(Qt.white)
        self.resize(800, 200)

        self._detinfo = None
        self._anglemap = None
        self._infowindow = None
        self._infolabel = None
        self._xs = self._ys = None
        self._type = None
 def handle_y(self, evt):
     if evt.attr_value is not None:
         if evt.attr_value.value != self.y:
             self.y = evt.attr_value.value / 1e9
             self.mark = QwtPlotMarker()
             self.mark.setSymbol(self.sym)
             self.mark.attach(self.l_plot)
             self.mark.setValue(self.x, self.y)
             if len(self.list_mark) > 10:
                 self.list_mark[0].setVisible(False)
                 l_mark = self.list_mark[0]
                 self.list_mark.pop(0)
             for mark in self.list_mark:
                 mark.setSymbol(self.sym_old)
             self.list_mark.append(self.mark)
             self.trigger.emit()
Example #3
0
    def __init__(self, parent=None):
        super(TestPlot, self).__init__(parent)
        self.setWindowTitle("PyQwt" if USE_PYQWT5 else "PythonQwt")
        self.enableAxis(self.xTop, True)
        self.enableAxis(self.yRight, True)
        y = np.linspace(0, 10, 500)
        curve1 = QwtPlotCurve('Test Curve 1')
        curve1.setData(np.sin(y), y)
        curve2 = QwtPlotCurve('Test Curve 2')
        curve2.setData(y**3, y)
        if USE_PYQWT5:
            curve2.setAxis(self.xTop, self.yRight)
        else:
            # PythonQwt
            curve2.setAxes(self.xTop, self.yRight)

        for item, col, xa, ya in ((curve1, Qt.green, self.xBottom, self.yLeft),
                                  (curve2, Qt.red, self.xTop, self.yRight)):
            if not USE_PYQWT5:
                # PythonQwt
                item.setOrientation(Qt.Vertical)
            item.attach(self)
            item.setPen(QPen(col))
            for axis_id in xa, ya:
                palette = self.axisWidget(axis_id).palette()
                palette.setColor(QPalette.WindowText, QColor(col))
                palette.setColor(QPalette.Text, QColor(col))
                self.axisWidget(axis_id).setPalette(palette)
                ticks_font = self.axisFont(axis_id)
                self.setAxisFont(axis_id, ticks_font)

        self.canvas().setFrameStyle(0)  #QFrame.Panel|QFrame.Sunken)
        self.plotLayout().setCanvasMargin(0)
        self.axisWidget(QwtPlot.yLeft).setMargin(0)
        self.axisWidget(QwtPlot.xTop).setMargin(0)
        self.axisWidget(QwtPlot.yRight).setMargin(0)
        self.axisWidget(QwtPlot.xBottom).setMargin(0)

        self.marker = QwtPlotMarker()
        self.marker.setValue(0, 5)
        self.marker.attach(self)
    def handle_y(self, evt):
        if evt.attr_value is not None:
            if evt.attr_value.value != self.y:
	        self.y = evt.attr_value.value / 1e9
                self.mark = QwtPlotMarker()
                self.mark.setSymbol(self.sym)
                self.mark.attach(self.l_plot)
	        self.mark.setValue(self.x, self.y)
                if len(self.list_mark) > 10:
                    self.list_mark[0].setVisible(False)
                    l_mark = self.list_mark[0]
                    self.list_mark.pop(0)
                for mark in self.list_mark:
                    mark.setSymbol(self.sym_old)
                self.list_mark.append(self.mark)
                self.trigger.emit()
Example #5
0
    def __init__(self, parent=None):
        super(TestPlot, self).__init__(parent)
        self.setWindowTitle("PyQwt" if USE_PYQWT5 else "PythonQwt")
        self.enableAxis(self.xTop, True)
        self.enableAxis(self.yRight, True)
        y = np.linspace(0, 10, 500)
        curve1 = QwtPlotCurve('Test Curve 1')
        curve1.setData(np.sin(y), y)
        curve2 = QwtPlotCurve('Test Curve 2')
        curve2.setData(y**3, y)
        if USE_PYQWT5:
            curve2.setAxis(self.xTop, self.yRight)
        else:
            # PythonQwt
            curve2.setAxes(self.xTop, self.yRight)

        for item, col, xa, ya in ((curve1, Qt.green, self.xBottom, self.yLeft),
                                  (curve2, Qt.red, self.xTop, self.yRight)):
            if not USE_PYQWT5:
                # PythonQwt
                item.setOrientation(Qt.Vertical)
            item.attach(self)
            item.setPen(QPen(col))
            for axis_id in xa, ya:
                palette = self.axisWidget(axis_id).palette()
                palette.setColor(QPalette.WindowText, QColor(col))
                palette.setColor(QPalette.Text, QColor(col))
                self.axisWidget(axis_id).setPalette(palette)
                ticks_font = self.axisFont(axis_id)
                self.setAxisFont(axis_id, ticks_font)
        
        self.canvas().setFrameStyle(0)#QFrame.Panel|QFrame.Sunken)
        self.plotLayout().setCanvasMargin(0)
        self.axisWidget(QwtPlot.yLeft).setMargin(0)
        self.axisWidget(QwtPlot.xTop).setMargin(0)
        self.axisWidget(QwtPlot.yRight).setMargin(0)
        self.axisWidget(QwtPlot.xBottom).setMargin(0)

        self.marker = QwtPlotMarker()
        self.marker.setValue(0, 5)
        self.marker.attach(self)
class LiberaBrilliancePlusMini(TaurusWidget):
    l_plot = None
    trigger = QtCore.pyqtSignal()
    def __init__(self, parent=None, designMode=False):
        TaurusWidget.__init__(self, parent, designMode=designMode)
        
        self._ui = Ui_LiberaBrilliancePlusMini()
        self._ui.setupUi(self)

        self._ui.taurusCurveDialog = myTaurusCurveDialog(self)
        self._ui.taurusCurveDialog.setObjectName("taurusCurveDialog")
        self._ui.gridLayout.addWidget(self._ui.taurusCurveDialog, 0, 0, 1, 1)

        self.l_plot = self._ui.taurusCurveDialog.get_active_plot()
        self.sym = QwtSymbol(QwtSymbol.Ellipse, QtGui.QBrush(QtCore.Qt.blue), QtGui.QPen(QtCore.Qt.blue), QtCore.QSize(10, 10))
        self.sym_old = QwtSymbol(QwtSymbol.Ellipse, QtGui.QBrush(QtCore.Qt.gray), QtGui.QPen(QtCore.Qt.gray), QtCore.QSize(4, 4))
        self.l_plot.set_axis_limits('left', -0.003, 0.003)
        self.l_plot.set_axis_title('left', "Y")
        self.l_plot.set_axis_unit('left', "mm")
        self.l_plot.set_axis_limits('bottom', -0.003, 0.003)
        self.l_plot.set_axis_title('bottom', "X")
        self.l_plot.set_axis_unit('bottom', "mm")
        self.x = 0
        self.y = 0
        self.list_mark = []
        self.apply_color = True
        self.trigger.connect(self.update_plot)
        
    
    @classmethod
    def getQtDesignerPluginInfo(cls):
        ret = TaurusWidget.getQtDesignerPluginInfo()
        ret['module'] = 'liberabrillianceplusmini'
        ret['group'] = 'Taurus Display'
        ret['container'] = ':/designer/frame.png'
        ret['container'] = False
        return ret

    def setModel(self, models):
        from guiqwt.styles import style_generator        
        self._ui.taurusTrend.style = style_generator("brmgcykG")
        self._ui.taurusTrend.setModel(models[:2])
        index = models[0].rfind("/")
        self.model = models[0][:index]
        self.dev = PyTango.DeviceProxy(self.model)
        self.id1 = self.dev.subscribe_event('XPosSP', PyTango.EventType.CHANGE_EVENT, self.handle_x)
        self.id2 = self.dev.subscribe_event('YPosSP', PyTango.EventType.CHANGE_EVENT, self.handle_y)
        self._ui.taurusTrend_2.setModel(models[2])

    def handle_x(self, evt):
        if evt.attr_value is not None:
            if evt.attr_value.value != self.x:
	        self.x = evt.attr_value.value / 1e9

    def handle_y(self, evt):
        if evt.attr_value is not None:
            if evt.attr_value.value != self.y:
	        self.y = evt.attr_value.value / 1e9
                self.mark = QwtPlotMarker()
                self.mark.setSymbol(self.sym)
                self.mark.attach(self.l_plot)
	        self.mark.setValue(self.x, self.y)
                if len(self.list_mark) > 10:
                    self.list_mark[0].setVisible(False)
                    l_mark = self.list_mark[0]
                    self.list_mark.pop(0)
                for mark in self.list_mark:
                    mark.setSymbol(self.sym_old)
                self.list_mark.append(self.mark)
                self.trigger.emit()

    def update_plot(self):
        if self.l_plot is not None:
            self.l_plot.replot()
Example #7
0
class ToftofProfileWindow(DlgUtils, QMainWindow):
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)
        DlgUtils.__init__(self, 'Live data')
        self.panel = parent
        layout1 = QVBoxLayout()
        self.plot = QwtPlot(self)
        layout1.addWidget(self.plot)
        self.curve = QwtPlotCurve()
        self.curve.setRenderHint(QwtPlotCurve.RenderAntialiased)
        self.curve.attach(self.plot)
        self.marker = QwtPlotMarker()
        self.marker.attach(self.plot)
        self.markerpen = QPen(Qt.red)
        self.marker.setSymbol(
            QwtSymbol(QwtSymbol.Ellipse, QBrush(), self.markerpen, QSize(7,
                                                                         7)))
        self.zoomer = QwtPlotZoomer(self.plot.canvas())
        self.zoomer.setMousePattern(QwtPlotZoomer.MouseSelect3, Qt.NoButton)
        self.picker = QwtPlotPicker(self.plot.canvas())
        self.picker.setSelectionFlags(QwtPlotPicker.PointSelection
                                      | QwtPlotPicker.ClickSelection)
        self.picker.setMousePattern(QwtPlotPicker.MouseSelect1, Qt.MidButton)
        self.picker.selected.connect(self.pickerSelected)
        layout2 = QHBoxLayout()
        layout2.addWidget(QLabel('Scale:', self))
        self.scale = QComboBox(self)
        self.scale.addItems([
            'Single detectors, sorted by angle',
            'Scattering angle 2theta (deg)', 'Q value (A-1)'
        ])
        self.scale.currentIndexChanged[int].connect(self.scaleChanged)
        layout2.addWidget(self.scale)
        layout2.addStretch()
        self.scaleframe = QFrame(self)
        self.scaleframe.setLayout(layout2)
        self.scaleframe.setVisible(False)
        layout1.addWidget(self.scaleframe)
        mainframe = QFrame(self)
        mainframe.setLayout(layout1)
        self.setCentralWidget(mainframe)
        self.setContentsMargins(6, 6, 6, 6)
        plotfont = scaledFont(self.font(), 0.7)
        self.plot.setAxisFont(QwtPlot.xBottom, plotfont)
        self.plot.setAxisFont(QwtPlot.yLeft, plotfont)
        self.plot.setCanvasBackground(Qt.white)
        self.resize(800, 200)

        self._detinfo = None
        self._anglemap = None
        self._infowindow = None
        self._infolabel = None
        self._xs = self._ys = None
        self._type = None

    def _retrieve_detinfo(self):
        if self._detinfo is None:
            info = self.panel.client.eval(
                'det._detinfo_parsed, '
                'det._anglemap', None)
            if not info:
                return self.showError('Cannot retrieve detector info.')
            self._lambda = self.panel.client.eval('chWL()', None)
            if not self._lambda:
                return self.showError('Cannot retrieve wavelength.')
            self._detinfo, self._anglemap = info
            self._inverse_anglemap = 0
            self._infowindow = QMainWindow(self)
            self._infolabel = QLabel(self._infowindow)
            self._infolabel.setTextFormat(Qt.RichText)
            self._infowindow.setCentralWidget(self._infolabel)
            self._infowindow.setContentsMargins(10, 10, 10, 10)
            self._inv_anglemap = [[
                entry for entry in self._detinfo[1:]
                if entry[12] == self._anglemap[detnr] + 1
            ][0] for detnr in range(len(self._xs))]

    def scaleChanged(self, scale):
        self.update(self._type, self._orig_nbins, self._orig_x, self._orig_y)

    def update(self, proftype, nbins, x, y):
        self._orig_x = x
        self._orig_y = y
        self._orig_nbins = nbins
        x.setsize(8 * nbins)
        y.setsize(8 * nbins)
        xs = struct.unpack('d' * nbins, x)
        ys = struct.unpack('d' * nbins, y)
        if proftype == 0:
            if self.scale.currentIndex() == 0:
                xs = xs
            elif self.scale.currentIndex() == 1:
                self._retrieve_detinfo()
                xs = [self._inv_anglemap[int(xi)][5] for xi in xs]
            else:
                self._retrieve_detinfo()
                if self._lambda is None:
                    self.showError('Could not determine wavelength.')
                    self.scale.setCurrentIndex(1)
                    return
                xs = [
                    4 * pi / self._lambda *
                    sin(radians(self._inv_anglemap[int(xi)][5] / 2.))
                    for xi in xs
                ]
        self._xs = xs
        self._ys = ys
        self.curve.setData(xs, ys)
        self.plot.setAxisAutoScale(QwtPlot.xBottom)
        self.plot.setAxisAutoScale(QwtPlot.yLeft)
        self.marker.setVisible(False)
        self.zoomer.setZoomBase(True)
        self._type = proftype
        if proftype == 0:
            self.setWindowTitle(
                'Single detector view (time-channel integrated)')
            self.scaleframe.setVisible(True)
        elif proftype == 1:
            self.setWindowTitle('Time channel view (detector integrated)')
            self.scaleframe.setVisible(False)
        else:
            self.scaleframe.setVisible(False)

    def pickerSelected(self, point):
        if self._type != 0:
            return
        self._retrieve_detinfo()
        index = self.curve.closestPoint(self.picker.transform(point))[0]
        detentry = self._inv_anglemap[index][:]
        detentry.append(self._xs[index])
        detentry.append(self._ys[index])
        self.marker.setXValue(self._xs[index])
        self.marker.setYValue(self._ys[index])
        self.marker.setVisible(True)
        self.plot.replot()
        self._infowindow.show()
        entrynames = [
            'EntryNr', 'Rack', 'Plate', 'Pos', 'RPos', '2Theta', 'CableNr',
            'CableType', 'CableLen', 'CableEmpty', 'Card', 'Chan', 'Total',
            'DetName', 'BoxNr', 'BoxChan', 'XValue', 'Counts'
        ]
        formats = [
            '%s', '%d', '%d', '%d', '%d', '%.3f', '%d', '%d', '%.2f', '%d',
            '%d', '%d', '%d', '%r', '%d', '%d', '%s', '%d'
        ]
        empties = [1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0]
        self._infolabel.setText('Detector info:<br><table>' + ''.join(
            '<tr><td>%s</td><td></td><td>%s</td></tr>%s' %
            (name, format % value, '<tr></tr>' if empty else '')
            for (name, format, empty,
                 value) in zip(entrynames, formats, empties, detentry)) +
                                '</table>')

    def closeEvent(self, event):
        if self._infowindow:
            self._infowindow.close()
Example #8
0
 def __init__(self):
     QwtPlotMarker.__init__(self)
Example #9
0
 def setValue(self, x, y):
     return QwtPlotMarker.setValue(self, float(x), float(y))
Example #10
0
 def setValue(self, x, y):
     return QwtPlotMarker.setValue(self, float(x), float(y))
Example #11
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(847, 480)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.horizontalLayout_2 = QtGui.QHBoxLayout(self.centralwidget)
        self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
        self.verticalLayout = QtGui.QVBoxLayout()
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
        
        #Tworzenie zakładek
        self.tabs = QtGui.QTabWidget(self.centralwidget)        
        
        #Główny wykre
        self.plot = QwtPlot(self.centralwidget)
        self.plot.setObjectName(_fromUtf8("plot"))
        self.plot.setAxisScale(self.plot.yLeft, -20, 80)
        self.plot.setAutoFillBackground(True)
        #self.plot.setPalette(Qt.Qt.black)
        self.plot.setCanvasBackground(Qt.Qt.black)
        
        self.grid = QwtPlotGrid()
        '''self.Yscale = QwtScaleDiv()
        self.Yscale.setInterval(10)
        self.Xscale = QwtScaleDiv()
        self.Xscale.setInterval(10)
        self.grid.setYDiv(self.YScale)
        self.grid.setXDiv(self.Xscale)'''
        self.grid.setMajPen(Qt.Qt.gray)
        self.grid.attach(self.plot)
        
        self.tabs.addTab(self.plot, "Spectrum")
       
        self.curve = QwtPlotCurve('')
        self.curve.setPen(Qt.Qt.yellow)
        self.curve.attach(self.plot)
        
        self.hold_curve = QwtPlotCurve('')
        self.hold_curve.setPen(Qt.Qt.red)
        
        self.peak_marker = QwtPlotMarker()
        self.symbol = QwtSymbol(QwtSymbol.DTriangle, QtGui.QBrush(Qt.Qt.red), QtGui.QPen(Qt.Qt.red), QtCore.QSize(10,10))
        self.peak_marker.setSymbol(self.symbol)
        self.peak_marker.setLabelAlignment(Qt.Qt.AlignTop)
        
        self.sybmol_2 = QwtSymbol(QwtSymbol.DTriangle, QtGui.QBrush(Qt.Qt.red), QtGui.QPen(Qt.Qt.white), QtCore.QSize(10,10))
        self.marker_1 = QwtPlotMarker()
        self.marker_1.setSymbol(self.sybmol_2)
        self.marker_1.setLabelAlignment(Qt.Qt.AlignTop)
        self.marker_2 = QwtPlotMarker()
        self.marker_2.setSymbol(self.sybmol_2)
        self.marker_2.setLabelAlignment(Qt.Qt.AlignTop)
        self.marker_3 = QwtPlotMarker()
        self.marker_3.setSymbol(self.sybmol_2)
        self.marker_3.setLabelAlignment(Qt.Qt.AlignTop)
        self.marker_4 = QwtPlotMarker()
        self.marker_4.setSymbol(self.sybmol_2)
        self.marker_4.setLabelAlignment(Qt.Qt.AlignTop)
        self.delta_marker = QwtPlotMarker()
        self.delta_marker.setSymbol(self.sybmol_2)
        self.delta_marker.setLabelAlignment(Qt.Qt.AlignTop)
        
        self.markers = [self.marker_1, self.marker_2, self.marker_3, self.marker_4]
        
        self.save_curve_1 = QwtPlotCurve('')
        self.save_curve_1.setPen(Qt.Qt.green)
        self.save_curve_2 = QwtPlotCurve('')
        self.save_curve_2.setPen(Qt.Qt.cyan)
        self.save_curve_3 = QwtPlotCurve('')
        self.save_curve_3.setPen(Qt.Qt.magenta)
        self.saved_curves = [self.save_curve_1, self.save_curve_2, self.save_curve_3]
        
        #Wykres waterfall
        '''self.plot_2 = QwtPlot(self.centralwidget)
        self.plot_2.setObjectName(_fromUtf8("plot_2"))
        
        self.waterfall = QwtPlotSpectrogram()
        self.waterfall.attach(self.plot_2)
        
        self.colorMap = QwtLinearColorMap(Qt.Qt.darkCyan, Qt.Qt.red)
        self.scaleColors(80)
        self.waterfall.setColorMap(self.colorMap)
        #self.waterfallData = QwtRasterData()
        #self.tabs.addTab(self.plot_2, "Waterfall")'''
        
        self.verticalLayout.addWidget(self.tabs)
        
        self.picker = QwtPlotPicker(QwtPlot.xBottom, 
                                    QwtPlot.yLeft, 
                                    QwtPicker.PointSelection | QwtPicker.DragSelection,
                                    QwtPlotPicker.CrossRubberBand,
                                    QwtPicker.AlwaysOn,
                                    self.plot.canvas())
        self.picker.setTrackerPen(Qt.Qt.white)
        self.picker.setRubberBandPen(Qt.Qt.gray)
        
        self.freqBox = QtGui.QGroupBox(self.centralwidget)
        self.freqBox.setObjectName(_fromUtf8("freqBox"))
        self.verticalLayout_3 = QtGui.QVBoxLayout(self.freqBox)
        
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
        
        self.formLayout_3 = QtGui.QFormLayout()
        self.formLayout_3.setObjectName(_fromUtf8("formLayout_3"))
        self.label = QtGui.QLabel(self.freqBox)
        self.label.setObjectName(_fromUtf8("label"))
        self.formLayout_3.setWidget(0, QtGui.QFormLayout.LabelRole, self.label)
        
        self.startEdit = QtGui.QDoubleSpinBox(self.freqBox)
        self.startEdit.setObjectName(_fromUtf8("startEdit"))
        self.startEdit.setDecimals(2)
        self.startEdit.setRange(1, 1280)
        self.startEdit.setKeyboardTracking(False)         
        self.formLayout_3.setWidget(0, QtGui.QFormLayout.FieldRole, self.startEdit)
        self.horizontalLayout.addLayout(self.formLayout_3)
        
        self.formLayout_4 = QtGui.QFormLayout()
        self.formLayout_4.setObjectName(_fromUtf8("formLayout_4"))
        self.label_2 = QtGui.QLabel(self.freqBox)
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.formLayout_4.setWidget(0, QtGui.QFormLayout.LabelRole, self.label_2)
        
        self.stopEdit = QtGui.QDoubleSpinBox(self.freqBox)
        self.stopEdit.setObjectName(_fromUtf8("stopEdit"))
        self.stopEdit.setDecimals(2)
        self.stopEdit.setRange(1, 1280)
        self.stopEdit.setKeyboardTracking(False)
        
        self.formLayout_4.setWidget(0, QtGui.QFormLayout.FieldRole, self.stopEdit)
        self.horizontalLayout.addLayout(self.formLayout_4)
        self.formLayout_5 = QtGui.QFormLayout()
        self.formLayout_5.setObjectName(_fromUtf8("formLayout_5"))
        self.label_3 = QtGui.QLabel(self.freqBox)
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.formLayout_5.setWidget(0, QtGui.QFormLayout.LabelRole, self.label_3)
        
        self.rbwEdit = QtGui.QComboBox(self.freqBox)
        self.rbwEdit.setObjectName(_fromUtf8("rbwEdit"))
        self.rbwEdit.addItem('0,21 kHz', 16384)
        self.rbwEdit.addItem('0,42 kHz', 8192)
        self.rbwEdit.addItem('0,84 kHz', 4096)
        self.rbwEdit.addItem('1,69 kHz', 2048)
        self.rbwEdit.addItem('3,38 kHz', 1024)
        self.rbwEdit.addItem('6,75 kHz', 512)
        self.rbwEdit.addItem('13,5 kHz', 256)
        self.rbwEdit.addItem('27 kHz', 128)
        self.rbwEdit.addItem('54 kHz', 64)
        self.rbwEdit.addItem('108 kHz', 32)
        self.rbwEdit.addItem('216 kHz', 16)
        self.rbwEdit.addItem('432 kHz', 8)
        self.rbwEdit.setCurrentIndex(4)
        
        
        self.formLayout_5.setWidget(0, QtGui.QFormLayout.FieldRole, self.rbwEdit)
        self.horizontalLayout.addLayout(self.formLayout_5)
        spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.verticalLayout_3.addLayout(self.horizontalLayout)
        
        self.horizontalLayout_3 = QtGui.QHBoxLayout()
        self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
        self.formLayout_7 = QtGui.QFormLayout()
        self.formLayout_7.setObjectName(_fromUtf8("formLayout_7"))
        self.centerLabel = QtGui.QLabel(self.freqBox)
        self.centerLabel.setObjectName(_fromUtf8("centerLabel"))
        self.formLayout_7.setWidget(0, QtGui.QFormLayout.LabelRole, self.centerLabel)
        
        self.centerEdit = QtGui.QDoubleSpinBox(self.freqBox)
        self.centerEdit.setObjectName(_fromUtf8("centerEdit"))
        self.centerEdit.setDecimals(2)
        self.centerEdit.setRange(1, 1280)
        self.centerEdit.setKeyboardTracking(False)         
        self.formLayout_7.setWidget(0, QtGui.QFormLayout.FieldRole, self.centerEdit)
        self.horizontalLayout_3.addLayout(self.formLayout_7)
        
        self.formLayout_8 = QtGui.QFormLayout()
        self.formLayout_8.setObjectName(_fromUtf8("formLayout_8"))
        self.spanLabel = QtGui.QLabel(self.freqBox)
        self.spanLabel.setObjectName(_fromUtf8("spanLabel"))
        self.formLayout_8.setWidget(0, QtGui.QFormLayout.LabelRole, self.spanLabel)
        
        self.spanEdit = QtGui.QDoubleSpinBox(self.freqBox)
        self.spanEdit.setObjectName(_fromUtf8("spanEdit"))
        self.spanEdit.setDecimals(2)
        self.spanEdit.setRange(0.1, 1280)
        self.spanEdit.setKeyboardTracking(False)         
        self.formLayout_8.setWidget(0, QtGui.QFormLayout.FieldRole, self.spanEdit)
        self.horizontalLayout_3.addLayout(self.formLayout_8)
        self.horizontalLayout_3.addItem(spacerItem)
        self.verticalLayout_3.addLayout(self.horizontalLayout_3)
        
        self.verticalLayout.addWidget(self.freqBox)
        self.horizontalLayout_2.addLayout(self.verticalLayout)
        
        self.settingsBox = QtGui.QGroupBox(self.centralwidget)
        self.settingsBox.setMaximumSize(QtCore.QSize(250, 16777215))
        self.settingsBox.setObjectName(_fromUtf8("settingsBox"))
        self.verticalLayout_2 = QtGui.QVBoxLayout(self.settingsBox)
        self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
        
        self.formLayout = QtGui.QFormLayout()
        self.formLayout.setObjectName(_fromUtf8("formLayout"))
        self.gainLabel = QtGui.QLabel(self.settingsBox)
        self.gainLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.gainLabel.setObjectName(_fromUtf8("gainLabel"))
        self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.gainLabel)
        self.gainSlider = QtGui.QSlider(self.settingsBox)
        self.gainSlider.setMaximum(49)
        self.gainSlider.setSingleStep(1)
        self.gainSlider.setProperty("value", 20)
        self.gainSlider.setOrientation(QtCore.Qt.Horizontal)
        self.gainSlider.setObjectName(_fromUtf8("gainSlider"))
        self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.gainSlider)
        self.verticalLayout_2.addLayout(self.formLayout)
        
        self.gainDisp = QtGui.QLCDNumber(self.settingsBox)
        self.gainDisp.setSegmentStyle(QtGui.QLCDNumber.Flat)
        self.verticalLayout_2.addWidget(self.gainDisp)
        
        '''self.offsetButton = QtGui.QPushButton(self.settingsBox)
        self.offsetButton.setText("Remove DC offset")
        self.verticalLayout_2.addWidget(self.offsetButton)  ''' 
        
        self.formLayout_2 = QtGui.QFormLayout()
        self.formLayout_2.setObjectName(_fromUtf8("formLayout_2"))
        self.refLabel = QtGui.QLabel(self.settingsBox)
        self.refLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.refLabel.setObjectName(_fromUtf8("refLabel"))
        self.formLayout_2.setWidget(0, QtGui.QFormLayout.LabelRole, self.refLabel)        
        self.refEdit = QtGui.QDoubleSpinBox(self.settingsBox)
        self.refEdit.setObjectName(_fromUtf8("refEdit"))
        self.refEdit.setDecimals(0)
        self.refEdit.setKeyboardTracking(False)
        self.formLayout_2.setWidget(0, QtGui.QFormLayout.FieldRole, self.refEdit)
        self.verticalLayout_2.addLayout(self.formLayout_2) 
        
        spacerItem1 = QtGui.QSpacerItem(158, 304, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        self.verticalLayout_2.addItem(spacerItem1)
        
        
        #Settings tabs
        self.settings_tabs = QtGui.QTabWidget(self.settingsBox) 
        self.verticalLayout_2.addWidget(self.settings_tabs)
        
        self.verticalLayout_4 = QtGui.QVBoxLayout()
        self.saveButton = QtGui.QPushButton(self.settingsBox)
        self.saveButton.setText("Save plot")
        self.verticalLayout_4.addWidget(self.saveButton)          
        
        self.formLayout_9 = QtGui.QFormLayout()
        self.formLayout_9.setObjectName(_fromUtf8("formLayout_9"))
        self.avgLabel = QtGui.QLabel(self.settingsBox)
        self.avgLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.avgLabel.setObjectName(_fromUtf8("avgLabel"))
        self.formLayout_9.setWidget(0, QtGui.QFormLayout.LabelRole, self.avgLabel)  
        self.avgCheck = QtGui.QCheckBox(self.settingsBox) 
        self.formLayout_9.setWidget(0, QtGui.QFormLayout.FieldRole, self.avgCheck)
        self.verticalLayout_4.addLayout(self.formLayout_9)
        
        self.formLayout_10 = QtGui.QFormLayout()
        self.avgLabel_2 = QtGui.QLabel(self.settingsBox)
        self.avgLabel_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.avgLabel_2.setObjectName(_fromUtf8("avgLabel_2"))
        self.formLayout_10.setWidget(0, QtGui.QFormLayout.LabelRole, self.avgLabel_2) 
        self.avgEdit = QtGui.QDoubleSpinBox(self.settingsBox)
        self.avgEdit.setDecimals(0)
        self.avgEdit.setRange(1, 100)
        self.avgEdit.setKeyboardTracking(False)
        self.avgEdit.setValue(10)
        self.formLayout_10.setWidget(0, QtGui.QFormLayout.FieldRole, self.avgEdit)
        self.verticalLayout_4.addLayout(self.formLayout_10)
         
        self.formLayout_6 = QtGui.QFormLayout()
        self.formLayout_6.setObjectName(_fromUtf8("formLayout_6"))
        self.holdLabel = QtGui.QLabel(self.settingsBox)
        self.holdLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.holdLabel.setObjectName(_fromUtf8("holdLabel"))
        self.formLayout_6.setWidget(0, QtGui.QFormLayout.LabelRole, self.holdLabel)                   
        self.holdCheck = QtGui.QCheckBox(self.settingsBox)  
        self.formLayout_6.setWidget(0, QtGui.QFormLayout.FieldRole, self.holdCheck)
        self.verticalLayout_4.addLayout(self.formLayout_6) 
        
        self.formLayout_11 = QtGui.QFormLayout()
        self.formLayout_11.setObjectName(_fromUtf8("formLayout_11"))
        self.peakLabel = QtGui.QLabel(self.settingsBox)
        self.peakLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.peakLabel.setObjectName(_fromUtf8("peakLabel"))
        self.formLayout_11.setWidget(0, QtGui.QFormLayout.LabelRole, self.peakLabel)                   
        self.peakCheck = QtGui.QCheckBox(self.settingsBox)  
        self.formLayout_11.setWidget(0, QtGui.QFormLayout.FieldRole, self.peakCheck)
        self.verticalLayout_4.addLayout(self.formLayout_11)
        
        self.peakStatus = QtGui.QLabel("Peak: ")        
        
        self.correctButton = QtGui.QPushButton(self.settingsBox)
        self.correctButton.setText("Correction")
        self.verticalLayout_4.addWidget(self.correctButton)
        
        self.verticalLayout_5 = QtGui.QVBoxLayout()
        self.traceButton = QtGui.QPushButton(self.settingsBox)
        self.traceButton.setText("Save trace 1")
        self.verticalLayout_5.addWidget(self.traceButton)    
        
        self.traceButton_2 = QtGui.QPushButton(self.settingsBox)
        self.traceButton_2.setText("Save trace 2")
        self.verticalLayout_5.addWidget(self.traceButton_2)  
        
        self.traceButton_3 = QtGui.QPushButton(self.settingsBox)
        self.traceButton_3.setText("Save trace 3")
        self.verticalLayout_5.addWidget(self.traceButton_3) 
        
        self.traces = [self.traceButton, self.traceButton_2, self.traceButton_3]        
        
        #MARKERS
        self.gridLayout = QtGui.QGridLayout()
        self.markerLabel = QtGui.QLabel(self.settingsBox)
        self.markerLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.gridLayout.addWidget(self.markerLabel, 0,0)        
        self.markerCheck = QtGui.QCheckBox(self.settingsBox)
        self.gridLayout.addWidget(self.markerCheck, 0,1)
        self.markerEdit = QtGui.QDoubleSpinBox(self.settingsBox)
        self.markerEdit.setDecimals(2)
        self.markerEdit.setKeyboardTracking(False)
        self.markerEdit.setDisabled(True)
        self.markerEdit.setSingleStep(0.1)
        self.gridLayout.addWidget(self.markerEdit, 0,2)
        
        self.markerLabel_2 = QtGui.QLabel(self.settingsBox)
        self.markerLabel_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.gridLayout.addWidget(self.markerLabel_2, 2,0)        
        self.markerCheck_2 = QtGui.QCheckBox(self.settingsBox)
        self.gridLayout.addWidget(self.markerCheck_2, 2,1)
        self.markerEdit_2 = QtGui.QDoubleSpinBox(self.settingsBox)
        self.markerEdit_2.setDecimals(2)
        self.markerEdit_2.setKeyboardTracking(False)
        self.markerEdit_2.setDisabled(True)
        self.markerEdit_2.setSingleStep(0.1)
        self.gridLayout.addWidget(self.markerEdit_2, 2,2)
        
        self.markerLabel_3 = QtGui.QLabel(self.settingsBox)
        self.markerLabel_3.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.gridLayout.addWidget(self.markerLabel_3, 3,0)        
        self.markerCheck_3 = QtGui.QCheckBox(self.settingsBox)
        self.gridLayout.addWidget(self.markerCheck_3, 3,1)
        self.markerEdit_3 = QtGui.QDoubleSpinBox(self.settingsBox)
        self.markerEdit_3.setDecimals(2)
        self.markerEdit_3.setKeyboardTracking(False)
        self.markerEdit_3.setDisabled(True)
        self.markerEdit_3.setSingleStep(0.1)
        self.gridLayout.addWidget(self.markerEdit_3, 3,2)
        
        self.markerLabel_4 = QtGui.QLabel(self.settingsBox)
        self.markerLabel_4.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.gridLayout.addWidget(self.markerLabel_4, 4,0)        
        self.markerCheck_4 = QtGui.QCheckBox(self.settingsBox)
        self.gridLayout.addWidget(self.markerCheck_4, 4,1)
        self.markerEdit_4 = QtGui.QDoubleSpinBox(self.settingsBox)
        self.markerEdit_4.setDecimals(2)
        self.markerEdit_4.setKeyboardTracking(False)
        self.markerEdit_4.setDisabled(True)
        self.markerEdit_4.setSingleStep(0.1)
        self.gridLayout.addWidget(self.markerEdit_4, 4,2)
        
        self.deltaLabel = QtGui.QLabel(self.settingsBox)
        self.deltaLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.gridLayout.addWidget(self.deltaLabel, 1,0)        
        self.deltaCheck = QtGui.QCheckBox(self.settingsBox)
        self.gridLayout.addWidget(self.deltaCheck, 1,1)
        self.deltaEdit = QtGui.QDoubleSpinBox(self.settingsBox)
        self.deltaEdit.setDecimals(2)
        self.deltaEdit.setSingleStep(0.1)
        self.deltaEdit.setKeyboardTracking(False)
        self.deltaEdit.setDisabled(True)
        self.gridLayout.addWidget(self.deltaEdit, 1,2)
        self.deltaCheck.setDisabled(True)
        
        self.tab1 = QtGui.QWidget()
        self.settings_tabs.addTab(self.tab1, "Misc.")
        self.settings_tabs.widget(0).setLayout(self.verticalLayout_4)

        self.tab2 = QtGui.QWidget()
        self.settings_tabs.addTab(self.tab2, "Traces")  
        self.settings_tabs.widget(1).setLayout(self.verticalLayout_5)
        
        self.tab3 = QtGui.QWidget()
        self.settings_tabs.addTab(self.tab3, "Markers")
        self.settings_tabs.widget(2).setLayout(self.gridLayout)
        
        self.horizontalLayout_2.addWidget(self.settingsBox)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 847, 21))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)
        self.statusbar.addWidget(self.peakStatus)
        self.statusbar.setVisible(False)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        
        self.gainSlider.valueChanged.connect(self.gainDisp.display)
        self.saveButton.clicked.connect(self.savePlot)
Example #12
0
    def __init__(self, image, parent, imgman, name=None, save=False):
        QFrame.__init__(self, parent)
        self.setFrameStyle(QFrame.StyledPanel | QFrame.Raised)
        # init state
        self.image = image
        self._imgman = imgman
        self._currier = PersistentCurrier()
        self._control_dialog = None
        # create widgets
        self._lo = lo = QHBoxLayout(self)
        lo.setContentsMargins(0, 0, 0, 0)
        lo.setSpacing(2)
        # raise button
        self._wraise = QToolButton(self)
        lo.addWidget(self._wraise)
        self._wraise.setIcon(pixmaps.raise_up.icon())
        self._wraise.setAutoRaise(True)
        self._can_raise = False
        QObject.connect(self._wraise, SIGNAL("clicked()"), self._raiseButtonPressed)
        self._wraise.setToolTip("""<P>Click here to raise this image above other images. Hold the button down briefly to
      show a menu of image operations.</P>""")
        # center label
        self._wcenter = QLabel(self)
        self._wcenter.setPixmap(pixmaps.center_image.pm())
        self._wcenter.setToolTip(
            "<P>The plot is currently centered on (the reference pixel %d,%d) of this image.</P>" % self.image.referencePixel())
        lo.addWidget(self._wcenter)
        # name/filename label
        self.name = image.name
        self._wlabel = QLabel(self.name, self)
        self._number = 0
        self.setName(self.name)
        self._wlabel.setToolTip("%s %s" % (image.filename, "\u00D7".join(map(str, image.data().shape))))
        lo.addWidget(self._wlabel, 1)
        # if 'save' is specified, create a "save" button
        if save:
            self._wsave = QToolButton(self)
            lo.addWidget(self._wsave)
            self._wsave.setText("save")
            self._wsave.setAutoRaise(True)
            self._save_dir = save if isinstance(save, str) else "."
            QObject.connect(self._wsave, SIGNAL("clicked()"), self._saveImage)
            self._wsave.setToolTip("""<P>Click here to write this image to a FITS file.</P>""")
        # render control
        dprint(2, "creating RenderControl")
        self._rc = RenderControl(image, self)
        dprint(2, "done")
        # selectors for extra axes
        self._wslicers = []
        curslice = self._rc.currentSlice();  # this may be loaded from config, so not necessarily 0
        for iextra, axisname, labels in self._rc.slicedAxes():
            if axisname.upper() not in ["STOKES", "COMPLEX"]:
                lbl = QLabel("%s:" % axisname, self)
                lo.addWidget(lbl)
            else:
                lbl = None
            slicer = QComboBox(self)
            self._wslicers.append(slicer)
            lo.addWidget(slicer)
            slicer.addItems(labels)
            slicer.setToolTip("""<P>Selects current slice along the %s axis.</P>""" % axisname)
            slicer.setCurrentIndex(curslice[iextra])
            QObject.connect(slicer, SIGNAL("activated(int)"), self._currier.curry(self._rc.changeSlice, iextra))
        # min/max display ranges
        lo.addSpacing(5)
        self._wrangelbl = QLabel(self)
        lo.addWidget(self._wrangelbl)
        self._minmaxvalidator = FloatValidator(self)
        self._wmin = QLineEdit(self)
        self._wmax = QLineEdit(self)
        width = self._wmin.fontMetrics().width("1.234567e-05")
        for w in self._wmin, self._wmax:
            lo.addWidget(w, 0)
            w.setValidator(self._minmaxvalidator)
            w.setMaximumWidth(width)
            w.setMinimumWidth(width)
            QObject.connect(w, SIGNAL("editingFinished()"), self._changeDisplayRange)
        # full-range button
        self._wfullrange = QToolButton(self)
        lo.addWidget(self._wfullrange, 0)
        self._wfullrange.setIcon(pixmaps.zoom_range.icon())
        self._wfullrange.setAutoRaise(True)
        QObject.connect(self._wfullrange, SIGNAL("clicked()"), self.renderControl().resetSubsetDisplayRange)
        rangemenu = QMenu(self)
        rangemenu.addAction(pixmaps.full_range.icon(), "Full subset", self.renderControl().resetSubsetDisplayRange)
        for percent in (99.99, 99.9, 99.5, 99, 98, 95):
            rangemenu.addAction("%g%%" % percent, self._currier.curry(self._changeDisplayRangeToPercent, percent))
        self._wfullrange.setPopupMode(QToolButton.DelayedPopup)
        self._wfullrange.setMenu(rangemenu)
        # update widgets from current display range
        self._updateDisplayRange(*self._rc.displayRange())
        # lock button
        self._wlock = QToolButton(self)
        self._wlock.setIcon(pixmaps.unlocked.icon())
        self._wlock.setAutoRaise(True)
        self._wlock.setToolTip("""<P>Click to lock or unlock the intensity range. When the intensity range is locked across multiple images, any changes in the intensity
          range of one are propagated to the others. Hold the button down briefly for additional options.</P>""")
        lo.addWidget(self._wlock)
        QObject.connect(self._wlock, SIGNAL("clicked()"), self._toggleDisplayRangeLock)
        QObject.connect(self.renderControl(), SIGNAL("displayRangeLocked"), self._setDisplayRangeLock)
        QObject.connect(self.renderControl(), SIGNAL("dataSubsetChanged"), self._dataSubsetChanged)
        lockmenu = QMenu(self)
        lockmenu.addAction(pixmaps.locked.icon(), "Lock all to this",
                           self._currier.curry(imgman.lockAllDisplayRanges, self.renderControl()))
        lockmenu.addAction(pixmaps.unlocked.icon(), "Unlock all", imgman.unlockAllDisplayRanges)
        self._wlock.setPopupMode(QToolButton.DelayedPopup)
        self._wlock.setMenu(lockmenu)
        self._setDisplayRangeLock(self.renderControl().isDisplayRangeLocked())
        # dialog button
        self._wshowdialog = QToolButton(self)
        lo.addWidget(self._wshowdialog)
        self._wshowdialog.setIcon(pixmaps.colours.icon())
        self._wshowdialog.setAutoRaise(True)
        self._wshowdialog.setToolTip("""<P>Click for colourmap and intensity policy options.</P>""")
        QObject.connect(self._wshowdialog, SIGNAL("clicked()"), self.showRenderControls)
        tooltip = """<P>You can change the currently displayed intensity range by entering low and high limits here.</P>
    <TABLE>
      <TR><TD><NOBR>Image min:</NOBR></TD><TD>%g</TD><TD>max:</TD><TD>%g</TD></TR>
      </TABLE>""" % self.image.imageMinMax()
        for w in self._wmin, self._wmax, self._wrangelbl:
            w.setToolTip(tooltip)

        # create image operations menu
        self._menu = QMenu(self.name, self)
        self._qa_raise = self._menu.addAction(pixmaps.raise_up.icon(), "Raise image",
                                              self._currier.curry(self.image.emit, SIGNAL("raise")))
        self._qa_center = self._menu.addAction(pixmaps.center_image.icon(), "Center plot on image",
                                               self._currier.curry(self.image.emit, SIGNAL("center")))
        self._qa_show_rc = self._menu.addAction(pixmaps.colours.icon(), "Colours && Intensities...",
                                                self.showRenderControls)
        if save:
            self._qa_save = self._menu.addAction("Save image...", self._saveImage)
        self._menu.addAction("Export image to PNG file...", self._exportImageToPNG)
        self._export_png_dialog = None
        self._menu.addAction("Unload image", self._currier.curry(self.image.emit, SIGNAL("unload")))
        self._wraise.setMenu(self._menu)
        self._wraise.setPopupMode(QToolButton.DelayedPopup)

        # connect updates from renderControl and image
        self.image.connect(SIGNAL("slice"), self._updateImageSlice)
        QObject.connect(self._rc, SIGNAL("displayRangeChanged"), self._updateDisplayRange)

        # default plot depth of image markers
        self._z_markers = None
        # and the markers themselves
        self._image_border = QwtPlotCurve()
        self._image_label = QwtPlotMarker()

        # subset markers
        self._subset_pen = QPen(QColor("Light Blue"))
        self._subset_border = QwtPlotCurve()
        self._subset_border.setPen(self._subset_pen)
        self._subset_border.setVisible(False)
        self._subset_label = QwtPlotMarker()
        text = QwtText("subset")
        text.setColor(self._subset_pen.color())
        self._subset_label.setLabel(text)
        self._subset_label.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom)
        self._subset_label.setVisible(False)
        self._setting_lmrect = False

        self._all_markers = [self._image_border, self._image_label, self._subset_border, self._subset_label]
Example #13
0
class ImageController(QFrame):
    """An ImageController is a widget for controlling the display of one image.
    It can emit the following signals from the image:
    raise                     raise button was clicked
    center                  center-on-image option was selected
    unload                  unload option was selected
    slice                     image slice has changed, need to redraw (emitted by SkyImage automatically)
    repaint                 image display range or colormap has changed, need to redraw (emitted by SkyImage automatically)
    """

    def __init__(self, image, parent, imgman, name=None, save=False):
        QFrame.__init__(self, parent)
        self.setFrameStyle(QFrame.StyledPanel | QFrame.Raised)
        # init state
        self.image = image
        self._imgman = imgman
        self._currier = PersistentCurrier()
        self._control_dialog = None
        # create widgets
        self._lo = lo = QHBoxLayout(self)
        lo.setContentsMargins(0, 0, 0, 0)
        lo.setSpacing(2)
        # raise button
        self._wraise = QToolButton(self)
        lo.addWidget(self._wraise)
        self._wraise.setIcon(pixmaps.raise_up.icon())
        self._wraise.setAutoRaise(True)
        self._can_raise = False
        QObject.connect(self._wraise, SIGNAL("clicked()"), self._raiseButtonPressed)
        self._wraise.setToolTip("""<P>Click here to raise this image above other images. Hold the button down briefly to
      show a menu of image operations.</P>""")
        # center label
        self._wcenter = QLabel(self)
        self._wcenter.setPixmap(pixmaps.center_image.pm())
        self._wcenter.setToolTip(
            "<P>The plot is currently centered on (the reference pixel %d,%d) of this image.</P>" % self.image.referencePixel())
        lo.addWidget(self._wcenter)
        # name/filename label
        self.name = image.name
        self._wlabel = QLabel(self.name, self)
        self._number = 0
        self.setName(self.name)
        self._wlabel.setToolTip("%s %s" % (image.filename, "\u00D7".join(map(str, image.data().shape))))
        lo.addWidget(self._wlabel, 1)
        # if 'save' is specified, create a "save" button
        if save:
            self._wsave = QToolButton(self)
            lo.addWidget(self._wsave)
            self._wsave.setText("save")
            self._wsave.setAutoRaise(True)
            self._save_dir = save if isinstance(save, str) else "."
            QObject.connect(self._wsave, SIGNAL("clicked()"), self._saveImage)
            self._wsave.setToolTip("""<P>Click here to write this image to a FITS file.</P>""")
        # render control
        dprint(2, "creating RenderControl")
        self._rc = RenderControl(image, self)
        dprint(2, "done")
        # selectors for extra axes
        self._wslicers = []
        curslice = self._rc.currentSlice();  # this may be loaded from config, so not necessarily 0
        for iextra, axisname, labels in self._rc.slicedAxes():
            if axisname.upper() not in ["STOKES", "COMPLEX"]:
                lbl = QLabel("%s:" % axisname, self)
                lo.addWidget(lbl)
            else:
                lbl = None
            slicer = QComboBox(self)
            self._wslicers.append(slicer)
            lo.addWidget(slicer)
            slicer.addItems(labels)
            slicer.setToolTip("""<P>Selects current slice along the %s axis.</P>""" % axisname)
            slicer.setCurrentIndex(curslice[iextra])
            QObject.connect(slicer, SIGNAL("activated(int)"), self._currier.curry(self._rc.changeSlice, iextra))
        # min/max display ranges
        lo.addSpacing(5)
        self._wrangelbl = QLabel(self)
        lo.addWidget(self._wrangelbl)
        self._minmaxvalidator = FloatValidator(self)
        self._wmin = QLineEdit(self)
        self._wmax = QLineEdit(self)
        width = self._wmin.fontMetrics().width("1.234567e-05")
        for w in self._wmin, self._wmax:
            lo.addWidget(w, 0)
            w.setValidator(self._minmaxvalidator)
            w.setMaximumWidth(width)
            w.setMinimumWidth(width)
            QObject.connect(w, SIGNAL("editingFinished()"), self._changeDisplayRange)
        # full-range button
        self._wfullrange = QToolButton(self)
        lo.addWidget(self._wfullrange, 0)
        self._wfullrange.setIcon(pixmaps.zoom_range.icon())
        self._wfullrange.setAutoRaise(True)
        QObject.connect(self._wfullrange, SIGNAL("clicked()"), self.renderControl().resetSubsetDisplayRange)
        rangemenu = QMenu(self)
        rangemenu.addAction(pixmaps.full_range.icon(), "Full subset", self.renderControl().resetSubsetDisplayRange)
        for percent in (99.99, 99.9, 99.5, 99, 98, 95):
            rangemenu.addAction("%g%%" % percent, self._currier.curry(self._changeDisplayRangeToPercent, percent))
        self._wfullrange.setPopupMode(QToolButton.DelayedPopup)
        self._wfullrange.setMenu(rangemenu)
        # update widgets from current display range
        self._updateDisplayRange(*self._rc.displayRange())
        # lock button
        self._wlock = QToolButton(self)
        self._wlock.setIcon(pixmaps.unlocked.icon())
        self._wlock.setAutoRaise(True)
        self._wlock.setToolTip("""<P>Click to lock or unlock the intensity range. When the intensity range is locked across multiple images, any changes in the intensity
          range of one are propagated to the others. Hold the button down briefly for additional options.</P>""")
        lo.addWidget(self._wlock)
        QObject.connect(self._wlock, SIGNAL("clicked()"), self._toggleDisplayRangeLock)
        QObject.connect(self.renderControl(), SIGNAL("displayRangeLocked"), self._setDisplayRangeLock)
        QObject.connect(self.renderControl(), SIGNAL("dataSubsetChanged"), self._dataSubsetChanged)
        lockmenu = QMenu(self)
        lockmenu.addAction(pixmaps.locked.icon(), "Lock all to this",
                           self._currier.curry(imgman.lockAllDisplayRanges, self.renderControl()))
        lockmenu.addAction(pixmaps.unlocked.icon(), "Unlock all", imgman.unlockAllDisplayRanges)
        self._wlock.setPopupMode(QToolButton.DelayedPopup)
        self._wlock.setMenu(lockmenu)
        self._setDisplayRangeLock(self.renderControl().isDisplayRangeLocked())
        # dialog button
        self._wshowdialog = QToolButton(self)
        lo.addWidget(self._wshowdialog)
        self._wshowdialog.setIcon(pixmaps.colours.icon())
        self._wshowdialog.setAutoRaise(True)
        self._wshowdialog.setToolTip("""<P>Click for colourmap and intensity policy options.</P>""")
        QObject.connect(self._wshowdialog, SIGNAL("clicked()"), self.showRenderControls)
        tooltip = """<P>You can change the currently displayed intensity range by entering low and high limits here.</P>
    <TABLE>
      <TR><TD><NOBR>Image min:</NOBR></TD><TD>%g</TD><TD>max:</TD><TD>%g</TD></TR>
      </TABLE>""" % self.image.imageMinMax()
        for w in self._wmin, self._wmax, self._wrangelbl:
            w.setToolTip(tooltip)

        # create image operations menu
        self._menu = QMenu(self.name, self)
        self._qa_raise = self._menu.addAction(pixmaps.raise_up.icon(), "Raise image",
                                              self._currier.curry(self.image.emit, SIGNAL("raise")))
        self._qa_center = self._menu.addAction(pixmaps.center_image.icon(), "Center plot on image",
                                               self._currier.curry(self.image.emit, SIGNAL("center")))
        self._qa_show_rc = self._menu.addAction(pixmaps.colours.icon(), "Colours && Intensities...",
                                                self.showRenderControls)
        if save:
            self._qa_save = self._menu.addAction("Save image...", self._saveImage)
        self._menu.addAction("Export image to PNG file...", self._exportImageToPNG)
        self._export_png_dialog = None
        self._menu.addAction("Unload image", self._currier.curry(self.image.emit, SIGNAL("unload")))
        self._wraise.setMenu(self._menu)
        self._wraise.setPopupMode(QToolButton.DelayedPopup)

        # connect updates from renderControl and image
        self.image.connect(SIGNAL("slice"), self._updateImageSlice)
        QObject.connect(self._rc, SIGNAL("displayRangeChanged"), self._updateDisplayRange)

        # default plot depth of image markers
        self._z_markers = None
        # and the markers themselves
        self._image_border = QwtPlotCurve()
        self._image_label = QwtPlotMarker()

        # subset markers
        self._subset_pen = QPen(QColor("Light Blue"))
        self._subset_border = QwtPlotCurve()
        self._subset_border.setPen(self._subset_pen)
        self._subset_border.setVisible(False)
        self._subset_label = QwtPlotMarker()
        text = QwtText("subset")
        text.setColor(self._subset_pen.color())
        self._subset_label.setLabel(text)
        self._subset_label.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom)
        self._subset_label.setVisible(False)
        self._setting_lmrect = False

        self._all_markers = [self._image_border, self._image_label, self._subset_border, self._subset_label]

    def close(self):
        if self._control_dialog:
            self._control_dialog.close()
            self._control_dialog = None

    def __del__(self):
        self.close()

    def __eq__(self, other):
        return self is other

    def renderControl(self):
        return self._rc

    def getMenu(self):
        return self._menu

    def getFilename(self):
        return self.image.filename

    def setName(self, name):
        self.name = name
        self._wlabel.setText("%s: %s" % (chr(ord('a') + self._number), self.name))

    def setNumber(self, num):
        self._number = num
        self._menu.menuAction().setText("%s: %s" % (chr(ord('a') + self._number), self.name))
        self._qa_raise.setShortcut(QKeySequence("Alt+" + chr(ord('A') + num)))
        self.setName(self.name)

    def getNumber(self):
        return self._number

    def setPlotProjection(self, proj):
        self.image.setPlotProjection(proj)
        sameproj = proj == self.image.projection
        self._wcenter.setVisible(sameproj)
        self._qa_center.setVisible(not sameproj)
        if self._image_border:
            (l0, l1), (m0, m1) = self.image.getExtents()
            path = numpy.array([l0, l0, l1, l1, l0]), numpy.array([m0, m1, m1, m0, m0])
            self._image_border.setData(*path)
            if self._image_label:
                self._image_label.setValue(path[0][2], path[1][2])

    def addPlotBorder(self, border_pen, label, label_color=None, bg_brush=None):
        # make plot items for image frame
        # make curve for image borders
        (l0, l1), (m0, m1) = self.image.getExtents()
        self._border_pen = QPen(border_pen)
        self._image_border.show()
        self._image_border.setData([l0, l0, l1, l1, l0], [m0, m1, m1, m0, m0])
        self._image_border.setPen(self._border_pen)
        self._image_border.setZ(self.image.z() + 1 if self._z_markers is None else self._z_markers)
        if label:
            self._image_label.show()
            self._image_label_text = text = QwtText(" %s " % label)
            text.setColor(label_color)
            text.setBackgroundBrush(bg_brush)
            self._image_label.setValue(l1, m1)
            self._image_label.setLabel(text)
            self._image_label.setLabelAlignment(Qt.AlignRight | Qt.AlignVCenter)
            self._image_label.setZ(self.image.z() + 2 if self._z_markers is None else self._z_markers)

    def setPlotBorderStyle(self, border_color=None, label_color=None):
        if border_color:
            self._border_pen.setColor(border_color)
            self._image_border.setPen(self._border_pen)
        if label_color:
            self._image_label_text.setColor(label_color)
            self._image_label.setLabel(self._image_label_text)

    def showPlotBorder(self, show=True):
        self._image_border.setVisible(show)
        self._image_label.setVisible(show)

    def attachToPlot(self, plot, z_markers=None):
        for item in [self.image] + self._all_markers:
            if item.plot() != plot:
                item.attach(plot)

    def setImageVisible(self, visible):
        self.image.setVisible(visible)

    def showRenderControls(self):
        if not self._control_dialog:
            dprint(1, "creating control dialog")
            self._control_dialog = ImageControlDialog(self, self._rc, self._imgman)
            dprint(1, "done")
        if not self._control_dialog.isVisible():
            dprint(1, "showing control dialog")
            self._control_dialog.show()
        else:
            self._control_dialog.hide()

    def _changeDisplayRangeToPercent(self, percent):
        if not self._control_dialog:
            self._control_dialog = ImageControlDialog(self, self._rc, self._imgman)
        self._control_dialog._changeDisplayRangeToPercent(percent)

    def _updateDisplayRange(self, dmin, dmax):
        """Updates display range widgets."""
        self._wmin.setText("%.4g" % dmin)
        self._wmax.setText("%.4g" % dmax)
        self._updateFullRangeIcon()

    def _changeDisplayRange(self):
        """Gets display range from widgets and updates the image with it."""
        try:
            newrange = float(str(self._wmin.text())), float(str(self._wmax.text()))
        except ValueError:
            return
        self._rc.setDisplayRange(*newrange)

    def _dataSubsetChanged(self, subset, minmax, desc, subset_type):
        """Called when the data subset changes (or is reset)"""
        # hide the subset indicator -- unless we're invoked while we're actually setting the subset itself
        if not self._setting_lmrect:
            self._subset = None
            self._subset_border.setVisible(False)
            self._subset_label.setVisible(False)

    def setLMRectSubset(self, rect):
        self._subset = rect
        l0, m0, l1, m1 = rect.getCoords()
        self._subset_border.setData([l0, l0, l1, l1, l0], [m0, m1, m1, m0, m0])
        self._subset_border.setVisible(True)
        self._subset_label.setValue(max(l0, l1), max(m0, m1))
        self._subset_label.setVisible(True)
        self._setting_lmrect = True
        self.renderControl().setLMRectSubset(rect)
        self._setting_lmrect = False

    def currentSlice(self):
        return self._rc.currentSlice()

    def _updateImageSlice(self, slice):
        dprint(2, slice)
        for i, (iextra, name, labels) in enumerate(self._rc.slicedAxes()):
            slicer = self._wslicers[i]
            if slicer.currentIndex() != slice[iextra]:
                dprint(3, "setting widget", i, "to", slice[iextra])
                slicer.setCurrentIndex(slice[iextra])

    def setMarkersZ(self, z):
        self._z_markers = z
        for i, elem in enumerate(self._all_markers):
            elem.setZ(z + i)

    def setZ(self, z, top=False, depthlabel=None, can_raise=True):
        self.image.setZ(z)
        if self._z_markers is None:
            for i, elem in enumerate(self._all_markers):
                elem.setZ(z + i + i)
        # set the depth label, if any
        label = "%s: %s" % (chr(ord('a') + self._number), self.name)
        # label = "%s %s"%(depthlabel,self.name) if depthlabel else self.name
        if top:
            label = "%s: <B>%s</B>" % (chr(ord('a') + self._number), self.name)
        self._wlabel.setText(label)
        # set hotkey
        self._qa_show_rc.setShortcut(Qt.Key_F9 if top else QKeySequence())
        # set raise control
        self._can_raise = can_raise
        self._qa_raise.setVisible(can_raise)
        self._wlock.setVisible(can_raise)
        if can_raise:
            self._wraise.setToolTip(
                "<P>Click here to raise this image to the top. Click on the down-arrow to access the image menu.</P>")
        else:
            self._wraise.setToolTip("<P>Click to access the image menu.</P>")

    def _raiseButtonPressed(self):
        if self._can_raise:
            self.image.emit(SIGNAL("raise"))
        else:
            self._wraise.showMenu()

    def _saveImage(self):
        filename = QFileDialog.getSaveFileName(self, "Save FITS file", self._save_dir,
                                               "FITS files(*.fits *.FITS *fts *FTS)")
        filename = str(filename)
        if not filename:
            return
        busy = BusyIndicator()
        self._imgman.showMessage("""Writing FITS image %s""" % filename, 3000)
        QApplication.flush()
        try:
            self.image.save(filename)
        except Exception as exc:
            busy = None
            traceback.print_exc()
            self._imgman.showErrorMessage("""Error writing FITS image %s: %s""" % (filename, str(sys.exc_info()[1])))
            return None
        self.renderControl().startSavingConfig(filename)
        self.setName(self.image.name)
        self._qa_save.setVisible(False)
        self._wsave.hide()
        busy = None

    def _exportImageToPNG(self, filename=None):
        if not filename:
            if not self._export_png_dialog:
                dialog = self._export_png_dialog = QFileDialog(self, "Export image to PNG", ".", "*.png")
                dialog.setDefaultSuffix("png")
                dialog.setFileMode(QFileDialog.AnyFile)
                dialog.setAcceptMode(QFileDialog.AcceptSave)
                dialog.setModal(True)
                QObject.connect(dialog, SIGNAL("filesSelected(const QStringList &)"), self._exportImageToPNG)
            return self._export_png_dialog.exec_() == QDialog.Accepted
        busy = BusyIndicator()
        if isinstance(filename, QStringList):
            filename = filename[0]
        filename = str(filename)
        # make QPixmap
        nx, ny = self.image.imageDims()
        (l0, l1), (m0, m1) = self.image.getExtents()
        pixmap = QPixmap(nx, ny)
        painter = QPainter(pixmap)
        # use QwtPlot implementation of draw canvas, since we want to avoid caching
        xmap = QwtScaleMap()
        xmap.setPaintInterval(0, nx)
        xmap.setScaleInterval(l1, l0)
        ymap = QwtScaleMap()
        ymap.setPaintInterval(ny, 0)
        ymap.setScaleInterval(m0, m1)
        self.image.draw(painter, xmap, ymap, pixmap.rect())
        painter.end()
        # save to file
        try:
            pixmap.save(filename, "PNG")
        except Exception as exc:
            self.emit(SIGNAL("showErrorMessage"), "Error writing %s: %s" % (filename, str(exc)))
            return
        self.emit(SIGNAL("showMessage"), "Exported image to file %s" % filename)

    def _toggleDisplayRangeLock(self):
        self.renderControl().lockDisplayRange(not self.renderControl().isDisplayRangeLocked())

    def _setDisplayRangeLock(self, locked):
        self._wlock.setIcon(pixmaps.locked.icon() if locked else pixmaps.unlocked.icon())

    def _updateFullRangeIcon(self):
        if self._rc.isSubsetDisplayRange():
            self._wfullrange.setIcon(pixmaps.zoom_range.icon())
            self._wfullrange.setToolTip(
                """<P>The current intensity range is the full range. Hold this button down briefly for additional options.</P>""")
        else:
            self._wfullrange.setIcon(pixmaps.full_range.icon())
            self._wfullrange.setToolTip(
                """<P>Click to reset to a full intensity range. Hold the button down briefly for additional options.</P>""")
Example #14
0
 def __init__(self):
     QwtPlotMarker.__init__(self)
Example #15
0
class TestPlot(QwtPlot):
    def __init__(self, parent=None):
        super(TestPlot, self).__init__(parent)
        self.setWindowTitle("PyQwt" if USE_PYQWT5 else "PythonQwt")
        self.enableAxis(self.xTop, True)
        self.enableAxis(self.yRight, True)
        y = np.linspace(0, 10, 500)
        curve1 = QwtPlotCurve('Test Curve 1')
        curve1.setData(np.sin(y), y)
        curve2 = QwtPlotCurve('Test Curve 2')
        curve2.setData(y**3, y)
        if USE_PYQWT5:
            curve2.setAxis(self.xTop, self.yRight)
        else:
            # PythonQwt
            curve2.setAxes(self.xTop, self.yRight)

        for item, col, xa, ya in ((curve1, Qt.green, self.xBottom, self.yLeft),
                                  (curve2, Qt.red, self.xTop, self.yRight)):
            if not USE_PYQWT5:
                # PythonQwt
                item.setOrientation(Qt.Vertical)
            item.attach(self)
            item.setPen(QPen(col))
            for axis_id in xa, ya:
                palette = self.axisWidget(axis_id).palette()
                palette.setColor(QPalette.WindowText, QColor(col))
                palette.setColor(QPalette.Text, QColor(col))
                self.axisWidget(axis_id).setPalette(palette)
                ticks_font = self.axisFont(axis_id)
                self.setAxisFont(axis_id, ticks_font)
        
        self.canvas().setFrameStyle(0)#QFrame.Panel|QFrame.Sunken)
        self.plotLayout().setCanvasMargin(0)
        self.axisWidget(QwtPlot.yLeft).setMargin(0)
        self.axisWidget(QwtPlot.xTop).setMargin(0)
        self.axisWidget(QwtPlot.yRight).setMargin(0)
        self.axisWidget(QwtPlot.xBottom).setMargin(0)

        self.marker = QwtPlotMarker()
        self.marker.setValue(0, 5)
        self.marker.attach(self)
        
    def resizeEvent(self, event):
        super(TestPlot, self).resizeEvent(event)
        self.show_layout_details()
    
    def show_layout_details(self):
        text = QwtText(
          "plotLayout().canvasRect():\n%r\n\n"
          "canvas().geometry():\n%r\n\n"
          "plotLayout().scaleRect(QwtPlot.yLeft):\n%r\n\n"
          "axisWidget(QwtPlot.yLeft).geometry():\n%r\n\n"
          "plotLayout().scaleRect(QwtPlot.yRight):\n%r\n\n"
          "axisWidget(QwtPlot.yRight).geometry():\n%r\n\n"
          "plotLayout().scaleRect(QwtPlot.xBottom):\n%r\n\n"
          "axisWidget(QwtPlot.xBottom).geometry():\n%r\n\n"
          "plotLayout().scaleRect(QwtPlot.xTop):\n%r\n\n"
          "axisWidget(QwtPlot.xTop).geometry():\n%r\n\n"
              % (self.plotLayout().canvasRect().getCoords(),
                 self.canvas().geometry().getCoords(),
                 self.plotLayout().scaleRect(QwtPlot.yLeft).getCoords(),
                 self.axisWidget(QwtPlot.yLeft).geometry().getCoords(),
                 self.plotLayout().scaleRect(QwtPlot.yRight).getCoords(),
                 self.axisWidget(QwtPlot.yRight).geometry().getCoords(),
                 self.plotLayout().scaleRect(QwtPlot.xBottom).getCoords(),
                 self.axisWidget(QwtPlot.xBottom).geometry().getCoords(),
                 self.plotLayout().scaleRect(QwtPlot.xTop).getCoords(),
                 self.axisWidget(QwtPlot.xTop).geometry().getCoords(),
                 )
                       )
        text.setFont(QFont('Courier New'))
        text.setColor(Qt.blue)
        self.marker.setLabel(text)
Example #16
0
class TestPlot(QwtPlot):
    def __init__(self, parent=None):
        super(TestPlot, self).__init__(parent)
        self.setWindowTitle("PyQwt" if USE_PYQWT5 else "PythonQwt")
        self.enableAxis(self.xTop, True)
        self.enableAxis(self.yRight, True)
        y = np.linspace(0, 10, 500)
        curve1 = QwtPlotCurve('Test Curve 1')
        curve1.setData(np.sin(y), y)
        curve2 = QwtPlotCurve('Test Curve 2')
        curve2.setData(y**3, y)
        if USE_PYQWT5:
            curve2.setAxis(self.xTop, self.yRight)
        else:
            # PythonQwt
            curve2.setAxes(self.xTop, self.yRight)

        for item, col, xa, ya in ((curve1, Qt.green, self.xBottom, self.yLeft),
                                  (curve2, Qt.red, self.xTop, self.yRight)):
            if not USE_PYQWT5:
                # PythonQwt
                item.setOrientation(Qt.Vertical)
            item.attach(self)
            item.setPen(QPen(col))
            for axis_id in xa, ya:
                palette = self.axisWidget(axis_id).palette()
                palette.setColor(QPalette.WindowText, QColor(col))
                palette.setColor(QPalette.Text, QColor(col))
                self.axisWidget(axis_id).setPalette(palette)
                ticks_font = self.axisFont(axis_id)
                self.setAxisFont(axis_id, ticks_font)

        self.canvas().setFrameStyle(0)  #QFrame.Panel|QFrame.Sunken)
        self.plotLayout().setCanvasMargin(0)
        self.axisWidget(QwtPlot.yLeft).setMargin(0)
        self.axisWidget(QwtPlot.xTop).setMargin(0)
        self.axisWidget(QwtPlot.yRight).setMargin(0)
        self.axisWidget(QwtPlot.xBottom).setMargin(0)

        self.marker = QwtPlotMarker()
        self.marker.setValue(0, 5)
        self.marker.attach(self)

    def resizeEvent(self, event):
        super(TestPlot, self).resizeEvent(event)
        self.show_layout_details()

    def show_layout_details(self):
        text = QwtText(
            "plotLayout().canvasRect():\n%r\n\n"
            "canvas().geometry():\n%r\n\n"
            "plotLayout().scaleRect(QwtPlot.yLeft):\n%r\n\n"
            "axisWidget(QwtPlot.yLeft).geometry():\n%r\n\n"
            "plotLayout().scaleRect(QwtPlot.yRight):\n%r\n\n"
            "axisWidget(QwtPlot.yRight).geometry():\n%r\n\n"
            "plotLayout().scaleRect(QwtPlot.xBottom):\n%r\n\n"
            "axisWidget(QwtPlot.xBottom).geometry():\n%r\n\n"
            "plotLayout().scaleRect(QwtPlot.xTop):\n%r\n\n"
            "axisWidget(QwtPlot.xTop).geometry():\n%r\n\n" % (
                self.plotLayout().canvasRect().getCoords(),
                self.canvas().geometry().getCoords(),
                self.plotLayout().scaleRect(QwtPlot.yLeft).getCoords(),
                self.axisWidget(QwtPlot.yLeft).geometry().getCoords(),
                self.plotLayout().scaleRect(QwtPlot.yRight).getCoords(),
                self.axisWidget(QwtPlot.yRight).geometry().getCoords(),
                self.plotLayout().scaleRect(QwtPlot.xBottom).getCoords(),
                self.axisWidget(QwtPlot.xBottom).geometry().getCoords(),
                self.plotLayout().scaleRect(QwtPlot.xTop).getCoords(),
                self.axisWidget(QwtPlot.xTop).geometry().getCoords(),
            ))
        text.setFont(QFont('Courier New'))
        text.setColor(Qt.blue)
        self.marker.setLabel(text)
Example #17
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(847, 480)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.horizontalLayout_2 = QtGui.QHBoxLayout(self.centralwidget)
        self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
        self.verticalLayout = QtGui.QVBoxLayout()
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))

        #Tworzenie zakładek
        self.tabs = QtGui.QTabWidget(self.centralwidget)

        #Główny wykre
        self.plot = QwtPlot(self.centralwidget)
        self.plot.setObjectName(_fromUtf8("plot"))
        self.plot.setAxisScale(self.plot.yLeft, -20, 80)
        self.plot.setAutoFillBackground(True)
        #self.plot.setPalette(Qt.Qt.black)
        self.plot.setCanvasBackground(Qt.Qt.black)

        self.grid = QwtPlotGrid()
        '''self.Yscale = QwtScaleDiv()
        self.Yscale.setInterval(10)
        self.Xscale = QwtScaleDiv()
        self.Xscale.setInterval(10)
        self.grid.setYDiv(self.YScale)
        self.grid.setXDiv(self.Xscale)'''
        self.grid.setMajPen(Qt.Qt.gray)
        self.grid.attach(self.plot)

        self.tabs.addTab(self.plot, "Spectrum")

        self.curve = QwtPlotCurve('')
        self.curve.setPen(Qt.Qt.yellow)
        self.curve.attach(self.plot)

        self.hold_curve = QwtPlotCurve('')
        self.hold_curve.setPen(Qt.Qt.red)

        self.peak_marker = QwtPlotMarker()
        self.symbol = QwtSymbol(QwtSymbol.DTriangle, QtGui.QBrush(Qt.Qt.red),
                                QtGui.QPen(Qt.Qt.red), QtCore.QSize(10, 10))
        self.peak_marker.setSymbol(self.symbol)
        self.peak_marker.setLabelAlignment(Qt.Qt.AlignTop)

        self.sybmol_2 = QwtSymbol(QwtSymbol.DTriangle, QtGui.QBrush(Qt.Qt.red),
                                  QtGui.QPen(Qt.Qt.white),
                                  QtCore.QSize(10, 10))
        self.marker_1 = QwtPlotMarker()
        self.marker_1.setSymbol(self.sybmol_2)
        self.marker_1.setLabelAlignment(Qt.Qt.AlignTop)
        self.marker_2 = QwtPlotMarker()
        self.marker_2.setSymbol(self.sybmol_2)
        self.marker_2.setLabelAlignment(Qt.Qt.AlignTop)
        self.marker_3 = QwtPlotMarker()
        self.marker_3.setSymbol(self.sybmol_2)
        self.marker_3.setLabelAlignment(Qt.Qt.AlignTop)
        self.marker_4 = QwtPlotMarker()
        self.marker_4.setSymbol(self.sybmol_2)
        self.marker_4.setLabelAlignment(Qt.Qt.AlignTop)
        self.delta_marker = QwtPlotMarker()
        self.delta_marker.setSymbol(self.sybmol_2)
        self.delta_marker.setLabelAlignment(Qt.Qt.AlignTop)

        self.markers = [
            self.marker_1, self.marker_2, self.marker_3, self.marker_4
        ]

        self.save_curve_1 = QwtPlotCurve('')
        self.save_curve_1.setPen(Qt.Qt.green)
        self.save_curve_2 = QwtPlotCurve('')
        self.save_curve_2.setPen(Qt.Qt.cyan)
        self.save_curve_3 = QwtPlotCurve('')
        self.save_curve_3.setPen(Qt.Qt.magenta)
        self.saved_curves = [
            self.save_curve_1, self.save_curve_2, self.save_curve_3
        ]

        #Wykres waterfall
        '''self.plot_2 = QwtPlot(self.centralwidget)
        self.plot_2.setObjectName(_fromUtf8("plot_2"))
        
        self.waterfall = QwtPlotSpectrogram()
        self.waterfall.attach(self.plot_2)
        
        self.colorMap = QwtLinearColorMap(Qt.Qt.darkCyan, Qt.Qt.red)
        self.scaleColors(80)
        self.waterfall.setColorMap(self.colorMap)
        #self.waterfallData = QwtRasterData()
        #self.tabs.addTab(self.plot_2, "Waterfall")'''

        self.verticalLayout.addWidget(self.tabs)

        self.picker = QwtPlotPicker(
            QwtPlot.xBottom, QwtPlot.yLeft,
            QwtPicker.PointSelection | QwtPicker.DragSelection,
            QwtPlotPicker.CrossRubberBand, QwtPicker.AlwaysOn,
            self.plot.canvas())
        self.picker.setTrackerPen(Qt.Qt.white)
        self.picker.setRubberBandPen(Qt.Qt.gray)

        self.freqBox = QtGui.QGroupBox(self.centralwidget)
        self.freqBox.setObjectName(_fromUtf8("freqBox"))
        self.verticalLayout_3 = QtGui.QVBoxLayout(self.freqBox)

        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))

        self.formLayout_3 = QtGui.QFormLayout()
        self.formLayout_3.setObjectName(_fromUtf8("formLayout_3"))
        self.label = QtGui.QLabel(self.freqBox)
        self.label.setObjectName(_fromUtf8("label"))
        self.formLayout_3.setWidget(0, QtGui.QFormLayout.LabelRole, self.label)

        self.startEdit = QtGui.QDoubleSpinBox(self.freqBox)
        self.startEdit.setObjectName(_fromUtf8("startEdit"))
        self.startEdit.setDecimals(2)
        self.startEdit.setRange(1, 1280)
        self.startEdit.setKeyboardTracking(False)
        self.formLayout_3.setWidget(0, QtGui.QFormLayout.FieldRole,
                                    self.startEdit)
        self.horizontalLayout.addLayout(self.formLayout_3)

        self.formLayout_4 = QtGui.QFormLayout()
        self.formLayout_4.setObjectName(_fromUtf8("formLayout_4"))
        self.label_2 = QtGui.QLabel(self.freqBox)
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.formLayout_4.setWidget(0, QtGui.QFormLayout.LabelRole,
                                    self.label_2)

        self.stopEdit = QtGui.QDoubleSpinBox(self.freqBox)
        self.stopEdit.setObjectName(_fromUtf8("stopEdit"))
        self.stopEdit.setDecimals(2)
        self.stopEdit.setRange(1, 1280)
        self.stopEdit.setKeyboardTracking(False)

        self.formLayout_4.setWidget(0, QtGui.QFormLayout.FieldRole,
                                    self.stopEdit)
        self.horizontalLayout.addLayout(self.formLayout_4)
        self.formLayout_5 = QtGui.QFormLayout()
        self.formLayout_5.setObjectName(_fromUtf8("formLayout_5"))
        self.label_3 = QtGui.QLabel(self.freqBox)
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.formLayout_5.setWidget(0, QtGui.QFormLayout.LabelRole,
                                    self.label_3)

        self.rbwEdit = QtGui.QComboBox(self.freqBox)
        self.rbwEdit.setObjectName(_fromUtf8("rbwEdit"))
        self.rbwEdit.addItem('0,21 kHz', 16384)
        self.rbwEdit.addItem('0,42 kHz', 8192)
        self.rbwEdit.addItem('0,84 kHz', 4096)
        self.rbwEdit.addItem('1,69 kHz', 2048)
        self.rbwEdit.addItem('3,38 kHz', 1024)
        self.rbwEdit.addItem('6,75 kHz', 512)
        self.rbwEdit.addItem('13,5 kHz', 256)
        self.rbwEdit.addItem('27 kHz', 128)
        self.rbwEdit.addItem('54 kHz', 64)
        self.rbwEdit.addItem('108 kHz', 32)
        self.rbwEdit.addItem('216 kHz', 16)
        self.rbwEdit.addItem('432 kHz', 8)
        self.rbwEdit.setCurrentIndex(4)

        self.formLayout_5.setWidget(0, QtGui.QFormLayout.FieldRole,
                                    self.rbwEdit)
        self.horizontalLayout.addLayout(self.formLayout_5)
        spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                                       QtGui.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.verticalLayout_3.addLayout(self.horizontalLayout)

        self.horizontalLayout_3 = QtGui.QHBoxLayout()
        self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
        self.formLayout_7 = QtGui.QFormLayout()
        self.formLayout_7.setObjectName(_fromUtf8("formLayout_7"))
        self.centerLabel = QtGui.QLabel(self.freqBox)
        self.centerLabel.setObjectName(_fromUtf8("centerLabel"))
        self.formLayout_7.setWidget(0, QtGui.QFormLayout.LabelRole,
                                    self.centerLabel)

        self.centerEdit = QtGui.QDoubleSpinBox(self.freqBox)
        self.centerEdit.setObjectName(_fromUtf8("centerEdit"))
        self.centerEdit.setDecimals(2)
        self.centerEdit.setRange(1, 1280)
        self.centerEdit.setKeyboardTracking(False)
        self.formLayout_7.setWidget(0, QtGui.QFormLayout.FieldRole,
                                    self.centerEdit)
        self.horizontalLayout_3.addLayout(self.formLayout_7)

        self.formLayout_8 = QtGui.QFormLayout()
        self.formLayout_8.setObjectName(_fromUtf8("formLayout_8"))
        self.spanLabel = QtGui.QLabel(self.freqBox)
        self.spanLabel.setObjectName(_fromUtf8("spanLabel"))
        self.formLayout_8.setWidget(0, QtGui.QFormLayout.LabelRole,
                                    self.spanLabel)

        self.spanEdit = QtGui.QDoubleSpinBox(self.freqBox)
        self.spanEdit.setObjectName(_fromUtf8("spanEdit"))
        self.spanEdit.setDecimals(2)
        self.spanEdit.setRange(0.1, 1280)
        self.spanEdit.setKeyboardTracking(False)
        self.formLayout_8.setWidget(0, QtGui.QFormLayout.FieldRole,
                                    self.spanEdit)
        self.horizontalLayout_3.addLayout(self.formLayout_8)
        self.horizontalLayout_3.addItem(spacerItem)
        self.verticalLayout_3.addLayout(self.horizontalLayout_3)

        self.verticalLayout.addWidget(self.freqBox)
        self.horizontalLayout_2.addLayout(self.verticalLayout)

        self.settingsBox = QtGui.QGroupBox(self.centralwidget)
        self.settingsBox.setMaximumSize(QtCore.QSize(250, 16777215))
        self.settingsBox.setObjectName(_fromUtf8("settingsBox"))
        self.verticalLayout_2 = QtGui.QVBoxLayout(self.settingsBox)
        self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))

        self.formLayout = QtGui.QFormLayout()
        self.formLayout.setObjectName(_fromUtf8("formLayout"))
        self.gainLabel = QtGui.QLabel(self.settingsBox)
        self.gainLabel.setAlignment(QtCore.Qt.AlignRight
                                    | QtCore.Qt.AlignTrailing
                                    | QtCore.Qt.AlignVCenter)
        self.gainLabel.setObjectName(_fromUtf8("gainLabel"))
        self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole,
                                  self.gainLabel)
        self.gainSlider = QtGui.QSlider(self.settingsBox)
        self.gainSlider.setMaximum(49)
        self.gainSlider.setSingleStep(1)
        self.gainSlider.setProperty("value", 20)
        self.gainSlider.setOrientation(QtCore.Qt.Horizontal)
        self.gainSlider.setObjectName(_fromUtf8("gainSlider"))
        self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole,
                                  self.gainSlider)
        self.verticalLayout_2.addLayout(self.formLayout)

        self.gainDisp = QtGui.QLCDNumber(self.settingsBox)
        self.gainDisp.setSegmentStyle(QtGui.QLCDNumber.Flat)
        self.verticalLayout_2.addWidget(self.gainDisp)
        '''self.offsetButton = QtGui.QPushButton(self.settingsBox)
        self.offsetButton.setText("Remove DC offset")
        self.verticalLayout_2.addWidget(self.offsetButton)  '''

        self.formLayout_2 = QtGui.QFormLayout()
        self.formLayout_2.setObjectName(_fromUtf8("formLayout_2"))
        self.refLabel = QtGui.QLabel(self.settingsBox)
        self.refLabel.setAlignment(QtCore.Qt.AlignRight
                                   | QtCore.Qt.AlignTrailing
                                   | QtCore.Qt.AlignVCenter)
        self.refLabel.setObjectName(_fromUtf8("refLabel"))
        self.formLayout_2.setWidget(0, QtGui.QFormLayout.LabelRole,
                                    self.refLabel)
        self.refEdit = QtGui.QDoubleSpinBox(self.settingsBox)
        self.refEdit.setObjectName(_fromUtf8("refEdit"))
        self.refEdit.setDecimals(0)
        self.refEdit.setKeyboardTracking(False)
        self.formLayout_2.setWidget(0, QtGui.QFormLayout.FieldRole,
                                    self.refEdit)
        self.verticalLayout_2.addLayout(self.formLayout_2)

        spacerItem1 = QtGui.QSpacerItem(158, 304, QtGui.QSizePolicy.Minimum,
                                        QtGui.QSizePolicy.Expanding)
        self.verticalLayout_2.addItem(spacerItem1)

        #Settings tabs
        self.settings_tabs = QtGui.QTabWidget(self.settingsBox)
        self.verticalLayout_2.addWidget(self.settings_tabs)

        self.verticalLayout_4 = QtGui.QVBoxLayout()
        self.saveButton = QtGui.QPushButton(self.settingsBox)
        self.saveButton.setText("Save plot")
        self.verticalLayout_4.addWidget(self.saveButton)

        self.formLayout_9 = QtGui.QFormLayout()
        self.formLayout_9.setObjectName(_fromUtf8("formLayout_9"))
        self.avgLabel = QtGui.QLabel(self.settingsBox)
        self.avgLabel.setAlignment(QtCore.Qt.AlignRight
                                   | QtCore.Qt.AlignTrailing
                                   | QtCore.Qt.AlignVCenter)
        self.avgLabel.setObjectName(_fromUtf8("avgLabel"))
        self.formLayout_9.setWidget(0, QtGui.QFormLayout.LabelRole,
                                    self.avgLabel)
        self.avgCheck = QtGui.QCheckBox(self.settingsBox)
        self.formLayout_9.setWidget(0, QtGui.QFormLayout.FieldRole,
                                    self.avgCheck)
        self.verticalLayout_4.addLayout(self.formLayout_9)

        self.formLayout_10 = QtGui.QFormLayout()
        self.avgLabel_2 = QtGui.QLabel(self.settingsBox)
        self.avgLabel_2.setAlignment(QtCore.Qt.AlignRight
                                     | QtCore.Qt.AlignTrailing
                                     | QtCore.Qt.AlignVCenter)
        self.avgLabel_2.setObjectName(_fromUtf8("avgLabel_2"))
        self.formLayout_10.setWidget(0, QtGui.QFormLayout.LabelRole,
                                     self.avgLabel_2)
        self.avgEdit = QtGui.QDoubleSpinBox(self.settingsBox)
        self.avgEdit.setDecimals(0)
        self.avgEdit.setRange(1, 100)
        self.avgEdit.setKeyboardTracking(False)
        self.avgEdit.setValue(10)
        self.formLayout_10.setWidget(0, QtGui.QFormLayout.FieldRole,
                                     self.avgEdit)
        self.verticalLayout_4.addLayout(self.formLayout_10)

        self.formLayout_6 = QtGui.QFormLayout()
        self.formLayout_6.setObjectName(_fromUtf8("formLayout_6"))
        self.holdLabel = QtGui.QLabel(self.settingsBox)
        self.holdLabel.setAlignment(QtCore.Qt.AlignRight
                                    | QtCore.Qt.AlignTrailing
                                    | QtCore.Qt.AlignVCenter)
        self.holdLabel.setObjectName(_fromUtf8("holdLabel"))
        self.formLayout_6.setWidget(0, QtGui.QFormLayout.LabelRole,
                                    self.holdLabel)
        self.holdCheck = QtGui.QCheckBox(self.settingsBox)
        self.formLayout_6.setWidget(0, QtGui.QFormLayout.FieldRole,
                                    self.holdCheck)
        self.verticalLayout_4.addLayout(self.formLayout_6)

        self.formLayout_11 = QtGui.QFormLayout()
        self.formLayout_11.setObjectName(_fromUtf8("formLayout_11"))
        self.peakLabel = QtGui.QLabel(self.settingsBox)
        self.peakLabel.setAlignment(QtCore.Qt.AlignRight
                                    | QtCore.Qt.AlignTrailing
                                    | QtCore.Qt.AlignVCenter)
        self.peakLabel.setObjectName(_fromUtf8("peakLabel"))
        self.formLayout_11.setWidget(0, QtGui.QFormLayout.LabelRole,
                                     self.peakLabel)
        self.peakCheck = QtGui.QCheckBox(self.settingsBox)
        self.formLayout_11.setWidget(0, QtGui.QFormLayout.FieldRole,
                                     self.peakCheck)
        self.verticalLayout_4.addLayout(self.formLayout_11)

        self.peakStatus = QtGui.QLabel("Peak: ")

        self.correctButton = QtGui.QPushButton(self.settingsBox)
        self.correctButton.setText("Correction")
        self.verticalLayout_4.addWidget(self.correctButton)

        self.verticalLayout_5 = QtGui.QVBoxLayout()
        self.traceButton = QtGui.QPushButton(self.settingsBox)
        self.traceButton.setText("Save trace 1")
        self.verticalLayout_5.addWidget(self.traceButton)

        self.traceButton_2 = QtGui.QPushButton(self.settingsBox)
        self.traceButton_2.setText("Save trace 2")
        self.verticalLayout_5.addWidget(self.traceButton_2)

        self.traceButton_3 = QtGui.QPushButton(self.settingsBox)
        self.traceButton_3.setText("Save trace 3")
        self.verticalLayout_5.addWidget(self.traceButton_3)

        self.traces = [
            self.traceButton, self.traceButton_2, self.traceButton_3
        ]

        #MARKERS
        self.gridLayout = QtGui.QGridLayout()
        self.markerLabel = QtGui.QLabel(self.settingsBox)
        self.markerLabel.setAlignment(QtCore.Qt.AlignRight
                                      | QtCore.Qt.AlignTrailing
                                      | QtCore.Qt.AlignVCenter)
        self.gridLayout.addWidget(self.markerLabel, 0, 0)
        self.markerCheck = QtGui.QCheckBox(self.settingsBox)
        self.gridLayout.addWidget(self.markerCheck, 0, 1)
        self.markerEdit = QtGui.QDoubleSpinBox(self.settingsBox)
        self.markerEdit.setDecimals(2)
        self.markerEdit.setKeyboardTracking(False)
        self.markerEdit.setDisabled(True)
        self.markerEdit.setSingleStep(0.1)
        self.gridLayout.addWidget(self.markerEdit, 0, 2)

        self.markerLabel_2 = QtGui.QLabel(self.settingsBox)
        self.markerLabel_2.setAlignment(QtCore.Qt.AlignRight
                                        | QtCore.Qt.AlignTrailing
                                        | QtCore.Qt.AlignVCenter)
        self.gridLayout.addWidget(self.markerLabel_2, 2, 0)
        self.markerCheck_2 = QtGui.QCheckBox(self.settingsBox)
        self.gridLayout.addWidget(self.markerCheck_2, 2, 1)
        self.markerEdit_2 = QtGui.QDoubleSpinBox(self.settingsBox)
        self.markerEdit_2.setDecimals(2)
        self.markerEdit_2.setKeyboardTracking(False)
        self.markerEdit_2.setDisabled(True)
        self.markerEdit_2.setSingleStep(0.1)
        self.gridLayout.addWidget(self.markerEdit_2, 2, 2)

        self.markerLabel_3 = QtGui.QLabel(self.settingsBox)
        self.markerLabel_3.setAlignment(QtCore.Qt.AlignRight
                                        | QtCore.Qt.AlignTrailing
                                        | QtCore.Qt.AlignVCenter)
        self.gridLayout.addWidget(self.markerLabel_3, 3, 0)
        self.markerCheck_3 = QtGui.QCheckBox(self.settingsBox)
        self.gridLayout.addWidget(self.markerCheck_3, 3, 1)
        self.markerEdit_3 = QtGui.QDoubleSpinBox(self.settingsBox)
        self.markerEdit_3.setDecimals(2)
        self.markerEdit_3.setKeyboardTracking(False)
        self.markerEdit_3.setDisabled(True)
        self.markerEdit_3.setSingleStep(0.1)
        self.gridLayout.addWidget(self.markerEdit_3, 3, 2)

        self.markerLabel_4 = QtGui.QLabel(self.settingsBox)
        self.markerLabel_4.setAlignment(QtCore.Qt.AlignRight
                                        | QtCore.Qt.AlignTrailing
                                        | QtCore.Qt.AlignVCenter)
        self.gridLayout.addWidget(self.markerLabel_4, 4, 0)
        self.markerCheck_4 = QtGui.QCheckBox(self.settingsBox)
        self.gridLayout.addWidget(self.markerCheck_4, 4, 1)
        self.markerEdit_4 = QtGui.QDoubleSpinBox(self.settingsBox)
        self.markerEdit_4.setDecimals(2)
        self.markerEdit_4.setKeyboardTracking(False)
        self.markerEdit_4.setDisabled(True)
        self.markerEdit_4.setSingleStep(0.1)
        self.gridLayout.addWidget(self.markerEdit_4, 4, 2)

        self.deltaLabel = QtGui.QLabel(self.settingsBox)
        self.deltaLabel.setAlignment(QtCore.Qt.AlignRight
                                     | QtCore.Qt.AlignTrailing
                                     | QtCore.Qt.AlignVCenter)
        self.gridLayout.addWidget(self.deltaLabel, 1, 0)
        self.deltaCheck = QtGui.QCheckBox(self.settingsBox)
        self.gridLayout.addWidget(self.deltaCheck, 1, 1)
        self.deltaEdit = QtGui.QDoubleSpinBox(self.settingsBox)
        self.deltaEdit.setDecimals(2)
        self.deltaEdit.setSingleStep(0.1)
        self.deltaEdit.setKeyboardTracking(False)
        self.deltaEdit.setDisabled(True)
        self.gridLayout.addWidget(self.deltaEdit, 1, 2)
        self.deltaCheck.setDisabled(True)

        self.tab1 = QtGui.QWidget()
        self.settings_tabs.addTab(self.tab1, "Misc.")
        self.settings_tabs.widget(0).setLayout(self.verticalLayout_4)

        self.tab2 = QtGui.QWidget()
        self.settings_tabs.addTab(self.tab2, "Traces")
        self.settings_tabs.widget(1).setLayout(self.verticalLayout_5)

        self.tab3 = QtGui.QWidget()
        self.settings_tabs.addTab(self.tab3, "Markers")
        self.settings_tabs.widget(2).setLayout(self.gridLayout)

        self.horizontalLayout_2.addWidget(self.settingsBox)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 847, 21))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)
        self.statusbar.addWidget(self.peakStatus)
        self.statusbar.setVisible(False)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.gainSlider.valueChanged.connect(self.gainDisp.display)
        self.saveButton.clicked.connect(self.savePlot)
class LiberaSinglePassEMini(TaurusWidget):
    l_plot = None
    trigger = QtCore.pyqtSignal()

    def __init__(self, parent=None, designMode=False):
        TaurusWidget.__init__(self, parent, designMode=designMode)

        self._ui = Ui_LiberaSinglePassEMini()
        self._ui.setupUi(self)
        self._ui.taurusCurveDialog = myTaurusCurveDialog(self)
        self._ui.taurusCurveDialog.setObjectName("taurusCurveDialog")
        self._ui.gridLayout.addWidget(self._ui.taurusCurveDialog, 0, 0, 1, 1)
        self.l_plot = self._ui.taurusCurveDialog.get_active_plot()
        self.sym = QwtSymbol(QwtSymbol.Ellipse, QtGui.QBrush(QtCore.Qt.blue),
                             QtGui.QPen(QtCore.Qt.blue), QtCore.QSize(10, 10))
        self.sym_old = QwtSymbol(QwtSymbol.Ellipse,
                                 QtGui.QBrush(QtCore.Qt.gray),
                                 QtGui.QPen(QtCore.Qt.gray),
                                 QtCore.QSize(4, 4))
        self.l_plot.set_axis_limits('left', -0.003, 0.003)
        self.l_plot.set_axis_title('left', "Y")
        self.l_plot.set_axis_unit('left', "mm")
        self.l_plot.set_axis_limits('bottom', -0.003, 0.003)
        self.l_plot.set_axis_title('bottom', "X")
        self.l_plot.set_axis_unit('bottom', "mm")
        self.x = 0
        self.y = 0
        self.list_mark = []
        self.trigger.connect(self.update_plot)

    @classmethod
    def getQtDesignerPluginInfo(cls):
        ret = TaurusWidget.getQtDesignerPluginInfo()
        ret['module'] = 'liberasinglepassemini'
        ret['group'] = 'Taurus Display'
        ret['container'] = ':/designer/frame.png'
        ret['container'] = False
        return ret

    def setModel(self, models):
        self._ui.taurusTrend.setModel(models[:3])
        index = models[0].rfind("/")
        self.dev = PyTango.DeviceProxy(models[0][:index])
        self.id1 = self.dev.subscribe_event('X',
                                            PyTango.EventType.CHANGE_EVENT,
                                            self.handle_x)
        self.id2 = self.dev.subscribe_event('Y',
                                            PyTango.EventType.CHANGE_EVENT,
                                            self.handle_y)
        self._ui.taurusTrend_2.setModel(models[3])

    def handle_x(self, evt):
        if evt.attr_value is not None:
            if evt.attr_value.value != self.x:
                self.x = evt.attr_value.value / 1e9

    def handle_y(self, evt):
        if evt.attr_value is not None:
            if evt.attr_value.value != self.y:
                self.y = evt.attr_value.value / 1e9
                self.mark = QwtPlotMarker()
                self.mark.setSymbol(self.sym)
                self.mark.attach(self.l_plot)
                self.mark.setValue(self.x, self.y)
                if len(self.list_mark) > 10:
                    self.list_mark[0].setVisible(False)
                    l_mark = self.list_mark[0]
                    self.list_mark.pop(0)
                for mark in self.list_mark:
                    mark.setSymbol(self.sym_old)
                self.list_mark.append(self.mark)
                self.trigger.emit()

    def update_plot(self):
        if self.l_plot is not None:
            self.l_plot.replot()