diff --git a/src/calibre/gui2/tweak_book/__init__.py b/src/calibre/gui2/tweak_book/__init__.py index a4d041a9ec..8c78d907ab 100644 --- a/src/calibre/gui2/tweak_book/__init__.py +++ b/src/calibre/gui2/tweak_book/__init__.py @@ -102,3 +102,5 @@ def set_book_locale(lang): raise ValueError('') except ValueError: dictionaries.default_locale = dictionaries.ui_locale + from calibre.gui2.tweak_book.editor.syntax.html import refresh_spell_check_status + refresh_spell_check_status() diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index b71ba9f4ce..fa9e8c05f6 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -123,9 +123,9 @@ class Boss(QObject): self.gui.manage_fonts.subset_all_fonts.connect(self.manage_fonts_subset) def preferences(self): + orig_spell = tprefs['inline_spell_check'] p = Preferences(self.gui) ret = p.exec_() - orig_spell = tprefs['inline_spell_check'] if p.dictionaries_changed: dictionaries.clear_caches() dictionaries.initialize(force=True) # Reread user dictionaries @@ -141,6 +141,8 @@ class Boss(QObject): for ed in editors.itervalues(): ed.apply_settings(dictionaries_changed=p.dictionaries_changed) if orig_spell != tprefs['inline_spell_check']: + from calibre.gui2.tweak_book.editor.syntax.html import refresh_spell_check_status + refresh_spell_check_status() for ed in editors.itervalues(): try: ed.editor.highlighter.rehighlight() diff --git a/src/calibre/gui2/tweak_book/editor/syntax/html.py b/src/calibre/gui2/tweak_book/editor/syntax/html.py index 13a7f91e96..9fe89f0808 100644 --- a/src/calibre/gui2/tweak_book/editor/syntax/html.py +++ b/src/calibre/gui2/tweak_book/editor/syntax/html.py @@ -53,6 +53,12 @@ TagStart = namedtuple('TagStart', 'offset prefix name closing is_start') TagEnd = namedtuple('TagEnd', 'offset self_closing is_start') Attr = namedtuple('Attr', 'offset type data') +do_spell_check = False + +def refresh_spell_check_status(): + global do_spell_check + do_spell_check = tprefs['inline_spell_check'] and hasattr(dictionaries, 'active_user_dictionaries') + class Tag(object): __slots__ = ('name', 'bold', 'italic', 'lang') @@ -263,7 +269,7 @@ def process_text(state, text, nbsp_format, spell_format, user_data): elif last < len(text): ans.append((len(text) - last, fmt)) - if tprefs['inline_spell_check'] and state.tags and user_data.tag_ok_for_spell(state.tags[-1].name) and hasattr(dictionaries, 'active_user_dictionaries'): + if do_spell_check and state.tags and user_data.tag_ok_for_spell(state.tags[-1].name): split_ans = [] locale = state.current_lang or dictionaries.default_locale sfmt = QTextCharFormat(spell_format)