Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #848 from ess-dmsc/717_component_edit_add_confirm_…
Browse files Browse the repository at this point in the history
…window

717 component edit add confirm window
  • Loading branch information
kmurica authored Mar 12, 2021
2 parents 48147d5 + c6710e2 commit 6c76cfc
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
42 changes: 41 additions & 1 deletion nexus_constructor/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,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,
Expand All @@ -194,3 +194,43 @@ def show_add_component_window(self, component: Component = None):
)
self.add_component_window.ui.setupUi(self.add_component_window)
self.add_component_window.show()


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

def disable_msg_box(self):
self._is_accepting_component = False

def close_without_msg_box(self):
"""
Close widget without producing the message box in closeEvent method.
"""
self.disable_msg_box()
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
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()
6 changes: 4 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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
from nexus_constructor.pixel_options import PixelOptions
Expand All @@ -12,7 +12,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")
Expand Down
15 changes: 8 additions & 7 deletions tests/ui_tests/test_ui_add_component_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from mock import Mock, call, mock_open, patch
from PySide2.QtCore import Qt
from PySide2.QtGui import QVector3D
from PySide2.QtWidgets import QDialog, QMainWindow, QRadioButton
from PySide2.QtWidgets import QMainWindow, QRadioButton
from pytestqt.qtbot import QtBot

from nexus_constructor import component_type
Expand All @@ -19,6 +19,7 @@
from nexus_constructor.geometry.pixel_data_utils import PIXEL_FIELDS
from nexus_constructor.instrument_view.instrument_view import InstrumentView
from nexus_constructor.main_window import MainWindow
from nexus_constructor.main_window import QDialogCustom as QDialog
from nexus_constructor.model.component import Component
from nexus_constructor.model.entry import Entry
from nexus_constructor.model.geometry import (
Expand Down Expand Up @@ -86,7 +87,7 @@
else:
NO_PIXEL_OPTIONS[component_class] = i

# Select a subset of the component class to use in parameterised tests
# Select a subset of the component class to use in parameterised tests.
# Should include any for which the UI is specialised
_components_subset = {"NXdetector", "NXdisk_chopper", "NXsensor"}
COMPONENT_TYPES_SUBSET = {
Expand Down Expand Up @@ -193,7 +194,7 @@ def mock_component():

def enter_component_name(
qtbot: pytestqt.qtbot.QtBot,
template: PySide2.QtWidgets.QDialog,
template: QDialog,
dialog: AddComponentDialog,
component_name: str,
):
Expand Down Expand Up @@ -239,7 +240,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,
):
"""
Expand All @@ -258,7 +259,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"],
):
"""
Expand Down Expand Up @@ -294,7 +295,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,
):
Expand All @@ -317,7 +318,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",
):
"""
Expand Down
4 changes: 3 additions & 1 deletion ui/add_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_msg_box,
)
QtCore.QMetaObject.connectSlotsByName(AddComponentDialog)

Expand Down

0 comments on commit 6c76cfc

Please sign in to comment.