This commit is contained in:
Tim Bentley 2014-11-01 07:47:43 +00:00
commit ee4bd0f521
3 changed files with 47 additions and 3 deletions

View File

@ -33,7 +33,6 @@ from datetime import datetime
from distutils.version import LooseVersion from distutils.version import LooseVersion
import logging import logging
import os import os
import sys
import threading import threading
from PyQt4 import QtGui from PyQt4 import QtGui
@ -55,6 +54,8 @@ except OSError as e:
if is_win(): if is_win():
if not isinstance(e, WindowsError) and e.winerror != 126: if not isinstance(e, WindowsError) and e.winerror != 126:
raise raise
elif is_macosx():
pass
else: else:
raise raise

View File

@ -57,6 +57,11 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog, RegistryProperties):
self.processes = [] self.processes = []
self.setupUi(self) self.setupUi(self)
self.setting_list_widget.currentRowChanged.connect(self.list_item_changed) self.setting_list_widget.currentRowChanged.connect(self.list_item_changed)
self.general_tab = None
self.themes_tab = None
self.projector_tab = None
self.advanced_tab = None
self.player_tab = None
def exec_(self): def exec_(self):
""" """
@ -125,8 +130,18 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog, RegistryProperties):
Process the form saving the settings Process the form saving the settings
""" """
self.processes = [] self.processes = []
for tabIndex in range(self.stacked_layout.count()): # Same as accept(), we need to loop over the visible tabs, and skip the inactive ones
self.stacked_layout.widget(tabIndex).cancel() for item_index in range(self.setting_list_widget.count()):
# Get the list item
list_item = self.setting_list_widget.item(item_index)
if not list_item:
continue
# Now figure out if there's a tab for it, and save the tab.
plugin_name = list_item.data(QtCore.Qt.UserRole)
for tab_index in range(self.stacked_layout.count()):
tab_widget = self.stacked_layout.widget(tab_index)
if tab_widget.tab_title == plugin_name:
tab_widget.cancel()
return QtGui.QDialog.reject(self) return QtGui.QDialog.reject(self)
def bootstrap_post_set_up(self): def bootstrap_post_set_up(self):

View File

@ -130,3 +130,31 @@ class TestSettingsForm(TestCase):
# THEN: The rest of the method should not have been called # THEN: The rest of the method should not have been called
self.assertEqual(0, mocked_count.call_count, 'The count method of the stacked layout should not be called') self.assertEqual(0, mocked_count.call_count, 'The count method of the stacked layout should not be called')
def reject_with_inactive_items_test(self):
"""
Test that the reject() method works correctly when some of the plugins are inactive
"""
# GIVEN: A visible general tab and an invisible theme tab in a Settings Form
settings_form = SettingsForm(None)
general_tab = QtGui.QWidget(None)
general_tab.tab_title = 'mock-general'
general_tab.tab_title_visible = 'Mock General'
general_tab.icon_path = ':/icon/openlp-logo-16x16.png'
mocked_general_cancel = MagicMock()
general_tab.cancel = mocked_general_cancel
settings_form.insert_tab(general_tab, is_visible=True)
themes_tab = QtGui.QWidget(None)
themes_tab.tab_title = 'mock-themes'
themes_tab.tab_title_visible = 'Mock Themes'
themes_tab.icon_path = ':/icon/openlp-logo-16x16.png'
mocked_theme_cancel = MagicMock()
themes_tab.cancel = mocked_theme_cancel
settings_form.insert_tab(themes_tab, is_visible=False)
# WHEN: The reject() method is called
settings_form.reject()
# THEN: The general tab's cancel() method should have been called, but not the themes tab
mocked_general_cancel.assert_called_with()
self.assertEqual(0, mocked_theme_cancel.call_count, 'The Themes tab\'s cancel() should not have been called')