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
28
29
30
31
32
33
34
35
36
37
38
39
40
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
69
|
# Grammalecte - Lexicographe
# by Olivier R. License: MPL 2
import uno
import unohelper
import traceback
from com.sun.star.task import XJob
from com.sun.star.ui import XContextMenuInterceptor
#from com.sun.star.ui.ContextMenuInterceptorAction import IGNORED
#from com.sun.star.ui.ContextMenuInterceptorAction import EXECUTE_MODIFIED
import grammalecte.fr.lexicographe as lxg
from grammalecte.graphspell.spellchecker import SpellChecker
from grammalecte.graphspell.echo import echo
import helpers
xDesktop = None
oSpellChecker = None
oLexicographe = None
class MyContextMenuInterceptor (XContextMenuInterceptor, unohelper.Base):
def __init__ (self, ctx):
self.ctx = ctx
def notifyContextMenuExecute (self, xEvent):
sWord = self._getWord()
try:
aItem, aVerb = oLexicographe.analyzeWord(sWord)
if not aItem:
return uno.Enum("com.sun.star.ui.ContextMenuInterceptorAction", "IGNORED") # don’t work on AOO, have to import the value
#return IGNORED
xContextMenu = xEvent.ActionTriggerContainer
if xContextMenu:
# entries index
i = xContextMenu.Count
nUnoConstantLine = uno.getConstantByName("com.sun.star.ui.ActionTriggerSeparatorType.LINE")
# word analysis
i = self._addItemToContextMenu(xContextMenu, i, "ActionTriggerSeparator", SeparatorType=nUnoConstantLine)
for item in aItem:
if isinstance(item, str):
i = self._addItemToContextMenu(xContextMenu, i, "ActionTrigger", Text=item, CommandURL="service:net.grammalecte.AppLauncher?None")
elif isinstance(item, tuple):
sRoot, lMorph = item
# submenu
xSubMenuContainer = xContextMenu.createInstance("com.sun.star.ui.ActionTriggerContainer")
for j, s in enumerate(lMorph):
self._addItemToContextMenu(xSubMenuContainer, j, "ActionTrigger", Text=s, CommandURL="service:net.grammalecte.AppLauncher?None")
# create root menu entry
i = self._addItemToContextMenu(xContextMenu, i, "ActionTrigger", Text=sRoot, SubContainer=xSubMenuContainer)
else:
i = self._addItemToContextMenu(xContextMenu, i, "ActionTrigger", Text="# erreur : {}".format(item))
# Links to Conjugueur
if aVerb:
i = self._addItemToContextMenu(xContextMenu, i, "ActionTriggerSeparator", SeparatorType=nUnoConstantLine)
for sVerb in aVerb:
i = self._addItemToContextMenu(xContextMenu, i, "ActionTrigger", Text="Conjuguer “{}”…".format(sVerb),
CommandURL="service:net.grammalecte.AppLauncher?CJ/"+sVerb)
# Search
xDoc = xDesktop.getCurrentComponent()
xViewCursor = xDoc.CurrentController.ViewCursor
if not xViewCursor.isCollapsed():
sSelec = xViewCursor.getString()
if sSelec.count(" ") <= 2:
|
<
<
|
|
|
|
>
|
<
|
|
|
|
|
>
|
|
|
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
28
29
30
31
32
33
34
35
36
37
38
39
40
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
|
# Grammalecte - Lexicographe
# by Olivier R. License: MPL 2
import uno
import unohelper
import traceback
from com.sun.star.task import XJob
from com.sun.star.ui import XContextMenuInterceptor
#from com.sun.star.ui.ContextMenuInterceptorAction import IGNORED
#from com.sun.star.ui.ContextMenuInterceptorAction import EXECUTE_MODIFIED
from grammalecte.graphspell.spellchecker import SpellChecker
from grammalecte.graphspell.echo import echo
import helpers
xDesktop = None
oSpellChecker = None
class MyContextMenuInterceptor (XContextMenuInterceptor, unohelper.Base):
def __init__ (self, ctx):
self.ctx = ctx
def notifyContextMenuExecute (self, xEvent):
sWord = self._getWord()
try:
lWordAndMorph = oSpellChecker.analyze(sWord)
if not lWordAndMorph:
return uno.Enum("com.sun.star.ui.ContextMenuInterceptorAction", "IGNORED") # don’t work on AOO, have to import the value
#return IGNORED
xContextMenu = xEvent.ActionTriggerContainer
if xContextMenu:
# entries index
i = xContextMenu.Count
nUnoConstantLine = uno.getConstantByName("com.sun.star.ui.ActionTriggerSeparatorType.LINE")
# word analysis
i = self._addItemToContextMenu(xContextMenu, i, "ActionTriggerSeparator", SeparatorType=nUnoConstantLine)
for sWord, lMorph in lWordAndMorph:
if len(lMorph) == 1:
sMorph, sReadableMorph = lMorph[0]
i = self._addItemToContextMenu(xContextMenu, i, "ActionTrigger", Text=sWord + " : " + sReadableMorph, CommandURL="service:net.grammalecte.AppLauncher?None")
elif len(lMorph) >= 1:
# submenu
xSubMenuContainer = xContextMenu.createInstance("com.sun.star.ui.ActionTriggerContainer")
for j, (sMorph, sReadableMorph) in enumerate(lMorph):
self._addItemToContextMenu(xSubMenuContainer, j, "ActionTrigger", Text=sReadableMorph, CommandURL="service:net.grammalecte.AppLauncher?None")
# create root menu entry
i = self._addItemToContextMenu(xContextMenu, i, "ActionTrigger", Text=sWord, SubContainer=xSubMenuContainer)
else:
i = self._addItemToContextMenu(xContextMenu, i, "ActionTrigger", Text=sWord + " : [erreur] aucun résultat trouvé.")
# Links to Conjugueur
aVerb = { sMorph[1:sMorph.find("/")] for sMorph in oSpellChecker.getMorph(sWord) if ":V" in sMorph }
if aVerb:
i = self._addItemToContextMenu(xContextMenu, i, "ActionTriggerSeparator", SeparatorType=nUnoConstantLine)
for sVerb in aVerb:
i = self._addItemToContextMenu(xContextMenu, i, "ActionTrigger", Text="Conjuguer “{}”…".format(sVerb), \
CommandURL="service:net.grammalecte.AppLauncher?CJ/"+sVerb)
# Search
xDoc = xDesktop.getCurrentComponent()
xViewCursor = xDoc.CurrentController.ViewCursor
if not xViewCursor.isCollapsed():
sSelec = xViewCursor.getString()
if sSelec.count(" ") <= 2:
|
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
|
class JobExecutor (XJob, unohelper.Base):
def __init__ (self, ctx):
self.ctx = ctx
global xDesktop
global oSpellChecker
global oLexicographe
try:
if not xDesktop:
xDesktop = self.ctx.getServiceManager().createInstanceWithContext('com.sun.star.frame.Desktop', self.ctx)
if not oSpellChecker:
xCurCtx = uno.getComponentContext()
oGC = self.ctx.ServiceManager.createInstanceWithContext("org.openoffice.comp.pyuno.Lightproof.grammalecte", self.ctx)
if hasattr(oGC, "getSpellChecker"):
# https://bugs.documentfoundation.org/show_bug.cgi?id=97790
oSpellChecker = oGC.getSpellChecker()
else:
oSpellChecker = SpellChecker("${lang}", "fr-allvars.bdic")
if not oLexicographe:
oLexicographe = lxg.Lexicographe(oSpellChecker)
except:
traceback.print_exc()
def execute (self, args):
if not args:
return
try:
|
<
<
<
|
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
|
class JobExecutor (XJob, unohelper.Base):
def __init__ (self, ctx):
self.ctx = ctx
global xDesktop
global oSpellChecker
try:
if not xDesktop:
xDesktop = self.ctx.getServiceManager().createInstanceWithContext('com.sun.star.frame.Desktop', self.ctx)
if not oSpellChecker:
xCurCtx = uno.getComponentContext()
oGC = self.ctx.ServiceManager.createInstanceWithContext("org.openoffice.comp.pyuno.Lightproof.grammalecte", self.ctx)
if hasattr(oGC, "getSpellChecker"):
# https://bugs.documentfoundation.org/show_bug.cgi?id=97790
oSpellChecker = oGC.getSpellChecker()
else:
oSpellChecker = SpellChecker("${lang}", "fr-allvars.bdic")
except:
traceback.print_exc()
def execute (self, args):
if not args:
return
try:
|