diff --git a/openlp/core/widgets/widgets.py b/openlp/core/widgets/widgets.py index 7e3811eec..acb280aae 100644 --- a/openlp/core/widgets/widgets.py +++ b/openlp/core/widgets/widgets.py @@ -25,6 +25,7 @@ from PyQt5 import QtCore, QtWidgets from openlp.core.common.i18n import translate from openlp.core.common.settings import ProxyMode, Settings +from openlp.core.lib.ui import critical_error_message_box SCREENS_LAYOUT_STYLE = """ @@ -281,6 +282,8 @@ class ScreenSelectionWidget(QtWidgets.QWidget): self.layout.addStretch() # Signals and slots + self.display_group_box.clicked.connect(self.on_display_clicked) + self.use_screen_check_box.clicked.connect(self.on_display_clicked) self.use_screen_check_box.toggled.connect(self.display_group_box.setChecked) self.custom_geometry_button.toggled.connect(self.height_spin_box.setEnabled) self.custom_geometry_button.toggled.connect(self.left_spin_box.setEnabled) @@ -306,6 +309,20 @@ class ScreenSelectionWidget(QtWidgets.QWidget): self.height_label.setText(translate('OpenLP.ScreensTab', 'Height:')) self.identify_button.setText(translate('OpenLP.ScreensTab', 'Identify Screens')) + def on_display_clicked(self, is_checked): + if not is_checked: + critical_error_message_box(translate('OpenLP.ScreensTab', 'Select a Display'), + translate('OpenLP.ScreensTab', 'You need to select at least one screen to be ' + 'used as a display. Select the screen you wish to use as a display, ' + 'and check the checkbox for that screen.'), + parent=self, question=False) + self.use_screen_check_box.setChecked(True) + self.display_group_box.setChecked(True) + else: + for screen in self.screens: + screen.is_display = False + self.current_screen.is_display = True + def _save_screen(self, screen): """ Save the details in the UI to the screen diff --git a/tests/openlp_core/widgets/test_widgets.py b/tests/openlp_core/widgets/test_widgets.py index bbe52a2ac..5754e4346 100644 --- a/tests/openlp_core/widgets/test_widgets.py +++ b/tests/openlp_core/widgets/test_widgets.py @@ -480,3 +480,48 @@ class TestScreenSelectionWidget(TestCase, TestMixin): mocked_label.show.assert_called_once() assert instance.identify_labels == [mocked_label] instance.timer.start.assert_called_once() + + def test_on_display_clicked_with_checked(self): + """ + Test that the on_display_clicked() sets the first screen as display when the checkbx is checked + """ + # GIVEN: A ScreenSelectionWidget and a bunch o' mocks + instance = ScreenSelectionWidget() + mocked_screen_1 = MagicMock() + mocked_screen_2 = MagicMock() + mocked_screen_2.is_display = True + instance.screens = [mocked_screen_1, mocked_screen_2] + instance.current_screen = mocked_screen_1 + + # WHEN: on_display_clicked() is called when the checkbox is checked + instance.on_display_clicked(True) + + # THEN: The first screen should be marked as a display + assert mocked_screen_1.is_display is True + assert mocked_screen_2.is_display is False + + def test_on_display_clicked_with_unchecked(self): + """ + Test that the on_display_clicked() disallows the checkbox to be unchecked + """ + # GIVEN: A ScreenSelectionWidget and a bunch o' mocks + instance = ScreenSelectionWidget() + mocked_screen_1 = MagicMock() + mocked_screen_2 = MagicMock() + mocked_screen_2.is_display = True + instance.screens = [mocked_screen_1, mocked_screen_2] + instance.current_screen = mocked_screen_2 + + # WHEN: on_display_clicked() is called when the checkbox is checked + with patch('openlp.core.widgets.widgets.translate') as mocked_translate, \ + patch('openlp.core.widgets.widgets.critical_error_message_box') as mocked_error: + mocked_translate.side_effect = lambda c, s: s + instance.on_display_clicked(False) + + # THEN: The first screen should be marked as a display + mocked_error.assert_called_once_with('Select a Display', + 'You need to select at least one screen to be used as a display. ' + 'Select the screen you wish to use as a display, and check the ' + 'checkbox for that screen.', parent=instance, question=False) + assert instance.use_screen_check_box.isChecked() is True + assert instance.display_group_box.isChecked() is True