1#!/usr/bin/env python 2# 3# Copyright 2012,2013,2015 Free Software Foundation, Inc. 4# 5# This file is part of GNU Radio 6# 7# GNU Radio is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 3, or (at your option) 10# any later version. 11# 12# GNU Radio is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with GNU Radio; see the file COPYING. If not, write to 19# the Free Software Foundation, Inc., 51 Franklin Street, 20# Boston, MA 02110-1301, USA. 21# 22 23from __future__ import print_function 24from __future__ import unicode_literals 25from gnuradio import gr 26from gnuradio import blocks 27import sys 28 29try: 30 from gnuradio import qtgui 31 from PyQt5 import QtWidgets, Qt 32 import sip 33except ImportError: 34 print("Error: Program requires PyQt5 and gr-qtgui.") 35 sys.exit(1) 36 37class dialog_box(QtWidgets.QWidget): 38 def __init__(self, display): 39 QtWidgets.QWidget.__init__(self, None) 40 self.setWindowTitle('PyQt Test GUI') 41 42 self.boxlayout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.LeftToRight, self) 43 self.boxlayout.addWidget(display, 1) 44 45 self.resize(800, 500) 46 47class my_top_block(gr.top_block): 48 def __init__(self): 49 gr.top_block.__init__(self) 50 51 self.qapp = QtWidgets.QApplication(sys.argv) 52 53 data0 = 10*[0,] + 40*[1,0] + 10*[0,] 54 data0 += 10*[0,] + 40*[0,1] + 10*[0,] 55 data1 = 20*[0,] + [0,0,0,1,1,1,0,0,0,0] + 70*[0,] 56 57 # Adjust these to change the layout of the plot. 58 # Can be set to fractions. 59 ncols = 100.25 60 nrows = 100 61 62 fs = 200 63 src0 = blocks.vector_source_f(data0, True) 64 src1 = blocks.vector_source_f(data1, True) 65 thr = blocks.throttle(gr.sizeof_float, 50000) 66 hed = blocks.head(gr.sizeof_float, 10000000) 67 self.snk1 = qtgui.time_raster_sink_f(fs, nrows, ncols, [], [], 68 "Float Time Raster Example", 2) 69 70 self.connect(src0, thr, (self.snk1, 0)) 71 self.connect(src1, (self.snk1, 1)) 72 73 # Get the reference pointer to the SpectrumDisplayForm QWidget 74 pyQt = self.snk1.pyqwidget() 75 76 # Wrap the pointer as a PyQt SIP object 77 # This can now be manipulated as a PyQt5.QtWidgets.QWidget 78 pyWin = sip.wrapinstance(pyQt, QtWidgets.QWidget) 79 80 self.main_box = dialog_box(pyWin) 81 self.main_box.show() 82 83if __name__ == "__main__": 84 tb = my_top_block(); 85 tb.start() 86 tb.qapp.exec_() 87 tb.stop() 88