def __init__(self, *args): """ Plot constructor, change axis, init curve """ Qwt.QwtPlot.__init__(self, *args) self.setCanvasBackground(Qt.Qt.white) self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, TimeScaleDraw()) self.initGrid() self.alignScales() self.initZoom() self.timer = None self.picker = Qwt.QwtPlotPicker( Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection | Qwt.QwtPicker.DragSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn, self.canvas()) self.picker.setTrackerPen(Qt.QPen(Qt.Qt.blue)) self.curve = None self.initCurve() self.makeAction() self.setContextMenuPolicy(Qt.Qt.CustomContextMenu) Qt.QObject.connect(self, Qt.SIGNAL("customContextMenuRequested ( QPoint )"), self.contextMenu)
def __init__(self, *args): super(QwtChart, self).__init__(*args) # set title self.setTitle(u'<h4><font color=red>图表</font></h4>') # bgcolor self.setCanvasBackground(Qt.Qt.white) # legend self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.RightLegend) # a variation on the C++ example self.plotLayout().setAlignCanvasToScales(True) # grid grid = Qwt.QwtPlotGrid() grid.setPen(QtGui.QPen(Qt.Qt.gray, 0, Qt.Qt.DotLine)) grid.attach(self) # set axis titles self.setAxisTitle(Qwt.QwtPlot.xBottom, u'X') self.setAxisTitle(Qwt.QwtPlot.yLeft, u'Amplitude') # set Scale Range self.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, 1000.0) self.setAxisScale(Qwt.QwtPlot.yLeft, -10.0, 10.0) # picker self.picker = Qwt.QwtPlotPicker( Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection | Qwt.QwtPicker.DragSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn, self.canvas()) self.picker.setRubberBandPen(QtGui.QPen(Qt.Qt.red)) self.picker.setTrackerPen(QtGui.QPen(Qt.Qt.red)) self.connect(self.picker, QtCore.SIGNAL('moved(const QPoint &)'), self.moved) # insert a horizontal marker at y = 0 mY = Qwt.QwtPlotMarker() mY.setLabel(Qwt.QwtText('y = 0')) mY.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop) mY.setLineStyle(Qwt.QwtPlotMarker.HLine) mY.setLinePen(Qt.QPen(Qt.Qt.cyan, 1, Qt.Qt.DashDotLine)) mY.setYValue(0.0) mY.attach(self) # insert a vertical marker at x = 500 mX = Qwt.QwtPlotMarker() mX.setLabel(Qwt.QwtText('x = 500')) mX.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop) mX.setLineStyle(Qwt.QwtPlotMarker.VLine) mX.setLinePen(QtGui.QPen(Qt.Qt.cyan, 1, Qt.Qt.DashDotLine)) mX.setXValue(500) mX.attach(self) #Initialize data self.curves = [] self.dataLength = 1000 self.x = np.arange(0.0, 1001.0, 1.0)
def make(): demo = Qwt.QwtPlot() picker = Qwt.QwtPlotPicker(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn, demo.canvas()) picker.connect(picker, Qt.SIGNAL("selected(const QwtDoublePoint&)"), aSlot) return demo
def __init__(self, *args): super(DataPlot, self).__init__(*args) self.setCanvasBackground(Qt.white) self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend) self.curves = {} self.pauseFlag = False self.dataOffsetX = 0 self.canvasOffsetX = 0 self.canvasOffsetY = 0 self.lastCanvasX = 0 self.lastCanvasY = 0 self.pressedCanvasY = 0 self.redrawOnEachUpdate = False self.redrawOnFullUpdate = True self.redrawTimerInterval = None self.redrawManually = False self.oscilloscopeNextDataPosition = 0 self.oscilloscopeMode = False self.lastClickCoordinates = None markerAxisY = Qwt.QwtPlotMarker() markerAxisY.setLabelAlignment(Qt.AlignRight | Qt.AlignTop) markerAxisY.setLineStyle(Qwt.QwtPlotMarker.HLine) markerAxisY.setYValue(0.0) markerAxisY.attach(self) #self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time") #self.setAxisTitle(Qwt.QwtPlot.yLeft, "Value") self.picker = Qwt.QwtPlotPicker( Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PolygonSelection, Qwt.QwtPlotPicker.PolygonRubberBand, Qwt.QwtPicker.AlwaysOn, self.canvas() ) self.picker.setRubberBandPen(QPen(self.colors[-1])) self.picker.setTrackerPen(QPen(self.colors[-1])) # Initialize data self.timeAxis = arange(self.dataNumValuesPloted) self.canvasDisplayHeight = 1000 self.canvasDisplayWidth = self.canvas().width() self.dataOffsetX = self.dataNumValuesSaved - len(self.timeAxis) self.redraw() self.moveCanvas(0, 0) self.canvas().setMouseTracking(True) self.canvas().installEventFilter(self) # init and start redraw timer self.timerRedraw = QTimer(self) self.timerRedraw.timeout.connect(self.redraw) if self.redrawTimerInterval: self.timerRedraw.start(self.redrawTimerInterval)
def main(args): app = Qt.QApplication(args) demo = make() zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOff, demo.canvas()) zoomer.setRubberBandPen(Qt.QPen(Qt.Qt.green)) picker = Qwt.QwtPlotPicker(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.NoSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn, demo.canvas()) picker.setTrackerPen(Qt.QPen(Qt.Qt.red)) sys.exit(app.exec_())
def __init__(self, *args): apply(Qt.QFrame.__init__, (self, ) + args) vknobpos = scopeheight + 30 hknobpos = scopewidth + 10 # the following: setPal.. doesn't seem to work on Ein try: self.setPaletteBackgroundColor(QColor(240, 240, 245)) except: pass self.setFixedSize(scopewidth + 160, scopeheight + 160) self.freezeState = 0 self.knbSignal = LblKnob(self, 160, vknobpos, "Signal", 1) self.knbTime = LblKnob(self, 310, vknobpos, "Frequency", 1) self.knbTime.setRange(1.0, 1250.0) self.knbSignal.setRange(100, 1000000) self.plot = FScope(self) self.plot.setGeometry(12.5, 10, scopewidth + 120, scopeheight) self.picker = Qwt.QwtPlotPicker( Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection | Qwt.QwtPicker.DragSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.ActiveOnly, #AlwaysOn, self.plot.canvas()) self.picker.setRubberBandPen(Qt.QPen(Qt.Qt.green)) self.picker.setTrackerPen(Qt.QPen(Qt.Qt.cyan)) self.connect(self.knbTime.knob, Qt.SIGNAL("valueChanged(double)"), self.setTimebase) self.knbTime.setValue(1000.0) self.connect(self.knbSignal.knob, Qt.SIGNAL("valueChanged(double)"), self.setAmplitude) self.knbSignal.setValue(1000000) self.plot.show()
def __init__(self, *args): apply(Qt.QFrame.__init__, (self, ) + args) # the following: setPal.. doesn't seem to work on Win try: self.setPaletteBackgroundColor(QColor(240, 240, 245)) except: pass hknobpos = scopewidth + 20 vknobpos = scopeheight + 30 self.setFixedSize(scopewidth + 150, scopeheight + 150) self.freezeState = 0 self.triggerComboBox = Qt.QComboBox(self) self.triggerComboBox.setGeometry(hknobpos + 10, 50, 100, 40) #"Channel: ") self.triggerComboBox.addItem("Trigger off") self.triggerComboBox.addItem("CH1") self.triggerComboBox.addItem("CH2") self.triggerComboBox.setCurrentIndex(0) self.triggerSlopeComboBox = Qt.QComboBox(self) self.triggerSlopeComboBox.setGeometry(hknobpos + 10, 100, 100, 40) #"Channel: ") self.triggerSlopeComboBox.addItem("Any Slope") self.triggerSlopeComboBox.addItem("Positive") self.triggerSlopeComboBox.addItem("Negative") self.triggerSlopeComboBox.setCurrentIndex(0) self.knbLevel = LblKnob(self, hknobpos, 160, "Trigger level (%FS)") self.knbTime = LblKnob(self, hknobpos, 300, "Time", 1) self.knbSignal = LblKnob(self, 150, vknobpos, "Signal1", 1) self.knbSignal2 = LblKnob(self, 450, vknobpos, "Signal2", 1) self.knbOffset1 = LblKnob(self, 10, vknobpos, "offset1") self.knbOffset2 = LblKnob(self, 310, vknobpos, "offset2") self.knbTime.setRange(0.0001, 1.0) self.knbTime.setValue(DEFAULT_TIMEBASE) self.knbSignal.setRange(1, 1e6, 1) self.knbSignal.setValue(100.0) self.knbSignal2.setRange(1, 1e6, 1) self.knbSignal2.setValue(100.0) self.knbOffset2.setRange(-1.0, 1.0, 0.1) self.knbOffset2.setValue(0.0) self.knbOffset1.setRange(-1.0, 1.0, 0.1) self.knbOffset1.setValue(0.0) self.knbLevel.setRange(-1.0, 1.0, 0.1) self.knbLevel.setValue(0.1) self.knbLevel.setScaleMaxMajor(10) self.plot = Scope(self) self.plot.setGeometry(10, 10, scopewidth, scopeheight) self.picker = Qwt.QwtPlotPicker( Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection | Qwt.QwtPicker.DragSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.ActiveOnly, #AlwaysOn, self.plot.canvas()) self.picker.setRubberBandPen(Qt.QPen(Qt.Qt.green)) self.picker.setTrackerPen(Qt.QPen(Qt.Qt.cyan)) self.connect(self.knbTime.knob, Qt.SIGNAL("valueChanged(double)"), self.setTimebase) self.knbTime.setValue(0.01) self.connect(self.knbSignal.knob, Qt.SIGNAL("valueChanged(double)"), self.setAmplitude) self.connect(self.knbSignal2.knob, Qt.SIGNAL("valueChanged(double)"), self.setAmplitude2) #self.knbSignal.setValue(0.1) self.connect(self.knbLevel.knob, Qt.SIGNAL("valueChanged(double)"), self.setTriggerlevel) self.connect(self.knbOffset1.knob, Qt.SIGNAL("valueChanged(double)"), self.plot.setOffset1) self.connect(self.knbOffset2.knob, Qt.SIGNAL("valueChanged(double)"), self.plot.setOffset2) self.connect(self.triggerComboBox, Qt.SIGNAL('currentIndexChanged(int)'), self.setTriggerCH) self.connect(self.triggerSlopeComboBox, Qt.SIGNAL('currentIndexChanged(int)'), self.plot.setTriggerSlope) self.knbLevel.setValue(0.1) self.plot.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, 10.0 * inittime) self.plot.setAxisScale(Qwt.QwtPlot.yLeft, -initamp, initamp) self.plot.setAxisScale(Qwt.QwtPlot.yRight, -initamp, initamp) self.plot.show()
def __init__(self, options, parent=None): QtGui.QMainWindow.__init__(self, parent) self.options = options # load and uic the file right away, no additional step necessary self.gui = uic.loadUi(os.path.join(os.path.dirname(__file__),'ofdm_mrrc_rx_gui_window.ui'), self) # GUI update timer self.update_timer = Qt.QTimer() # ZeroMQ self.probe_manager = zeromq.probe_manager() self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5555", 'float32', self.plot_snr) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5554", 'float32', self.plot_snr2) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5556", 'float32', self.plot_ber) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5557", 'float32', self.plot_freqoffset) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5553", 'float32', self.plot_freqoffset2) self.probe_manager.add_socket("tcp://"+self.options.tx_hostname+":4445", 'uint8', self.plot_rate) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5559", 'float32', self.plot_csi) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5558", 'float32', self.plot_csi2) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5560", 'complex64', self.plot_scatter) self.rpc_mgr_tx = zeromq.rpc_manager() self.rpc_mgr_tx.set_request_socket("tcp://"+self.options.tx_hostname+":6660") self.rpc_mgr_rx = zeromq.rpc_manager() self.rpc_mgr_rx.set_request_socket("tcp://"+self.options.rx_hostname+":5550") # Window Title self.gui.setWindowTitle("Receiver") #Plots self.gui.qwtPlotSNR.setAxisTitle(Qwt.QwtPlot.yLeft, "Rx 1 SNR[dB]") self.gui.qwtPlotSNR.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotSNR.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotSNR.setAxisScale(Qwt.QwtPlot.yLeft, 0, 30) self.snr_x = range(0,128) self.snr_y = [0.0] self.curve_snr = Qwt.QwtPlotCurve() self.curve_snr.setPen(Qt.QPen(Qt.Qt.red, 1)) self.curve_snr.setBrush(Qt.Qt.red) self.curve_snr.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_snr.attach(self.gui.qwtPlotSNR) #Plots self.gui.qwtPlotSNR2.setAxisTitle(Qwt.QwtPlot.yLeft, "Rx 2 SNR[dB]") self.gui.qwtPlotSNR2.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotSNR2.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotSNR2.setAxisScale(Qwt.QwtPlot.yLeft, 0, 30) self.snr2_x = range(0,128) self.snr2_y = [0.0] self.curve_snr2 = Qwt.QwtPlotCurve() self.curve_snr2.setPen(Qt.QPen(Qt.Qt.red, 1)) self.curve_snr2.setBrush(Qt.Qt.red) self.curve_snr2.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_snr2.attach(self.gui.qwtPlotSNR2) self.gui.qwtPlotBER.setAxisTitle(Qwt.QwtPlot.yLeft, "BER") self.gui.qwtPlotBER.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotBER.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotBER.setAxisScale(Qwt.QwtPlot.yLeft, 0.0001, 0.5) scale_engine = Qwt.QwtLog10ScaleEngine() self.gui.qwtPlotBER.setAxisScaleEngine(Qwt.QwtPlot.yLeft, scale_engine) self.ber_x = range(0,128) self.ber_y = [0.0] self.curve_ber = Qwt.QwtPlotCurve() self.curve_ber.setBaseline(1e-100) self.curve_ber.setPen(Qt.QPen(Qt.Qt.green, 1)) self.curve_ber.setBrush(Qt.Qt.green) self.curve_ber.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_ber.attach(self.gui.qwtPlotBER) self.gui.qwtPlotFreqoffset.setAxisTitle(Qwt.QwtPlot.yLeft, "RX 1 Frequency Offset") self.gui.qwtPlotFreqoffset.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotFreqoffset.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotFreqoffset.setAxisScale(Qwt.QwtPlot.yLeft, -1, 1) self.freqoffset_x = range(0,128) self.freqoffset_y = [0.0] self.curve_freqoffset = Qwt.QwtPlotCurve() self.curve_freqoffset.setPen(Qt.QPen(Qt.Qt.black, 1)) self.curve_freqoffset.attach(self.gui.qwtPlotFreqoffset) self.gui.qwtPlotFreqoffset2.setAxisTitle(Qwt.QwtPlot.yLeft, "RX 2 Frequency Offset") self.gui.qwtPlotFreqoffset2.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotFreqoffset2.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotFreqoffset2.setAxisScale(Qwt.QwtPlot.yLeft, -1, 1) self.freqoffset2_x = range(0,128) self.freqoffset2_y = [0.0] self.curve_freqoffset2 = Qwt.QwtPlotCurve() self.curve_freqoffset2.setPen(Qt.QPen(Qt.Qt.black, 1)) self.curve_freqoffset2.attach(self.gui.qwtPlotFreqoffset2) self.gui.qwtPlotRate.setAxisTitle(Qwt.QwtPlot.yLeft, "Datarate[Mbits/s]") self.gui.qwtPlotRate.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotRate.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotRate.setAxisScale(Qwt.QwtPlot.yLeft, 0, 10) self.rate_x = range(0,128) self.rate_y = [0]*len(self.rate_x) self.curve_rate = Qwt.QwtPlotCurve() self.curve_rate.setPen(Qt.QPen(Qt.Qt.lightGray, 1)) self.curve_rate.setBrush(Qt.Qt.lightGray) self.curve_rate.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_rate.attach(self.gui.qwtPlotRate) self.gui.qwtPlotCSI.setTitle("Rx 1 Normalized CTF") self.gui.qwtPlotCSI.setAxisTitle(Qwt.QwtPlot.xBottom, "Subcarrier") self.gui.qwtPlotCSI.setAxisScale(Qwt.QwtPlot.xBottom, -99, 100) self.gui.qwtPlotCSI.setAxisScale(Qwt.QwtPlot.yLeft, 0, 2) self.csi_x = range(-99,101) self.csi_y = [0]*len(self.csi_x) self.curve_csi = Qwt.QwtPlotCurve() self.curve_csi.setPen(Qt.QPen(Qt.Qt.blue, 1)) self.curve_csi.setBrush(Qt.Qt.blue) self.curve_csi.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_csi.attach(self.gui.qwtPlotCSI) self.gui.qwtPlotCSI2.setTitle("Rx 2 Normalized CTF") self.gui.qwtPlotCSI2.setAxisTitle(Qwt.QwtPlot.xBottom, "Subcarrier") self.gui.qwtPlotCSI2.setAxisScale(Qwt.QwtPlot.xBottom, -99, 100) self.gui.qwtPlotCSI2.setAxisScale(Qwt.QwtPlot.yLeft, 0, 2) #self.csi_x = range(-99,101) #self.csi_y = [0]*len(self.csi_x) self.curve_csi2 = Qwt.QwtPlotCurve() self.curve_csi2.setPen(Qt.QPen(Qt.Qt.blue, 1)) self.curve_csi2.setBrush(Qt.Qt.blue) self.curve_csi2.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_csi2.attach(self.gui.qwtPlotCSI2) self.gui.qwtPlotScatter.setTitle("Scatterplot (Subcarrier -99)") self.gui.qwtPlotScatter.setAxisTitle(Qwt.QwtPlot.xBottom, "I") self.gui.qwtPlotScatter.setAxisTitle(Qwt.QwtPlot.yLeft, "Q") self.gui.qwtPlotScatter.setAxisScale(Qwt.QwtPlot.xBottom, -1.5, 1.5) self.gui.qwtPlotScatter.setAxisScale(Qwt.QwtPlot.yLeft, -1.5, 1.5) self.scatter_buffer = numpy.complex64([0+0j]) self.curve_scatter = Qwt.QwtPlotCurve() self.curve_scatter.setPen(Qt.QPen(Qt.Qt.blue, 1)) self.curve_scatter.setStyle(Qwt.QwtPlotCurve.Dots) self.curve_scatter.attach(self.gui.qwtPlotScatter) self.marker = Qwt.QwtSymbol() self.marker.setStyle(Qwt.QwtSymbol.XCross) self.marker.setSize(Qt.QSize(3,3)) self.curve_scatter.setSymbol(self.marker) # plot picker self.plot_picker = Qwt.QwtPlotPicker(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPlotPicker.VLineRubberBand, Qwt.QwtPicker.AlwaysOff, self.gui.qwtPlotCSI.canvas(), #self.gui.qwtPlotCSI2.canvas() ) #Signals self.connect(self.update_timer, QtCore.SIGNAL("timeout()"), self.probe_manager.watcher) self.connect(self.gui.pushButtonMeasure, QtCore.SIGNAL("clicked()"), self.measure_average) self.connect(self.gui.pushButtonUpdate, QtCore.SIGNAL("clicked()"), self.update_modulation) self.connect(self.gui.horizontalSliderAmplitude, QtCore.SIGNAL("valueChanged(int)"), self.slide_amplitude) self.connect(self.gui.lineEditAmplitude, QtCore.SIGNAL("editingFinished()"), self.edit_amplitude) self.connect(self.gui.horizontalSliderOffset, QtCore.SIGNAL("valueChanged(int)"), self.slide_freq_offset) self.connect(self.gui.lineEditOffset, QtCore.SIGNAL("editingFinished()"), self.edit_freq_offset) self.connect(self.plot_picker, QtCore.SIGNAL("selected(const QwtDoublePoint &)"), self.subcarrier_selected) self.connect(self.gui.comboBoxChannelModel, QtCore.SIGNAL("currentIndexChanged(QString)"), self.set_channel_profile) # start GUI update timer self.update_timer.start(33) # get transmitter settings self.update_tx_params()
def __init__(self, *args): Qt.QMainWindow.__init__(self, *args) self.resize(800, 600) self.setWindowTitle("PlotMeNow") centralWidget = QtGui.QWidget(self) gridLayout = QtGui.QGridLayout(centralWidget) gridLayout.setMargin(0) plot = CartesianPlot(centralWidget) gridLayout.addWidget(plot, 0, 0, 1, 1) self.setCentralWidget(centralWidget) def addToolBar(parent, name): toolBar = QtGui.QToolBar(parent) toolBar.setWindowTitle(name) parent.addToolBar(QtCore.Qt.TopToolBarArea, toolBar) return toolBar toolBar = addToolBar(self, u'Сессия') def genButton(name, res, *args): return toolBar.addAction(QtGui.QIcon(QtGui.QPixmap(":/image/%s.png" % res)), name, *args) def projSaveAs(): print 'projSaveAs()', pc.isChanged() fileName = QtGui.QFileDialog.getSaveFileName(self, u'Сохранить сессию', '.', 'PlotMeNow (*.pmn)') if not fileName.isNull(): return pc.save(unicode(fileName)) return False def projSave(): print 'projSave()', pc.isChanged() if not pc.onDisk(): return projSaveAs() return pc.save() def projNew(): print 'projNew()', pc.isChanged() if pc.isChanged(): reply = QtGui.QMessageBox.question(self, u'Несохраненные изменения', u'Сохранить текущую сессию?', QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Cancel) if reply == QtGui.QMessageBox.Save: projSave() elif reply == QtGui.QMessageBox.Cancel: return self.e.setAB(None, None) print '1', pc.getElements() ret = pc.new() print '2', pc.getElements() if ret: for i in xrange(comboBoxF.count()): comboBoxF.setItemData(i, None) print '3', pc.getElements() print 'comboBoxF.clear()' comboBoxF.clear() print '4', pc.getElements() self.l.destroy() del self.l self.l = None print '5', pc.getElements() self.l = pc.create(Lagrange.__name__) self.l.setEditing() print '6', pc.getElements() self.e.setAB(None, self.l) print 'Control elems', pc.getElements() self.e.reconnect() self.e.setB(self.l) plot.replot() else: if comboBoxF.count() > 0: index = comboBoxF.currentIndex() obj = comboBoxF.itemData(index).toPyObject() self.e.setAB(obj, self.l) return ret def projOpen(): print 'projOpen()', pc.isChanged() fileName = QtGui.QFileDialog.getOpenFileName(self, u'Открыть сессию', '.', 'PlotMeNow (*.pmn)') if not fileName.isNull(): if pc.isChanged() and QtGui.QMessageBox.Save == QtGui.QMessageBox.question(self, u'Несохраненные изменения', u'Сохранить текущую сессию?', QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard, QtGui.QMessageBox.Save): projSave() #return pc.load(unicode(fileName)) self.e.setAB(None, None) print '1', pc.getElements() ret = pc.load(unicode(fileName)) print '2', pc.getElements() if ret: """ self.l.destroy() self.ep.destroy() pc.detach(self.l) pc.detach(self.ep) del self.l del self.ep self.l = None self.ep = None self.l = pc.getElementsByClassName(Lagrange.__name__).pop() self.ep = pc.getElementsByClassName(EvalPlot.__name__).pop() self.e.setAB(self.ep, self.l) plot.replot() """ """ for ep in pc.getElementsByClassName(EvalPlot.__name__): pc.detach(ep) ep.destroy() del ep ep = None self.l.destroy() pc.detach(self.l) del self.l self.l = None """ self.l = pc.getElementsByClassName(Lagrange.__name__).pop() print '3', pc.getElements() print 'comboBoxF.clear()' comboBoxF.clear() print '4', pc.getElements() print 'for ep in pc.getElementsByClassName(EvalPlot.__name__)' for ep in pc.getElementsByClassName(EvalPlot.__name__): f = ep.getExpression() if f is None: print 'Warning!', ep, 'has None function' else: comboBoxF.addItem(f, ep) print '5', pc.getElements() if comboBoxF.count() > 0: index = comboBoxF.currentIndex() obj = comboBoxF.itemData(index).toPyObject() self.e.setA(obj) self.e.reconnect() self.e.setB(self.l).replot() return ret return False projectNew = genButton(u"Новый", "new", projNew) projectOpen = genButton(u"Открыть", "open", projOpen) projectSave = genButton(u"Сохранить", "fileSave", projSave) projectSaveAs = genButton(u"Сохранить как", "fileSaveAs", projSaveAs) toolBar = addToolBar(self, u'Навигация') #toolBar.addSeparator() editUndo = genButton(u"Отменить действие", "editUndo", lambda: pc.undo()) editRedo = genButton(u"Вернуть действие", "editRedo", lambda: pc.redo()) toolBar = addToolBar(self, u'Выражения') #toolBar.addSeparator() comboBoxF = QtGui.QComboBox(toolBar) comboBoxF.setMinimumSize(QtCore.QSize(220, 0)) #comboBoxF.addItems(['4*pi*sin(x)*cos(x)^2', 'x^2', 'e^(-x^2)']) comboBoxF.setEditable(True) comboBoxF.setIconSize(QtCore.QSize(16, 16)) toolBar.addAction("f(x):") toolBar.addWidget(comboBoxF) #QtCore.QObject.connect(comboBoxF, QtCore.SIGNAL("editTextChanged(QString)"), lambda x: self.ep.setExpression(x)) #QtCore.QObject.connect(comboBoxF, QtCore.SIGNAL("currentIndexChanged(QString)"), lambda x: self.ep.setExpression(x)) #QtCore.QObject.connect(comboBoxF, QtCore.SIGNAL("currentIndexChanged(int)"), lambda i: self.e.setA(comboBoxF.itemData(i).toPyObject()).replot()) def currentIndexChanged(index): print 'currentIndexChanged', index if index > -1: obj = comboBoxF.itemData(index).toPyObject() if obj is None: obj = pc.create(EvalPlot.__name__, comboBoxF.itemText(index)) comboBoxF.setItemData(index, obj) self.e.reconnect() self.e.setA(obj) else: self.e.setA(None) self.e.replot() #def editTextChanged(text): QtCore.QObject.connect(comboBoxF, QtCore.SIGNAL("currentIndexChanged(int)"), currentIndexChanged) #QtCore.QObject.connect(comboBoxF, QtCore.SIGNAL("editTextChanged(QString)"), editTextChanged) deleteButtonF = QtGui.QPushButton(QtGui.QIcon(QtGui.QPixmap(":/image/editDelete.png")), '', toolBar) deleteButtonF.setIconSize(QtCore.QSize(12, 12)) deleteButtonF.setMaximumSize(QtCore.QSize(22, 22)) #QtCore.QObject.connect(deleteButtonF, QtCore.SIGNAL("clicked()"), lambda: comboBoxF.removeItem(comboBoxF.currentIndex())) def deleteEP(): if comboBoxF.count() == 0: return index = comboBoxF.currentIndex() obj = comboBoxF.itemData(index).toPyObject() pc.detach(obj) obj.destroy() del obj comboBoxF.removeItem(index) QtCore.QObject.connect(deleteButtonF, QtCore.SIGNAL("clicked()"), deleteEP) toolBar.addWidget(deleteButtonF) toolBar = addToolBar(self, u'Отчет') #toolBar.addSeparator() #generateReportAction = genButton(u"Составить отчет", "fileResource", lambda: generateReport(self, plot, [unicode(comboBoxF.itemText(i)) for i in xrange(comboBoxF.count())], [l])) generateReportAction = genButton(u"Составить отчет", "fileResource", lambda: generateReport(self, plot, pc.getElementsByClassName(EvalPlot.__name__), pc.getElementsByClassName(Lagrange.__name__))) toolBar = addToolBar(self, u'Справка') #toolBar.addSeparator() helpAction = genButton(u"Справка", "help", lambda: HelpDialog(self).show()) aboutAction = genButton(u"О программе", "helpAbout", lambda: AboutDialog(self).show()) pc = PlotControl(plot, editUndo.setEnabled, editRedo.setEnabled) #self.ep = EvalPlot(plot, '4*pi*sin(x)*cos(x)^2') self.l = Lagrange(plot) #self.e = Epsilon(plot, self.ep, self.l) self.l.setEditing() self.e = Epsilon(plot, None, self.l) func = ['4*pi*sin(x)*cos(x)^2', 'x^2', 'e^(-x^2)'] for f in func: comboBoxF.addItem(f, pc.create(EvalPlot.__name__, f)) self.e.reconnect() pc.attach(self.l) #pc.attach(self.ep) picker = Qwt.QwtPlotPicker(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn, plot.canvas())
def __init__(self, options, parent=None): QtGui.QMainWindow.__init__(self, parent) self.options = options # load and uic the file right away, no additional step necessary self.gui = uic.loadUi( os.path.join(os.path.dirname(__file__), 'ofdm_rx_gui_window.ui'), self) # GUI update timer self.update_timer = Qt.QTimer() # ZeroMQ self.probe_manager = zeromq.probe_manager() self.probe_manager.add_socket( "tcp://" + self.options.rx_hostname + ":5555", 'float32', self.plot_snr) self.probe_manager.add_socket( "tcp://" + self.options.rx_hostname + ":5556", 'float32', self.plot_ber) if options.measurement: self.probe_manager.add_socket( "tcp://" + self.options.rx_hostname + ":5556", 'float32', self.take_measurement) self.probe_manager.add_socket( "tcp://" + self.options.rx_hostname + ":5557", 'float32', self.plot_freqoffset) self.probe_manager.add_socket( "tcp://" + self.options.tx_hostname + ":4445", 'uint8', self.plot_rate) self.probe_manager.add_socket( "tcp://" + self.options.rx_hostname + ":5559", 'float32', self.plot_csi) self.probe_manager.add_socket( "tcp://" + self.options.rx_hostname + ":5560", 'complex64', self.plot_scatter) self.rpc_mgr_tx = zeromq.rpc_manager() self.rpc_mgr_tx.set_request_socket("tcp://" + self.options.tx_hostname + ":6660") self.rpc_mgr_rx = zeromq.rpc_manager() self.rpc_mgr_rx.set_request_socket("tcp://" + self.options.rx_hostname + ":5550") # Window Title self.gui.setWindowTitle("Receiver") #Plots self.gui.qwtPlotSNR.setAxisTitle(Qwt.QwtPlot.yLeft, "SNR[dB]") self.gui.qwtPlotSNR.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotSNR.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotSNR.setAxisScale(Qwt.QwtPlot.yLeft, 0, 30) self.snr_x = range(0, 128) self.snr_y = [0.0] self.curve_snr = Qwt.QwtPlotCurve() self.curve_snr.setPen(Qt.QPen(Qt.Qt.red, 1)) self.curve_snr.setBrush(Qt.Qt.red) self.curve_snr.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_snr.attach(self.gui.qwtPlotSNR) self.gui.qwtPlotBER.setAxisTitle(Qwt.QwtPlot.yLeft, "BER") self.gui.qwtPlotBER.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotBER.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotBER.setAxisScale(Qwt.QwtPlot.yLeft, 0.0001, 0.5) scale_engine = Qwt.QwtLog10ScaleEngine() self.gui.qwtPlotBER.setAxisScaleEngine(Qwt.QwtPlot.yLeft, scale_engine) self.ber_x = range(0, 128) self.ber_y = [0.0] self.curve_ber = Qwt.QwtPlotCurve() self.curve_ber.setBaseline(1e-100) self.curve_ber.setPen(Qt.QPen(Qt.Qt.green, 1)) self.curve_ber.setBrush(Qt.Qt.green) self.curve_ber.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_ber.attach(self.gui.qwtPlotBER) self.gui.qwtPlotFreqoffset.setAxisTitle(Qwt.QwtPlot.yLeft, "Frequency Offset") self.gui.qwtPlotFreqoffset.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotFreqoffset.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotFreqoffset.setAxisScale(Qwt.QwtPlot.yLeft, -1, 1) self.freqoffset_x = range(0, 128) self.freqoffset_y = [0.0] self.curve_freqoffset = Qwt.QwtPlotCurve() self.curve_freqoffset.setPen(Qt.QPen(Qt.Qt.black, 1)) self.curve_freqoffset.attach(self.gui.qwtPlotFreqoffset) self.gui.qwtPlotRate.setAxisTitle(Qwt.QwtPlot.yLeft, "Datarate[Mbits/s]") self.gui.qwtPlotRate.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotRate.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotRate.setAxisScale(Qwt.QwtPlot.yLeft, 0, 10) self.rate_x = range(0, 128) self.rate_y = [0] * len(self.rate_x) self.curve_rate = Qwt.QwtPlotCurve() self.curve_rate.setPen(Qt.QPen(Qt.Qt.lightGray, 1)) self.curve_rate.setBrush(Qt.Qt.lightGray) self.curve_rate.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_rate.attach(self.gui.qwtPlotRate) self.gui.qwtPlotCSI.setTitle("Normalized Channel State Information") self.gui.qwtPlotCSI.setAxisTitle(Qwt.QwtPlot.xBottom, "Subcarrier") self.gui.qwtPlotCSI.setAxisScale(Qwt.QwtPlot.xBottom, -99, 100) self.gui.qwtPlotCSI.setAxisScale(Qwt.QwtPlot.yLeft, 0, 2) self.csi_x = range(-99, 101) self.csi_y = [0] * len(self.csi_x) self.curve_csi = Qwt.QwtPlotCurve() self.curve_csi.setPen(Qt.QPen(Qt.Qt.blue, 1)) self.curve_csi.setBrush(Qt.Qt.blue) self.curve_csi.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_csi.attach(self.gui.qwtPlotCSI) self.gui.qwtPlotScatter.setTitle("Scatterplot (Subcarrier -99)") self.gui.qwtPlotScatter.setAxisTitle(Qwt.QwtPlot.xBottom, "I") self.gui.qwtPlotScatter.setAxisTitle(Qwt.QwtPlot.yLeft, "Q") self.gui.qwtPlotScatter.setAxisScale(Qwt.QwtPlot.xBottom, -1.5, 1.5) self.gui.qwtPlotScatter.setAxisScale(Qwt.QwtPlot.yLeft, -1.5, 1.5) self.scatter_buffer = numpy.complex64([0 + 0j]) self.curve_scatter = Qwt.QwtPlotCurve() self.curve_scatter.setPen(Qt.QPen(Qt.Qt.blue, 1)) self.curve_scatter.setStyle(Qwt.QwtPlotCurve.Dots) self.curve_scatter.attach(self.gui.qwtPlotScatter) self.marker = Qwt.QwtSymbol() self.marker.setStyle(Qwt.QwtSymbol.XCross) self.marker.setSize(Qt.QSize(3, 3)) self.curve_scatter.setSymbol(self.marker) # plot picker self.plot_picker = Qwt.QwtPlotPicker(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPlotPicker.VLineRubberBand, Qwt.QwtPicker.AlwaysOff, self.gui.qwtPlotCSI.canvas()) #Signals self.connect(self.update_timer, QtCore.SIGNAL("timeout()"), self.probe_manager.watcher) self.connect(self.gui.pushButtonMeasure, QtCore.SIGNAL("clicked()"), self.measure_average) #self.connect(self.gui.pushButtonUpdate, QtCore.SIGNAL("clicked()"), self.update_modulation) self.connect(self.gui.horizontalSliderAmplitude, QtCore.SIGNAL("valueChanged(int)"), self.slide_amplitude) self.connect(self.gui.lineEditAmplitude, QtCore.SIGNAL("editingFinished()"), self.edit_amplitude) self.connect(self.gui.horizontalSliderOffset, QtCore.SIGNAL("valueChanged(int)"), self.slide_freq_offset) self.connect(self.gui.lineEditOffset, QtCore.SIGNAL("editingFinished()"), self.edit_freq_offset) self.connect(self.plot_picker, QtCore.SIGNAL("selected(const QwtDoublePoint &)"), self.subcarrier_selected) self.connect(self.gui.comboBoxChannelModel, QtCore.SIGNAL("currentIndexChanged(QString)"), self.set_channel_profile) self.connect(self.gui.horizontalSliderTxGain, QtCore.SIGNAL("valueChanged(int)"), self.slide_tx_gain) self.connect(self.gui.horizontalSliderRxGain, QtCore.SIGNAL("valueChanged(int)"), self.slide_rx_gain) self.connect(self.gui.comboBoxScheme, QtCore.SIGNAL("currentIndexChanged(QString)"), self.set_allocation_scheme) self.connect(self.gui.horizontalSliderDataRate, QtCore.SIGNAL("valueChanged(int)"), self.slide_data_rate) self.connect(self.gui.lineEditDataRate, QtCore.SIGNAL("editingFinished()"), self.edit_data_rate) self.connect(self.gui.horizontalSliderGap, QtCore.SIGNAL("valueChanged(int)"), self.slide_gap) self.connect(self.gui.lineEditGap, QtCore.SIGNAL("editingFinished()"), self.edit_gap) self.connect(self.gui.horizontalSliderResourceBlockSize, QtCore.SIGNAL("valueChanged(int)"), self.slide_resource_block_size) self.connect(self.gui.lineEditResourceBlockSize, QtCore.SIGNAL("editingFinished()"), self.edit_resource_block_size) self.connect(self.gui.comboBoxResourceBlocksScheme, QtCore.SIGNAL("currentIndexChanged(QString)"), self.set_resource_block_scheme) self.connect(self.gui.comboBoxModulation, QtCore.SIGNAL("currentIndexChanged(QString)"), self.set_modulation_scheme) if options.measurement: self.rpc_mgr_tx.request("set_amplitude", [0.018]) self.rpc_mgr_tx.request("set_amplitude_ideal", [0.018]) self.i = 0 self.ii = 0 self.iii = 1 self.ber = 0.0 self.snr = 0.0 self.snrsum = 0.0 self.datarate = 0.0 self.ratesum = 0.0 self.dirname = "Simulation_" + strftime("%Y_%m_%d_%H_%M_%S", gmtime()) + "/" print self.dirname if not os.path.isdir("./" + self.dirname): os.mkdir("./" + self.dirname + "/") self.iter_points = 60 self.snr_points = 30 amp_min_log = numpy.log10(0.018**2) amp_max_log = numpy.log10(0.7**2) self.txpow_range = numpy.logspace(amp_min_log, amp_max_log, self.snr_points) self.meas_ber = 0.5 self.change_mod = 1 # start GUI update timer (33ms for 30 FPS) self.update_timer.start(33) # get transmitter settings self.update_tx_params()
def __init__(self, *args): apply(Qt.QFrame.__init__, (self, ) + args) # the following: setPal.. doesn't seem to work on Win try: self.setPaletteBackgroundColor(QColor(240, 240, 245)) except: pass knobpos = scopeheight + 30 self.setFixedSize(700, scopeheight + 150) self.freezeState = 0 self.knbLevel = LblKnob(self, 560, 50, "Trigger level") self.knbTime = LblKnob(self, 560, 220, "Time", 1) self.knbSignal = LblKnob(self, 150, knobpos, "Signal1", 1) self.knbSignal2 = LblKnob(self, 450, knobpos, "Signal2", 1) self.knbOffset1 = LblKnob(self, 10, knobpos, "offset1") self.knbOffset2 = LblKnob(self, 310, knobpos, "offset2") self.knbTime.setRange(0.0001, 1.0) self.knbTime.setValue(0.01) self.knbSignal.setRange(0.0001, 1.0) self.knbSignal.setValue(0.1) self.knbSignal2.setRange(0.0001, 1.0) self.knbSignal2.setValue(0.1) self.knbOffset2.setRange(-1.0, 1.0, 0.001) self.knbOffset2.setValue(0.0) self.knbOffset1.setRange(-1.0, 1.0, 0.001) self.knbOffset1.setValue(0.0) self.knbLevel.setRange(-1.0, 1.0, 0.001) self.knbLevel.setValue(0.1) self.knbLevel.setScaleMaxMajor(10) self.plot = Scope(self) self.plot.setGeometry(10, 10, 550, scopeheight) self.picker = Qwt.QwtPlotPicker( Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection | Qwt.QwtPicker.DragSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.ActiveOnly, #AlwaysOn, self.plot.canvas()) self.picker.setRubberBandPen(Qt.QPen(Qt.Qt.green)) self.picker.setTrackerPen(Qt.QPen(Qt.Qt.cyan)) self.connect(self.knbTime.knob, Qt.SIGNAL("valueChanged(double)"), self.setTimebase) self.knbTime.setValue(0.01) self.connect(self.knbSignal.knob, Qt.SIGNAL("valueChanged(double)"), self.setAmplitude) self.connect(self.knbSignal2.knob, Qt.SIGNAL("valueChanged(double)"), self.setAmplitude2) self.knbSignal.setValue(0.1) self.connect(self.knbLevel.knob, Qt.SIGNAL("valueChanged(double)"), self.setTriggerlevel) self.connect(self.knbOffset1.knob, Qt.SIGNAL("valueChanged(double)"), self.plot.setOffset1) self.connect(self.knbOffset2.knob, Qt.SIGNAL("valueChanged(double)"), self.plot.setOffset2) self.knbLevel.setValue(0.1) self.plot.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, 10.0 * inittime) self.plot.setAxisScale(Qwt.QwtPlot.yLeft, -5.0 * initamp, 5.0 * initamp) self.plot.setAxisScale(Qwt.QwtPlot.yRight, -5.0 * initamp, 5.0 * initamp) self.plot.show()