summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2016-09-27 16:08:17 -0400
committerKali Kaneko (leap communications) <kali@leap.se>2016-09-27 16:22:47 -0400
commitaefa2d446c1641a92c8074374919fd796ed17202 (patch)
tree647e5e3b36c22e405f6804617ea099eb6ffc094d
parent62a0f06397e8229df648427d5e43da7267a20f4e (diff)
[feature] catch SIGINT from gui
-rw-r--r--src/leap/bitmask/gui/app.py24
1 files changed, 23 insertions, 1 deletions
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_())