Editing Guided Tutorial GNU Radio in Python

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 44: Line 44:
  
 
<syntaxhighlight lang="python" line="line">
 
<syntaxhighlight lang="python" line="line">
#!/usr/bin/env python3
+
#!/usr/bin/env Python
# -*- coding: utf-8 -*-
+
##################################################
 
+
# Gnuradio Python Flow Graph
#
+
# Title: Tutorial Three
# SPDX-License-Identifier: GPL-3.0
+
# Generated: Wed Mar 12 15:35:18 2014
#
+
##################################################
# GNU Radio Python Flow Graph
 
# Title: tutorial_three_1
 
# GNU Radio version: 3.8.0.0
 
 
 
from distutils.version import StrictVersion
 
 
 
if __name__ == '__main__':
 
    import ctypes
 
    import sys
 
    if sys.platform.startswith('linux'):
 
        try:
 
            x11 = ctypes.cdll.LoadLibrary('libX11.so')
 
            x11.XInitThreads()
 
        except:
 
            print("Warning: failed to XInitThreads()")
 
  
 
from gnuradio import analog
 
from gnuradio import analog
 
from gnuradio import audio
 
from gnuradio import audio
 +
from gnuradio import eng_notation
 
from gnuradio import gr
 
from gnuradio import gr
 +
from gnuradio.eng_option import eng_option
 
from gnuradio.filter import firdes
 
from gnuradio.filter import firdes
import sys
+
from optparse import OptionParser
import signal
 
from PyQt5 import Qt
 
from argparse import ArgumentParser
 
from gnuradio.eng_arg import eng_float, intx
 
from gnuradio import eng_notation
 
from gnuradio import qtgui
 
  
class tutorial_three_1(gr.top_block, Qt.QWidget):
+
class tutorial_three(gr.top_block):
  
 
     def __init__(self):
 
     def __init__(self):
         gr.top_block.__init__(self, "tutorial_three_1")
+
         gr.top_block.__init__(self, "Tutorial Three")
        Qt.QWidget.__init__(self)
 
        self.setWindowTitle("tutorial_three_1")
 
        qtgui.util.check_set_qss()
 
        try:
 
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
 
        except:
 
            pass
 
        self.top_scroll_layout = Qt.QVBoxLayout()
 
        self.setLayout(self.top_scroll_layout)
 
        self.top_scroll = Qt.QScrollArea()
 
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
 
        self.top_scroll_layout.addWidget(self.top_scroll)
 
        self.top_scroll.setWidgetResizable(True)
 
        self.top_widget = Qt.QWidget()
 
        self.top_scroll.setWidget(self.top_widget)
 
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
 
        self.top_grid_layout = Qt.QGridLayout()
 
        self.top_layout.addLayout(self.top_grid_layout)
 
 
 
        self.settings = Qt.QSettings("GNU Radio", "tutorial_three_1")
 
 
 
        try:
 
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
 
                self.restoreGeometry(self.settings.value("geometry").toByteArray())
 
            else:
 
                self.restoreGeometry(self.settings.value("geometry"))
 
        except:
 
            pass
 
  
 
         ##################################################
 
         ##################################################
Line 119: Line 72:
 
         # Blocks
 
         # Blocks
 
         ##################################################
 
         ##################################################
         self.audio_sink_0 = audio.sink(samp_rate, '', True)
+
         self.audio_sink_0 = audio.sink(samp_rate, "", True)
         self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 350, 0.1, 0, 0)
+
         self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 350, .1, 0)
         self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 440, 0.1, 0, 0)
+
         self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 440, .1, 0)
 
 
 
 
  
 
         ##################################################
 
         ##################################################
 
         # Connections
 
         # Connections
 
         ##################################################
 
         ##################################################
 +
        self.connect((self.analog_sig_source_x_1, 0), (self.audio_sink_0, 1))
 
         self.connect((self.analog_sig_source_x_0, 0), (self.audio_sink_0, 0))
 
         self.connect((self.analog_sig_source_x_0, 0), (self.audio_sink_0, 0))
        self.connect((self.analog_sig_source_x_1, 0), (self.audio_sink_0, 1))
 
  
    def closeEvent(self, event):
+
 
        self.settings = Qt.QSettings("GNU Radio", "tutorial_three_1")
+
# QT sink close method reimplementation
        self.settings.setValue("geometry", self.saveGeometry())
 
        event.accept()
 
  
 
     def get_samp_rate(self):
 
     def get_samp_rate(self):
Line 144: Line 93:
 
         self.analog_sig_source_x_1.set_sampling_freq(self.samp_rate)
 
         self.analog_sig_source_x_1.set_sampling_freq(self.samp_rate)
  
 
+
if __name__ == '__main__':
 
+
     parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
def main(top_block_cls=tutorial_three_1, options=None):
+
    (options, args) = parser.parse_args()
 
+
     tb = tutorial_three()
     if StrictVersion("4.5.0") <= StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
 
        style = gr.prefs().get_string('qtgui', 'style', 'raster')
 
        Qt.QApplication.setGraphicsSystem(style)
 
    qapp = Qt.QApplication(sys.argv)
 
 
 
     tb = top_block_cls()
 
 
     tb.start()
 
     tb.start()
     tb.show()
+
     raw_input('Press Enter to quit: ')
 
+
     tb.stop()
    def sig_handler(sig=None, frame=None):
+
    tb.wait()
        Qt.QApplication.quit()
 
 
 
    signal.signal(signal.SIGINT, sig_handler)
 
    signal.signal(signal.SIGTERM, sig_handler)
 
 
 
    timer = Qt.QTimer()
 
    timer.start(500)
 
    timer.timeout.connect(lambda: None)
 
 
 
     def quitting():
 
        tb.stop()
 
        tb.wait()
 
    qapp.aboutToQuit.connect(quitting)
 
    qapp.exec_()
 
 
 
 
 
if __name__ == '__main__':
 
    main()
 
  
 
</syntaxhighlight>
 
</syntaxhighlight>

Please note that all contributions to GNU Radio are considered to be released under the Creative Commons Attribution-ShareAlike (see GNU Radio:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel | Editing help (opens in new window)