mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
Clicking start starts running the tasks
This commit is contained in:
parent
dbff6b4b79
commit
bdcd61b964
4 changed files with 75 additions and 27 deletions
|
@ -44,10 +44,12 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
self.doc_selection_widget.document_selected.connect(
|
self.doc_selection_widget.document_selected.connect(
|
||||||
self.settings_widget.document_selected
|
self.settings_widget.document_selected
|
||||||
)
|
)
|
||||||
|
self.settings_widget.start_clicked.connect(self.start_clicked)
|
||||||
self.settings_widget.hide()
|
self.settings_widget.hide()
|
||||||
|
|
||||||
# Tasks
|
# Tasks
|
||||||
self.tasks_widget = TasksWidget(self.common)
|
self.tasks_widget = TasksWidget(self.common)
|
||||||
|
self.settings_widget.start_clicked.connect(self.tasks_widget.start)
|
||||||
self.tasks_widget.hide()
|
self.tasks_widget.hide()
|
||||||
|
|
||||||
# Layout
|
# Layout
|
||||||
|
@ -67,6 +69,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
self.doc_selection_widget.hide()
|
self.doc_selection_widget.hide()
|
||||||
self.settings_widget.show()
|
self.settings_widget.show()
|
||||||
|
|
||||||
|
def start_clicked(self):
|
||||||
|
self.settings_widget.hide()
|
||||||
|
self.tasks_widget.show()
|
||||||
|
|
||||||
def closeEvent(self, e):
|
def closeEvent(self, e):
|
||||||
e.accept()
|
e.accept()
|
||||||
self.app.quit()
|
self.app.quit()
|
||||||
|
|
|
@ -24,7 +24,6 @@ class Settings:
|
||||||
|
|
||||||
def set(self, key, val):
|
def set(self, key, val):
|
||||||
self.settings[key] = val
|
self.settings[key] = val
|
||||||
self.settings.save()
|
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
if os.path.isfile(self.settings_filename):
|
if os.path.isfile(self.settings_filename):
|
||||||
|
|
|
@ -3,6 +3,8 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
|
|
||||||
class SettingsWidget(QtWidgets.QWidget):
|
class SettingsWidget(QtWidgets.QWidget):
|
||||||
|
start_clicked = QtCore.pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, common):
|
def __init__(self, common):
|
||||||
super(SettingsWidget, self).__init__()
|
super(SettingsWidget, self).__init__()
|
||||||
self.common = common
|
self.common = common
|
||||||
|
@ -53,13 +55,14 @@ class SettingsWidget(QtWidgets.QWidget):
|
||||||
update_layout.addStretch()
|
update_layout.addStretch()
|
||||||
|
|
||||||
# Button
|
# Button
|
||||||
self.button_start = QtWidgets.QPushButton("Convert to Save Document")
|
self.start_button = QtWidgets.QPushButton("Convert to Save Document")
|
||||||
self.button_start.setStyleSheet(
|
self.start_button.clicked.connect(self.start_button_clicked)
|
||||||
|
self.start_button.setStyleSheet(
|
||||||
"QPushButton { font-size: 16px; font-weight: bold; padding: 10px; }"
|
"QPushButton { font-size: 16px; font-weight: bold; padding: 10px; }"
|
||||||
)
|
)
|
||||||
button_layout = QtWidgets.QHBoxLayout()
|
button_layout = QtWidgets.QHBoxLayout()
|
||||||
button_layout.addStretch()
|
button_layout.addStretch()
|
||||||
button_layout.addWidget(self.button_start)
|
button_layout.addWidget(self.start_button)
|
||||||
button_layout.addStretch()
|
button_layout.addStretch()
|
||||||
|
|
||||||
# Layout
|
# Layout
|
||||||
|
@ -124,3 +127,24 @@ class SettingsWidget(QtWidgets.QWidget):
|
||||||
if filename[0] != "":
|
if filename[0] != "":
|
||||||
self.common.save_filename = filename[0]
|
self.common.save_filename = filename[0]
|
||||||
self.save_lineedit.setText(os.path.basename(self.common.save_filename))
|
self.save_lineedit.setText(os.path.basename(self.common.save_filename))
|
||||||
|
|
||||||
|
def start_button_clicked(self):
|
||||||
|
# Update settings
|
||||||
|
self.common.settings.set(
|
||||||
|
"save", self.save_checkbox.checkState() == QtCore.Qt.Checked
|
||||||
|
)
|
||||||
|
self.common.settings.set(
|
||||||
|
"ocr", self.ocr_checkbox.checkState() == QtCore.Qt.Checked
|
||||||
|
)
|
||||||
|
self.common.settings.set("ocr_language", self.ocr_combobox.currentText())
|
||||||
|
self.common.settings.set(
|
||||||
|
"open", self.open_checkbox.checkState() == QtCore.Qt.Checked
|
||||||
|
)
|
||||||
|
self.common.settings.set("open_app", self.open_combobox.currentText())
|
||||||
|
self.common.settings.set(
|
||||||
|
"update_container", self.update_checkbox.checkState() == QtCore.Qt.Checked
|
||||||
|
)
|
||||||
|
self.common.settings.save()
|
||||||
|
|
||||||
|
# Start!
|
||||||
|
self.start_clicked.emit()
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import shlex
|
||||||
|
import subprocess
|
||||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
from .tasks import PullImageTask, BuildContainerTask, ConvertToPixels, ConvertToPDF
|
from .tasks import PullImageTask, BuildContainerTask, ConvertToPixels, ConvertToPDF
|
||||||
|
@ -26,18 +28,23 @@ class TasksWidget(QtWidgets.QWidget):
|
||||||
self.scroll_to_bottom
|
self.scroll_to_bottom
|
||||||
)
|
)
|
||||||
|
|
||||||
self.tasks = [PullImageTask, BuildContainerTask, ConvertToPixels, ConvertToPDF]
|
# Layout
|
||||||
|
layout = QtWidgets.QVBoxLayout()
|
||||||
|
layout.addWidget(self.task_label)
|
||||||
|
layout.addWidget(self.details_scrollarea)
|
||||||
|
self.setLayout(layout)
|
||||||
|
|
||||||
def start(self, filename):
|
self.tasks = []
|
||||||
print(f"Input document: {filename}")
|
|
||||||
self.common.set_document_filename(filename)
|
|
||||||
self.show()
|
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
if self.common.settings.get("update_container"):
|
||||||
|
self.tasks += [PullImageTask, BuildContainerTask]
|
||||||
|
self.tasks += [ConvertToPixels, ConvertToPDF]
|
||||||
self.next_task()
|
self.next_task()
|
||||||
|
|
||||||
def next_task(self):
|
def next_task(self):
|
||||||
if len(self.tasks) == 0:
|
if len(self.tasks) == 0:
|
||||||
self.save_safe_pdf()
|
self.all_done()
|
||||||
return
|
return
|
||||||
|
|
||||||
self.task_details.setText("")
|
self.task_details.setText("")
|
||||||
|
@ -62,21 +69,33 @@ class TasksWidget(QtWidgets.QWidget):
|
||||||
f"Directory with pixel data: {self.common.pixel_dir.name}\n\n{err}"
|
f"Directory with pixel data: {self.common.pixel_dir.name}\n\n{err}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def save_safe_pdf(self):
|
def all_done(self):
|
||||||
suggested_filename = (
|
# Save safe PDF
|
||||||
f"{os.path.splitext(self.common.document_filename)[0]}-safe.pdf"
|
if self.common.settings.get("save"):
|
||||||
)
|
|
||||||
|
|
||||||
filename = QtWidgets.QFileDialog.getSaveFileName(
|
|
||||||
self, "Save safe PDF", suggested_filename, filter="Documents (*.pdf)"
|
|
||||||
)
|
|
||||||
if filename[0] == "":
|
|
||||||
print("Save file dialog canceled")
|
|
||||||
else:
|
|
||||||
source_filename = f"{self.common.safe_dir.name}/safe-output-compressed.pdf"
|
source_filename = f"{self.common.safe_dir.name}/safe-output-compressed.pdf"
|
||||||
dest_filename = filename[0]
|
dest_filename = self.common.save_filename
|
||||||
shutil.move(source_filename, dest_filename)
|
shutil.move(source_filename, dest_filename)
|
||||||
|
|
||||||
|
# Open
|
||||||
|
if self.common.settings.get("open"):
|
||||||
|
if self.common.settings.get("open_app") in self.common.pdf_viewers:
|
||||||
|
# Get the PDF reader command
|
||||||
|
args = shlex.split(
|
||||||
|
self.common.pdf_viewers[self.common.settings.get("open_app")]
|
||||||
|
)
|
||||||
|
# %f, %F, %u, and %U are filenames or URLS -- so replace with the file to open
|
||||||
|
for i in range(len(args)):
|
||||||
|
if (
|
||||||
|
args[i] == "%f"
|
||||||
|
or args[i] == "%F"
|
||||||
|
or args[i] == "%u"
|
||||||
|
or args[i] == "%U"
|
||||||
|
):
|
||||||
|
args[i] = self.save_filename
|
||||||
|
|
||||||
|
# Open as a background process
|
||||||
|
subprocess.Popen(args)
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
self.common.pixel_dir.cleanup()
|
self.common.pixel_dir.cleanup()
|
||||||
self.common.safe_dir.cleanup()
|
self.common.safe_dir.cleanup()
|
||||||
|
|
Loading…
Reference in a new issue