Hi Michael,

Thanks for looking at this for me.  I'm using gnuradio-3.7.13.5 on
ubuntu 18.04.

Chris

On Mon, Aug 26, 2019 at 11:05 AM Michael Dickens
<michael.dick...@ettus.com> wrote:
>
> OK good to know, Chris. Can you send me the latest version of your test 
> script as an attachment? I'll give it a go & see what happens for me. Sorry 
> if you've answered this already: Which version of GR are you using? - MLD
>
> On Mon, Aug 26, 2019, at 10:48 AM, Chris Gorman wrote:
> > Oh yes, audio is working fine.  It is a linux system and audio is
> > working when I use the flowgraph.  Just not when I attempt to make a
> > python script of my own.  I basically used the gnuradio-companion
> > generated code and reduced it to try to connect events to a
> > QtPushButton.  I'm sure the error is due to my lack of experience with
> > Qt and python.
> >
> > Chris
from PyQt4 import Qt
from gnuradio import gr
from gnuradio import audio
from gnuradio import analog
from gnuradio import eng_notation
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
import sys
from gnuradio import qtgui

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()"

class top_block(gr.top_block, Qt.QWidget):
    def __init__(self):
        gr.top_block.__init__(self)
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        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", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        sample_rate = 32000
        ampl = 0.5

        _Zero_push_button = Qt.QPushButton('0')
        _Zero_push_button.pressed.connect(lambda: dtmf(self, 941, 1336, sample_rate, ampl))
        _Zero_push_button.released.connect(lambda: dtmf(self, 0, 0, sample_rate, ampl))
        self.top_grid_layout.addWidget(_Zero_push_button, 3, 1, 1, 1)
        for r in range(3, 4):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        
def dtmf(self, freq_one, freq_two, sample_rate, ampl):
    src0 = analog.sig_source_f(sample_rate, analog.GR_SIN_WAVE, freq_one, ampl)
    src1 = analog.sig_source_f(sample_rate, analog.GR_SIN_WAVE, freq_two, ampl)
    dst = audio.sink(sample_rate, 'sysdefault:CARD=Intel', True)
    self.connect(src0, (dst,0))
    self.connect(src1, (dst,1))

def main(top_block_cls=top_block, options=None):

    from distutils.version import StrictVersion
    if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.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.show()

    def quitting():
        tb.stop()
        tb.wait()
    qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
    qapp.exec_()

if __name__ == '__main__':
    main()
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to