Another small speedup

This commit is contained in:
Kovid Goyal 2014-06-23 15:58:45 +05:30
parent cf3c80598e
commit 8d1433ae78
3 changed files with 12 additions and 2 deletions

View File

@ -102,3 +102,5 @@ def set_book_locale(lang):
raise ValueError('') raise ValueError('')
except ValueError: except ValueError:
dictionaries.default_locale = dictionaries.ui_locale dictionaries.default_locale = dictionaries.ui_locale
from calibre.gui2.tweak_book.editor.syntax.html import refresh_spell_check_status
refresh_spell_check_status()

View File

@ -123,9 +123,9 @@ class Boss(QObject):
self.gui.manage_fonts.subset_all_fonts.connect(self.manage_fonts_subset) self.gui.manage_fonts.subset_all_fonts.connect(self.manage_fonts_subset)
def preferences(self): def preferences(self):
orig_spell = tprefs['inline_spell_check']
p = Preferences(self.gui) p = Preferences(self.gui)
ret = p.exec_() ret = p.exec_()
orig_spell = tprefs['inline_spell_check']
if p.dictionaries_changed: if p.dictionaries_changed:
dictionaries.clear_caches() dictionaries.clear_caches()
dictionaries.initialize(force=True) # Reread user dictionaries dictionaries.initialize(force=True) # Reread user dictionaries
@ -141,6 +141,8 @@ class Boss(QObject):
for ed in editors.itervalues(): for ed in editors.itervalues():
ed.apply_settings(dictionaries_changed=p.dictionaries_changed) ed.apply_settings(dictionaries_changed=p.dictionaries_changed)
if orig_spell != tprefs['inline_spell_check']: 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(): for ed in editors.itervalues():
try: try:
ed.editor.highlighter.rehighlight() ed.editor.highlighter.rehighlight()

View File

@ -53,6 +53,12 @@ TagStart = namedtuple('TagStart', 'offset prefix name closing is_start')
TagEnd = namedtuple('TagEnd', 'offset self_closing is_start') TagEnd = namedtuple('TagEnd', 'offset self_closing is_start')
Attr = namedtuple('Attr', 'offset type data') 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): class Tag(object):
__slots__ = ('name', 'bold', 'italic', 'lang') __slots__ = ('name', 'bold', 'italic', 'lang')
@ -263,7 +269,7 @@ def process_text(state, text, nbsp_format, spell_format, user_data):
elif last < len(text): elif last < len(text):
ans.append((len(text) - last, fmt)) 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 = [] split_ans = []
locale = state.current_lang or dictionaries.default_locale locale = state.current_lang or dictionaries.default_locale
sfmt = QTextCharFormat(spell_format) sfmt = QTextCharFormat(spell_format)