do not try to load en_US when the default dictionary could not be loaded to fix bug #747206

Fixes: https://launchpad.net/bugs/747206
This commit is contained in:
Andreas Preikschat 2011-04-07 19:34:49 +02:00
parent 3a86148b5d
commit e553cd959b

View File

@ -23,7 +23,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 # # with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
import logging
import re import re
try: try:
import enchant import enchant
@ -38,6 +38,8 @@ except ImportError:
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import translate, DisplayTags from openlp.core.lib import translate, DisplayTags
log = logging.getLogger(__name__)
class SpellTextEdit(QtGui.QPlainTextEdit): class SpellTextEdit(QtGui.QPlainTextEdit):
""" """
Spell checking widget based on QPlanTextEdit. Spell checking widget based on QPlanTextEdit.
@ -48,10 +50,10 @@ class SpellTextEdit(QtGui.QPlainTextEdit):
if ENCHANT_AVAILABLE: if ENCHANT_AVAILABLE:
try: try:
self.dictionary = enchant.Dict() self.dictionary = enchant.Dict()
self.highlighter = Highlighter(self.document())
self.highlighter.spellingDictionary = self.dictionary
except DictNotFoundError: except DictNotFoundError:
self.dictionary = enchant.Dict(u'en_US') log.debug(u'Could not load default dictionary')
self.highlighter = Highlighter(self.document())
self.highlighter.spellingDictionary = self.dictionary
def mousePressEvent(self, event): def mousePressEvent(self, event):
""" """
@ -78,7 +80,8 @@ class SpellTextEdit(QtGui.QPlainTextEdit):
self.setTextCursor(cursor) self.setTextCursor(cursor)
# Check if the selected word is misspelled and offer spelling # Check if the selected word is misspelled and offer spelling
# suggestions if it is. # suggestions if it is.
if ENCHANT_AVAILABLE and self.textCursor().hasSelection(): if ENCHANT_AVAILABLE and hasattr(self, u'dictionary') and \
self.textCursor().hasSelection():
text = unicode(self.textCursor().selectedText()) text = unicode(self.textCursor().selectedText())
if not self.dictionary.check(text): if not self.dictionary.check(text):
spell_menu = QtGui.QMenu(translate('OpenLP.SpellTextEdit', spell_menu = QtGui.QMenu(translate('OpenLP.SpellTextEdit',