From 236dba77e8757baec5d3886691aaf58d0811029a Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Thu, 21 May 2015 23:15:15 -0400 Subject: [PATCH 1/5] Fix bug 1395848 by setting the WindowStaysOnTop window flag when the MainDisplay is not on the primary screen. --- openlp/core/ui/maindisplay.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 68d5d6d3d..9c0593d5d 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -164,6 +164,8 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties): # and menu bar if self.screens.current['primary']: self.setWindowState(QtCore.Qt.WindowFullScreen) + else: + window_flags |= QtCore.Qt.WindowStaysOnTopHint self.setWindowFlags(window_flags) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.set_transparency(False) From a880d152ec4ea3795e965bd542a2a43c1ffefff7 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Mon, 25 May 2015 17:41:18 -0400 Subject: [PATCH 2/5] Add tests for window flags change --- .../openlp_core_ui/test_maindisplay.py | 91 ++++++++++++++++--- 1 file changed, 77 insertions(+), 14 deletions(-) diff --git a/tests/functional/openlp_core_ui/test_maindisplay.py b/tests/functional/openlp_core_ui/test_maindisplay.py index 049bb874f..3a4f6059b 100644 --- a/tests/functional/openlp_core_ui/test_maindisplay.py +++ b/tests/functional/openlp_core_ui/test_maindisplay.py @@ -34,13 +34,6 @@ from openlp.core.ui.maindisplay import TRANSPARENT_STYLESHEET, OPAQUE_STYLESHEET from tests.helpers.testmixin import TestMixin from tests.functional import MagicMock, patch -SCREEN = { - 'primary': False, - 'number': 1, - 'size': QtCore.QRect(0, 0, 1024, 768) -} - - class TestMainDisplay(TestCase, TestMixin): def setUp(self): @@ -49,9 +42,10 @@ class TestMainDisplay(TestCase, TestMixin): """ # Mocked out desktop object self.desktop = MagicMock() - self.desktop.primaryScreen.return_value = SCREEN['primary'] - self.desktop.screenCount.return_value = SCREEN['number'] - self.desktop.screenGeometry.return_value = SCREEN['size'] + self.desktop.primaryScreen.return_value = 0 + self.desktop.screenCount.return_value = 2 + self.desktop.screenGeometry.side_effect = lambda x: {0: QtCore.QRect(0, 0, 1024, 768), + 1: QtCore.QRect(0, 0, 1024, 768)}[x] self.screens = ScreenList.create(self.desktop) Registry.create() self.registry = Registry() @@ -69,16 +63,16 @@ class TestMainDisplay(TestCase, TestMixin): def initial_main_display_test(self): """ - Test the initial Main Display state . + Test the initial Main Display state """ - # GIVEN: A new slideController instance. + # GIVEN: A new SlideController instance. display = MagicMock() display.is_live = True - # WHEN: the default controller is built. + # WHEN: The default controller is built. main_display = MainDisplay(display) - # THEN: The controller should not be a live controller. + # THEN: The controller should be a live controller. self.assertEqual(main_display.is_live, True, 'The main display should be a live controller') def set_transparency_enabled_test(self): @@ -138,3 +132,72 @@ class TestMainDisplay(TestCase, TestMixin): # THEN: The plugins should have each been given an opportunity to add their bit to the CSS mocked_songs_plugin.refresh_css.assert_called_with(main_display.frame) mocked_bibles_plugin.refresh_css.assert_called_with(main_display.frame) + + @patch('openlp.core.is_macosx') + def macosx_non_primary_screen_window_flags_test(self, mocked_is_macosx): + """ + Test that on Mac OS X when the current screen isn't primary we use the WindowStaysOnTop window flag + """ + # GIVEN: A new SlideController instance on Mac OS X with the current display not being primary. + mocked_is_macosx.return_value = True + self.screens.set_current_display(1) + display = MagicMock() + + # WHEN: The default controller is built. + main_display = MainDisplay(display) + + # THEN: The window flags should be the same as those needed on Mac OS X for the non primary display. + self.assertEqual(QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint, + main_display.windowFlags(), + 'The window flags should be Qt.WindowStaysOnTop, Qt.Window, and Qt.FramelessWindowHint.') + + @patch('openlp.core.is_macosx') + def macosx_primary_screen_window_flags_test(self, mocked_is_macosx): + """ + Test that on Mac OS X when the current screen is primary we don't use the WindowStaysOnTop window flag + """ + # GIVEN: A new SlideController instance on Mac OS X with the current display being primary. + mocked_is_macosx.return_value = True + self.screens.set_current_display(0) + display = MagicMock() + + # WHEN: The default controller is built. + main_display = MainDisplay(display) + + # THEN: The window flags should be the same as those needed on Mac OS X for the primary display. + self.assertEqual(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint, main_display.windowFlags(), + 'The window flags should be Qt.Window and Qt.FramelessWindowHint.') + + @patch('openlp.core.is_macosx') + def macosx_non_primary_screen_window_state_test(self, mocked_is_macosx): + """ + Test that on Mac OS X when the current screen isn't primary we don't set the window state to full screen + """ + # GIVEN: A new SlideController instance on Mac OS X with the current display not being primary. + mocked_is_macosx.return_value = True + self.screens.set_current_display(1) + display = MagicMock() + + # WHEN: The default controller is built. + main_display = MainDisplay(display) + + # THEN: The window state should not be full screen. + self.assertNotEqual(QtCore.Qt.WindowFullScreen, main_display.windowState(), + 'The window state should not be full screen.') + + @patch('openlp.core.is_macosx') + def macosx_primary_screen_window_state_test(self, mocked_is_macosx): + """ + Test that on Mac OS X when the current screen is primary we set the window state to full screen + """ + # GIVEN: A new SlideController instance on Mac OS X with the current display being primary. + mocked_is_macosx.return_value = True + self.screens.set_current_display(0) + display = MagicMock() + + # WHEN: The default controller is built. + main_display = MainDisplay(display) + + # THEN: The window state should be full screen. + self.assertEqual(QtCore.Qt.WindowFullScreen, main_display.windowState(), + 'The window state should be full screen.') From 0a8d1906ce231cc33cb2a83f7672fbef37dee5bf Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Tue, 26 May 2015 00:27:43 -0400 Subject: [PATCH 3/5] Fix patch in tests --- .../openlp_core_ui/test_maindisplay.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/functional/openlp_core_ui/test_maindisplay.py b/tests/functional/openlp_core_ui/test_maindisplay.py index 3a4f6059b..7e9feff48 100644 --- a/tests/functional/openlp_core_ui/test_maindisplay.py +++ b/tests/functional/openlp_core_ui/test_maindisplay.py @@ -133,13 +133,13 @@ class TestMainDisplay(TestCase, TestMixin): mocked_songs_plugin.refresh_css.assert_called_with(main_display.frame) mocked_bibles_plugin.refresh_css.assert_called_with(main_display.frame) - @patch('openlp.core.is_macosx') - def macosx_non_primary_screen_window_flags_test(self, mocked_is_macosx): + @patch('openlp.core.ui.maindisplay.is_macosx') + def macosx_non_primary_screen_window_flags_test(self, is_macosx): """ Test that on Mac OS X when the current screen isn't primary we use the WindowStaysOnTop window flag """ # GIVEN: A new SlideController instance on Mac OS X with the current display not being primary. - mocked_is_macosx.return_value = True + is_macosx.return_value = True self.screens.set_current_display(1) display = MagicMock() @@ -151,13 +151,13 @@ class TestMainDisplay(TestCase, TestMixin): main_display.windowFlags(), 'The window flags should be Qt.WindowStaysOnTop, Qt.Window, and Qt.FramelessWindowHint.') - @patch('openlp.core.is_macosx') - def macosx_primary_screen_window_flags_test(self, mocked_is_macosx): + @patch('openlp.core.ui.maindisplay.is_macosx') + def macosx_primary_screen_window_flags_test(self, is_macosx): """ Test that on Mac OS X when the current screen is primary we don't use the WindowStaysOnTop window flag """ # GIVEN: A new SlideController instance on Mac OS X with the current display being primary. - mocked_is_macosx.return_value = True + is_macosx.return_value = True self.screens.set_current_display(0) display = MagicMock() @@ -168,13 +168,13 @@ class TestMainDisplay(TestCase, TestMixin): self.assertEqual(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint, main_display.windowFlags(), 'The window flags should be Qt.Window and Qt.FramelessWindowHint.') - @patch('openlp.core.is_macosx') - def macosx_non_primary_screen_window_state_test(self, mocked_is_macosx): + @patch('openlp.core.ui.maindisplay.is_macosx') + def macosx_non_primary_screen_window_state_test(self, is_macosx): """ Test that on Mac OS X when the current screen isn't primary we don't set the window state to full screen """ # GIVEN: A new SlideController instance on Mac OS X with the current display not being primary. - mocked_is_macosx.return_value = True + is_macosx.return_value = True self.screens.set_current_display(1) display = MagicMock() @@ -185,13 +185,13 @@ class TestMainDisplay(TestCase, TestMixin): self.assertNotEqual(QtCore.Qt.WindowFullScreen, main_display.windowState(), 'The window state should not be full screen.') - @patch('openlp.core.is_macosx') - def macosx_primary_screen_window_state_test(self, mocked_is_macosx): + @patch('openlp.core.ui.maindisplay.is_macosx') + def macosx_primary_screen_window_state_test(self, is_macosx): """ Test that on Mac OS X when the current screen is primary we set the window state to full screen """ # GIVEN: A new SlideController instance on Mac OS X with the current display being primary. - mocked_is_macosx.return_value = True + is_macosx.return_value = True self.screens.set_current_display(0) display = MagicMock() From 79abd9b82e34acaa5c5a138f7c753d0b14cbdd66 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Tue, 26 May 2015 00:33:55 -0400 Subject: [PATCH 4/5] PEP8 fix --- tests/functional/openlp_core_ui/test_maindisplay.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functional/openlp_core_ui/test_maindisplay.py b/tests/functional/openlp_core_ui/test_maindisplay.py index 7e9feff48..17325b59a 100644 --- a/tests/functional/openlp_core_ui/test_maindisplay.py +++ b/tests/functional/openlp_core_ui/test_maindisplay.py @@ -34,6 +34,7 @@ from openlp.core.ui.maindisplay import TRANSPARENT_STYLESHEET, OPAQUE_STYLESHEET from tests.helpers.testmixin import TestMixin from tests.functional import MagicMock, patch + class TestMainDisplay(TestCase, TestMixin): def setUp(self): From f41dc964c7fd856ae6c50ac05eeca1636e703eb1 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Tue, 26 May 2015 00:52:00 -0400 Subject: [PATCH 5/5] Merge tests --- .../openlp_core_ui/test_maindisplay.py | 46 ++++--------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/tests/functional/openlp_core_ui/test_maindisplay.py b/tests/functional/openlp_core_ui/test_maindisplay.py index 17325b59a..04f2ddef5 100644 --- a/tests/functional/openlp_core_ui/test_maindisplay.py +++ b/tests/functional/openlp_core_ui/test_maindisplay.py @@ -135,9 +135,9 @@ class TestMainDisplay(TestCase, TestMixin): mocked_bibles_plugin.refresh_css.assert_called_with(main_display.frame) @patch('openlp.core.ui.maindisplay.is_macosx') - def macosx_non_primary_screen_window_flags_test(self, is_macosx): + def macosx_non_primary_screen_window_flags_state_test(self, is_macosx): """ - Test that on Mac OS X when the current screen isn't primary we use the WindowStaysOnTop window flag + Test that on Mac OS X when the current screen isn't primary we set the proper window flags and window state """ # GIVEN: A new SlideController instance on Mac OS X with the current display not being primary. is_macosx.return_value = True @@ -147,49 +147,17 @@ class TestMainDisplay(TestCase, TestMixin): # WHEN: The default controller is built. main_display = MainDisplay(display) - # THEN: The window flags should be the same as those needed on Mac OS X for the non primary display. + # THEN: The window flags and state should be the same as those needed on Mac OS X for the non primary display. self.assertEqual(QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint, main_display.windowFlags(), 'The window flags should be Qt.WindowStaysOnTop, Qt.Window, and Qt.FramelessWindowHint.') - - @patch('openlp.core.ui.maindisplay.is_macosx') - def macosx_primary_screen_window_flags_test(self, is_macosx): - """ - Test that on Mac OS X when the current screen is primary we don't use the WindowStaysOnTop window flag - """ - # GIVEN: A new SlideController instance on Mac OS X with the current display being primary. - is_macosx.return_value = True - self.screens.set_current_display(0) - display = MagicMock() - - # WHEN: The default controller is built. - main_display = MainDisplay(display) - - # THEN: The window flags should be the same as those needed on Mac OS X for the primary display. - self.assertEqual(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint, main_display.windowFlags(), - 'The window flags should be Qt.Window and Qt.FramelessWindowHint.') - - @patch('openlp.core.ui.maindisplay.is_macosx') - def macosx_non_primary_screen_window_state_test(self, is_macosx): - """ - Test that on Mac OS X when the current screen isn't primary we don't set the window state to full screen - """ - # GIVEN: A new SlideController instance on Mac OS X with the current display not being primary. - is_macosx.return_value = True - self.screens.set_current_display(1) - display = MagicMock() - - # WHEN: The default controller is built. - main_display = MainDisplay(display) - - # THEN: The window state should not be full screen. self.assertNotEqual(QtCore.Qt.WindowFullScreen, main_display.windowState(), 'The window state should not be full screen.') @patch('openlp.core.ui.maindisplay.is_macosx') - def macosx_primary_screen_window_state_test(self, is_macosx): + def macosx_primary_screen_window_flags_state_test(self, is_macosx): """ - Test that on Mac OS X when the current screen is primary we set the window state to full screen + Test that on Mac OS X when the current screen is primary we set the proper window flags and window state """ # GIVEN: A new SlideController instance on Mac OS X with the current display being primary. is_macosx.return_value = True @@ -199,6 +167,8 @@ class TestMainDisplay(TestCase, TestMixin): # WHEN: The default controller is built. main_display = MainDisplay(display) - # THEN: The window state should be full screen. + # THEN: The window flags and state should be the same as those needed on Mac OS X for the primary display. + self.assertEqual(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint, main_display.windowFlags(), + 'The window flags should be Qt.Window and Qt.FramelessWindowHint.') self.assertEqual(QtCore.Qt.WindowFullScreen, main_display.windowState(), 'The window state should be full screen.')