gui: exit when main window is closed

This commit is contained in:
Sebastien Bourdeauducq 2015-07-19 18:27:41 +02:00
parent 97ebdee2c6
commit 1a0dc499dd
1 changed files with 13 additions and 5 deletions

View File

@ -41,6 +41,17 @@ def get_argparser():
return parser 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(): def main():
args = get_argparser().parse_args() args = get_argparser().parse_args()
@ -56,15 +67,12 @@ def main():
args.server, args.port_control, "master_schedule")) args.server, args.port_control, "master_schedule"))
atexit.register(lambda: schedule_ctl.close_rpc()) atexit.register(lambda: schedule_ctl.close_rpc())
win = QtGui.QMainWindow() win = _MainWindow(app)
win.setWindowIcon(QtGui.QIcon(os.path.join(data_dir, "icon.png")))
area = dockarea.DockArea() area = dockarea.DockArea()
win.setCentralWidget(area) win.setCentralWidget(area)
status_bar = QtGui.QStatusBar() status_bar = QtGui.QStatusBar()
status_bar.showMessage("Connected to {}".format(args.server)) status_bar.showMessage("Connected to {}".format(args.server))
win.setStatusBar(status_bar) win.setStatusBar(status_bar)
win.resize(1400, 800)
win.setWindowTitle("ARTIQ")
d_explorer = ExplorerDock(win, status_bar, schedule_ctl) d_explorer = ExplorerDock(win, status_bar, schedule_ctl)
loop.run_until_complete(d_explorer.sub_connect( loop.run_until_complete(d_explorer.sub_connect(
@ -101,7 +109,7 @@ def main():
area.addDock(d_schedule, "above", d_log) area.addDock(d_schedule, "above", d_log)
win.show() win.show()
loop.run_forever() loop.run_until_complete(win.exit_request.wait())
if __name__ == "__main__": if __name__ == "__main__":
main() main()