mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
Merge pull request #37 from firstlookmedia/36_macos_new_window
When you activate dangerzone in macOS and no windows are open, open a…
This commit is contained in:
commit
d0b8a33f33
2 changed files with 34 additions and 6 deletions
|
@ -5,6 +5,7 @@ import signal
|
||||||
import platform
|
import platform
|
||||||
import click
|
import click
|
||||||
import time
|
import time
|
||||||
|
import uuid
|
||||||
|
|
||||||
from .global_common import GlobalCommon
|
from .global_common import GlobalCommon
|
||||||
from .main_window import MainWindow
|
from .main_window import MainWindow
|
||||||
|
@ -20,6 +21,7 @@ dangerzone_version = "0.0.3"
|
||||||
|
|
||||||
class Application(QtWidgets.QApplication):
|
class Application(QtWidgets.QApplication):
|
||||||
document_selected = QtCore.pyqtSignal(str)
|
document_selected = QtCore.pyqtSignal(str)
|
||||||
|
application_activated = QtCore.pyqtSignal()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QtWidgets.QApplication.__init__(self, sys.argv)
|
QtWidgets.QApplication.__init__(self, sys.argv)
|
||||||
|
@ -29,6 +31,9 @@ class Application(QtWidgets.QApplication):
|
||||||
if event.type() == QtCore.QEvent.FileOpen:
|
if event.type() == QtCore.QEvent.FileOpen:
|
||||||
self.document_selected.emit(event.file())
|
self.document_selected.emit(event.file())
|
||||||
return True
|
return True
|
||||||
|
elif event.type() == QtCore.QEvent.ApplicationActivate:
|
||||||
|
self.application_activated.emit()
|
||||||
|
return True
|
||||||
|
|
||||||
return QtWidgets.QApplication.event(self, event)
|
return QtWidgets.QApplication.event(self, event)
|
||||||
|
|
||||||
|
@ -66,15 +71,25 @@ def main(filename):
|
||||||
docker_installer.start()
|
docker_installer.start()
|
||||||
return
|
return
|
||||||
|
|
||||||
windows = []
|
closed_windows = {}
|
||||||
|
windows = {}
|
||||||
|
|
||||||
|
def delete_window(window_id):
|
||||||
|
closed_windows[window_id] = windows[window_id]
|
||||||
|
del windows[window_id]
|
||||||
|
|
||||||
# Open a document in a window
|
# Open a document in a window
|
||||||
def select_document(filename=None):
|
def select_document(filename=None):
|
||||||
if len(windows) == 1 and windows[0].common.document_filename == None:
|
if (
|
||||||
window = windows[0]
|
len(windows) == 1
|
||||||
|
and windows[list(windows.keys())[0]].common.document_filename == None
|
||||||
|
):
|
||||||
|
window = windows[list(windows.keys())[0]]
|
||||||
else:
|
else:
|
||||||
window = MainWindow(global_common)
|
window_id = uuid.uuid4().hex
|
||||||
windows.append(window)
|
window = MainWindow(global_common, window_id)
|
||||||
|
window.delete_window.connect(delete_window)
|
||||||
|
windows[window_id] = window
|
||||||
|
|
||||||
if filename:
|
if filename:
|
||||||
# Validate filename
|
# Validate filename
|
||||||
|
@ -100,7 +115,15 @@ def main(filename):
|
||||||
if not select_document(filename):
|
if not select_document(filename):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# Open a new window, if all windows are closed
|
||||||
|
def application_activated():
|
||||||
|
if len(windows) == 0:
|
||||||
|
select_document()
|
||||||
|
|
||||||
# If we get a file open event, open it
|
# If we get a file open event, open it
|
||||||
app.document_selected.connect(select_document)
|
app.document_selected.connect(select_document)
|
||||||
|
|
||||||
|
# If the application is activated and all windows are closed, open a new one
|
||||||
|
app.application_activated.connect(application_activated)
|
||||||
|
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|
|
@ -10,9 +10,12 @@ from .common import Common
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QtWidgets.QMainWindow):
|
class MainWindow(QtWidgets.QMainWindow):
|
||||||
def __init__(self, global_common):
|
delete_window = QtCore.pyqtSignal(str)
|
||||||
|
|
||||||
|
def __init__(self, global_common, window_id):
|
||||||
super(MainWindow, self).__init__()
|
super(MainWindow, self).__init__()
|
||||||
self.global_common = global_common
|
self.global_common = global_common
|
||||||
|
self.window_id = window_id
|
||||||
self.common = Common()
|
self.common = Common()
|
||||||
|
|
||||||
self.setWindowTitle("dangerzone")
|
self.setWindowTitle("dangerzone")
|
||||||
|
@ -83,5 +86,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
|
|
||||||
def closeEvent(self, e):
|
def closeEvent(self, e):
|
||||||
e.accept()
|
e.accept()
|
||||||
|
self.delete_window.emit(self.window_id)
|
||||||
|
|
||||||
if platform.system() != "Darwin":
|
if platform.system() != "Darwin":
|
||||||
self.global_common.app.quit()
|
self.global_common.app.quit()
|
||||||
|
|
Loading…
Reference in a new issue