mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 10:12:38 +02:00
Unwrap ApplicationWrapper in GUI
Reverts commit b8e8c74
as the conditions that lead the
ApplicationWrapper to crash if not done with a wrapper no longer
seem to apply.
This commit is contained in:
parent
c40502fb46
commit
814b8b9d0f
2 changed files with 12 additions and 21 deletions
|
@ -19,21 +19,18 @@ from .main_window import MainWindow
|
||||||
from .systray import SysTray
|
from .systray import SysTray
|
||||||
|
|
||||||
|
|
||||||
# For some reason, Dangerzone segfaults if I inherit from QApplication directly, so instead
|
class Application(QtWidgets.QApplication):
|
||||||
# this is a class whose job is to hold a QApplication object and customize it
|
|
||||||
class ApplicationWrapper(QtCore.QObject):
|
|
||||||
document_selected = QtCore.Signal(str)
|
document_selected = QtCore.Signal(str)
|
||||||
new_window = QtCore.Signal()
|
new_window = QtCore.Signal()
|
||||||
application_activated = QtCore.Signal()
|
application_activated = QtCore.Signal()
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super(ApplicationWrapper, self).__init__()
|
super(Application, self).__init__()
|
||||||
self.app = QtWidgets.QApplication()
|
self.setQuitOnLastWindowClosed(False)
|
||||||
self.app.setQuitOnLastWindowClosed(False)
|
|
||||||
with open(get_resource_path("dangerzone.css"), "r") as f:
|
with open(get_resource_path("dangerzone.css"), "r") as f:
|
||||||
style = f.read()
|
style = f.read()
|
||||||
self.app.setStyleSheet(style)
|
self.setStyleSheet(style)
|
||||||
self.original_event = self.app.event
|
self.original_event = self.event
|
||||||
|
|
||||||
def monkeypatch_event(arg__1: QtCore.QEvent) -> bool:
|
def monkeypatch_event(arg__1: QtCore.QEvent) -> bool:
|
||||||
event = arg__1 # oddly Qt calls internally event by "arg__1"
|
event = arg__1 # oddly Qt calls internally event by "arg__1"
|
||||||
|
@ -49,7 +46,7 @@ class ApplicationWrapper(QtCore.QObject):
|
||||||
|
|
||||||
return self.original_event(event)
|
return self.original_event(event)
|
||||||
|
|
||||||
self.app.event = monkeypatch_event # type: ignore [assignment]
|
self.event = monkeypatch_event # type: ignore [assignment]
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
|
@ -76,8 +73,7 @@ def gui_main(filenames: Optional[List[str]]) -> bool:
|
||||||
colorama.deinit()
|
colorama.deinit()
|
||||||
|
|
||||||
# Create the Qt app
|
# Create the Qt app
|
||||||
app_wrapper = ApplicationWrapper()
|
app = Application()
|
||||||
app = app_wrapper.app
|
|
||||||
|
|
||||||
# Common objects
|
# Common objects
|
||||||
dangerzone = DangerzoneGui(app)
|
dangerzone = DangerzoneGui(app)
|
||||||
|
@ -86,7 +82,7 @@ def gui_main(filenames: Optional[List[str]]) -> bool:
|
||||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||||
|
|
||||||
# Create the system tray
|
# Create the system tray
|
||||||
systray = SysTray(dangerzone, app, app_wrapper)
|
systray = SysTray(dangerzone, app)
|
||||||
|
|
||||||
closed_windows: Dict[str, MainWindow] = {}
|
closed_windows: Dict[str, MainWindow] = {}
|
||||||
windows: Dict[str, MainWindow] = {}
|
windows: Dict[str, MainWindow] = {}
|
||||||
|
@ -112,11 +108,11 @@ def gui_main(filenames: Optional[List[str]]) -> bool:
|
||||||
new_window()
|
new_window()
|
||||||
|
|
||||||
# If we get a file open event, open it
|
# If we get a file open event, open it
|
||||||
app_wrapper.document_selected.connect(new_window)
|
app.document_selected.connect(new_window)
|
||||||
app_wrapper.new_window.connect(new_window)
|
app.new_window.connect(new_window)
|
||||||
|
|
||||||
# If the application is activated and all windows are closed, open a new one
|
# If the application is activated and all windows are closed, open a new one
|
||||||
app_wrapper.application_activated.connect(application_activated)
|
app.application_activated.connect(application_activated)
|
||||||
|
|
||||||
# Launch the GUI
|
# Launch the GUI
|
||||||
ret = app.exec_()
|
ret = app.exec_()
|
||||||
|
|
|
@ -5,21 +5,16 @@ from PySide2 import QtWidgets
|
||||||
|
|
||||||
from .logic import DangerzoneGui
|
from .logic import DangerzoneGui
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from . import ApplicationWrapper
|
|
||||||
|
|
||||||
|
|
||||||
class SysTray(QtWidgets.QSystemTrayIcon):
|
class SysTray(QtWidgets.QSystemTrayIcon):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
dangerzone: DangerzoneGui,
|
dangerzone: DangerzoneGui,
|
||||||
app: QtWidgets.QApplication,
|
app: QtWidgets.QApplication,
|
||||||
app_wrapper: "ApplicationWrapper",
|
|
||||||
) -> None:
|
) -> None:
|
||||||
super(SysTray, self).__init__()
|
super(SysTray, self).__init__()
|
||||||
self.dangerzone = dangerzone
|
self.dangerzone = dangerzone
|
||||||
self.app = app
|
self.app = app
|
||||||
self.app_wrapper = app_wrapper
|
|
||||||
|
|
||||||
self.setIcon(self.dangerzone.get_window_icon())
|
self.setIcon(self.dangerzone.get_window_icon())
|
||||||
|
|
||||||
|
@ -35,7 +30,7 @@ class SysTray(QtWidgets.QSystemTrayIcon):
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def new_window(self) -> None:
|
def new_window(self) -> None:
|
||||||
self.app_wrapper.new_window.emit()
|
self.new_window.emit()
|
||||||
|
|
||||||
def quit_clicked(self) -> None:
|
def quit_clicked(self) -> None:
|
||||||
self.app.quit()
|
self.app.quit()
|
||||||
|
|
Loading…
Reference in a new issue