mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +02:00
Make GUI use the new container too
This commit is contained in:
parent
7f93c1e752
commit
450320de6f
3 changed files with 25 additions and 65 deletions
|
@ -92,15 +92,13 @@ def cli_main(output_filename, ocr_lang, filename):
|
||||||
def stdout_callback(line):
|
def stdout_callback(line):
|
||||||
print(line.rstrip())
|
print(line.rstrip())
|
||||||
|
|
||||||
success = convert(
|
if convert(
|
||||||
global_common,
|
global_common,
|
||||||
common.input_filename,
|
common.input_filename,
|
||||||
common.output_filename,
|
common.output_filename,
|
||||||
ocr_lang,
|
ocr_lang,
|
||||||
stdout_callback,
|
stdout_callback,
|
||||||
)
|
):
|
||||||
|
|
||||||
if success:
|
|
||||||
print_header("Safe PDF created successfully")
|
print_header("Safe PDF created successfully")
|
||||||
click.echo(common.output_filename)
|
click.echo(common.output_filename)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -26,7 +26,6 @@ else:
|
||||||
|
|
||||||
|
|
||||||
def exec(args, stdout_callback=None):
|
def exec(args, stdout_callback=None):
|
||||||
print(f"exec, stdout_callback={stdout_callback}")
|
|
||||||
with subprocess.Popen(
|
with subprocess.Popen(
|
||||||
args,
|
args,
|
||||||
stdin=None,
|
stdin=None,
|
||||||
|
|
|
@ -6,6 +6,7 @@ from PySide2 import QtCore, QtGui, QtWidgets
|
||||||
from colorama import Style, Fore
|
from colorama import Style, Fore
|
||||||
|
|
||||||
from ..common import Common
|
from ..common import Common
|
||||||
|
from ..container import convert
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QtWidgets.QMainWindow):
|
class MainWindow(QtWidgets.QMainWindow):
|
||||||
|
@ -422,7 +423,7 @@ class SettingsWidget(QtWidgets.QWidget):
|
||||||
|
|
||||||
class ConvertThread(QtCore.QThread):
|
class ConvertThread(QtCore.QThread):
|
||||||
task_finished = QtCore.Signal()
|
task_finished = QtCore.Signal()
|
||||||
task_failed = QtCore.Signal(str)
|
task_failed = QtCore.Signal()
|
||||||
update_label = QtCore.Signal(str)
|
update_label = QtCore.Signal(str)
|
||||||
update_details = QtCore.Signal(str)
|
update_details = QtCore.Signal(str)
|
||||||
|
|
||||||
|
@ -431,77 +432,39 @@ class ConvertThread(QtCore.QThread):
|
||||||
self.global_common = global_common
|
self.global_common = global_common
|
||||||
self.common = common
|
self.common = common
|
||||||
|
|
||||||
def exec_container(self, args):
|
|
||||||
output = ""
|
|
||||||
self.update_details.emit(output)
|
|
||||||
|
|
||||||
with self.global_common.exec_dangerzone_container(args) as p:
|
|
||||||
for line in p.stdout:
|
|
||||||
output += line.decode()
|
|
||||||
|
|
||||||
if line.startswith(b"> "):
|
|
||||||
print(
|
|
||||||
Style.DIM + "> " + Style.NORMAL + Fore.CYAN + line.decode()[2:],
|
|
||||||
end="",
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
print(" " + line.decode(), end="")
|
|
||||||
|
|
||||||
self.update_details.emit(output)
|
|
||||||
|
|
||||||
stderr = p.stderr.read().decode()
|
|
||||||
if len(stderr) > 0:
|
|
||||||
print("")
|
|
||||||
for line in stderr.strip().split("\n"):
|
|
||||||
print(" " + Style.DIM + line)
|
|
||||||
|
|
||||||
self.update_details.emit(output)
|
|
||||||
|
|
||||||
print(f"return code: {p.returncode}")
|
|
||||||
if p.returncode == 126 or p.returncode == 127:
|
|
||||||
self.task_failed.emit(f"Authorization failed")
|
|
||||||
elif p.returncode != 0:
|
|
||||||
self.task_failed.emit(f"Return code: {p.returncode}")
|
|
||||||
|
|
||||||
print("")
|
|
||||||
return p.returncode, output, stderr
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.update_label.emit("Converting document to safe PDF")
|
self.update_label.emit("Converting document to safe PDF")
|
||||||
|
|
||||||
if self.global_common.settings.get("ocr"):
|
|
||||||
ocr = "1"
|
|
||||||
else:
|
|
||||||
ocr = "0"
|
|
||||||
ocr_lang = self.global_common.ocr_languages[
|
ocr_lang = self.global_common.ocr_languages[
|
||||||
self.global_common.settings.get("ocr_language")
|
self.global_common.settings.get("ocr_language")
|
||||||
]
|
]
|
||||||
|
|
||||||
args = [
|
self.output = ""
|
||||||
"convert",
|
self.update_details.emit(self.output)
|
||||||
"--input-filename",
|
|
||||||
|
if convert(
|
||||||
|
self.global_common,
|
||||||
self.common.input_filename,
|
self.common.input_filename,
|
||||||
"--output-filename",
|
|
||||||
self.common.output_filename,
|
self.common.output_filename,
|
||||||
"--ocr",
|
|
||||||
ocr,
|
|
||||||
"--ocr-lang",
|
|
||||||
ocr_lang,
|
ocr_lang,
|
||||||
]
|
self.stdout_callback,
|
||||||
returncode, _, _ = self.exec_container(args)
|
):
|
||||||
|
self.task_finished.emit()
|
||||||
|
else:
|
||||||
|
self.task_failed.emit()
|
||||||
|
|
||||||
if returncode != 0:
|
def stdout_callback(self, line):
|
||||||
return
|
self.output += line
|
||||||
|
|
||||||
# success, error_message = self.global_common.validate_convert_to_pixel_output(
|
if line.startswith("> "):
|
||||||
# self.common, output
|
print(
|
||||||
# )
|
Style.DIM + "> " + Style.NORMAL + Fore.CYAN + line[2:],
|
||||||
# if not success:
|
end="",
|
||||||
# self.task_failed.emit(error_message)
|
)
|
||||||
# return
|
else:
|
||||||
|
print(" " + line, end="")
|
||||||
self.task_finished.emit()
|
|
||||||
|
|
||||||
|
self.update_details.emit(self.output)
|
||||||
|
|
||||||
|
|
||||||
class TasksWidget(QtWidgets.QWidget):
|
class TasksWidget(QtWidgets.QWidget):
|
||||||
|
@ -566,7 +529,7 @@ class TasksWidget(QtWidgets.QWidget):
|
||||||
def update_details(self, s):
|
def update_details(self, s):
|
||||||
self.task_details.setText(s)
|
self.task_details.setText(s)
|
||||||
|
|
||||||
def task_failed(self, err):
|
def task_failed(self):
|
||||||
self.task_label.setText("Failed :(")
|
self.task_label.setText("Failed :(")
|
||||||
self.task_details.setWordWrap(True)
|
self.task_details.setWordWrap(True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue