From b33d27f77c14312153b8ca2d497db9b83d28ef00 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 20 Sep 2020 17:35:49 +0000 Subject: [PATCH] Fix theme combo box not showing at start The theme combo box did not show when the currently rendered item doesn't support the service/song theme levels. This changes the theme combo box to use the theme level from the settings rather than the currently rendered item. --- openlp/core/display/html/display.js | 2 ++ openlp/core/display/render.py | 8 ++--- openlp/core/ui/media/vlcplayer.py | 1 - openlp/core/ui/servicemanager.py | 2 +- openlp/core/ui/slidecontroller.py | 4 +++ openlp/core/ui/themeform.py | 10 ++---- .../openlp_core/ui/media/test_vlcplayer.py | 2 -- .../openlp_core/ui/test_servicemanager.py | 32 +++++++++---------- .../openlp_core/ui/test_slidecontroller.py | 1 + tests/js/test_display.js | 10 ++++++ tests/openlp_core/ui/test_themeform.py | 7 +--- 11 files changed, 39 insertions(+), 40 deletions(-) diff --git a/openlp/core/display/html/display.js b/openlp/core/display/html/display.js index 5ce47e6a4..260b191f7 100644 --- a/openlp/core/display/html/display.js +++ b/openlp/core/display/html/display.js @@ -701,6 +701,8 @@ var Display = { var html = _prepareText(text); slide = document.createElement("section"); slide.setAttribute("id", verse); + // The "future" class is used internally by reveal, it's used here to hide newly added slides + slide.classList.add("future"); slide.innerHTML = html; return slide; }, diff --git a/openlp/core/display/render.py b/openlp/core/display/render.py index 11ff9d74c..3d03a15d8 100644 --- a/openlp/core/display/render.py +++ b/openlp/core/display/render.py @@ -27,7 +27,6 @@ import mako import math import os import re -import time from PyQt5 import QtWidgets, QtGui @@ -823,12 +822,9 @@ class ThemePreviewRenderer(DisplayWindow, LogMixin): Save a screenshot, either returning it or saving it to file. Do some extra work to actually get a picture. """ self.setVisible(True) + QtWidgets.QApplication.instance().processEvents() + wait_for(lambda: False, timeout=1) pixmap = self.grab() - for i in range(0, 4): - QtWidgets.QApplication.instance().processEvents() - time.sleep(0.05) - QtWidgets.QApplication.instance().processEvents() - pixmap = self.grab() self.setVisible(False) pixmap = QtGui.QPixmap(self.webview.size()) self.webview.render(pixmap) diff --git a/openlp/core/ui/media/vlcplayer.py b/openlp/core/ui/media/vlcplayer.py index ffad98a8b..9aa8dd9db 100644 --- a/openlp/core/ui/media/vlcplayer.py +++ b/openlp/core/ui/media/vlcplayer.py @@ -287,7 +287,6 @@ class VlcPlayer(MediaPlayer): controller.vlc_media_player.set_time(int(start_time)) controller.seek_slider.setMaximum(controller.media_info.length) self.set_state(MediaState.Playing, controller) - controller.vlc_widget.raise_() return True def pause(self, controller): diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 55c6016e2..fc44c58fd 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -1361,7 +1361,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi """ The theme may have changed in the settings dialog so make sure the theme combo box is in the correct state. """ - visible = self.renderer.theme_level != ThemeLevel.Global + visible = self.settings.value('themes/theme level') != ThemeLevel.Global self.toolbar.actions['theme_combo_box'].setVisible(visible) self.toolbar.actions['theme_label'].setVisible(visible) self.regenerate_service_items() diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 7dd56441e..6992076c7 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -981,6 +981,10 @@ class SlideController(QtWidgets.QWidget, LogMixin, RegistryProperties): if self.service_item.is_command(): self.preview_display.load_verses(media_empty_song, True) self.on_media_start(self.service_item) + # Let media window init, then put webengine back on top + self.application.process_events() + for display in self.displays: + display.raise_() self.slide_selected(True) if self.service_item.from_service: self.preview_widget.setFocus() diff --git a/openlp/core/ui/themeform.py b/openlp/core/ui/themeform.py index 8c91ca764..2e84249d0 100644 --- a/openlp/core/ui/themeform.py +++ b/openlp/core/ui/themeform.py @@ -119,6 +119,7 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): # Make sure we don't resize before the widgets are actually created if hasattr(self, 'preview_area_layout'): self.preview_area_layout.set_aspect_ratio(self.display_aspect_ratio) + self.application.process_events() self.preview_box.set_scale(float(self.preview_box.width()) / self.renderer.width()) def validateCurrentPage(self): @@ -160,15 +161,8 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): self.setOption(QtWidgets.QWizard.HaveCustomButton1, enabled) if self.page(page_id) == self.preview_page: self.update_theme() - self.preview_box.set_theme(self.theme, service_item_type=ServiceItemType.Text) - self.preview_box.clear_slides() - self.preview_box.set_scale(float(self.preview_box.width()) / self.renderer.width()) - try: - self.display_aspect_ratio = self.renderer.width() / self.renderer.height() - except ZeroDivisionError: - self.display_aspect_ratio = 1 - self.preview_area_layout.set_aspect_ratio(self.display_aspect_ratio) self.resizeEvent() + self.preview_box.clear_slides() self.preview_box.show() self.preview_box.generate_preview(self.theme, False, False) diff --git a/tests/functional/openlp_core/ui/media/test_vlcplayer.py b/tests/functional/openlp_core/ui/media/test_vlcplayer.py index 5cccd4760..f11c67d47 100644 --- a/tests/functional/openlp_core/ui/media/test_vlcplayer.py +++ b/tests/functional/openlp_core/ui/media/test_vlcplayer.py @@ -597,7 +597,6 @@ def test_play(mocked_get_vlc, mocked_threading): mocked_thread.start.assert_called_with() mocked_volume.assert_called_with(mocked_controller, 100) assert MediaState.Playing == vlc_player.get_live_state() - mocked_controller.vlc_widget.raise_.assert_called_with() assert result is True, 'The value returned from play() should be True' @@ -667,7 +666,6 @@ def test_play_dvd(mocked_get_vlc, mocked_threading): mocked_controller.vlc_media_player.video_set_spu.assert_called_with(1) mocked_volume.assert_called_with(mocked_controller, 100) assert MediaState.Playing == vlc_player.get_live_state() - mocked_controller.vlc_widget.raise_.assert_called_with() assert result is True, 'The value returned from play() should be True' diff --git a/tests/functional/openlp_core/ui/test_servicemanager.py b/tests/functional/openlp_core/ui/test_servicemanager.py index 33655bb20..028eaed6d 100644 --- a/tests/functional/openlp_core/ui/test_servicemanager.py +++ b/tests/functional/openlp_core/ui/test_servicemanager.py @@ -697,16 +697,16 @@ def test_theme_change_global(mocked_regenerate_service_items, registry): """ Test that when a Toolbar theme combobox displays correctly when the theme is set to Global """ - # GIVEN: A service manager, a service to display with a theme level in the renderer - mocked_renderer = MagicMock() + # GIVEN: A service manager, settings set to Global theme service_manager = ServiceManager(None) - Registry().register('renderer', mocked_renderer) service_manager.toolbar = OpenLPToolbar(None) service_manager.toolbar.add_toolbar_action('theme_combo_box', triggers=MagicMock()) service_manager.toolbar.add_toolbar_action('theme_label', triggers=MagicMock()) + mocked_settings = MagicMock() + mocked_settings.value.return_value = ThemeLevel.Global + Registry().register('settings', mocked_settings) - # WHEN: The service manager has a Global theme - mocked_renderer.theme_level = ThemeLevel.Global + # WHEN: theme_change is called service_manager.theme_change() # THEN: The the theme toolbar should not be visible @@ -719,16 +719,16 @@ def test_theme_change_service(mocked_regenerate_service_items, registry): """ Test that when a Toolbar theme combobox displays correctly when the theme is set to Theme """ - # GIVEN: A service manager, a service to display with a theme level in the renderer - mocked_renderer = MagicMock() + # GIVEN: A service manager, settings set to Service theme service_manager = ServiceManager(None) - Registry().register('renderer', mocked_renderer) service_manager.toolbar = OpenLPToolbar(None) service_manager.toolbar.add_toolbar_action('theme_combo_box', triggers=MagicMock()) service_manager.toolbar.add_toolbar_action('theme_label', triggers=MagicMock()) + mocked_settings = MagicMock() + mocked_settings.value.return_value = ThemeLevel.Service + Registry().register('settings', mocked_settings) - # WHEN: The service manager has a Service theme - mocked_renderer.theme_level = ThemeLevel.Service + # WHEN: theme_change is called service_manager.theme_change() # THEN: The the theme toolbar should be visible @@ -741,18 +741,18 @@ def test_theme_change_song(mocked_regenerate_service_items, registry): """ Test that when a Toolbar theme combobox displays correctly when the theme is set to Song """ - # GIVEN: A service manager, a service to display with a theme level in the renderer - mocked_renderer = MagicMock() + # GIVEN: A service manager, settings set to Song theme service_manager = ServiceManager(None) - Registry().register('renderer', mocked_renderer) service_manager.toolbar = OpenLPToolbar(None) service_manager.toolbar.add_toolbar_action('theme_combo_box', triggers=MagicMock()) service_manager.toolbar.add_toolbar_action('theme_label', triggers=MagicMock()) + mocked_settings = MagicMock() + mocked_settings.value.return_value = ThemeLevel.Song + Registry().register('settings', mocked_settings) - # WHEN: The service manager has a Song theme - mocked_renderer.theme_level = ThemeLevel.Song + # WHEN: theme_change is called service_manager.theme_change() - # THEN: The the theme toolbar should be visible + # THEN: The the theme toolbar should be visible assert service_manager.toolbar.actions['theme_combo_box'].isVisible() is True, \ 'The visibility should be True' diff --git a/tests/functional/openlp_core/ui/test_slidecontroller.py b/tests/functional/openlp_core/ui/test_slidecontroller.py index afed98d08..4a6a4dbf9 100644 --- a/tests/functional/openlp_core/ui/test_slidecontroller.py +++ b/tests/functional/openlp_core/ui/test_slidecontroller.py @@ -794,6 +794,7 @@ def test_process_item(mocked_execute, registry): mocked_main_window = MagicMock() Registry().register('main_window', mocked_main_window) Registry().register('media_controller', MagicMock()) + Registry().register('application', MagicMock()) slide_controller = SlideController(None) slide_controller.service_item = mocked_pres_item slide_controller.is_live = False diff --git a/tests/js/test_display.js b/tests/js/test_display.js index d371cc88f..751fcf491 100644 --- a/tests/js/test_display.js +++ b/tests/js/test_display.js @@ -568,6 +568,16 @@ describe("Display.setTextSlide", function () { expect($(".slides > section > section")[0].innerHTML).toEqual(_prepareText(text)); expect(Display.reinit).toHaveBeenCalledTimes(1); // only called once for the first setTextSlide }); + + it("should give the new slide the future class", function () { + var text = "That saved a wretch\nlike me"; + spyOn(Display, "reinit"); + Display.setTextSlide("Amazing grace,\nhow sweet the sound"); + + Display.setTextSlide(text); + + expect($(".slides > section > section")[0].classList.contains("future")).toEqual(true); + }); }); describe("Display.setTextSlides", function () { diff --git a/tests/openlp_core/ui/test_themeform.py b/tests/openlp_core/ui/test_themeform.py index 802284a3a..2a80a0926 100644 --- a/tests/openlp_core/ui/test_themeform.py +++ b/tests/openlp_core/ui/test_themeform.py @@ -24,7 +24,6 @@ Test the ThemeForm class and related methods. from pathlib import Path from unittest.mock import patch, MagicMock -from openlp.core.common.enum import ServiceItemType from openlp.core.common.registry import Registry from openlp.core.lib.theme import BackgroundType from openlp.core.ui.themeform import ThemeForm @@ -266,12 +265,8 @@ def test_on_current_id_changed_preview(mocked_setup, settings): # THEN: The right options should have been set theme_form.update_theme.assert_called_once() - theme_form.preview_box.set_theme.assert_called_once_with('my fake theme', - service_item_type=ServiceItemType.Text) - theme_form.preview_box.clear_slides.assert_called_once() - theme_form.preview_box.set_scale.assert_called_once_with(float(300 / 1920)) - theme_form.preview_area_layout.set_aspect_ratio(16 / 9) theme_form.resizeEvent.assert_called_once() + theme_form.preview_box.clear_slides.assert_called_once() theme_form.preview_box.show.assert_called_once() theme_form.preview_box.generate_preview.assert_called_once_with('my fake theme', False, False)