1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
-
+
+
|
# -*- encoding: UTF-8 -*-
# Grammalecte for Writer
# License: MPL 2
# A derivative work of Lightproof from László Németh (http://cgit.freedesktop.org/libreoffice/lightproof/)
import uno
import unohelper
import json
import sys
import traceback
from collections import deque
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):
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
+
+
-
+
-
|
xCurCtx = uno.getComponentContext()
# init
gce.load("Writer")
# GC options
# opt_handler.load(xCurCtx)
dOpt = Options.load(xCurCtx)
gce.setOptions(dOpt)
# dictionaries options
self.loadUserDictionaries()
# store for results of big paragraphs
self.dResult = {}
self.nMaxRes = 1500
self.lLastRes = deque(maxlen=self.nMaxRes)
self.nRes = 0
#oSpellChecker = gce.getSpellChecker();
#oSpellChecker.setPersonalDictionary("fr.personal.json")
# XServiceName method implementations
def getServiceName (self):
return self.ImplementationName
# XServiceInfo method implementations
def getImplementationName (self):
|
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
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
|
+
+
+
+
+
+
+
+
+
+
+
+
|
# 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_grammalecte/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()
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",),)
|