From e3b65b06acbc36c64c58d189035ad3664094bad1 Mon Sep 17 00:00:00 2001 From: Kenan Muric Date: Wed, 3 Mar 2021 23:28:20 +0100 Subject: [PATCH 1/7] Adding message box when exiting component editor without accepting changes --- nexus_constructor/main_window.py | 35 ++++++++++++++++++++++++++++++-- ui/add_component.py | 4 +++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/nexus_constructor/main_window.py b/nexus_constructor/main_window.py index 4ccc882c4..b753841e9 100644 --- a/nexus_constructor/main_window.py +++ b/nexus_constructor/main_window.py @@ -189,7 +189,7 @@ def _update_3d_view_with_component_shapes(self): self.sceneWidget.add_transformation(component.name, component.qtransform) def show_add_component_window(self, component: Component = None): - self.add_component_window = QDialog() + self.add_component_window = QDialogCustom() self.add_component_window.ui = AddComponentDialog( self.model, self.component_tree_view_tab.component_model, @@ -197,5 +197,36 @@ def show_add_component_window(self, component: Component = None): nx_classes=self.nx_classes, parent=self, ) - self.add_component_window.ui.setupUi(self.add_component_window) + self.add_component_window.ui.setupUi( + self.add_component_window + ) # Make necessary changes here. self.add_component_window.show() + + +class QDialogCustom(QDialog): + def __init__(self): + super().__init__() + self._is_accepting_component = True + + def enable_msg_box(self): + self._is_accepting_component = True + + def disable_msg_box(self): + self._is_accepting_component = False + + def close_without_msgbox(self): + self.disable_msg_box() + self.close() + + def closeEvent(self, event): + if not self._is_accepting_component: + event.accept() + return + quit_msg = "Are you sure you want to exit the component editor?" + reply = QMessageBox.question( + self, "Message", quit_msg, QMessageBox.Yes, QMessageBox.No + ) + if reply == QMessageBox.Yes: + event.accept() + else: + event.ignore() diff --git a/ui/add_component.py b/ui/add_component.py index 9941ec14e..eb6894357 100644 --- a/ui/add_component.py +++ b/ui/add_component.py @@ -230,7 +230,9 @@ def setupUi(self, AddComponentDialog): self.retranslateUi(AddComponentDialog) QtCore.QObject.connect( - self.ok_button, QtCore.SIGNAL("clicked()"), AddComponentDialog.close + self.ok_button, + QtCore.SIGNAL("clicked()"), + AddComponentDialog.close_without_msgbox, ) QtCore.QMetaObject.connectSlotsByName(AddComponentDialog) From ee19f37e706de13ed4d29910a42a832f4dd4745c Mon Sep 17 00:00:00 2001 From: Kenan Muric Date: Wed, 3 Mar 2021 23:30:32 +0100 Subject: [PATCH 2/7] Removing junk comment --- nexus_constructor/main_window.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nexus_constructor/main_window.py b/nexus_constructor/main_window.py index b753841e9..b2b1782b8 100644 --- a/nexus_constructor/main_window.py +++ b/nexus_constructor/main_window.py @@ -197,9 +197,7 @@ def show_add_component_window(self, component: Component = None): nx_classes=self.nx_classes, parent=self, ) - self.add_component_window.ui.setupUi( - self.add_component_window - ) # Make necessary changes here. + self.add_component_window.ui.setupUi(self.add_component_window) self.add_component_window.show() From ba14e3ac30d282524d5016d1518af6eb455a3f35 Mon Sep 17 00:00:00 2001 From: Kenan Muric Date: Wed, 3 Mar 2021 23:38:35 +0100 Subject: [PATCH 3/7] Adding some minor documentation of QDialogCustom class --- nexus_constructor/main_window.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nexus_constructor/main_window.py b/nexus_constructor/main_window.py index b2b1782b8..fabb822ec 100644 --- a/nexus_constructor/main_window.py +++ b/nexus_constructor/main_window.py @@ -202,6 +202,12 @@ def show_add_component_window(self, component: Component = None): class QDialogCustom(QDialog): + """ + Custom QDialog class that enables the possibility to properly produce + a message box in the component editor to the users, + asking if they are sure to quit editing component when exiting. + """ + def __init__(self): super().__init__() self._is_accepting_component = True @@ -213,6 +219,9 @@ def disable_msg_box(self): self._is_accepting_component = False def close_without_msgbox(self): + """ + Close widget without producing the message box in closeEvent method. + """ self.disable_msg_box() self.close() From 342a01c0863a81b263d24ac123d99153183106cb Mon Sep 17 00:00:00 2001 From: Kenan Muric Date: Thu, 4 Mar 2021 16:12:01 +0100 Subject: [PATCH 4/7] Fixing some unit tests for the user interface that broke due to the updates in component editor --- tests/conftest.py | 6 ++++-- tests/ui_tests/test_ui_add_component_window.py | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f3d233c59..b249e2a5a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ from unittest.mock import Mock import pytest -from PySide2.QtWidgets import QDialog +from nexus_constructor.main_window import QDialogCustom as QDialog from nexus_constructor.model.instrument import Instrument from nexus_constructor.model.model import Model @@ -11,7 +11,9 @@ @pytest.fixture(scope="function") def template(qtbot) -> QDialog: - return QDialog() + q_dialog = QDialog() + q_dialog.disable_msg_box() + return q_dialog @pytest.fixture(scope="function") diff --git a/tests/ui_tests/test_ui_add_component_window.py b/tests/ui_tests/test_ui_add_component_window.py index 33a83799f..4c9bebffb 100644 --- a/tests/ui_tests/test_ui_add_component_window.py +++ b/tests/ui_tests/test_ui_add_component_window.py @@ -6,7 +6,7 @@ import pytestqt from PySide2.QtCore import Qt from PySide2.QtGui import QVector3D -from PySide2.QtWidgets import QDialog, QRadioButton, QMainWindow +from PySide2.QtWidgets import QRadioButton, QMainWindow from mock import Mock, call, patch, mock_open from pytestqt.qtbot import QtBot import numpy as np @@ -25,7 +25,10 @@ from nexus_constructor.model.instrument import Instrument from nexus_constructor.model.model import Model from nexus_constructor.instrument_view.instrument_view import InstrumentView -from nexus_constructor.main_window import MainWindow +from nexus_constructor.main_window import ( + MainWindow, + QDialogCustom as QDialog, +) from nexus_constructor.model.link import Link from nexus_constructor.model.stream import StreamGroup, F142Stream from nexus_constructor.geometry.pixel_data import PixelGrid, PixelMapping, PixelData From a7aa46e3e7859860ab3e49a902aa4992727c76e6 Mon Sep 17 00:00:00 2001 From: Kenan Muric Date: Fri, 5 Mar 2021 08:56:57 +0100 Subject: [PATCH 5/7] Updating test files --- tests/conftest.py | 2 +- tests/ui_tests/test_ui_add_component_window.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b249e2a5a..179da9b8c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,7 @@ from unittest.mock import Mock import pytest -from nexus_constructor.main_window import QDialogCustom as QDialog +from nexus_constructor.main_window import QDialogCustom as QDialog from nexus_constructor.model.instrument import Instrument from nexus_constructor.model.model import Model from nexus_constructor.pixel_options import PixelOptions diff --git a/tests/ui_tests/test_ui_add_component_window.py b/tests/ui_tests/test_ui_add_component_window.py index 4c9bebffb..03fb7d97e 100644 --- a/tests/ui_tests/test_ui_add_component_window.py +++ b/tests/ui_tests/test_ui_add_component_window.py @@ -197,7 +197,7 @@ def mock_component(): def enter_component_name( qtbot: pytestqt.qtbot.QtBot, - template: PySide2.QtWidgets.QDialog, + template: QDialog, dialog: AddComponentDialog, component_name: str, ): @@ -243,7 +243,7 @@ def get_shape_type_button(dialog: AddComponentDialog, button_name: str): def make_pixel_options_disappear( qtbot: pytestqt.qtbot.QtBot, dialog: AddComponentDialog, - template: PySide2.QtWidgets.QDialog, + template: QDialog, component_index: int, ): """ @@ -262,7 +262,7 @@ def make_pixel_options_appear( qtbot: pytestqt.qtbot.QtBot, button: QRadioButton, dialog: AddComponentDialog, - template: PySide2.QtWidgets.QDialog, + template: QDialog, pixel_options_index: int = PIXEL_OPTIONS["NXdetector"], ): """ @@ -298,7 +298,7 @@ def enter_units(qtbot: pytestqt.qtbot.QtBot, dialog: AddComponentDialog, units: def enter_file_path( qtbot: pytestqt.qtbot.QtBot, dialog: AddComponentDialog, - template: PySide2.QtWidgets.QDialog, + template: QDialog, file_path: str, file_contents: str, ): @@ -321,7 +321,7 @@ def enter_file_path( def enter_disk_chopper_fields( qtbot: pytestqt.qtbot.QtBot, dialog: AddComponentDialog, - template: PySide2.QtWidgets.QDialog, + template: QDialog, component_name: str = "ThisIsADiskChopper", ): """ From b22a009ad49f1a57d80b039089fe94f703fea548 Mon Sep 17 00:00:00 2001 From: Kenan Muric Date: Mon, 8 Mar 2021 20:45:38 +0100 Subject: [PATCH 6/7] Updating Jenkins file to fix broken test impoorts --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6f3588834..280433cf7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,9 +17,10 @@ properties([ ]) container_build_nodes = [ - 'centos7': ContainerBuildNode.getDefaultContainerBuildNode('centos7') + 'centos7': ContainerBuildNode.getDefaultContainerBuildNode('centos7-gcc8') ] + pipeline_builder = new PipelineBuilder(this, container_build_nodes) builders = pipeline_builder.createBuilders { container -> From c6710e2f7d874028977af2e39fa6bdd1d763bff7 Mon Sep 17 00:00:00 2001 From: Kenan Muric Date: Fri, 12 Mar 2021 13:37:13 +0100 Subject: [PATCH 7/7] Removing uneccesary function in QDialogCustom class and adding docstring to closeEvent --- nexus_constructor/main_window.py | 10 ++++++---- ui/add_component.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/nexus_constructor/main_window.py b/nexus_constructor/main_window.py index 8baccb542..ceeeeb3a8 100644 --- a/nexus_constructor/main_window.py +++ b/nexus_constructor/main_window.py @@ -211,13 +211,10 @@ def __init__(self): super().__init__() self._is_accepting_component = True - def enable_msg_box(self): - self._is_accepting_component = True - def disable_msg_box(self): self._is_accepting_component = False - def close_without_msgbox(self): + def close_without_msg_box(self): """ Close widget without producing the message box in closeEvent method. """ @@ -225,6 +222,11 @@ def close_without_msgbox(self): self.close() def closeEvent(self, event): + """ + Overriding closeEvent function in the superclass to produce a message box prompting + the user to exit the add/edit component window. This message box pops up + when the user exits by pressing the window close (X) button. + """ if not self._is_accepting_component: event.accept() return diff --git a/ui/add_component.py b/ui/add_component.py index eb6894357..d9947e981 100644 --- a/ui/add_component.py +++ b/ui/add_component.py @@ -232,7 +232,7 @@ def setupUi(self, AddComponentDialog): QtCore.QObject.connect( self.ok_button, QtCore.SIGNAL("clicked()"), - AddComponentDialog.close_without_msgbox, + AddComponentDialog.close_without_msg_box, ) QtCore.QMetaObject.connectSlotsByName(AddComponentDialog)