mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
Make save browse button let you select an output file
This commit is contained in:
parent
85644ad097
commit
dbff6b4b79
2 changed files with 24 additions and 3 deletions
|
@ -22,13 +22,22 @@ class Common(object):
|
||||||
f"Temporary directories created, dangerous={self.pixel_dir.name}, safe={self.safe_dir.name}"
|
f"Temporary directories created, dangerous={self.pixel_dir.name}, safe={self.safe_dir.name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Name of input file
|
||||||
self.document_filename = None
|
self.document_filename = None
|
||||||
|
|
||||||
|
# Name of output file
|
||||||
|
self.save_filename = None
|
||||||
|
|
||||||
|
# Preload font
|
||||||
self.fixed_font = QtGui.QFontDatabase.systemFont(QtGui.QFontDatabase.FixedFont)
|
self.fixed_font = QtGui.QFontDatabase.systemFont(QtGui.QFontDatabase.FixedFont)
|
||||||
|
|
||||||
|
# App data folder
|
||||||
self.appdata_path = appdirs.user_config_dir("dangerzone")
|
self.appdata_path = appdirs.user_config_dir("dangerzone")
|
||||||
|
|
||||||
|
# Preload list of PDF viewers on computer
|
||||||
self.pdf_viewers = self._find_pdf_viewers()
|
self.pdf_viewers = self._find_pdf_viewers()
|
||||||
|
|
||||||
|
# Languages supported by tesseract
|
||||||
self.ocr_languages = {
|
self.ocr_languages = {
|
||||||
"Afrikaans": "ar",
|
"Afrikaans": "ar",
|
||||||
"Amharic": "amh",
|
"Amharic": "amh",
|
||||||
|
@ -192,6 +201,7 @@ class Common(object):
|
||||||
"Vietnamese script": "Vietnamese",
|
"Vietnamese script": "Vietnamese",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Load settings
|
||||||
self.settings = Settings(self)
|
self.settings = Settings(self)
|
||||||
|
|
||||||
def set_document_filename(self, filename):
|
def set_document_filename(self, filename):
|
||||||
|
|
|
@ -19,12 +19,12 @@ class SettingsWidget(QtWidgets.QWidget):
|
||||||
self.save_lineedit = QtWidgets.QLineEdit()
|
self.save_lineedit = QtWidgets.QLineEdit()
|
||||||
self.save_lineedit.setReadOnly(True)
|
self.save_lineedit.setReadOnly(True)
|
||||||
self.save_browse_button = QtWidgets.QPushButton("Save as...")
|
self.save_browse_button = QtWidgets.QPushButton("Save as...")
|
||||||
|
self.save_browse_button.clicked.connect(self.save_browse_button_clicked)
|
||||||
save_layout = QtWidgets.QHBoxLayout()
|
save_layout = QtWidgets.QHBoxLayout()
|
||||||
save_layout.addWidget(self.save_checkbox)
|
save_layout.addWidget(self.save_checkbox)
|
||||||
save_layout.addWidget(self.save_lineedit)
|
save_layout.addWidget(self.save_lineedit)
|
||||||
save_layout.addWidget(self.save_browse_button)
|
save_layout.addWidget(self.save_browse_button)
|
||||||
save_layout.addStretch()
|
save_layout.addStretch()
|
||||||
self.save_location = None
|
|
||||||
|
|
||||||
# OCR document
|
# OCR document
|
||||||
self.ocr_checkbox = QtWidgets.QCheckBox("OCR document, language")
|
self.ocr_checkbox = QtWidgets.QCheckBox("OCR document, language")
|
||||||
|
@ -109,7 +109,18 @@ class SettingsWidget(QtWidgets.QWidget):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Update the save location
|
# Update the save location
|
||||||
self.save_location = (
|
self.common.save_filename = (
|
||||||
f"{os.path.splitext(self.common.document_filename)[0]}-safe.pdf"
|
f"{os.path.splitext(self.common.document_filename)[0]}-safe.pdf"
|
||||||
)
|
)
|
||||||
self.save_lineedit.setText(os.path.basename(self.save_location))
|
self.save_lineedit.setText(os.path.basename(self.common.save_filename))
|
||||||
|
|
||||||
|
def save_browse_button_clicked(self):
|
||||||
|
filename = QtWidgets.QFileDialog.getSaveFileName(
|
||||||
|
self,
|
||||||
|
"Save safe PDF as...",
|
||||||
|
self.common.save_filename,
|
||||||
|
filter="Documents (*.pdf)",
|
||||||
|
)
|
||||||
|
if filename[0] != "":
|
||||||
|
self.common.save_filename = filename[0]
|
||||||
|
self.save_lineedit.setText(os.path.basename(self.common.save_filename))
|
||||||
|
|
Loading…
Reference in a new issue