mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 10:12:38 +02:00
Remove window management logic
Since everything now happens in a single window, there is no need to have a way to keep track other windows. They simply won't exist. But on windows and Linux it will still be possible to start multiple windows by starting various Dangerzone processes. On MacOS this doesn't seem to be as easy from the launcher, but it should not be critical as multiple documents can be converted at the same time in the one window.
This commit is contained in:
parent
6f8eb96b35
commit
df8e2f1b8b
2 changed files with 7 additions and 24 deletions
|
@ -20,7 +20,6 @@ from .main_window import MainWindow
|
||||||
|
|
||||||
class Application(QtWidgets.QApplication):
|
class Application(QtWidgets.QApplication):
|
||||||
document_selected = QtCore.Signal(str)
|
document_selected = QtCore.Signal(str)
|
||||||
new_window = QtCore.Signal()
|
|
||||||
application_activated = QtCore.Signal()
|
application_activated = QtCore.Signal()
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
@ -80,32 +79,20 @@ def gui_main(filenames: Optional[List[str]]) -> bool:
|
||||||
# Allow Ctrl-C to smoothly quit the program instead of throwing an exception
|
# Allow Ctrl-C to smoothly quit the program instead of throwing an exception
|
||||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||||
|
|
||||||
closed_windows: Dict[str, MainWindow] = {}
|
def new_window(filenames: Optional[List[str]] = []) -> MainWindow:
|
||||||
windows: Dict[str, MainWindow] = {}
|
window = MainWindow(dangerzone)
|
||||||
|
|
||||||
def delete_window(window_id: str) -> None:
|
|
||||||
closed_windows[window_id] = windows[window_id]
|
|
||||||
del windows[window_id]
|
|
||||||
|
|
||||||
# Open a document in a window
|
|
||||||
def new_window(filenames: Optional[List[str]] = []) -> None:
|
|
||||||
window_id = uuid.uuid4().hex
|
|
||||||
window = MainWindow(dangerzone, window_id)
|
|
||||||
if filenames:
|
if filenames:
|
||||||
window.content_widget.doc_selection_widget.document_selected.emit(filenames)
|
window.content_widget.doc_selection_widget.document_selected.emit(filenames)
|
||||||
window.delete_window.connect(delete_window)
|
return window
|
||||||
windows[window_id] = window
|
|
||||||
|
|
||||||
new_window(filenames)
|
window = new_window(filenames)
|
||||||
|
|
||||||
# Open a new window, if all windows are closed
|
# MacOS: Open a new window, if all windows are closed
|
||||||
def application_activated() -> None:
|
def application_activated() -> None:
|
||||||
if len(windows) == 0:
|
window.show()
|
||||||
new_window()
|
|
||||||
|
|
||||||
# If we get a file open event, open it
|
# If we get a file open event, open it
|
||||||
app.document_selected.connect(new_window)
|
app.document_selected.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.application_activated.connect(application_activated)
|
app.application_activated.connect(application_activated)
|
||||||
|
|
|
@ -20,12 +20,9 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QtWidgets.QMainWindow):
|
class MainWindow(QtWidgets.QMainWindow):
|
||||||
delete_window = QtCore.Signal(str)
|
def __init__(self, dangerzone: DangerzoneGui) -> None:
|
||||||
|
|
||||||
def __init__(self, dangerzone: DangerzoneGui, window_id: str) -> None:
|
|
||||||
super(MainWindow, self).__init__()
|
super(MainWindow, self).__init__()
|
||||||
self.dangerzone = dangerzone
|
self.dangerzone = dangerzone
|
||||||
self.window_id = window_id
|
|
||||||
|
|
||||||
self.setWindowTitle("Dangerzone")
|
self.setWindowTitle("Dangerzone")
|
||||||
self.setWindowIcon(self.dangerzone.get_window_icon())
|
self.setWindowIcon(self.dangerzone.get_window_icon())
|
||||||
|
@ -82,7 +79,6 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
|
|
||||||
def closeEvent(self, e: QtGui.QCloseEvent) -> None:
|
def closeEvent(self, e: QtGui.QCloseEvent) -> None:
|
||||||
e.accept()
|
e.accept()
|
||||||
self.delete_window.emit(self.window_id)
|
|
||||||
|
|
||||||
if platform.system() != "Darwin":
|
if platform.system() != "Darwin":
|
||||||
# in MacOS applications only quit when the user
|
# in MacOS applications only quit when the user
|
||||||
|
|
Loading…
Reference in a new issue