Example #1
0
    def _on_context_menu(self, point=None):
        selection = normalize(unicode(self.textCursor().selectedText()))
        word = self.highlight.get_word_of_position(self.cursorForPosition(point).position())
        if word is None:
            if not self.textCursor().hasSelection():
                return

            # highlight selected word
            from NewWordEditor import create_new_word

            nw = create_new_word(self, selection)
            if nw is None:
                return

            nw.article_id = self.article_id
            s = get_session()
            s.add(nw)
            s.commit()

            cursor = self.textCursor()
            cursor.clearSelection()
            self.setTextCursor(cursor)

        else:
            s = get_session()
            s.delete(ArticleNewWord.find_by_article_word(s, self.article_id, word))
            s.commit()

        self._refresh()
Example #2
0
    def update_words(self, article_id=None):
        self.clear()

        if article_id is None:
            article_id = self.article_id

        if article_id is None:
            return

        self.article_id = article_id
        s = get_session()
        self.new_words = ArticleNewWord.all_article_new_word(s, article_id)
        for nw in self.new_words:
            self.addItem(WordItem(nw))
        self.sortItems()
Example #3
0
    def del_word(self, window, article_id, word_content):
        word_content = unicode(word_content)
        msg = 'Delete "%s"?' % word_content
        btn = QMessageBox.question(window, 'Delete word', msg, QMessageBox.Yes | QMessageBox.No)
        if btn != QMessageBox.Yes:
            return

        from ljn.Repository import get_session
        s = get_session()
        anw = ArticleNewWord.find_by_article_word(s, article_id, word_content)
        if anw is not None:
            s.delete(anw)
            s.commit()

            self._update_word_list(window, article_id)