Jon Tibble has proposed merging lp:~meths/openlp/testing into lp:openlp. Requested reviews: OpenLP Core (openlp-core)
For more details, see: https://code.launchpad.net/~meths/openlp/testing/+merge/46367 Refactor error messages. Although there is a small coding benefit to this the bigger benefit is smaller/deduplicated translation files. -- https://code.launchpad.net/~meths/openlp/testing/+merge/46367 Your team OpenLP Core is requested to review the proposed merge of lp:~meths/openlp/testing into lp:openlp.
=== modified file 'openlp/core/ui/__init__.py' --- openlp/core/ui/__init__.py 2011-01-10 10:21:39 +0000 +++ openlp/core/ui/__init__.py 2011-01-15 01:27:34 +0000 @@ -26,6 +26,9 @@ """ The :mod:`ui` module provides the core user interface for OpenLP """ +from PyQt4 import QtGui + +from openlp.core.lib import translate class HideMode(object): """ @@ -48,6 +51,28 @@ Theme = 2 Screen = 3 + +def criticalErrorMessageBox(parent, message, question=False): + """ + Provides a standard critical message box for errors that OpenLP displays + to users. + + ``parent`` + The parent UI element to attach the dialog to. + + ``message`` + The message to display to the user. + + ``question`` + Should this message box question the user. + """ + error = translate('OpenLP.Ui', 'Error') + if question: + return QtGui.QMessageBox.critical(parent, error, message, + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) + return QtGui.QMessageBox.critical(parent, error, message) + from themeform import ThemeForm from filerenameform import FileRenameForm from maindisplay import MainDisplay @@ -68,6 +93,6 @@ from servicemanager import ServiceManager from thememanager import ThemeManager -__all__ = ['SplashScreen', 'AboutForm', 'SettingsForm', - 'MainDisplay', 'SlideController', 'ServiceManager', 'ThemeManager', - 'MediaDockManager', 'ServiceItemEditForm'] +__all__ = ['criticalErrorMessageBox', 'SplashScreen', 'AboutForm', + 'SettingsForm', 'MainDisplay', 'SlideController', 'ServiceManager', + 'ThemeManager', 'MediaDockManager', 'ServiceItemEditForm'] === modified file 'openlp/core/ui/servicemanager.py' --- openlp/core/ui/servicemanager.py 2011-01-13 01:14:38 +0000 +++ openlp/core/ui/servicemanager.py 2011-01-15 01:27:34 +0000 @@ -36,7 +36,8 @@ from openlp.core.lib import OpenLPToolbar, ServiceItem, context_menu_action, \ Receiver, build_icon, ItemCapabilities, SettingsManager, translate, \ ThemeLevel -from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm +from openlp.core.ui import criticalErrorMessageBox, ServiceNoteForm, \ + ServiceItemEditForm from openlp.core.utils import AppLocation, file_is_unicode, split_filename class ServiceManagerList(QtGui.QTreeWidget): @@ -486,8 +487,7 @@ for file in zip.namelist(): ucsfile = file_is_unicode(file) if not ucsfile: - QtGui.QMessageBox.critical( - self, translate('OpenLP.ServiceManager', 'Error'), + criticalErrorMessageBox(self, translate('OpenLP.ServiceManager', 'File is not a valid service.\n' 'The content encoding is not UTF-8.')) @@ -521,10 +521,8 @@ except (IOError, OSError): log.exception(u'Failed to remove osd file') else: - QtGui.QMessageBox.critical( - self, translate('OpenLP.ServiceManager', 'Error'), - translate('OpenLP.ServiceManager', - 'File is not a valid service.')) + criticalErrorMessageBox(self, translate('OpenLP.ServiceManager', + 'File is not a valid service.')) log.exception(u'File contains no service data') except (IOError, NameError): log.exception(u'Problem loading a service file') === modified file 'openlp/core/ui/thememanager.py' --- openlp/core/ui/thememanager.py 2011-01-13 01:14:38 +0000 +++ openlp/core/ui/thememanager.py 2011-01-15 01:27:34 +0000 @@ -32,7 +32,7 @@ from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui -from openlp.core.ui import FileRenameForm, ThemeForm +from openlp.core.ui import criticalErrorMessageBox, FileRenameForm, ThemeForm from openlp.core.theme import Theme from openlp.core.lib import OpenLPToolbar, ThemeXML, get_text_file_string, \ build_icon, Receiver, SettingsManager, translate, check_item_selected, \ @@ -359,9 +359,7 @@ """ item = self.themeListWidget.currentItem() if item is None: - QtGui.QMessageBox.critical(self, - translate('OpenLP.ThemeManager', 'Error'), - translate('OpenLP.ThemeManager', + criticalErrorMessageBox(self, translate('OpenLP.ThemeManager', 'You have not selected a theme.')) return theme = unicode(item.data(QtCore.Qt.UserRole).toString()) @@ -498,11 +496,9 @@ for file in zip.namelist(): ucsfile = file_is_unicode(file) if not ucsfile: - QtGui.QMessageBox.critical( - self, translate('OpenLP.ThemeManager', 'Error'), - translate('OpenLP.ThemeManager', - 'File is not a valid theme.\n' - 'The content encoding is not UTF-8.')) + criticalErrorMessageBox(self, + translate('OpenLP.ThemeManager', 'File is not a valid ' + 'theme.\nThe content encoding is not UTF-8.')) continue osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile)) theme_dir = None @@ -700,10 +696,8 @@ return False # should be the same unless default if theme != unicode(item.data(QtCore.Qt.UserRole).toString()): - QtGui.QMessageBox.critical(self, - translate('OpenLP.ThemeManager', 'Error'), - translate('OpenLP.ThemeManager', - 'You are unable to delete the default theme.')) + criticalErrorMessageBox(self, translate('OpenLP.ThemeManager', + 'You are unable to delete the default theme.')) return False # check for use in the system else where. if testPlugin: === modified file 'openlp/plugins/bibles/lib/mediaitem.py' --- openlp/plugins/bibles/lib/mediaitem.py 2011-01-13 17:55:29 +0000 +++ openlp/plugins/bibles/lib/mediaitem.py 2011-01-15 01:27:34 +0000 @@ -534,13 +534,11 @@ if item_second_bible and second_bible or not item_second_bible and \ not second_bible: self.displayResults(bible, second_bible) - elif QtGui.QMessageBox.critical(self, - translate('BiblePlugin.MediaItem', 'Error'), + elif criticalErrorMessageBox(self, translate('BiblePlugin.MediaItem', 'You cannot combine single ' 'and second bible verses. Do you want to delete your search ' 'results and start a new search?'), - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | - QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes: + True) == QtGui.QMessageBox.Yes: self.listView.clear() self.displayResults(bible, second_bible) else: @@ -584,13 +582,11 @@ if item_second_bible and second_bible or not item_second_bible and \ not second_bible: self.displayResults(bible, second_bible) - elif QtGui.QMessageBox.critical(self, - translate('BiblePlugin.MediaItem', 'Error'), + elif criticalErrorMessageBox(self, translate('BiblePlugin.MediaItem', 'You cannot combine single ' 'and second bible verses. Do you want to delete your search ' 'results and start a new search?'), - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | - QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes: + True) == QtGui.QMessageBox.Yes: self.listView.clear() self.displayResults(bible, second_bible) elif self.search_results: === modified file 'openlp/plugins/custom/forms/editcustomform.py' --- openlp/plugins/custom/forms/editcustomform.py 2010-12-26 11:04:47 +0000 +++ openlp/plugins/custom/forms/editcustomform.py 2011-01-15 01:27:34 +0000 @@ -29,6 +29,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import Receiver, translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.custom.lib import CustomXMLBuilder, CustomXMLParser from openlp.plugins.custom.lib.db import CustomSlide from editcustomdialog import Ui_CustomEditDialog @@ -151,8 +152,7 @@ """ valid, message = self._validate() if not valid: - QtGui.QMessageBox.critical(self, - translate('CustomPlugin.EditCustomForm', 'Error'), message) + criticalErrorMessageBox(self, message) return False sxml = CustomXMLBuilder() sxml.new_document() @@ -265,4 +265,4 @@ if self.slideListView.count() == 0: return False, translate('CustomPlugin.EditCustomForm', 'You need to add at least one slide') - return True, u'' \ No newline at end of file + return True, u'' === modified file 'openlp/plugins/songs/forms/authorsform.py' --- openlp/plugins/songs/forms/authorsform.py 2011-01-04 21:06:50 +0000 +++ openlp/plugins/songs/forms/authorsform.py 2011-01-15 01:27:34 +0000 @@ -27,6 +27,7 @@ from PyQt4 import QtGui, QtCore from openlp.core.lib import translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.songs.forms.authorsdialog import Ui_AuthorsDialog class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): @@ -79,28 +80,21 @@ def accept(self): if not self.firstNameEdit.text(): - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.AuthorsForm', 'Error'), - translate('SongsPlugin.AuthorsForm', - 'You need to type in the first name of the author.')) + criticalErrorMessageBox(self, translate('SongsPlugin.AuthorsForm', + 'You need to type in the first name of the author.')) self.firstNameEdit.setFocus() return False elif not self.lastNameEdit.text(): - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.AuthorsForm', 'Error'), - translate('SongsPlugin.AuthorsForm', - 'You need to type in the last name of the author.')) + criticalErrorMessageBox(self, translate('SongsPlugin.AuthorsForm', + 'You need to type in the last name of the author.')) self.lastNameEdit.setFocus() return False elif not self.displayEdit.text(): - if QtGui.QMessageBox.critical( - self, translate('SongsPlugin.AuthorsForm', 'Error'), - translate('SongsPlugin.AuthorsForm', - 'You have not set a display name for the ' - 'author, combine the first and last names?'), - QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) - ) == QtGui.QMessageBox.Yes: + if criticalErrorMessageBox(self, + translate('SongsPlugin.AuthorsForm', + 'You have not set a display name for the ' + 'author, combine the first and last names?'), + True) == QtGui.QMessageBox.Yes: self.displayEdit.setText(self.firstNameEdit.text() + \ u' ' + self.lastNameEdit.text()) return QtGui.QDialog.accept(self) === modified file 'openlp/plugins/songs/forms/editsongform.py' --- openlp/plugins/songs/forms/editsongform.py 2011-01-09 16:52:31 +0000 +++ openlp/plugins/songs/forms/editsongform.py 2011-01-15 01:27:34 +0000 @@ -30,6 +30,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import Receiver, translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.songs.forms import EditVerseForm from openlp.plugins.songs.lib import SongXML, VerseType from openlp.plugins.songs.lib.db import Book, Song, Author, Topic @@ -346,8 +347,7 @@ author = self.manager.get_object(Author, item_id) if self.authorsListView.findItems(unicode(author.display_name), QtCore.Qt.MatchExactly): - QtGui.QMessageBox.warning(self, - translate('SongsPlugin.EditSongForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', 'This author is ' 'already in the list.')) else: @@ -400,8 +400,7 @@ topic = self.manager.get_object(Topic, item_id) if self.topicsListView.findItems(unicode(topic.name), QtCore.Qt.MatchExactly): - QtGui.QMessageBox.warning(self, - translate('SongsPlugin.EditSongForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', 'This topic is ' 'already in the list.')) else: @@ -533,25 +532,19 @@ if len(self.titleEdit.displayText()) == 0: self.songTabWidget.setCurrentIndex(0) self.titleEdit.setFocus() - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.EditSongForm', 'Error'), - translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', 'You need to type in a song title.')) return False if self.verseListWidget.rowCount() == 0: self.songTabWidget.setCurrentIndex(0) self.verseListWidget.setFocus() - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.EditSongForm', 'Error'), - translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', 'You need to type in at least one verse.')) return False if self.authorsListView.count() == 0: self.songTabWidget.setCurrentIndex(1) self.authorsListView.setFocus() - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.EditSongForm', 'Warning'), - translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', 'You need to have an author for this song.')) return False if self.song.verse_order: @@ -578,8 +571,7 @@ valid = verses.pop(0) for verse in verses: valid = valid + u', ' + verse - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.EditSongForm', 'Error'), + criticalErrorMessageBox(self, unicode(translate('SongsPlugin.EditSongForm', 'The verse order is invalid. There is no verse ' 'corresponding to %s. Valid entries are %s.')) % \ === modified file 'openlp/plugins/songs/forms/editverseform.py' --- openlp/plugins/songs/forms/editverseform.py 2011-01-04 21:06:50 +0000 +++ openlp/plugins/songs/forms/editverseform.py 2011-01-15 01:27:34 +0000 @@ -29,6 +29,7 @@ from PyQt4 import QtCore, QtGui +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.songs.lib import VerseType, translate from editversedialog import Ui_EditVerseDialog @@ -167,9 +168,7 @@ else: value = self.getVerse()[0].split(u'\n')[1] if len(value) == 0: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.EditSongForm', 'Error'), - translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', 'You need to type some text in to the verse.')) return False QtGui.QDialog.accept(self) === modified file 'openlp/plugins/songs/forms/songbookform.py' --- openlp/plugins/songs/forms/songbookform.py 2011-01-04 21:06:50 +0000 +++ openlp/plugins/songs/forms/songbookform.py 2011-01-15 01:27:34 +0000 @@ -27,6 +27,7 @@ from PyQt4 import QtGui from openlp.core.lib import translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.songs.forms.songbookdialog import Ui_SongBookDialog class SongBookForm(QtGui.QDialog, Ui_SongBookDialog): @@ -49,10 +50,8 @@ def accept(self): if not self.nameEdit.text(): - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.SongBookForm', 'Error'), - translate('SongsPlugin.SongBookForm', - 'You need to type in a name for the book.')) + criticalErrorMessageBox(self, translate('SongsPlugin.SongBookForm', + 'You need to type in a name for the book.')) self.nameEdit.setFocus() return False else: === modified file 'openlp/plugins/songs/forms/songmaintenanceform.py' --- openlp/plugins/songs/forms/songmaintenanceform.py 2011-01-05 17:17:22 +0000 +++ openlp/plugins/songs/forms/songmaintenanceform.py 2011-01-15 01:27:34 +0000 @@ -23,15 +23,19 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +import logging from PyQt4 import QtGui, QtCore from sqlalchemy.sql import and_ from openlp.core.lib import Receiver, translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.songs.forms import AuthorsForm, TopicsForm, SongBookForm from openlp.plugins.songs.lib.db import Author, Book, Topic, Song from songmaintenancedialog import Ui_SongMaintenanceDialog +log = logging.getLogger(__name__) + class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): """ Class documentation goes here. @@ -229,13 +233,11 @@ if self.manager.save_object(author): self.resetAuthors() else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not add your author.')) else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'This author already exists.')) @@ -246,13 +248,11 @@ if self.manager.save_object(topic): self.resetTopics() else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not add your topic.')) else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'This topic already exists.')) @@ -264,13 +264,11 @@ if self.manager.save_object(book): self.resetBooks() else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not add your book.')) else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'This book already exists.')) @@ -298,20 +296,15 @@ self.resetAuthors() Receiver.send_message(u'songs_load_list') else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', - 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) - elif QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + elif criticalErrorMessageBox(self, unicode(translate('SongsPlugin.SongMaintenanceForm', 'The author %s already exists. Would you like to make songs' ' with author %s use the existing author %s?')) % (author.display_name, temp_display_name, - author.display_name), QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == \ - QtGui.QMessageBox.Yes: + author.display_name), True) == QtGui.QMessageBox.Yes: self.mergeAuthors(author) self.resetAuthors() Receiver.send_message(u'songs_load_list') @@ -321,8 +314,7 @@ author.first_name = temp_first_name author.last_name = temp_last_name author.display_name = temp_display_name - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not save your modified author, because the ' 'author already exists.')) @@ -340,26 +332,20 @@ if self.manager.save_object(topic): self.resetTopics() else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', - 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) - elif QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + elif criticalErrorMessageBox(self, unicode(translate('SongsPlugin.SongMaintenanceForm', 'The topic %s already exists. Would you like to make songs ' 'with topic %s use the existing topic %s?')) % (topic.name, - temp_name, topic.name), QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == \ - QtGui.QMessageBox.Yes: + temp_name, topic.name), True) == QtGui.QMessageBox.Yes: self.mergeTopics(topic) self.resetTopics() else: # We restore the topics's old name. topic.name = temp_name - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not save your modified topic, because it ' 'already exists.')) @@ -383,19 +369,14 @@ if self.manager.save_object(book): self.resetBooks() else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', - 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) - elif QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + elif criticalErrorMessageBox(self, unicode(translate('SongsPlugin.SongMaintenanceForm', 'The book %s already exists. Would you like to make songs ' 'with book %s use the existing book %s?')) % (book.name, - temp_name, book.name), QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == \ - QtGui.QMessageBox.Yes: + temp_name, book.name), True) == QtGui.QMessageBox.Yes: self.mergeBooks(book) self.resetBooks() else: === modified file 'openlp/plugins/songs/forms/topicsform.py' --- openlp/plugins/songs/forms/topicsform.py 2011-01-04 21:06:50 +0000 +++ openlp/plugins/songs/forms/topicsform.py 2011-01-15 01:27:34 +0000 @@ -27,6 +27,7 @@ from PyQt4 import QtGui from openlp.core.lib import translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.songs.forms.topicsdialog import Ui_TopicsDialog class TopicsForm(QtGui.QDialog, Ui_TopicsDialog): @@ -48,10 +49,8 @@ def accept(self): if not self.nameEdit.text(): - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.TopicsForm', 'Error'), - translate('SongsPlugin.TopicsForm', - 'You need to type in a topic name.')) + criticalErrorMessageBox(self, translate('SongsPlugin.TopicsForm', + 'You need to type in a topic name.')) self.nameEdit.setFocus() return False else:
_______________________________________________ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp