in en/Lightproof.py [0:0]
def doProofreading(self, nDocId, rText, rLocale, nStartOfSentencePos, \
nSuggestedSentenceEndPos, rProperties):
aRes = uno.createUnoStruct( "com.sun.star.linguistic2.ProofreadingResult" )
aRes.aDocumentIdentifier = nDocId
aRes.aText = rText
aRes.aLocale = rLocale
aRes.nStartOfSentencePosition = nStartOfSentencePos
aRes.nStartOfNextSentencePosition = nSuggestedSentenceEndPos
aRes.aProperties = ()
aRes.xProofreader = self
aRes.aErrors = ()
# PATCH FOR LO 4
# Fix for http://nabble.documentfoundation.org/Grammar-checker-Undocumented-change-in-the-API-for-LO-4-td4030639.html
if nStartOfSentencePos != 0:
return aRes
aRes.nStartOfNextSentencePosition = len(rText)
if len(rProperties) > 0 and rProperties[0].Name == "Update":
try:
import lightproof_compile_en
try:
code = lightproof_compile_en.c(rProperties[0].Value, rLocale.Language, True)
except Exception as e:
aRes.aText, aRes.nStartOfSentencePosition = e
return aRes
path = lightproof_impl_en.get_path()
f = open(path.replace("_impl", ""), "w")
f.write("dic = %s" % code["rules"])
f.close()
if pkg in lightproof_impl_en.langrule:
mo = lightproof_impl_en.langrule[pkg]
reload(mo)
lightproof_impl_en.compile_rules(mo.dic)
lightproof_impl_en.langrule[pkg] = mo
if "code" in code:
f = open(path, "r")
ft = f.read()
f.close()
f = open(path, "w")
f.write(ft[:ft.find("# [code]") + 8] + "\n" + code["code"])
f.close()
try:
reload(lightproof_impl_en)
except Exception as e:
aRes.aText = e.args[0]
if e.args[1][3] == "": # "expected an indented block" (end of file)
aRes.nStartOfSentencePosition = len(rText.split("\n"))
else:
aRes.nStartOfSentencePosition = rText.split("\n").index(e.args[1][3][:-1]) + 1
return aRes
aRes.aText = ""
return aRes
except:
if 'PYUNO_LOGLEVEL' in os.environ:
print(traceback.format_exc())
l = rText[aRes.nStartOfNextSentencePosition:aRes.nStartOfNextSentencePosition+1]
while l == " ":
aRes.nStartOfNextSentencePosition = aRes.nStartOfNextSentencePosition + 1
l = rText[aRes.nStartOfNextSentencePosition:aRes.nStartOfNextSentencePosition+1]
if aRes.nStartOfNextSentencePosition == nSuggestedSentenceEndPos and l!="":
aRes.nStartOfNextSentencePosition = nSuggestedSentenceEndPos + 1
aRes.nBehindEndOfSentencePosition = aRes.nStartOfNextSentencePosition
try:
aRes.aErrors = lightproof_impl_en.proofread( nDocId, rText, rLocale, \
nStartOfSentencePos, aRes.nBehindEndOfSentencePosition, rProperties)
except Exception as e:
if len(rProperties) > 0 and rProperties[0].Name == "Debug" and len(e.args) == 2:
aRes.aText, aRes.nStartOfSentencePosition = e
else:
if 'PYUNO_LOGLEVEL' in os.environ:
print(traceback.format_exc())
return aRes