| 
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2728
29
3031
32
33
34
35
36
3738
39
40
41
4243
44
45
46
47
48
49
50 | 
from com.sun.star.linguistic2 import XProofreader, XSupportedLocales
from com.sun.star.linguistic2 import ProofreadingResult
from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName
from com.sun.star.lang import Locale
import helpers
import grammalecte.${lang} as gce
#import lightproof_handler_${implname} as opt_handler
import Options
class Grammalecte (unohelper.Base, XProofreader, XServiceInfo, XServiceName, XServiceDisplayName, XSupportedLocales):
    def __init__ (self, ctx, *args):
        self.ctx = ctx
        self.ServiceName = "com.sun.star.linguistic2.Proofreader"        self.ImplementationName = "org.openoffice.comp.pyuno.Lightproof." + gce.pkg
self.SupportedServiceNames = (self.ServiceName, )
        self.locales = []        for i in gce.locales:
            l = gce.locales[i]
self.locales.append(Locale(l[0], l[1], l[2]))
        self.locales = tuple(self.locales)
        # debug
        #helpers.startConsole()
        # init        gce.load("Writer", "nInt")
# GC options
        #xContext = uno.getComponentContext()
        #opt_handler.load(xContext)
        dOpt = Options.loadOptions("${lang}")        gc# dictionaries options
        self.loadUserDictionaries()
        # underlining options
        self.setWriterUnderliningStyle()
        # store for results of big paragraphs
        self.dResult = {}
        self.nMaxRes = 1500e.setOptions(dOpt) | 
|
|
|
|
|
|
 | 
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 | 
from com.sun.star.linguistic2 import XProofreader, XSupportedLocales
from com.sun.star.linguistic2 import ProofreadingResult
from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName
from com.sun.star.lang import Locale
import helpers
import grammalecte.${lang} as gc_engine
#import lightproof_handler_${implname} as opt_handler
import Options
class Grammalecte (unohelper.Base, XProofreader, XServiceInfo, XServiceName, XServiceDisplayName, XSupportedLocales):
    def __init__ (self, ctx, *args):
        self.ctx = ctx
        self.ServiceName = "com.sun.star.linguistic2.Proofreader"
        self.ImplementationName = "org.openoffice.comp.pyuno.Lightproof." + gc_engine.pkg
        self.SupportedServiceNames = (self.ServiceName, )
        self.locales = []
        for i in gc_engine.locales:
            l = gc_engine.locales[i]
            self.locales.append(Locale(l[0], l[1], l[2]))
        self.locales = tuple(self.locales)
        # debug
        #helpers.startConsole()
        # init
        gc_engine.load("Writer", "nInt")
        # GC options
        #xContext = uno.getComponentContext()
        #opt_handler.load(xContext)
        dOpt = Options.loadOptions("${lang}")
        gc_engine.gc_options.setOptions(dOpt)
        # dictionaries options
        self.loadUserDictionaries()
        # underlining options
        self.setWriterUnderliningStyle()
        # store for results of big paragraphs
        self.dResult = {}
        self.nMaxRes = 1500
 | 
| 
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128129
130
131132
133
134
135136
137
138
139140
141
142
143
144
145
146
147
148149
150
151
152
153
154
155
156
157
158
159160
161
162
163
164
165166
167
168169
 | 
            if nHashedVal in self.dResult:
                return self.dResult[nHashedVal]
        # WORKAROUND ->>>
        xRes.nBehindEndOfSentencePosition = xRes.nStartOfNextSentencePosition
        try:
            xRes.aErrors = tuple(gce.parse(rText, rLocale.Country))
# ->>> WORKAROUND
            if xRes.nStartOfNextSentencePosition > 3000:
                self.dResult[nHashedVal] = xRes
                self.nRes += 1
                if self.nRes > self.nMaxRes:
                    del self.dResult[self.lLastRes.popleft()]
                    self.nRes = self.nMaxRes
                self.lLastRes.append(nHashedVal)
            # END OF WORKAROUND
        except:
            traceback.print_exc()
        return xRes
    def ignoreRule (self, rid, aLocale):        gce.ignoreRule(rid)
def resetIgnoreRules (self):        gce.resetIgnoreRules()
# XServiceDisplayName
    def getServiceDisplayName (self, aLocale):        return gce.name
# Grammalecte
    def getSpellChecker (self):        return gce.getSpellChecker()
def loadUserDictionaries (self):
        try:
            xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_${implname}/Other/", False)
            xChild = xSettingNode.getByName("o_${lang}")
            if xChild.getPropertyValue("use_personal_dic"):
                sJSON = xChild.getPropertyValue("personal_dic")
                if sJSON:                    oSpellChecker = gce.getSpellChecker();
oSpellChecker.setPersonalDictionary(json.loads(sJSON))
        except:
            traceback.print_exc()
    def setWriterUnderliningStyle (self):
        try:
            xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_${implname}/Other/", False)
            xChild = xSettingNode.getByName("o_${lang}")
            sLineType = xChild.getPropertyValue("line_type")
            bMulticolor = bool(xChild.getPropertyValue("line_multicolor"))            gce.setWriterUnderliningStyle(sLineType, bMulticolor)
except:
            traceback.print_exc()
g_ImplementationHelper = unohelper.ImplementationHelper()g_ImplementationHelper.addImplementation(Grammalecte, "org.openoffice.comp.pyuno.Lightproof."+gce.pkg, ("com.sun.star.linguistic2.Proofreader",),)
# g_ImplementationHelper.addImplementation( opt_handler.LightproofOptionsEventHandler, \#     "org.openoffice.comp.pyuno.LightproofOptionsEventHandler." + gce.pkg, ("com.sun.star.awt.XContainerWindowEventHandler",),)
 | 
|
|
|
|
|
|
|
|
|
 | 
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
 | 
            if nHashedVal in self.dResult:
                return self.dResult[nHashedVal]
        # WORKAROUND ->>>
        xRes.nBehindEndOfSentencePosition = xRes.nStartOfNextSentencePosition
        try:
            xRes.aErrors = tuple(gc_engine.parse(rText, rLocale.Country))
            # ->>> WORKAROUND
            if xRes.nStartOfNextSentencePosition > 3000:
                self.dResult[nHashedVal] = xRes
                self.nRes += 1
                if self.nRes > self.nMaxRes:
                    del self.dResult[self.lLastRes.popleft()]
                    self.nRes = self.nMaxRes
                self.lLastRes.append(nHashedVal)
            # END OF WORKAROUND
        except:
            traceback.print_exc()
        return xRes
    def ignoreRule (self, rid, aLocale):
        gc_engine.ignoreRule(rid)
    def resetIgnoreRules (self):
        gc_engine.resetIgnoreRules()
    # XServiceDisplayName
    def getServiceDisplayName (self, aLocale):
        return gc_engine.name
    # Grammalecte
    def getSpellChecker (self):
        return gc_engine.getSpellChecker()
    def loadUserDictionaries (self):
        try:
            xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_${implname}/Other/", False)
            xChild = xSettingNode.getByName("o_${lang}")
            if xChild.getPropertyValue("use_personal_dic"):
                sJSON = xChild.getPropertyValue("personal_dic")
                if sJSON:
                    oSpellChecker = gc_engine.getSpellChecker();
                    oSpellChecker.setPersonalDictionary(json.loads(sJSON))
        except:
            traceback.print_exc()
    def setWriterUnderliningStyle (self):
        try:
            xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_${implname}/Other/", False)
            xChild = xSettingNode.getByName("o_${lang}")
            sLineType = xChild.getPropertyValue("line_type")
            bMulticolor = bool(xChild.getPropertyValue("line_multicolor"))
            gc_engine.setWriterUnderliningStyle(sLineType, bMulticolor)
        except:
            traceback.print_exc()
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(Grammalecte, "org.openoffice.comp.pyuno.Lightproof."+gc_engine.pkg, ("com.sun.star.linguistic2.Proofreader",),)
# g_ImplementationHelper.addImplementation( opt_handler.LightproofOptionsEventHandler, \
#     "org.openoffice.comp.pyuno.LightproofOptionsEventHandler." + gc_engine.pkg, ("com.sun.star.awt.XContainerWindowEventHandler",),)
 |