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 <mchlw...@gmail.com> 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_()
>
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to