Esempio n. 1
0
    def return_data(idx):
        """
        Return a cleaned-up version of the field content.

        Get the text, remove html, and return the field name, the
        clean text, and what we got when we tried to split into kanji
        and kana, when different from the text.
        """
        text = note[field_names[idx]]
        # This is taken from aqt/browser.py.
        text = text.replace(u'<br>', u' ')
        text = text.replace(u'<br />', u' ')
        if strip_interpunct:
            text = text.replace(u'・', u'')
        text = stripHTML(text)
        text = stripSounds(text)
        # Reformat so we have exactly one space between words.
        text = u' '.join(text.split())
        if not text and not get_empty:
            raise ValueError('Source field empty')
        # We pass the reading/plain on to the update dialog. We don't
        # look at the texts any more to decide what to do. So don't
        # set anything to empty here. Rather do the split even if it
        # is pointless.
        base = furigana.kanji(text)
        ruby = furigana.kana(text)
        return field_names[idx], fname, text, base, ruby, readings
Esempio n. 2
0
    def return_data(idx):
        """
        Return a cleaned-up version of the field content.

        Get the text, remove html, and return the field name, the
        clean text, and what we got when we tried to split into kanji
        and kana, when different from the text.
        """
        text = note[field_names[idx]]
        # This is taken from aqt/browser.py.
        text = text.replace(u'<br>', u' ')
        text = text.replace(u'<br />', u' ')
        if strip_interpunct:
            text = text.replace(u'・', u'')
        text = stripHTML(text)
        text = stripSounds(text)
        # Reformat so we have exactly one space between words.
        text = u' '.join(text.split())
        if not text and not get_empty:
            raise ValueError('Source field empty')
        # We pass the reading/plain on to the update dialog. We don't
        # look at the texts any more to decide what to do. So don't
        # set anything to empty here. Rather do the split even if it
        # is pointless.
        base = furigana.kanji(text)
        ruby = furigana.kana(text)
        return field_names[idx], fname, text, base, ruby, readings
Esempio n. 3
0
def selectForvoSearchPhrase(n):
    exprName = None
    srcFields = config["patternSourceFields"]

    # Double loop because srcFields is meant to be ordered by priority
    for fieldCandidate in srcFields:
        for idx, name in enumerate(mw.col.models.fieldNames(n.model())):
            if name == fieldCandidate:
                exprName = name
                exprIdx = idx
                break

    if not exprName:
        return None

    phrase = mw.col.media.strip(n[exprName])

    # TODO: Are we sure that this always works?
    return furigana.kanji(phrase)
Esempio n. 4
0
 def download_files(self, field_data):
     """
     Get text from GoogleTTS.
     """
     self.downloads_list = []
     if field_data.split:
         return
     if self.language.lower().startswith('zh'):
         if not get_chinese:
             return
         word = furigana.kanji(field_data.word)
     else:
         word = field_data.word
     self.maybe_get_icon()
     if not field_data.word:
         raise ValueError('Nothing to download')
     word_path = self.get_tempfile_from_url(self.build_url(word))
     entry = DownloadEntry(field_data, word_path, dict(Source='GoogleTTS'),
                           self.site_icon)
     entry.action = Action.Delete
     # Google is a robot voice. The pronunciations are usually
     # bad. Default to not keeping them.
     self.downloads_list.append(entry)
Esempio n. 5
0
 def download_files(self, field_data):
     """
     Get text from GoogleTTS.
     """
     self.downloads_list = []
     if field_data.split:
         return
     if self.language.lower().startswith('zh'):
         if not get_chinese:
             return
         word = furigana.kanji(field_data.word)
     else:
         word = field_data.word
     self.maybe_get_icon()
     if not field_data.word:
         raise ValueError('Nothing to download')
     word_path = self.get_tempfile_from_url(self.build_url(word))
     entry = DownloadEntry(
         field_data, word_path, dict(Source='GoogleTTS'), self.site_icon)
     entry.action = Action.Delete
     # Google is a robot voice. The pronunciations are usually
     # bad. Default to not keeping them.
     self.downloads_list.append(entry)
Esempio n. 6
0
 def __init__(self, w_field, a_field, word):
     FieldData.__init__(self, w_field, a_field, word)
     self.kanji = furigana.kanji(self.word)
     self.kana = furigana.kana(self.word)
Esempio n. 7
0
 def __init__(self, w_field, a_field, word):
     FieldData.__init__(self, w_field, a_field, word)
     self.kanji = furigana.kanji(self.word)
     self.kana = furigana.kana(self.word)