Example #1
0
 def add_word(self):
     d = QDialog(self)
     d.l = l = QFormLayout(d)
     d.setWindowTitle(_('Add a word'))
     d.w = w = QLineEdit(d)
     w.setPlaceholderText(_('Word to add'))
     l.addRow(_('&Word:'), w)
     d.loc = loc = LanguagesEdit(parent=d)
     l.addRow(_('&Language:'), d.loc)
     loc.lang_codes = [canonicalize_lang(get_lang())]
     d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
     bb.accepted.connect(d.accept), bb.rejected.connect(d.reject)
     l.addRow(bb)
     if d.exec_() != d.Accepted:
         return
     word = unicode(w.text())
     lang = (loc.lang_codes or [canonicalize_lang(get_lang())])[0]
     if not word:
         return
     if (word, lang) not in self.current_dictionary.words:
         dictionaries.add_to_user_dictionary(self.current_dictionary.name, word, DictionaryLocale(lang, None))
         dictionaries.clear_caches()
         self.show_current_dictionary()
         self.dictionaries_changed = True
     idx = self.find_word(word, lang)
     if idx > -1:
         self.words.scrollToItem(self.words.item(idx))
Example #2
0
    def import_words(self):
        d = QDialog(self)
        d.l = l = QFormLayout(d)
        d.setWindowTitle(_('Import list of words'))
        d.w = w = QPlainTextEdit(d)
        l.addRow(QLabel(_('Enter a list of words, one per line')))
        l.addRow(w)
        d.b = b = QPushButton(_('Paste from clipboard'))
        l.addRow(b)
        b.clicked.connect(w.paste)
        d.la = la = QLabel(_('Words in the user dictionary must have an associated language. Choose the language below:'))
        la.setWordWrap(True)
        l.addRow(la)
        d.le = le = LanguagesEdit(d)
        lc = canonicalize_lang(get_lang())
        if lc:
            le.lang_codes = [lc]
        l.addRow(_('&Language:'), le)
        d.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
        l.addRow(bb)
        bb.accepted.connect(d.accept), bb.rejected.connect(d.reject)

        if d.exec_() != d.Accepted:
            return
        lc = le.lang_codes
        if not lc:
            return error_dialog(self, _('Must specify language'), _(
                'You must specify a language to import words'), show=True)
        words = set(filter(None, [x.strip() for x in unicode(w.toPlainText()).splitlines()]))
        lang = lc[0]
        words = {(w, lang) for w in words} - self.current_dictionary.words
        if dictionaries.add_to_user_dictionary(self.current_dictionary.name, words, None):
            dictionaries.clear_caches()
            self.show_current_dictionary()
            self.dictionaries_changed = True
Example #3
0
 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)
Example #4
0
 def _nuke_word(self, dic, word, locale):
     if dic is None:
         dictionaries.ignore_word(word, locale)
     else:
         dictionaries.add_to_user_dictionary(dic, word, locale)
     self.word_ignored.emit(word, locale)
Example #5
0
 def _nuke_word(self, dic, word, locale):
     if dic is None:
         dictionaries.ignore_word(word, locale)
     else:
         dictionaries.add_to_user_dictionary(dic, word, locale)
     self.word_ignored.emit(word, locale)
Example #6
0
 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)