mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +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:
|
) -> None:
|
||||||
setup_logging()
|
setup_logging()
|
||||||
global_common = GlobalCommon()
|
global_common = GlobalCommon()
|
||||||
document = Document()
|
|
||||||
|
|
||||||
display_banner()
|
display_banner()
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ def cli_main(
|
||||||
click.echo("Invalid filename")
|
click.echo("Invalid filename")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
document.input_filename = os.path.abspath(filename)
|
document = Document(os.path.abspath(filename))
|
||||||
|
|
||||||
# Validate safe PDF output filename
|
# Validate safe PDF output filename
|
||||||
if output_filename:
|
if output_filename:
|
||||||
|
|
|
@ -14,11 +14,13 @@ class Document:
|
||||||
document, and validating its info.
|
document, and validating its info.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self, input_filename: str = None) -> None:
|
||||||
# Name of input and out files
|
|
||||||
self._input_filename: Optional[str] = None
|
self._input_filename: Optional[str] = None
|
||||||
self._output_filename: Optional[str] = None
|
self._output_filename: Optional[str] = None
|
||||||
|
|
||||||
|
if input_filename:
|
||||||
|
self.input_filename = input_filename
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def input_filename(self) -> str:
|
def input_filename(self) -> str:
|
||||||
if self._input_filename is None:
|
if self._input_filename is None:
|
||||||
|
|
|
@ -10,6 +10,7 @@ import click
|
||||||
import colorama
|
import colorama
|
||||||
from PySide2 import QtCore, QtGui, QtWidgets
|
from PySide2 import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
|
from ..document import Document
|
||||||
from ..global_common import GlobalCommon
|
from ..global_common import GlobalCommon
|
||||||
from .common import GuiCommon
|
from .common import GuiCommon
|
||||||
from .main_window import MainWindow
|
from .main_window import MainWindow
|
||||||
|
@ -86,16 +87,11 @@ def gui_main(filename: Optional[str]) -> bool:
|
||||||
|
|
||||||
# Open a document in a window
|
# Open a document in a window
|
||||||
def select_document(filename: Optional[str] = None) -> bool:
|
def select_document(filename: Optional[str] = None) -> bool:
|
||||||
if (
|
document = Document(filename)
|
||||||
len(windows) == 1
|
window_id = uuid.uuid4().hex
|
||||||
and windows[list(windows.keys())[0]].document.input_filename == None
|
window = MainWindow(global_common, gui_common, window_id)
|
||||||
):
|
window.delete_window.connect(delete_window)
|
||||||
window = windows[list(windows.keys())[0]]
|
windows[window_id] = window
|
||||||
else:
|
|
||||||
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:
|
if filename:
|
||||||
# Validate filename
|
# Validate filename
|
||||||
|
|
|
@ -24,13 +24,17 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
delete_window = QtCore.Signal(str)
|
delete_window = QtCore.Signal(str)
|
||||||
|
|
||||||
def __init__(
|
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:
|
) -> None:
|
||||||
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.window_id = window_id
|
self.window_id = window_id
|
||||||
self.document = Document()
|
self.document = document
|
||||||
|
|
||||||
self.setWindowTitle("Dangerzone")
|
self.setWindowTitle("Dangerzone")
|
||||||
self.setWindowIcon(self.gui_common.get_window_icon())
|
self.setWindowIcon(self.gui_common.get_window_icon())
|
||||||
|
|
Loading…
Reference in a new issue