From 4b50c6f5d2119f0a3b65c5ba9a10616db2798b8c Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 4 Apr 2020 06:48:18 +0000 Subject: [PATCH] fix core/logo hide on startup setting, fix display stuck as hidden and invert transparent display setting --- openlp/core/common/settings.py | 1 + openlp/core/display/window.py | 12 ++- openlp/core/ui/advancedtab.py | 7 ++ .../openlp_core/display/test_window.py | 102 +++++++++++++++++- 4 files changed, 114 insertions(+), 8 deletions(-) diff --git a/openlp/core/common/settings.py b/openlp/core/common/settings.py index 4b82b2aef..a509da25e 100644 --- a/openlp/core/common/settings.py +++ b/openlp/core/common/settings.py @@ -137,6 +137,7 @@ class Settings(QtCore.QSettings): __default_settings__ = { 'settings/version': 0, 'advanced/add page break': False, + 'advanced/disable transparent display': True, 'advanced/alternate rows': not is_win(), 'advanced/autoscrolling': {'dist': 1, 'pos': 0}, 'advanced/current media plugin': -1, diff --git a/openlp/core/display/window.py b/openlp/core/display/window.py index 8cc16fd96..161355495 100644 --- a/openlp/core/display/window.py +++ b/openlp/core/display/window.py @@ -220,6 +220,9 @@ class DisplayWindow(QtWidgets.QWidget, RegistryProperties): if path_to_str(image).startswith(':'): image = self.openlp_splash_screen_path image_uri = image.as_uri() + # if set to hide logo on startup, do not send the logo + if self.settings.value('core/logo hide on startup'): + image_uri = '' self.run_javascript('Display.setStartupSplashScreen("{bg_color}", "{image}");'.format(bg_color=bg_color, image=image_uri)) @@ -423,10 +426,9 @@ class DisplayWindow(QtWidgets.QWidget, RegistryProperties): if len(ScreenList()) == 1 and not self.settings.value('core/display on monitor'): return self.run_javascript('Display.show();') - # Check if setting for hiding logo on startup is enabled. - # If it is, display should remain hidden, otherwise logo is shown. (from def setup) - if self.isHidden() and not self.settings.value('core/logo hide on startup'): + if self.isHidden(): self.setVisible(True) + self.webview.setVisible(True) self.hide_mode = None # Trigger actions when display is active again. if self.is_display: @@ -443,6 +445,10 @@ class DisplayWindow(QtWidgets.QWidget, RegistryProperties): # Only make visible on single monitor setup if setting enabled. if len(ScreenList()) == 1 and not self.settings.value('core/display on monitor'): return + # Use Screen mode if Transparent is disallowed via setting + if self.settings.value('advanced/disable transparent display') and mode == HideMode.Transparent: + mode = HideMode.Screen + # Now update display to the selected mode if mode == HideMode.Screen: self.setVisible(False) elif mode == HideMode.Blank: diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index c22df77db..2ae82da37 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -178,6 +178,9 @@ class AdvancedTab(SettingsTab): self.alternate_rows_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box) self.alternate_rows_check_box.setObjectName('alternate_rows_check_box') self.display_workaround_layout.addWidget(self.alternate_rows_check_box) + self.allow_transparent_display_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box) + self.allow_transparent_display_check_box.setObjectName('allow_transparent_display_check_box') + self.display_workaround_layout.addWidget(self.allow_transparent_display_check_box) self.right_layout.addWidget(self.display_workaround_group_box) # Default service name self.service_name_group_box = QtWidgets.QGroupBox(self.right_column) @@ -324,6 +327,8 @@ class AdvancedTab(SettingsTab): self.ignore_aspect_ratio_check_box.setText(translate('OpenLP.AdvancedTab', 'Ignore Aspect Ratio')) self.x11_bypass_check_box.setText(translate('OpenLP.AdvancedTab', 'Bypass X11 Window Manager')) self.alternate_rows_check_box.setText(translate('OpenLP.AdvancedTab', 'Use alternating row colours in lists')) + self.allow_transparent_display_check_box.setText( + translate('OpenLP.AdvancedTab', 'Disable display transparency')) # Slide Limits self.slide_group_box.setTitle(translate('OpenLP.GeneralTab', 'Service Item Slide Limits')) self.slide_label.setText(translate('OpenLP.GeneralTab', 'Behavior of next/previous on the last/first slide:')) @@ -377,6 +382,7 @@ class AdvancedTab(SettingsTab): self.alternate_rows_check_box.blockSignals(True) self.alternate_rows_check_box.setChecked(self.settings.value('alternate rows')) self.alternate_rows_check_box.blockSignals(False) + self.allow_transparent_display_check_box.setChecked(self.settings.value('disable transparent display')) if self.slide_limits == SlideLimits.End: self.end_slide_radio_button.setChecked(True) elif self.slide_limits == SlideLimits.Wrap: @@ -422,6 +428,7 @@ class AdvancedTab(SettingsTab): self.settings.setValue('enable exit confirmation', self.enable_auto_close_check_box.isChecked()) self.settings.setValue('hide mouse', self.hide_mouse_check_box.isChecked()) self.settings.setValue('alternate rows', self.alternate_rows_check_box.isChecked()) + self.settings.setValue('disable transparent display', self.allow_transparent_display_check_box.isChecked()) self.settings.setValue('slide limits', self.slide_limits) self.settings.setValue('ignore aspect ratio', self.ignore_aspect_ratio_check_box.isChecked()) if self.x11_bypass_check_box.isChecked() != self.settings.value('x11 bypass wm'): diff --git a/tests/functional/openlp_core/display/test_window.py b/tests/functional/openlp_core/display/test_window.py index d3bff5b72..2f059cb96 100644 --- a/tests/functional/openlp_core/display/test_window.py +++ b/tests/functional/openlp_core/display/test_window.py @@ -174,15 +174,63 @@ def test_run_javascript_sync_no_wait(mock_time, mocked_webengine, mocked_addWidg mock_time.sleep.assert_not_called() +@patch('PyQt5.QtWidgets.QVBoxLayout') +@patch('openlp.core.display.webengine.WebEngineView') +@patch('openlp.core.common.registry.Registry.execute') +@patch('openlp.core.display.screens.ScreenList') +def test_show_display(mocked_screenlist, mocked_registry_execute, mocked_webengine, mocked_addWidget, mock_settings): + """ + Test show_display function + """ + # GIVEN: Display window as the active display + display_window = DisplayWindow() + display_window.is_display = True + display_window.isHidden = MagicMock(return_value=True) + display_window.setVisible = MagicMock() + display_window.run_javascript = MagicMock() + mocked_screenlist.screens = [1, 2] + + # WHEN: Show display is run + display_window.show_display() + + # THEN: Should show the display and set the hide mode to none + display_window.setVisible.assert_called_once_with(True) + display_window.run_javascript.assert_called_once_with('Display.show();') + mocked_registry_execute.assert_called_once_with('live_display_active') + assert display_window.hide_mode is None + + +@patch('PyQt5.QtWidgets.QVBoxLayout') +@patch('openlp.core.display.webengine.WebEngineView') +@patch('openlp.core.display.window.ScreenList') +def test_show_display_no_display(mocked_screenlist, mocked_webengine, mocked_addWidget, mock_settings): + """ + Test show_display function when no displays are available + """ + # GIVEN: A Display window, one screen and core/display on monitor disabled + display_window = DisplayWindow() + display_window.hide_mode = HideMode.Screen + display_window.is_display = True + mocked_screenlist.return_value = [1] + mock_settings.value.return_value = False + + # WHEN: Show display is run + display_window.show_display() + + # THEN: Hide mode should still be screen + assert display_window.hide_mode == HideMode.Screen + + @patch('PyQt5.QtWidgets.QVBoxLayout') @patch('openlp.core.display.webengine.WebEngineView') def test_hide_display_to_screen(mocked_webengine, mocked_addWidget, mock_settings): """ Test hide to screen in the hide_display function """ - # GIVEN: + # GIVEN: Display window and setting advanced/disable transparent display = False display_window = DisplayWindow() display_window.setVisible = MagicMock() + mock_settings.value.return_value = False # WHEN: Hide display is run with no mode (should default to Screen) display_window.hide_display() @@ -198,9 +246,10 @@ def test_hide_display_to_blank(mocked_webengine, mocked_addWidget, mock_settings """ Test hide to screen in the hide_display function """ - # GIVEN: + # GIVEN: Display window and setting advanced/disable transparent display = False display_window = DisplayWindow() display_window.run_javascript = MagicMock() + mock_settings.value.return_value = False # WHEN: Hide display is run with HideMode.Blank display_window.hide_display(HideMode.Blank) @@ -216,9 +265,10 @@ def test_hide_display_to_theme(mocked_webengine, mocked_addWidget, mock_settings """ Test hide to screen in the hide_display function """ - # GIVEN: + # GIVEN: Display window and setting advanced/disable transparent display = False display_window = DisplayWindow() display_window.run_javascript = MagicMock() + mock_settings.value.return_value = False # WHEN: Hide display is run with HideMode.Theme display_window.hide_display(HideMode.Theme) @@ -234,13 +284,55 @@ def test_hide_display_to_transparent(mocked_webengine, mocked_addWidget, mock_se """ Test hide to screen in the hide_display function """ - # GIVEN: + # GIVEN: Display window and setting advanced/disable transparent display = False display_window = DisplayWindow() display_window.run_javascript = MagicMock() + mock_settings.value.return_value = False # WHEN: Hide display is run with HideMode.Transparent display_window.hide_display(HideMode.Transparent) # THEN: Should run the correct javascript on the display and set the hide mode - display_window.run_javascript.assert_called_once_with('Display.toTransparent();') assert display_window.hide_mode == HideMode.Transparent + display_window.run_javascript.assert_called_once_with('Display.toTransparent();') + + +@patch('PyQt5.QtWidgets.QVBoxLayout') +@patch('openlp.core.display.webengine.WebEngineView') +def test_hide_transparent_to_screen(mocked_webengine, mocked_addWidget, mock_settings): + """ + Test that when going transparent, and the disable transparent setting is enabled, + the screen mode should be used. + """ + # GIVEN: Display window and setting advanced/disable transparent display = True + display_window = DisplayWindow() + display_window.setVisible = MagicMock() + mock_settings.value.return_value = True + + # WHEN: Hide display is run with HideMode.Transparent + display_window.hide_display(HideMode.Transparent) + + # THEN: Should run the correct javascript on the display and set the hide mode + display_window.setVisible.assert_called_once_with(False) + assert display_window.hide_mode == HideMode.Screen + + +@patch('PyQt5.QtWidgets.QVBoxLayout') +@patch('openlp.core.display.webengine.WebEngineView') +@patch('openlp.core.display.window.ScreenList') +def test_hide_display_no_display(mocked_screenlist, mocked_webengine, mocked_addWidget, mock_settings): + """ + Test show_display function when no displays are available + """ + # GIVEN: A Display window, one screen and core/display on monitor disabled + display_window = DisplayWindow() + display_window.hide_mode = None + display_window.is_display = True + mocked_screenlist.return_value = [1] + mock_settings.value.return_value = False + + # WHEN: Hide display is run + display_window.hide_display(HideMode.Screen) + + # THEN: Hide mode should still be none + assert display_window.hide_mode is None