diff --git a/finalcif/appwindow.py b/finalcif/appwindow.py index 17995f08..d49922ae 100644 --- a/finalcif/appwindow.py +++ b/finalcif/appwindow.py @@ -100,7 +100,7 @@ def __init__(self, file: Optional[Path] = None): self.options = Options(self.ui, self.settings) self.deposit = CODdeposit(self.ui, self.cif, self.options) self.equipment = Equipment(app=self, settings=self.settings) - self.properties = Properties(app=self, settings=self.settings) + self.properties = Properties(parent=self, settings=self.settings) self.status_bar = StatusBar(ui=self.ui) self.status_bar.show_message('FinalCif version {}'.format(VERSION)) self.authors: Optional[AuthorLoops] = None @@ -114,9 +114,7 @@ def __init__(self, file: Optional[Path] = None): self.ui.TemplatesStackedWidget.setCurrentIndex(0) self.ui.MainStackedWidget.got_to_main_page() self.set_initial_button_states() - if len(sys.argv) > 1 and not file: - self.load_cif_file(Path(sys.argv[1])) - elif file: + if file: self.load_cif_file(file) self.load_recent_cifs_list() self.set_checkcif_output_font(self.ui.CheckcifPlaintextEdit) diff --git a/finalcif/equip_property/properties.py b/finalcif/equip_property/properties.py index ed2b7e08..429c07d7 100644 --- a/finalcif/equip_property/properties.py +++ b/finalcif/equip_property/properties.py @@ -17,11 +17,12 @@ from finalcif.appwindow import AppWindow -class Properties: - def __init__(self, app: 'AppWindow', settings: FinalCifSettings): - self.app = app +class Properties(QtCore.QObject): + def __init__(self, parent: 'AppWindow', settings: FinalCifSettings): + super().__init__(parent=parent) + self.app = parent self.settings = settings - if app: + if parent: self.signals_and_slots() self.app.ui.PropertiesTemplatesStackedWidget.setCurrentIndex(0) self.app.ui.PropertiesEditTableWidget.verticalHeader().hide() @@ -181,7 +182,7 @@ def export_property_template(self, filename: str = '') -> None: return show_general_warning('No permission to write file to {}'.format(Path(filename).resolve())) - def selected_template_name(self) -> None: + def selected_template_name(self) -> str: return self.app.ui.PropertiesTemplatesListWidget.currentIndex().data() def import_property_from_file(self, filename: str = '') -> None: diff --git a/finalcif/finalcif_start.py b/finalcif/finalcif_start.py index b8e3cce4..e2ea1a31 100644 --- a/finalcif/finalcif_start.py +++ b/finalcif/finalcif_start.py @@ -52,7 +52,10 @@ def main(): sys.excepthook = my_exception_hook # windows_style = QStyleFactory.create('Fusion') # app.setStyle(windows_style) - w = AppWindow() + file = None + if len(sys.argv) > 1 and Path(sys.argv[1]).is_file(): + file = Path(sys.argv[1]) + w = AppWindow(file=file) app.setWindowIcon(QIcon(os.path.join(application_path, r'icon/finalcif2.png'))) w.setWindowTitle('FinalCif v{}'.format(VERSION)) # w.showMaximized() # For full screen view diff --git a/finalcif/tools/platon.py b/finalcif/tools/platon.py index f57f3856..d6e89aaf 100644 --- a/finalcif/tools/platon.py +++ b/finalcif/tools/platon.py @@ -1,7 +1,6 @@ import os import subprocess import sys -import threading import time from contextlib import suppress from pathlib import Path @@ -35,7 +34,7 @@ def run_process(self): self.Z = '' self.process = QtCore.QProcess() self.output_widget.clear() - threading.Thread(target=self._monitor_output_log).start() + QtCore.QTimer(self).singleShot(100, self._monitor_output_log) # self.process.readyReadStandardOutput.connect(self.on_ready_read) self.process.finished.connect(self._onfinished) self.process.setWorkingDirectory(str(self.cif_file.parent)) diff --git a/tests/test_template_edit.py b/tests/test_template_edit.py index 40e1ed56..5c1f7fe3 100644 --- a/tests/test_template_edit.py +++ b/tests/test_template_edit.py @@ -1,4 +1,5 @@ import unittest +from pathlib import Path from PyQt5.QtCore import Qt from PyQt5.QtTest import QTest @@ -8,7 +9,7 @@ class EquipmentTestCase(unittest.TestCase): def setUp(self) -> None: - self.app = AppWindow() + self.app = AppWindow(Path('test-data/1000006.cif')) self.app.equipment.import_equipment_from_file('test-data/Crystallographer_Details.cif') self.app.hide() @@ -38,7 +39,7 @@ def test_template_edit_click(self): class PropertiesTestCase(unittest.TestCase): def setUp(self) -> None: - self.app = AppWindow() + self.app = AppWindow(Path('test-data/1000006.cif')) self.app.hide() def property_edit_click(self, field: str): diff --git a/tests/test_templated_report.py b/tests/test_templated_report.py index 85f30ef3..c5731bca 100644 --- a/tests/test_templated_report.py +++ b/tests/test_templated_report.py @@ -8,16 +8,15 @@ from docx.table import Table from finalcif import VERSION -from finalcif.appwindow import AppWindow +from finalcif.appwindow import AppWindow, app from finalcif.cif.cif_file_io import CifContainer from finalcif.report.templated_report import TemplatedReport class TemplateReportTestCase(unittest.TestCase): def setUp(self) -> None: - self.myapp = AppWindow() self.testcif = Path('tests/examples/1979688.cif').absolute() - self.myapp.load_cif_file(self.testcif.resolve()) + self.myapp = AppWindow(file=self.testcif) self.myapp.ui.HAtomsCheckBox.setChecked(False) self.myapp.ui.ReportTextCheckBox.setChecked(False) self.myapp.ui.PictureWidthDoubleSpinBox.setValue(7.43) @@ -26,7 +25,6 @@ def setUp(self) -> None: self.reportdoc = self.myapp.cif.finalcif_file_prefixed(prefix='report_', suffix='-finalcif.docx') self.report_zip = self.myapp.cif.finalcif_file_prefixed(prefix='', suffix='-finalcif.zip') self.myapp.select_report_picture(Path('finalcif/icon/finalcif.png')) - self.myapp.hide() def tearDown(self) -> None: self.myapp.cif.finalcif_file.unlink(missing_ok=True) @@ -40,6 +38,8 @@ def tearDown(self) -> None: self.myapp.ui.docxTemplatesListWidget.setCurrentRow(num) self.myapp.templates.remove_current_template() self.myapp.ui.docxTemplatesListWidget.blockSignals(False) + self.myapp.close() + app.quit() def import_templates(self): # blocking signals, because signal gets fired after delete and crashes: