Grammalecte  Check-in [b4038dd6fd]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[lo] small code cleaning
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | lo
Files: files | file ages | folders
SHA3-256:b4038dd6fd2c780a9e126535ca616e386b5e0c0cdcbd4aea5c1b1e380028d6db
User & Date: olr 2019-11-20 10:12:40
Context
2019-11-20
10:18
[core][lo][fr] formateur de texte: … check-in: 2785b3b65a user: olr tags: core, fr, lo, trunk
10:12
[lo] small code cleaning check-in: b4038dd6fd user: olr tags: lo, trunk
09:32
[fr] nr: étant donné que check-in: 63df9daceb user: olr tags: fr, trunk
Changes

Changes to gc_lang/fr/oxt/AppLauncher.py.


1
2



3


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# Grammalecte AppLauncher
# by Olivier R.



# License: MPL 2



import unohelper
import uno
import traceback

import helpers

from com.sun.star.task import XJobExecutor


xDesktop = None


class AppLauncher (unohelper.Base, XJobExecutor):
    def __init__ (self, ctx):
        self.ctx = ctx
>
|
<
>
>
>

>
>



|



<
<







1
2

3
4
5
6
7
8
9
10
11
12
13
14
15


16
17
18
19
20
21
22
"""
Grammalecte AppLauncher

Service to avoid creating a service for each feature (which would slows LO start-up)
"""

# License: MPL 2

import traceback

import unohelper
import uno
from com.sun.star.task import XJobExecutor

import helpers




xDesktop = None


class AppLauncher (unohelper.Base, XJobExecutor):
    def __init__ (self, ctx):
        self.ctx = ctx

Changes to gc_lang/fr/oxt/Graphspell.py.


1
2
3

4

5
6
7
8
9
10
11
12
13
14
15
16
17
18



19
20
21
22
23
24
25
..
41
42
43
44
45
46
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143

# Graphspell
#
# Spellchecker based on a DAWG (Direct Acyclic Word Graph)




import uno
import unohelper
import traceback
import re
import json

import helpers
from grammalecte.graphspell import SpellChecker

from com.sun.star.linguistic2 import XSupportedLocales, XSpellChecker, XSpellAlternatives
from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName
from com.sun.star.lang import Locale





lLocale = {
    # List of locales in LibreOffice
    # https://cgit.freedesktop.org/libreoffice/core/tree/i18nlangtag/source/isolang/isolang.cxx
    #('la', 'VA', ''),  # Latin (for testing purpose)
    ('fr', 'FR', ''),  # France
    ('fr', 'BE', ''),  # Belgique
................................................................................
    ('fr', 'TG', '')   # Togo
}

zElidedWords = re.compile("(?i)^(?:[ldnmtsjcçy]|qu|lorsqu|quoiqu|puisqu|jusqu)['’`‘]")


class Graphspell (unohelper.Base, XSpellChecker, XServiceInfo, XServiceName, XServiceDisplayName, XSupportedLocales):


    def __init__ (self, ctx, *args):
        try:
            self.ctx = ctx
            self.sServiceName = "com.sun.star.linguistic2.SpellChecker"
            self.sImplementationName = "net.grammalecte.graphspell"
            self.tSupportedServiceNames = (self.sServiceName, )
            self.xSvMgr = ctx.ServiceManager
            self.locales = tuple([ Locale(t[0], t[1], t[2])  for t in lLocale ])
            self.xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_grammalecte/Other/", False)
            self.xOptionNode = self.xSettingNode.getByName("o_fr")
            sMainDicName = self.xOptionNode.getPropertyValue("main_dic_name")
            personal_dic = ""
            if (self.xOptionNode.getPropertyValue("use_personal_dic")):
                sPersonalDicJSON = self.xOptionNode.getPropertyValue("personal_dic")
                if sPersonalDicJSON:
                    try:
                        personal_dic = json.loads(sPersonalDicJSON)
                    except:
                        print("Graphspell: wrong personal_dic")
                        traceback.print_exc()
................................................................................
        return self.sImplementationName     #self.sServiceName

    # XServiceInfo
    def getImplementationName (self):
        return self.sImplementationName

    def supportsService (self, sServiceName):
        return (sServiceName in self.tSupportedServiceNames)

    def getSupportedServiceNames (self):
        return self.tSupportedServiceNames

    # XSupportedLocales
    def hasLocale (self, aLocale):
        if aLocale in self.locales:
................................................................................
            traceback.print_exc()
        return False

    def spell (self, aWord, aLocale, aProperties):
        "returns an object SpellAlternatives"
        try:
            if not self.bHunspell:

                lSugg = []
                for l in self.oGraphspell.suggest(aWord):
                    lSugg.extend(l)
                return SpellAlternatives(aWord, tuple(lSugg))
            else:
                # fallback dictionary suggestions (Hunspell)
                return self.xHunspell.spell(aWord, self.xHunspellLocale, aProperties)
        except:
            traceback.print_exc()
        return None

    # XServiceDisplayName
    def getServiceDisplayName(self, aLocale):
        return "Graphspell (fr)"
>
|
<
|
>

>

<
<




|
|
<




>
>
>







 







>













|







 







|







 







>




<
|
|







1
2

3
4
5
6
7


8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
..
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
126
127
128
129
130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146
"""
Graphspell

Spellchecker based on a DAWG (Direct Acyclic Word Graph)
"""

# License: MPL 2



import traceback
import re
import json

#import uno
import unohelper

from com.sun.star.linguistic2 import XSupportedLocales, XSpellChecker, XSpellAlternatives
from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName
from com.sun.star.lang import Locale

import helpers
from grammalecte.graphspell import SpellChecker


lLocale = {
    # List of locales in LibreOffice
    # https://cgit.freedesktop.org/libreoffice/core/tree/i18nlangtag/source/isolang/isolang.cxx
    #('la', 'VA', ''),  # Latin (for testing purpose)
    ('fr', 'FR', ''),  # France
    ('fr', 'BE', ''),  # Belgique
................................................................................
    ('fr', 'TG', '')   # Togo
}

zElidedWords = re.compile("(?i)^(?:[ldnmtsjcçy]|qu|lorsqu|quoiqu|puisqu|jusqu)['’`‘]")


class Graphspell (unohelper.Base, XSpellChecker, XServiceInfo, XServiceName, XServiceDisplayName, XSupportedLocales):
    """Spellchecker class: will be loaded by LibreOffice"""

    def __init__ (self, ctx, *args):
        try:
            self.ctx = ctx
            self.sServiceName = "com.sun.star.linguistic2.SpellChecker"
            self.sImplementationName = "net.grammalecte.graphspell"
            self.tSupportedServiceNames = (self.sServiceName, )
            self.xSvMgr = ctx.ServiceManager
            self.locales = tuple([ Locale(t[0], t[1], t[2])  for t in lLocale ])
            self.xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_grammalecte/Other/", False)
            self.xOptionNode = self.xSettingNode.getByName("o_fr")
            sMainDicName = self.xOptionNode.getPropertyValue("main_dic_name")
            personal_dic = ""
            if self.xOptionNode.getPropertyValue("use_personal_dic"):
                sPersonalDicJSON = self.xOptionNode.getPropertyValue("personal_dic")
                if sPersonalDicJSON:
                    try:
                        personal_dic = json.loads(sPersonalDicJSON)
                    except:
                        print("Graphspell: wrong personal_dic")
                        traceback.print_exc()
................................................................................
        return self.sImplementationName     #self.sServiceName

    # XServiceInfo
    def getImplementationName (self):
        return self.sImplementationName

    def supportsService (self, sServiceName):
        return sServiceName in self.tSupportedServiceNames

    def getSupportedServiceNames (self):
        return self.tSupportedServiceNames

    # XSupportedLocales
    def hasLocale (self, aLocale):
        if aLocale in self.locales:
................................................................................
            traceback.print_exc()
        return False

    def spell (self, aWord, aLocale, aProperties):
        "returns an object SpellAlternatives"
        try:
            if not self.bHunspell:
                # Graphspell
                lSugg = []
                for l in self.oGraphspell.suggest(aWord):
                    lSugg.extend(l)
                return SpellAlternatives(aWord, tuple(lSugg))

            # fallback dictionary suggestions (Hunspell)
            return self.xHunspell.spell(aWord, self.xHunspellLocale, aProperties)
        except:
            traceback.print_exc()
        return None

    # XServiceDisplayName
    def getServiceDisplayName(self, aLocale):
        return "Graphspell (fr)"

Changes to gc_lang/fr/oxt/TextFormatter/TextFormatter.py.


1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24

# Text Formatter
# by Olivier R.
# License: MPL 2


import unohelper
import uno

import traceback
import time
import json

import tf_strings
import tf_options
import tf_tabrep
import helpers



from com.sun.star.task import XJobExecutor
from com.sun.star.awt import XActionListener


from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK
# BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_RETRY_CANCEL, BUTTONS_ABORT_IGNORE_RETRY
# DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE
>
|
<
|
>

<
|










|
>







1
2

3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""
Text Formatter

For LibreOffice
"""


# License: MPL 2

import traceback
import time
import json

import tf_strings
import tf_options
import tf_tabrep
import helpers

import unohelper
import uno
from com.sun.star.task import XJobExecutor
from com.sun.star.awt import XActionListener


from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK
# BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_RETRY_CANCEL, BUTTONS_ABORT_IGNORE_RETRY
# DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE

Changes to gc_lang/fr/oxt/TextFormatter/tf_strings.py.

1
2
3
4
5
6
7
8
# -*- encoding: UTF-8 -*-

def getUI (sLang):
    if sLang in dStrings:
        return dStrings[sLang]
    return dStrings["fr"]

dStrings = {
<








1
2
3
4
5
6
7


def getUI (sLang):
    if sLang in dStrings:
        return dStrings[sLang]
    return dStrings["fr"]

dStrings = {