From 2433efdfd064443d6adbd3327012a982c2f8e43c Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 29 Mar 2016 16:45:59 +0100 Subject: [PATCH 1/4] Update themes in service manager when themes are set in settings --- openlp/core/ui/servicemanager.py | 1 + openlp/core/ui/themestab.py | 1 + .../openlp_core_ui/test_themetab.py | 84 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 tests/functional/openlp_core_ui/test_themetab.py diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index fdae5c069..067fd86c7 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -1326,6 +1326,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa visible = self.renderer.theme_level == ThemeLevel.Global self.theme_label.setVisible(visible) self.theme_combo_box.setVisible(visible) + self.regenerate_service_items() def regenerate_service_items(self, changed=False): """ diff --git a/openlp/core/ui/themestab.py b/openlp/core/ui/themestab.py index a953ae013..07474ca74 100644 --- a/openlp/core/ui/themestab.py +++ b/openlp/core/ui/themestab.py @@ -160,6 +160,7 @@ class ThemesTab(SettingsTab): settings.endGroup() self.renderer.set_theme_level(self.theme_level) if self.tab_visited: + print("processed") self.settings_form.register_post_process('theme_update_global') self.tab_visited = False diff --git a/tests/functional/openlp_core_ui/test_themetab.py b/tests/functional/openlp_core_ui/test_themetab.py new file mode 100644 index 000000000..8896ae8f0 --- /dev/null +++ b/tests/functional/openlp_core_ui/test_themetab.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2016 OpenLP Developers # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +Package to test the openlp.core.ui.ThemeTab package. +""" +from unittest import TestCase + +from openlp.core.common import Registry +from openlp.core.ui.themestab import ThemesTab +from openlp.core.ui.settingsform import SettingsForm + +from tests.helpers.testmixin import TestMixin +from tests.functional import MagicMock + + +class TestThemeTab(TestCase, TestMixin): + + def setUp(self): + """ + Set up a few things for the tests + """ + Registry.create() + + def test_creation(self): + """ + Test that Themes Tab is created. + """ + # GIVEN: A new Advanced Tab + settings_form = SettingsForm(None) + + # WHEN: I create an advanced tab + themes_tab = ThemesTab(settings_form) + + # THEN: + self.assertEqual("Themes", themes_tab.tab_title, 'The tab title should be Theme') + + def test_save_triggers_processes_true(self): + """ + Test that the global theme event is triggered when the tab is visited. + """ + # GIVEN: A new Advanced Tab + settings_form = SettingsForm(None) + themes_tab = ThemesTab(settings_form) + Registry().register('renderer', MagicMock()) + themes_tab.tab_visited = True + # WHEN: I change search as type check box + themes_tab.save() + + # THEN: we should have two post save processed to run + self.assertEqual(1, len(settings_form.processes), 'One post save processes should be created') + + def test_save_triggers_processes_false(self): + """ + Test that the global theme event is not triggered when the tab is not visited. + """ + # GIVEN: A new Advanced Tab + settings_form = SettingsForm(None) + themes_tab = ThemesTab(settings_form) + Registry().register('renderer', MagicMock()) + themes_tab.tab_visited = False + # WHEN: I change search as type check box + themes_tab.save() + + # THEN: we should have two post save processed to run + self.assertEqual(0, len(settings_form.processes), 'No post save processes should be created') \ No newline at end of file From be8bdcf1f34afda94c182f5025894d9a86841360 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 29 Mar 2016 17:00:55 +0100 Subject: [PATCH 2/4] remove print --- openlp/core/ui/themestab.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/core/ui/themestab.py b/openlp/core/ui/themestab.py index 07474ca74..a953ae013 100644 --- a/openlp/core/ui/themestab.py +++ b/openlp/core/ui/themestab.py @@ -160,7 +160,6 @@ class ThemesTab(SettingsTab): settings.endGroup() self.renderer.set_theme_level(self.theme_level) if self.tab_visited: - print("processed") self.settings_form.register_post_process('theme_update_global') self.tab_visited = False From 77fca59e5711c651e2ff540e8a2b2f864ed081ef Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 29 Mar 2016 17:07:40 +0100 Subject: [PATCH 3/4] add new line --- tests/functional/openlp_core_ui/test_themetab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_ui/test_themetab.py b/tests/functional/openlp_core_ui/test_themetab.py index 8896ae8f0..c3bb6282d 100644 --- a/tests/functional/openlp_core_ui/test_themetab.py +++ b/tests/functional/openlp_core_ui/test_themetab.py @@ -81,4 +81,4 @@ class TestThemeTab(TestCase, TestMixin): themes_tab.save() # THEN: we should have two post save processed to run - self.assertEqual(0, len(settings_form.processes), 'No post save processes should be created') \ No newline at end of file + self.assertEqual(0, len(settings_form.processes), 'No post save processes should be created') From d11cb1d6222efc232606068e016b9913f9839063 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 29 Mar 2016 17:55:33 +0100 Subject: [PATCH 4/4] Only set tab_visited when the tab is visited and not on loading --- openlp/core/lib/settingstab.py | 2 +- openlp/core/ui/settingsform.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/openlp/core/lib/settingstab.py b/openlp/core/lib/settingstab.py index fb7da0e14..a236dbdf9 100644 --- a/openlp/core/lib/settingstab.py +++ b/openlp/core/lib/settingstab.py @@ -135,4 +135,4 @@ class SettingsTab(QtWidgets.QWidget, RegistryProperties): """ Tab has just been made visible to the user """ - self.tab_visited = True + pass diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index f8c3cbbc2..82d72694c 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -60,7 +60,8 @@ class SettingsForm(QtWidgets.QDialog, Ui_SettingsDialog, RegistryProperties): """ Execute the form """ - # load all the settings + # load all the + self.setting_list_widget.blockSignals(True) self.setting_list_widget.clear() while self.stacked_layout.count(): # take at 0 and the rest shuffle up. @@ -74,6 +75,7 @@ class SettingsForm(QtWidgets.QDialog, Ui_SettingsDialog, RegistryProperties): if plugin.settings_tab: self.insert_tab(plugin.settings_tab, plugin.is_active()) self.setting_list_widget.setCurrentRow(0) + self.setting_list_widget.blockSignals(False) return QtWidgets.QDialog.exec(self) def insert_tab(self, tab_widget, is_visible=True): @@ -177,6 +179,7 @@ class SettingsForm(QtWidgets.QDialog, Ui_SettingsDialog, RegistryProperties): # Check that the title of the tab (i.e. plugin name) is the same as the data in the list item if tab_widget.tab_title == list_item.data(QtCore.Qt.UserRole): # Make the matching tab visible + tab_widget.tab_visited = True self.stacked_layout.setCurrentIndex(tab_index) self.stacked_layout.currentWidget().tab_visible()