Пример #1
0
 def onKeyPress(self, fact, field, value):
     if findTag("Reading source", parseTags(field.fieldModel.features)):
         dst = None
         for field in fact.fields:
             if findTag("Reading destination",
                        parseTags(field.fieldModel.features)):
                 dst = field
                 break
         if not dst:
             return
         self.lazyInit()
         reading = self.unihan.reading(value)
         fact[dst.name] = reading
Пример #2
0
def onFocusLost(fact, field):
    if field.name != srcField:
        return
    if findTag(cantoneseTag, fact.model.tags):
        type = "cantonese"
    elif findTag(mandarinTag, fact.model.tags):
        type = "mandarin"
    else:
        return
    try:
        if fact[dstField]:
            return
    except:
        return
    fact[dstField] = unihan.toReading(type, field.value)
Пример #3
0
 def onKeyPress(self, fact, field, value):
     if self.kakasi and findTag("Reading source",
                                parseTags(field.fieldModel.features)):
         reading = self.kakasi.toFurigana(value)
         dst = None
         for field in fact.fields:
             if findTag("Reading destination", parseTags(
                 field.fieldModel.features)):
                 dst = field
                 break
         if dst:
             if self.kakasi.formatForKakasi(value) != reading:
                 fact[dst.name] = reading
             else:
                 fact[dst.name] = u""
Пример #4
0
def onFocusLost(fact, field):
    if not field.value:
        return

    if field.name != jField:
        #print "name <> Japanese"
        return

    if not findTag(modelTag, fact.model.tags):
        #print "no JpEnVi"
        return

    if not findTag(offlineTag, fact.model.tags):
        #print "no JpEnVi"
        return
    try:
        if fact[eField] or fact[svField] or fact[vField]:
            return
    except:
        return
    origText = re.sub("\[sound:.+?\]", "", field.value)
    o = origText.encode("utf-8")
    try:
        tmp = dict_hanviet[o]
        tmp = tmp.replace('\n', '<br>')
        fact[svField] = u'<b>%s</b>' % unicode(tmp, "utf-8")
    except:
        fact[svField] = u'. . . . .'

    try:
        tmp = dict_nhatanh[o]
        tmp = tmp.replace('\n', '<br>')
        fact[eField] = u'<b>%s</b>' % unicode(tmp, "utf-8")
    except:
        try:
            tmp = dict_nhatanh_alt[o]
            tmp = tmp.replace('\n', '<br>')
            fact[eField] = u'<b>%s</b>' % unicode(tmp, "utf-8")
        except:
            fact[eField] = u'. . . . .'

    try:
        tmp = dict_nhatviet[o]
        tmp = tmp.replace('\n', '<br>')
        fact[vField] = u'<b>%s</b>' % unicode(tmp, "utf-8")
    except:
        fact[vField] = u'. . . . .'
Пример #5
0
 def hasTags(self, tags):
     tags = parseTags(tags)
     if not self.limitTags:
         return True
     for tag in self.limitTags:
         if findTag(tag, tags):
             return True
     return False
Пример #6
0
 def run(tagstr, cmd, *args):
     "Run CMD on all matching features in DLIST."
     tags = parseTags(tagstr)
     for (name, feature) in FeatureManager.features.items():
         for tag in tags:
             if findTag(tag, feature.tags):
                 feature.run(cmd, *args)
                 break
Пример #7
0
def onFocusLost(fact, field):
    if field.name not in srcFields:
        return
    if findTag(cantoneseTag, fact.model.tags):
        type = "cantonese"
    elif findTag(mandarinTag, fact.model.tags):
        type = "mandarin"
    else:
        return

    idx = srcFields.index(field.name)
    dstField = dstFields[idx]

    try:
        if fact[dstField]:
            return
    except:
        return
    fact[dstField] = unihan.toReading(type, field.value)
Пример #8
0
def onFocusLost(fact, field):
    if field.name not in srcFields:
        return
    if findTag(cantoneseTag, fact.model.tags):
        type = "cantonese"
    elif findTag(mandarinTag, fact.model.tags):
        type = "mandarin"
    else:
        return

    idx = srcFields.index(field.name)
    dstField = dstFields[idx]

    try:
        if fact[dstField] and fact[dstField] != "<br />":
            return
    except:
        return
    fact[dstField] = unihan.toReading(type, field.value)
Пример #9
0
def onFocusLost(fact, field):
    if field.name not in srcFields:
        return
    if not findTag(modelTag, fact.model.tags):
        return
    if field.value == '':
        return
    dstField = dstFields[srcFields.index(field.name)]
    try:
        if fact[dstField]:
            return
    except:
        return
    fact[dstField] = uHeisigLevel(field.value)
Пример #10
0
def onFocusLost_online(fact, field):
    if not field.value:
        return
    if field.name != jField:
        #print "name <> Japanese"
        return

    if not findTag(modelTag, fact.model.tags):
        #print "no JpEnVi"
        return
    if not findTag(onlineTag, fact.model.tags):
        #print "no JpEnVi"
        return
    try:
        if fact[exField]:
            return
    except:
        return
    origText = re.sub("\[sound:.+?\]", "", field.value)
    tmp = u''
    tmp = online_search(origText,'jp_vn')


    fact[exField] = tmp #unicode(tmp, "utf-8")
Пример #11
0
def onFocusLost(fact, field):
    if not kakasi:
        return
    if field.name != srcField:
        return
    if not findTag(modelTag, fact.model.tags):
        return
    try:
        if fact[dstField]:
            return
    except:
        return
    tmp = kakasi.toFurigana(field.value)
    if tmp != field.value:
        fact[dstField] = tmp
def onFocusLost(fact, field):
    modelTag = "Esperanto"

    if not findTag(modelTag, fact.model.tags):
        return

    tmp = re.sub("cx", u"ĉ", field.value)
    tmp = re.sub("gx", u"ĝ", tmp)
    tmp = re.sub("hx", u"ĥ", tmp)
    tmp = re.sub("jx", u"ĵ", tmp)
    tmp = re.sub("sx", u"ŝ", tmp)
    tmp = re.sub("ux", u"ŭ", tmp)
    tmp = re.sub("Cx", u"Ĉ", tmp)
    tmp = re.sub("Gx", u"Ĝ", tmp)
    tmp = re.sub("Hx", u"Ĥ", tmp)
    tmp = re.sub("Jx", u"Ĵ", tmp)
    tmp = re.sub("Sx", u"Ŝ", tmp)
    tmp = re.sub("Ux", u"Ŭ", tmp)
    
    field.value = tmp
    fact[field.name] = tmp 
Пример #13
0
def onFocusLost(fact, field):
    if not kakasi:
        return
    if field.name not in srcFields:
        return
    if not findTag(modelTag, fact.model.tags):
        return

    idx = srcFields.index(field.name)
    dstField = dstFields[idx]

    try:
        if fact[dstField]:
            return
    except:
        return
    origText = re.sub("\[sound:.+?\]", "", field.value)
    if USE_MECAB:
        tmp = mecab.reading(origText)
        fact[dstField] = tmp
    else:
        tmp = kakasi.reading(origText)
        if tmp != origText:
            fact[dstField] = tmp
Пример #14
0
def onFocusLost(fact, field):
    if not kakasi:
        return
    if field.name not in srcFields:
        return
    if not findTag(modelTag, fact.model.tags):
        return

    idx = srcFields.index(field.name)
    dstField = dstFields[idx]

    try:
        if fact[dstField]:
            return
    except:
        return
    origText = re.sub("\[sound:.+?\]", "", field.value)
    if USE_MECAB:
        tmp = mecab.reading(origText)
        fact[dstField] = tmp
    else:
        tmp = kakasi.reading(origText)
        if tmp != origText:
            fact[dstField] = tmp
Пример #15
0
 def hasTag(self, tag):
     return findTag(tag, parseTags(self.allTags()))
Пример #16
0
 def hasTag(self, tag):
     return findTag(tag, parseTags(self.allTags()))
Пример #17
0
 def hasTag(self, tag):
     alltags = parseTags(self.tags + "," +
                         self.fact.tags + "," +
                         self.cardModel.name + "," +
                         self.fact.model.tags)
     return findTag(tag, alltags)