summaryrefslogtreecommitdiff
path: root/src/leap/bitmask
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2016-10-21 17:13:37 -0400
committerKali Kaneko (leap communications) <kali@leap.se>2016-10-21 17:17:43 -0400
commit12bbdc84a744aaa2af4130539a2a7188996c7659 (patch)
treede013b52796422112db6c68f2dc72a3493b5cc40 /src/leap/bitmask
parentdb8567e5035978dc16fd5bbac9aecb73b600d41e (diff)
[feat] fallback support for PySide
basically, I give up trying to compile pyqt5 for python2. not worthy. fortunately, the api changes are minimal so we can support two. the way forward should be Py3. still some bugs with rendering the viewport. trying to help that, I introduced the web inspector, use DEBUG=1 flag to have it visible.
Diffstat (limited to 'src/leap/bitmask')
-rw-r--r--src/leap/bitmask/gui/app.py78
1 files changed, 65 insertions, 13 deletions
diff --git a/src/leap/bitmask/gui/app.py b/src/leap/bitmask/gui/app.py
index cf4ac4b..f812a6b 100644
--- a/src/leap/bitmask/gui/app.py
+++ b/src/leap/bitmask/gui/app.py
@@ -22,32 +22,72 @@ when the web service is running.
"""
import os
+import platform
import signal
import sys
from functools import partial
-from PyQt5 import QtCore, QtGui, QtWidgets
-from PyQt5 import QtWebKit, QtWebKitWidgets
+if platform.system() == 'Windows':
+ from multiprocessing import freeze_support
+ from PySide import QtCore, QtGui
+ from PySide import QtWebKit
+ from PySide.QtGui import QDialog
+ from PySide.QtGui import QApplication
+ from PySide.QtWebKit import QWebView, QGraphicsWebView
+ from PySide.QtCore import QSize
+else:
+ from PyQt5 import QtCore, QtGui
+ from PyQt5 import QtWebKit
+ from PyQt5.QtWidgets import QDialog
+ from PyQt5.QtWidgets import QApplication
+ from PyQt5.QtWebKitWidgets import QWebView
+
+from multiprocessing import Process
from leap.bitmask.core.launcher import run_bitmaskd, pid
-from multiprocessing import Process
BITMASK_URI = 'http://localhost:7070'
+IS_WIN = platform.system() == "Windows"
+DEBUG = os.environ.get("DEBUG", False)
+
qApp = None
bitmaskd = None
-class BrowserWindow(QtWidgets.QDialog):
+class BrowserWindow(QDialog):
def __init__(self, parent):
super(BrowserWindow, self).__init__(parent)
- self.view = QtWebKitWidgets.QWebView(self)
+ if IS_WIN:
+ self.view = QWebView(self)
+ win_size = QSize(1024, 600)
+ self.setMinimumSize(win_size)
+ self.view.page().setViewportSize(win_size)
+ self.view.page().setPreferredContentsSize(win_size)
+ else:
+ self.view = QWebView(self)
+ win_size = QSize(800, 600)
+ self.win_size = win_size
+ self.resize(win_size)
+
+ if DEBUG:
+ self.view.settings().setAttribute(
+ QtWebKit.QWebSettings.WebAttribute.DeveloperExtrasEnabled, True)
+ self.inspector = QtWebKit.QWebInspector(self)
+ self.inspector.setPage(self.view.page())
+ self.inspector.show()
+ self.splitter = QtGui.QSplitter()
+ self.splitter.addWidget(self.view)
+ self.splitter.addWidget(self.inspector)
+ #TODO add layout also in non-DEBUG mode
+ layout = QtGui.QVBoxLayout(self)
+ layout.addWidget(self.splitter)
+
self.setWindowTitle('Bitmask')
- self.resize(800, 600)
self.load_app()
self.closing = False
@@ -60,10 +100,11 @@ class BrowserWindow(QtWidgets.QDialog):
self.closing = True
global bitmaskd
bitmaskd.join()
- with open(pid) as f:
- pidno = int(f.read())
- print('[bitmask] terminating bitmaskd...')
- os.kill(pidno, signal.SIGTERM)
+ if os.path.isfile(pid):
+ with open(pid) as f:
+ pidno = int(f.read())
+ print('[bitmask] terminating bitmaskd...')
+ os.kill(pidno, signal.SIGTERM)
print('[bitmask] shutting down gui...')
try:
self.view.stop()
@@ -74,6 +115,7 @@ class BrowserWindow(QtWidgets.QDialog):
sys.exit(1)
+
def _handle_kill(*args, **kw):
win = kw.get('win')
if win:
@@ -84,10 +126,12 @@ def launch_gui():
global qApp
global bitmaskd
+ if IS_WIN:
+ freeze_support()
bitmaskd = Process(target=run_bitmaskd)
bitmaskd.start()
- qApp = QtWidgets.QApplication([])
+ qApp = QApplication([])
browser = BrowserWindow(None)
qApp.setQuitOnLastWindowClosed(True)
@@ -97,6 +141,7 @@ def launch_gui():
signal.SIGINT,
partial(_handle_kill, win=browser))
+
# Avoid code to get stuck inside c++ loop, returning control
# to python land.
timer = QtCore.QTimer()
@@ -113,10 +158,17 @@ def start_app():
# Allow the frozen binary in the bundle double as the cli entrypoint
# Why have only a user interface when you can have two?
- if STANDALONE and len(sys.argv) > 1:
+ if platform.system() == 'Windows':
+ # In windows, there are some args added to the invocation
+ # by PyInstaller, I guess...
+ MIN_ARGS = 3
+ else:
+ MIN_ARGS = 1
+
+ # DEBUG ====================================
+ if STANDALONE and len(sys.argv) > MIN_ARGS:
from leap.bitmask.cli import bitmask_cli
return bitmask_cli.main()
-
launch_gui()