From 5b2fefd1505020f27da983c99ed2eee787385e42 Mon Sep 17 00:00:00 2001 From: deeplow Date: Thu, 17 Nov 2022 10:57:19 +0000 Subject: [PATCH] Open PDFs on Windows (instead of explorer.exe) Homogenize GUI by having on Windows the option of opening documents after conversion. This removes the need for windows-specific GTK widgets. --- dangerzone/gui/logic.py | 4 ++++ dangerzone/gui/main_window.py | 34 +++++++--------------------------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/dangerzone/gui/logic.py b/dangerzone/gui/logic.py index c4be210..343857f 100644 --- a/dangerzone/gui/logic.py +++ b/dangerzone/gui/logic.py @@ -4,6 +4,7 @@ import pipes import platform import shlex import subprocess +from pathlib import Path from typing import Dict from colorama import Fore @@ -56,6 +57,9 @@ class DangerzoneGui(DangerzoneCore): log.info(Fore.YELLOW + "> " + Fore.CYAN + args_str) subprocess.run(args) + elif platform.system() == "Windows": + os.startfile(Path(filename)) # type: ignore [attr-defined] + elif platform.system() == "Linux": # Get the PDF reader command args = shlex.split(self.pdf_viewers[self.settings.get("open_app")]) diff --git a/dangerzone/gui/main_window.py b/dangerzone/gui/main_window.py index 6a5c20b..b85336b 100644 --- a/dangerzone/gui/main_window.py +++ b/dangerzone/gui/main_window.py @@ -299,15 +299,7 @@ class SettingsWidget(QtWidgets.QWidget): # Save safe version self.save_checkbox = QtWidgets.QCheckBox("Save safe PDF to") self.save_checkbox.clicked.connect(self.update_ui) - self.save_label = QtWidgets.QLabel("Save safe PDF to") # For Windows - self.save_label.hide() self.output_dir = None - if platform.system() == "Windows": - # In Windows, users must save the PDF, since they can't open it - self.save_checkbox.setCheckState(QtCore.Qt.Checked) - self.save_checkbox.setEnabled(False) - self.save_checkbox.hide() - self.save_label.show() # Save safe to... self.save_location = QtWidgets.QLineEdit() @@ -343,14 +335,13 @@ class SettingsWidget(QtWidgets.QWidget): self.safe_extension_layout = QtWidgets.QHBoxLayout() self.safe_extension_layout.setContentsMargins(20, 0, 0, 0) self.safe_extension_layout.addWidget(self.safe_extension_label) - self.safe_extension_layout.addWidget(self.save_label) self.safe_extension_layout.addLayout(self.safe_extension_name_layout) self.safe_extension_layout.addWidget(self.safe_extension_invalid) self.safe_extension_layout.addStretch() # Open safe document - if platform.system() == "Darwin": + if platform.system() in ["Darwin", "Windows"]: self.open_checkbox = QtWidgets.QCheckBox( "Open safe documents after converting" ) @@ -365,12 +356,11 @@ class SettingsWidget(QtWidgets.QWidget): for k in self.dangerzone.pdf_viewers: self.open_combobox.addItem(k, self.dangerzone.pdf_viewers[k]) - if platform.system() == "Darwin" or platform.system() == "Linux": - open_layout = QtWidgets.QHBoxLayout() - open_layout.addWidget(self.open_checkbox) - if platform.system() == "Linux": - open_layout.addWidget(self.open_combobox) - open_layout.addStretch() + open_layout = QtWidgets.QHBoxLayout() + open_layout.addWidget(self.open_checkbox) + if platform.system() == "Linux": + open_layout.addWidget(self.open_combobox) + open_layout.addStretch() # OCR document self.ocr_checkbox = QtWidgets.QCheckBox("OCR document, language") @@ -398,8 +388,7 @@ class SettingsWidget(QtWidgets.QWidget): layout.addSpacing(20) layout.addLayout(self.save_location_layout) layout.addLayout(self.safe_extension_layout) - if platform.system() != "Windows": - layout.addLayout(open_layout) + layout.addLayout(open_layout) layout.addLayout(ocr_layout) layout.addSpacing(20) layout.addLayout(button_layout) @@ -689,15 +678,6 @@ class DocumentWidget(QtWidgets.QWidget): if self.error: return - # In Windows, open Explorer with the safe PDF in focus - if platform.system() == "Windows": - dest_filename_windows = self.document.output_filename.replace("/", "\\") - subprocess.Popen( - f'explorer.exe /select,"{dest_filename_windows}"', - shell=True, - startupinfo=get_subprocess_startupinfo(), - ) - # Open if self.dangerzone.settings.get("open"): self.dangerzone.open_pdf_viewer(self.document.output_filename)