Force the display checkbox to be selected for at least 1 screen

This commit is contained in:
Raoul Snyman 2019-11-02 07:05:08 +00:00 committed by Tim Bentley
parent 724f33c8ee
commit a019b42636
2 changed files with 62 additions and 0 deletions

View File

@ -25,6 +25,7 @@ from PyQt5 import QtCore, QtWidgets
from openlp.core.common.i18n import translate from openlp.core.common.i18n import translate
from openlp.core.common.settings import ProxyMode, Settings from openlp.core.common.settings import ProxyMode, Settings
from openlp.core.lib.ui import critical_error_message_box
SCREENS_LAYOUT_STYLE = """ SCREENS_LAYOUT_STYLE = """
@ -281,6 +282,8 @@ class ScreenSelectionWidget(QtWidgets.QWidget):
self.layout.addStretch() self.layout.addStretch()
# Signals and slots # 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.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.height_spin_box.setEnabled)
self.custom_geometry_button.toggled.connect(self.left_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.height_label.setText(translate('OpenLP.ScreensTab', 'Height:'))
self.identify_button.setText(translate('OpenLP.ScreensTab', 'Identify Screens')) 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): def _save_screen(self, screen):
""" """
Save the details in the UI to the screen Save the details in the UI to the screen

View File

@ -480,3 +480,48 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
mocked_label.show.assert_called_once() mocked_label.show.assert_called_once()
assert instance.identify_labels == [mocked_label] assert instance.identify_labels == [mocked_label]
instance.timer.start.assert_called_once() 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