From 1a0dc499ddc859b6eeb62cde8baf3e3ed708e154 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 19 Jul 2015 18:27:41 +0200 Subject: [PATCH] gui: exit when main window is closed --- artiq/frontend/artiq_gui.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/artiq/frontend/artiq_gui.py b/artiq/frontend/artiq_gui.py index 645643fb5..05b2e7384 100755 --- a/artiq/frontend/artiq_gui.py +++ b/artiq/frontend/artiq_gui.py @@ -41,6 +41,17 @@ def get_argparser(): return parser +class _MainWindow(QtGui.QMainWindow): + def __init__(self, app): + QtGui.QMainWindow.__init__(self) + self.setWindowIcon(QtGui.QIcon(os.path.join(data_dir, "icon.png"))) + self.resize(1400, 800) + self.setWindowTitle("ARTIQ") + self.exit_request = asyncio.Event() + + def closeEvent(self, *args): + self.exit_request.set() + def main(): args = get_argparser().parse_args() @@ -56,15 +67,12 @@ def main(): args.server, args.port_control, "master_schedule")) atexit.register(lambda: schedule_ctl.close_rpc()) - win = QtGui.QMainWindow() - win.setWindowIcon(QtGui.QIcon(os.path.join(data_dir, "icon.png"))) + win = _MainWindow(app) area = dockarea.DockArea() win.setCentralWidget(area) status_bar = QtGui.QStatusBar() status_bar.showMessage("Connected to {}".format(args.server)) win.setStatusBar(status_bar) - win.resize(1400, 800) - win.setWindowTitle("ARTIQ") d_explorer = ExplorerDock(win, status_bar, schedule_ctl) loop.run_until_complete(d_explorer.sub_connect( @@ -101,7 +109,7 @@ def main(): area.addDock(d_schedule, "above", d_log) win.show() - loop.run_forever() + loop.run_until_complete(win.exit_request.wait()) if __name__ == "__main__": main()