mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
Instantiate documents with a filename
Avoid setting document's filename via document.filename and instead do it via object instantiation where possible. Incidentally this has to change some window logic. When select_document() is called it no longer checks if there is already an open window with no document selected yet. The user can open as many windows with unselected documents as they want.
This commit is contained in:
parent
0493aca036
commit
e487b7f0a9
4 changed files with 17 additions and 16 deletions
|
@ -28,7 +28,6 @@ def cli_main(
|
|||
) -> None:
|
||||
setup_logging()
|
||||
global_common = GlobalCommon()
|
||||
document = Document()
|
||||
|
||||
display_banner()
|
||||
|
||||
|
@ -44,7 +43,7 @@ def cli_main(
|
|||
click.echo("Invalid filename")
|
||||
exit(1)
|
||||
|
||||
document.input_filename = os.path.abspath(filename)
|
||||
document = Document(os.path.abspath(filename))
|
||||
|
||||
# Validate safe PDF output filename
|
||||
if output_filename:
|
||||
|
|
|
@ -14,11 +14,13 @@ class Document:
|
|||
document, and validating its info.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
# Name of input and out files
|
||||
def __init__(self, input_filename: str = None) -> None:
|
||||
self._input_filename: Optional[str] = None
|
||||
self._output_filename: Optional[str] = None
|
||||
|
||||
if input_filename:
|
||||
self.input_filename = input_filename
|
||||
|
||||
@property
|
||||
def input_filename(self) -> str:
|
||||
if self._input_filename is None:
|
||||
|
|
|
@ -10,6 +10,7 @@ import click
|
|||
import colorama
|
||||
from PySide2 import QtCore, QtGui, QtWidgets
|
||||
|
||||
from ..document import Document
|
||||
from ..global_common import GlobalCommon
|
||||
from .common import GuiCommon
|
||||
from .main_window import MainWindow
|
||||
|
@ -86,16 +87,11 @@ def gui_main(filename: Optional[str]) -> bool:
|
|||
|
||||
# Open a document in a window
|
||||
def select_document(filename: Optional[str] = None) -> bool:
|
||||
if (
|
||||
len(windows) == 1
|
||||
and windows[list(windows.keys())[0]].document.input_filename == None
|
||||
):
|
||||
window = windows[list(windows.keys())[0]]
|
||||
else:
|
||||
window_id = uuid.uuid4().hex
|
||||
window = MainWindow(global_common, gui_common, window_id)
|
||||
window.delete_window.connect(delete_window)
|
||||
windows[window_id] = window
|
||||
document = Document(filename)
|
||||
window_id = uuid.uuid4().hex
|
||||
window = MainWindow(global_common, gui_common, window_id)
|
||||
window.delete_window.connect(delete_window)
|
||||
windows[window_id] = window
|
||||
|
||||
if filename:
|
||||
# Validate filename
|
||||
|
|
|
@ -24,13 +24,17 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||
delete_window = QtCore.Signal(str)
|
||||
|
||||
def __init__(
|
||||
self, global_common: GlobalCommon, gui_common: GuiCommon, window_id: str
|
||||
self,
|
||||
global_common: GlobalCommon,
|
||||
gui_common: GuiCommon,
|
||||
window_id: str,
|
||||
document: Document,
|
||||
) -> None:
|
||||
super(MainWindow, self).__init__()
|
||||
self.global_common = global_common
|
||||
self.gui_common = gui_common
|
||||
self.window_id = window_id
|
||||
self.document = Document()
|
||||
self.document = document
|
||||
|
||||
self.setWindowTitle("Dangerzone")
|
||||
self.setWindowIcon(self.gui_common.get_window_icon())
|
||||
|
|
Loading…
Reference in a new issue