Merge branch 'fix-cornercase-screens' into 'master'

Fix a bug in the screens code

See merge request openlp/openlp!273
This commit is contained in:
Tim Bentley 2020-12-03 08:11:46 +00:00
commit a4911076ba
2 changed files with 21 additions and 1 deletions

View File

@ -406,5 +406,5 @@ class ScreenList(metaclass=Singleton):
The primary screen has changed, let's sort it out and then notify everyone The primary screen has changed, let's sort it out and then notify everyone
""" """
for screen in self.screens: for screen in self.screens:
screen.is_primary = self.desktop.primaryScreen().geometry() == screen.geometry screen.is_primary = self.application.primaryScreen().geometry() == screen.geometry
Registry().execute('config_screen_changed') Registry().execute('config_screen_changed')

View File

@ -93,6 +93,26 @@ def test_create_screen_list(mocked_screens, settings):
assert screen_list.screens[1].is_primary is False assert screen_list.screens[1].is_primary is False
@patch('openlp.core.display.screens.QtWidgets.QApplication.screens')
def test_screen_list_on_primary_changed(mocked_screens, settings, registry):
"""Test that the screen is correctly updated when a primary screen is changed"""
# GIVEN: Mocked application
mocked_application = MagicMock()
mocked_screen1 = MagicMock(**{'geometry.return_value': QtCore.QRect(0, 0, 1024, 768)})
mocked_screen2 = MagicMock(**{'geometry.return_value': QtCore.QRect(1024, 0, 1024, 768)})
mocked_application.screens.return_value = [mocked_screen1, mocked_screen2]
mocked_application.primaryScreen.return_value = mocked_screen1
screen_list = ScreenList.create(mocked_application)
# WHEN: on_primary_screen_changed() is called
mocked_application.primaryScreen.return_value = mocked_screen2
screen_list.on_primary_screen_changed()
# THEN: The primary screen should have changed
assert screen_list.screens[0].is_primary is False
assert screen_list.screens[1].is_primary is True
def test_screen_from_dict(): def test_screen_from_dict():
"""Test that all the correct attributes are set when creating a screen from a dictionary""" """Test that all the correct attributes are set when creating a screen from a dictionary"""
# GIVEN: A dictionary of values # GIVEN: A dictionary of values