forked from openlp/openlp
[bug 1397606] Set the file dialogue box to the currently selected background image
bzr-revno: 2471 Fixes: https://launchpad.net/bugs/1397606
This commit is contained in:
commit
0deb0a10cc
@ -58,6 +58,12 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard, RegistryProperties):
|
||||
:param parent: The QWidget-derived parent of the wizard.
|
||||
"""
|
||||
super(ThemeForm, self).__init__(parent)
|
||||
self._setup()
|
||||
|
||||
def _setup(self):
|
||||
"""
|
||||
Set up the class. This method is mocked out by the tests.
|
||||
"""
|
||||
self.setupUi(self)
|
||||
self.registerFields()
|
||||
self.update_theme_allowed = True
|
||||
@ -429,10 +435,10 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard, RegistryProperties):
|
||||
"""
|
||||
images_filter = get_images_filter()
|
||||
images_filter = '%s;;%s (*.*)' % (images_filter, UiStrings().AllFiles)
|
||||
filename = QtGui.QFileDialog.getOpenFileName(self, translate('OpenLP.ThemeWizard', 'Select Image'), '',
|
||||
images_filter)
|
||||
filename = QtGui.QFileDialog.getOpenFileName(self, translate('OpenLP.ThemeWizard', 'Select Image'),
|
||||
self.image_file_edit.text(), images_filter)
|
||||
if filename:
|
||||
self.theme.background_filename = str(filename)
|
||||
self.theme.background_filename = filename
|
||||
self.set_background_page_values()
|
||||
|
||||
def on_image_file_edit_editing_finished(self):
|
||||
|
102
tests/functional/openlp_core_ui/test_themeform.py
Normal file
102
tests/functional/openlp_core_ui/test_themeform.py
Normal file
@ -0,0 +1,102 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2015 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2015 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
||||
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
||||
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
||||
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
||||
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
|
||||
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# 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.themeform package.
|
||||
"""
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from openlp.core.ui import ThemeForm
|
||||
|
||||
from tests.interfaces import MagicMock, patch
|
||||
|
||||
|
||||
class TestThemeManager(TestCase):
|
||||
"""
|
||||
Test the functions in the ThemeManager Class
|
||||
"""
|
||||
def select_image_file_dialog_cancelled_test(self):
|
||||
"""
|
||||
Test the select image file dialog when the user presses cancel
|
||||
"""
|
||||
# GIVEN: An instance of Theme Form and mocked QFileDialog which returns an empty string (similating a user
|
||||
# pressing cancel)
|
||||
with patch('openlp.core.ui.ThemeForm._setup'),\
|
||||
patch('openlp.core.ui.themeform.get_images_filter',
|
||||
**{'return_value': 'Image Files (*.bmp; *.gif)(*.bmp *.gif)'}),\
|
||||
patch('openlp.core.ui.themeform.QtGui.QFileDialog.getOpenFileName',
|
||||
**{'return_value': ''}) as mocked_get_open_file_name,\
|
||||
patch('openlp.core.ui.themeform.translate', **{'return_value': 'Translated String'}),\
|
||||
patch('openlp.core.ui.ThemeForm.set_background_page_values') as mocked_set_background_page_values:
|
||||
|
||||
instance = ThemeForm(None)
|
||||
mocked_image_file_edit = MagicMock()
|
||||
mocked_image_file_edit.text.return_value = '/original_path/file.ext'
|
||||
instance.image_file_edit = mocked_image_file_edit
|
||||
|
||||
# WHEN: on_image_browse_button is clicked
|
||||
instance.on_image_browse_button_clicked()
|
||||
|
||||
# THEN: The QFileDialog getOpenFileName and set_background_page_values moethods should have been called
|
||||
# with known arguments
|
||||
mocked_get_open_file_name.assert_called_once_with(instance, 'Translated String', '/original_path/file.ext',
|
||||
'Image Files (*.bmp; *.gif)(*.bmp *.gif);;All Files (*.*)'
|
||||
)
|
||||
mocked_set_background_page_values.assert_called_once_with()
|
||||
|
||||
def select_image_file_dialog_new_file_test(self):
|
||||
"""
|
||||
Test the select image file dialog when the user presses ok
|
||||
"""
|
||||
# GIVEN: An instance of Theme Form and mocked QFileDialog which returns a file path
|
||||
with patch('openlp.core.ui.ThemeForm._setup'),\
|
||||
patch('openlp.core.ui.themeform.get_images_filter',
|
||||
**{'return_value': 'Image Files (*.bmp; *.gif)(*.bmp *.gif)'}),\
|
||||
patch('openlp.core.ui.themeform.QtGui.QFileDialog.getOpenFileName',
|
||||
**{'return_value': '/new_path/file.ext'}) as mocked_get_open_file_name,\
|
||||
patch('openlp.core.ui.themeform.translate', **{'return_value': 'Translated String'}),\
|
||||
patch('openlp.core.ui.ThemeForm.set_background_page_values') as mocked_background_page_values:
|
||||
|
||||
instance = ThemeForm(None)
|
||||
mocked_image_file_edit = MagicMock()
|
||||
mocked_image_file_edit.text.return_value = '/original_path/file.ext'
|
||||
instance.image_file_edit = mocked_image_file_edit
|
||||
instance.theme = MagicMock()
|
||||
|
||||
# WHEN: on_image_browse_button is clicked
|
||||
instance.on_image_browse_button_clicked()
|
||||
|
||||
# THEN: The QFileDialog getOpenFileName and set_background_page_values moethods should have been called
|
||||
# with known arguments and theme.background_filename should be set
|
||||
mocked_get_open_file_name.assert_called_once_with(instance, 'Translated String', '/original_path/file.ext',
|
||||
'Image Files (*.bmp; *.gif)(*.bmp *.gif);;All Files (*.*)'
|
||||
)
|
||||
self.assertEqual(instance.theme.background_filename, '/new_path/file.ext',
|
||||
'theme.background_filename should be set to the path that the file dialog returns')
|
||||
mocked_background_page_values.assert_called_once_with()
|
Loading…
Reference in New Issue
Block a user