def toggle_ignored(self, row): w = self.word_for_row(row) if w is not None: ignored = dictionaries.is_word_ignored(*w) (dictionaries.unignore_word if ignored else dictionaries.ignore_word)(*w) self.spell_map[w] = dictionaries.recognized(*w) self.update_word(w)
def add_words(self, dicname, rows): words = {self.word_for_row(r) for r in rows} words.discard(None) for w in words: if not dictionaries.add_to_user_dictionary(dicname, *w): dictionaries.remove_from_user_dictionary(dicname, [w]) self.spell_map[w] = dictionaries.recognized(*w) self.update_word(w)
def ignore_words(self, rows): words = {self.word_for_row(r) for r in rows} words.discard(None) for w in words: ignored = dictionaries.is_word_ignored(*w) (dictionaries.unignore_word if ignored else dictionaries.ignore_word)(*w) self.spell_map[w] = dictionaries.recognized(*w) self.update_word(w)
def process_text(state, text, nbsp_format, spell_format, user_data): ans = [] fmt = None if state.is_bold or state.is_italic: fmt = SyntaxTextCharFormat() if state.is_bold: fmt.setFontWeight(QFont.Bold) if state.is_italic: fmt.setFontItalic(True) last = 0 for m in nbsp_pat.finditer(text): ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)]) last = m.end() if not ans: ans = [(len(text), fmt)] 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'): split_ans = [] locale = state.current_lang or dictionaries.default_locale sfmt = SyntaxTextCharFormat(spell_format) if fmt is not None: sfmt.merge(fmt) tpos = 0 for tlen, fmt in ans: if fmt is nbsp_format: split_ans.append((tlen, fmt)) else: ctext = text[tpos:tpos + tlen] ppos = 0 for start, length in split_into_words_and_positions( ctext, lang=locale.langcode): if start > ppos: split_ans.append((start - ppos, fmt)) ppos = start + length recognized = dictionaries.recognized( ctext[start:ppos], locale) if not recognized: wsfmt = SyntaxTextCharFormat(sfmt) wsfmt.setProperty(SPELL_PROPERTY, (ctext[start:ppos], locale)) split_ans.append((length, fmt if recognized else wsfmt)) if ppos < tlen: split_ans.append((tlen - ppos, fmt)) tpos += tlen ans = split_ans return ans
def get_words(self): try: words = get_all_words(current_container(), dictionaries.default_locale) spell_map = {w:dictionaries.recognized(*w) for w in words} except: import traceback traceback.print_exc() words = traceback.format_exc() spell_map = {} if self.cancel: self.end_work() else: self.work_finished.emit(words, spell_map)
def process_text(state, text, nbsp_format, spell_format, user_data): ans = [] fmt = None if state.is_bold or state.is_italic: fmt = SyntaxTextCharFormat() if state.is_bold: fmt.setFontWeight(QFont.Bold) if state.is_italic: fmt.setFontItalic(True) last = 0 for m in nbsp_pat.finditer(text): ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)]) last = m.end() if not ans: ans = [(len(text), fmt)] 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'): split_ans = [] locale = state.current_lang or dictionaries.default_locale sfmt = SyntaxTextCharFormat(spell_format) if fmt is not None: sfmt.merge(fmt) tpos = 0 for tlen, fmt in ans: if fmt is nbsp_format: split_ans.append((tlen, fmt)) else: ctext = text[tpos:tpos+tlen] ppos = 0 for start, length in split_into_words_and_positions(ctext, lang=locale.langcode): if start > ppos: split_ans.append((start - ppos, fmt)) ppos = start + length recognized = dictionaries.recognized(ctext[start:ppos], locale) if not recognized: wsfmt = SyntaxTextCharFormat(sfmt) wsfmt.setProperty(SPELL_PROPERTY, (ctext[start:ppos], locale)) split_ans.append((length, fmt if recognized else wsfmt)) if ppos < tlen: split_ans.append((tlen - ppos, fmt)) tpos += tlen ans = split_ans return ans
def replace_word(self, w, new_word): for location in self.words[w]: location.replace(new_word) if w[0] == new_word: return w new_key = (new_word, w[1]) if new_key in self.words: self.words[new_key] = merge_locations(self.words[new_key], self.words[w]) row = self.row_for_word(w) self.dataChanged.emit(self.index(row, 1), self.index(row, 1)) else: self.words[new_key] = self.words[w] self.spell_map[new_key] = dictionaries.recognized(*new_key) self.update_word(new_key) row = self.row_for_word(w) if row > -1: self.beginRemoveRows(QModelIndex(), row, row) del self.items[row] self.endRemoveRows() return new_key
def remove_word(self, row): w = self.word_for_row(row) if w is not None: if dictionaries.remove_from_user_dictionaries(*w): self.spell_map[w] = dictionaries.recognized(*w) self.update_word(w)
def add_word(self, row, udname): w = self.word_for_row(row) if w is not None: if dictionaries.add_to_user_dictionary(udname, *w): self.spell_map[w] = dictionaries.recognized(*w) self.update_word(w)