From aefa2d446c1641a92c8074374919fd796ed17202 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Tue, 27 Sep 2016 16:08:17 -0400 Subject: [feature] catch SIGINT from gui --- src/leap/bitmask/gui/app.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/leap/bitmask') diff --git a/src/leap/bitmask/gui/app.py b/src/leap/bitmask/gui/app.py index 4bd91909..cf4ac4b9 100644 --- a/src/leap/bitmask/gui/app.py +++ b/src/leap/bitmask/gui/app.py @@ -25,6 +25,8 @@ import os import signal import sys +from functools import partial + from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtWebKit, QtWebKitWidgets @@ -47,11 +49,15 @@ class BrowserWindow(QtWidgets.QDialog): self.setWindowTitle('Bitmask') self.resize(800, 600) self.load_app() + self.closing = False def load_app(self): self.view.load(QtCore.QUrl(BITMASK_URI)) - def shutdown(self): + def shutdown(self, *args): + if self.closing: + return + self.closing = True global bitmaskd bitmaskd.join() with open(pid) as f: @@ -68,6 +74,12 @@ class BrowserWindow(QtWidgets.QDialog): sys.exit(1) +def _handle_kill(*args, **kw): + win = kw.get('win') + if win: + QtCore.QTimer.singleShot(0, win.close) + + def launch_gui(): global qApp global bitmaskd @@ -81,6 +93,16 @@ def launch_gui(): qApp.setQuitOnLastWindowClosed(True) qApp.lastWindowClosed.connect(browser.shutdown) + signal.signal( + signal.SIGINT, + partial(_handle_kill, win=browser)) + + # Avoid code to get stuck inside c++ loop, returning control + # to python land. + timer = QtCore.QTimer() + timer.timeout.connect(lambda: None) + timer.start(500) + browser.show() sys.exit(qApp.exec_()) -- cgit v1.2.3