mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
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.
This commit is contained in:
parent
21dc5b29df
commit
5b2fefd150
2 changed files with 11 additions and 27 deletions
|
@ -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")])
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue