mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 18:22:37 +02:00
Fix removing PDF viewer search in Mac, and make the waiting widget look better
This commit is contained in:
parent
720810da5d
commit
d9d352a680
5 changed files with 82 additions and 12 deletions
|
@ -93,8 +93,8 @@ def gui_main(custom_container, filename):
|
||||||
# Allow Ctrl-C to smoothly quit the program instead of throwing an exception
|
# Allow Ctrl-C to smoothly quit the program instead of throwing an exception
|
||||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||||
|
|
||||||
# See if we need to install Docker...
|
# See if we need to install Docker (Windows-only)
|
||||||
if (platform.system() == "Darwin" or platform.system() == "Windows") and (
|
if platform.system() == "Windows" and (
|
||||||
not is_docker_installed() or not is_docker_ready(global_common)
|
not is_docker_installed() or not is_docker_ready(global_common)
|
||||||
):
|
):
|
||||||
click.echo("Docker is either not installed or not running")
|
click.echo("Docker is either not installed or not running")
|
||||||
|
@ -102,7 +102,7 @@ def gui_main(custom_container, filename):
|
||||||
docker_installer.start()
|
docker_installer.start()
|
||||||
return
|
return
|
||||||
|
|
||||||
# The dangerzone VM, for non-Linux platforms
|
# The dangerzone VM (Mac-only)
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
vm = Vm(global_common)
|
vm = Vm(global_common)
|
||||||
else:
|
else:
|
||||||
|
@ -110,8 +110,10 @@ def gui_main(custom_container, filename):
|
||||||
|
|
||||||
# Create the system tray
|
# Create the system tray
|
||||||
systray = SysTray(global_common, gui_common, app, vm)
|
systray = SysTray(global_common, gui_common, app, vm)
|
||||||
if vm:
|
|
||||||
vm.start()
|
# Start the VM
|
||||||
|
# if vm:
|
||||||
|
# vm.start()
|
||||||
|
|
||||||
closed_windows = {}
|
closed_windows = {}
|
||||||
windows = {}
|
windows = {}
|
||||||
|
@ -129,7 +131,7 @@ def gui_main(custom_container, filename):
|
||||||
window = windows[list(windows.keys())[0]]
|
window = windows[list(windows.keys())[0]]
|
||||||
else:
|
else:
|
||||||
window_id = uuid.uuid4().hex
|
window_id = uuid.uuid4().hex
|
||||||
window = MainWindow(global_common, gui_common, window_id)
|
window = MainWindow(global_common, gui_common, vm, window_id)
|
||||||
window.delete_window.connect(delete_window)
|
window.delete_window.connect(delete_window)
|
||||||
windows[window_id] = window
|
windows[window_id] = window
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import os
|
||||||
import platform
|
import platform
|
||||||
from PySide2 import QtCore, QtGui, QtWidgets
|
from PySide2 import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
|
from .waiting_widget import WaitingWidget
|
||||||
from .doc_selection_widget import DocSelectionWidget
|
from .doc_selection_widget import DocSelectionWidget
|
||||||
from .settings_widget import SettingsWidget
|
from .settings_widget import SettingsWidget
|
||||||
from .tasks_widget import TasksWidget
|
from .tasks_widget import TasksWidget
|
||||||
|
@ -12,10 +13,11 @@ from ..common import Common
|
||||||
class MainWindow(QtWidgets.QMainWindow):
|
class MainWindow(QtWidgets.QMainWindow):
|
||||||
delete_window = QtCore.Signal(str)
|
delete_window = QtCore.Signal(str)
|
||||||
|
|
||||||
def __init__(self, global_common, gui_common, window_id):
|
def __init__(self, global_common, gui_common, vm, window_id):
|
||||||
super(MainWindow, self).__init__()
|
super(MainWindow, self).__init__()
|
||||||
self.global_common = global_common
|
self.global_common = global_common
|
||||||
self.gui_common = gui_common
|
self.gui_common = gui_common
|
||||||
|
self.vm = vm
|
||||||
self.window_id = window_id
|
self.window_id = window_id
|
||||||
self.common = Common()
|
self.common = Common()
|
||||||
|
|
||||||
|
@ -42,10 +44,21 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
header_layout.addWidget(header_label)
|
header_layout.addWidget(header_label)
|
||||||
header_layout.addStretch()
|
header_layout.addStretch()
|
||||||
|
|
||||||
|
# Waiting widget
|
||||||
|
self.waiting_widget = WaitingWidget(self.gui_common, self.vm)
|
||||||
|
self.waiting_widget.vm_started.connect(self.vm_started)
|
||||||
|
|
||||||
# Doc selection widget
|
# Doc selection widget
|
||||||
self.doc_selection_widget = DocSelectionWidget(self.common)
|
self.doc_selection_widget = DocSelectionWidget(self.common)
|
||||||
self.doc_selection_widget.document_selected.connect(self.document_selected)
|
self.doc_selection_widget.document_selected.connect(self.document_selected)
|
||||||
self.doc_selection_widget.show()
|
|
||||||
|
# Only use the waiting widget if we have a VM
|
||||||
|
if self.vm:
|
||||||
|
self.waiting_widget.show()
|
||||||
|
self.doc_selection_widget.hide()
|
||||||
|
else:
|
||||||
|
self.waiting_widget.hide()
|
||||||
|
self.doc_selection_widget.show()
|
||||||
|
|
||||||
# Settings
|
# Settings
|
||||||
self.settings_widget = SettingsWidget(
|
self.settings_widget = SettingsWidget(
|
||||||
|
@ -75,6 +88,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
# Layout
|
# Layout
|
||||||
layout = QtWidgets.QVBoxLayout()
|
layout = QtWidgets.QVBoxLayout()
|
||||||
layout.addLayout(header_layout)
|
layout.addLayout(header_layout)
|
||||||
|
layout.addWidget(self.waiting_widget, stretch=1)
|
||||||
layout.addWidget(self.doc_selection_widget, stretch=1)
|
layout.addWidget(self.doc_selection_widget, stretch=1)
|
||||||
layout.addWidget(self.settings_widget, stretch=1)
|
layout.addWidget(self.settings_widget, stretch=1)
|
||||||
layout.addWidget(self.tasks_widget, stretch=1)
|
layout.addWidget(self.tasks_widget, stretch=1)
|
||||||
|
@ -85,6 +99,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
|
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
def vm_started(self):
|
||||||
|
self.waiting_widget.hide()
|
||||||
|
self.doc_selection_widget.show
|
||||||
|
|
||||||
def document_selected(self):
|
def document_selected(self):
|
||||||
self.doc_selection_widget.hide()
|
self.doc_selection_widget.hide()
|
||||||
self.settings_widget.show()
|
self.settings_widget.show()
|
||||||
|
|
|
@ -42,15 +42,14 @@ class SettingsWidget(QtWidgets.QWidget):
|
||||||
save_layout.addWidget(self.save_browse_button)
|
save_layout.addWidget(self.save_browse_button)
|
||||||
save_layout.addStretch()
|
save_layout.addStretch()
|
||||||
|
|
||||||
|
# Open safe document
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
# Open safe document
|
|
||||||
self.open_checkbox = QtWidgets.QCheckBox(
|
self.open_checkbox = QtWidgets.QCheckBox(
|
||||||
"Open safe document after converting"
|
"Open safe document after converting"
|
||||||
)
|
)
|
||||||
self.open_checkbox.clicked.connect(self.update_ui)
|
self.open_checkbox.clicked.connect(self.update_ui)
|
||||||
|
|
||||||
elif platform.system() != "Linux":
|
elif platform.system() != "Linux":
|
||||||
# Open safe document
|
|
||||||
self.open_checkbox = QtWidgets.QCheckBox(
|
self.open_checkbox = QtWidgets.QCheckBox(
|
||||||
"Open safe document after converting, using"
|
"Open safe document after converting, using"
|
||||||
)
|
)
|
||||||
|
@ -58,9 +57,12 @@ class SettingsWidget(QtWidgets.QWidget):
|
||||||
self.open_combobox = QtWidgets.QComboBox()
|
self.open_combobox = QtWidgets.QComboBox()
|
||||||
for k in self.gui_common.pdf_viewers:
|
for k in self.gui_common.pdf_viewers:
|
||||||
self.open_combobox.addItem(k, self.gui_common.pdf_viewers[k])
|
self.open_combobox.addItem(k, self.gui_common.pdf_viewers[k])
|
||||||
|
|
||||||
|
if platform.system() == "Darwin" or platform.system() == "Linux":
|
||||||
open_layout = QtWidgets.QHBoxLayout()
|
open_layout = QtWidgets.QHBoxLayout()
|
||||||
open_layout.addWidget(self.open_checkbox)
|
open_layout.addWidget(self.open_checkbox)
|
||||||
open_layout.addWidget(self.open_combobox)
|
if platform.system() == "Linux":
|
||||||
|
open_layout.addWidget(self.open_combobox)
|
||||||
open_layout.addStretch()
|
open_layout.addStretch()
|
||||||
|
|
||||||
# OCR document
|
# OCR document
|
||||||
|
|
|
@ -81,7 +81,7 @@ class Vm(QtCore.QObject):
|
||||||
self.hyperkit_p = subprocess.Popen(
|
self.hyperkit_p = subprocess.Popen(
|
||||||
args,
|
args,
|
||||||
stdout=sys.stdout,
|
stdout=sys.stdout,
|
||||||
stderr=sys.stderr,
|
stderr=subprocess.STDOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
|
|
48
dangerzone/gui/waiting_widget.py
Normal file
48
dangerzone/gui/waiting_widget.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
from PySide2 import QtCore, QtWidgets
|
||||||
|
|
||||||
|
|
||||||
|
class WaitingWidget(QtWidgets.QWidget):
|
||||||
|
vm_started = QtCore.Signal()
|
||||||
|
|
||||||
|
def __init__(self, gui_common, vm):
|
||||||
|
super(WaitingWidget, self).__init__()
|
||||||
|
self.gui_common = gui_common
|
||||||
|
self.vm = vm
|
||||||
|
|
||||||
|
self.vm.vm_state_change.connect(self.vm_state_change)
|
||||||
|
|
||||||
|
self.label = QtWidgets.QLabel(
|
||||||
|
"Waiting for the Dangerzone virtual machine to start..."
|
||||||
|
)
|
||||||
|
self.label.setAlignment(QtCore.Qt.AlignCenter)
|
||||||
|
self.label.setStyleSheet("QLabel { font-size: 20px; }")
|
||||||
|
|
||||||
|
self.details = QtWidgets.QLabel()
|
||||||
|
self.details.setStyleSheet(
|
||||||
|
"QLabel { background-color: #ffffff; font-size: 12px; padding: 10px; }"
|
||||||
|
)
|
||||||
|
self.details.setFont(self.gui_common.fixed_font)
|
||||||
|
self.details.setAlignment(QtCore.Qt.AlignTop)
|
||||||
|
|
||||||
|
self.details_scrollarea = QtWidgets.QScrollArea()
|
||||||
|
self.details_scrollarea.setMinimumHeight(200)
|
||||||
|
self.details_scrollarea.setWidgetResizable(True)
|
||||||
|
self.details_scrollarea.setWidget(self.details)
|
||||||
|
self.details_scrollarea.verticalScrollBar().rangeChanged.connect(
|
||||||
|
self.scroll_to_bottom
|
||||||
|
)
|
||||||
|
|
||||||
|
# Layout
|
||||||
|
layout = QtWidgets.QVBoxLayout()
|
||||||
|
layout.addStretch()
|
||||||
|
layout.addWidget(self.label)
|
||||||
|
layout.addWidget(self.details_scrollarea)
|
||||||
|
layout.addStretch()
|
||||||
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
def vm_state_change(self, state):
|
||||||
|
if state == self.vm.STATE_ON:
|
||||||
|
self.vm_started.emit()
|
||||||
|
|
||||||
|
def scroll_to_bottom(self, minimum, maximum):
|
||||||
|
self.scrollarea.verticalScrollBar().setValue(maximum)
|
Loading…
Reference in a new issue