discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Closing QT sink when flowgraph is done


From: Michael Wentz
Subject: Re: [Discuss-gnuradio] Closing QT sink when flowgraph is done
Date: Mon, 16 May 2016 21:10:14 -0400

For anyone that is interested, the way I ended up doing this was polling the nitems_written() function of the head block, and once it reached the terminal value, calling another function to quit the QT application. Then I connected that function call to the other quitting() procedure. Seems kind of roundabout, but works.

-Michael

---

qapp = Qt.QApplication(sys.argv)

def quitQT():
    qapp.quit()

max_n_samps = 1000000

tb = top_block_cls()
tb.start()
tb.show()

def check_status():
    fg_is_done = 0
    while not fg_is_done:
    time.sleep(1)
    if (tb.blocks_head_0.nitems_written(0) == max_n_samps):
    fg_is_done = 1
    quitQT()

def quitting():
    tb.stop()
    tb.wait()

qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
qapp.connect(qapp, Qt.SIGNAL("quitQT()"), quitting)

checker = Thread(target=check_status)
checker.start()

qapp.exec_()

On Mon, May 16, 2016 at 9:40 AM, Michael Wentz <address@hidden> wrote:
Hi,

Is there a way to automatically close a QT graphical sink after a flowgraph is done running? For example, I want to read in samples from a USRP, demodulate and plot the constellation, and then close everything automatically. My flowgraph looks like this:

USRP --> Head --> Demodulator --> QT Constellation Sink
                                    |
                                    --------------> File Sink

The head block stops the processing after a prescribed number of samples, but the QT sink remains open until I manually close it. If I disable graphics I can get this to run how I'd like, but having the option to see the constellation is important for me. 

I've initially implemented this using a separate thread with a timer (see below), but it seems like there should be a cleaner way of doing this?

Thanks,
Michael

---

qapp = Qt.QApplication(sys.argv)

tb = top_block_cls()
tb.start()
tb.show()

def quitter():
    time.sleep(run_time_in_seconds)
    qapp.quit()

def quitting():
    tb.stop()
    tb.wait()

qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)

t = Thread(target=quitter)
t.start()

qapp.exec_()


reply via email to

[Prev in Thread] Current Thread [Next in Thread]