52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
self.ctx = ctx
self.xSvMgr = self.ctx.ServiceManager
self.xDesktop = self.xSvMgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.ctx)
self.xDocument = self.xDesktop.getCurrentComponent()
self.xContainer = None
self.xDialog = None
self.oSpellChecker = None
def _addWidget (self, name, wtype, x, y, w, h, **kwargs):
xWidget = self.xDialog.createInstance('com.sun.star.awt.UnoControl%sModel' % wtype)
xWidget.Name = name
xWidget.PositionX = x
xWidget.PositionY = y
xWidget.Width = w
|
>
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
self.ctx = ctx
self.xSvMgr = self.ctx.ServiceManager
self.xDesktop = self.xSvMgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.ctx)
self.xDocument = self.xDesktop.getCurrentComponent()
self.xContainer = None
self.xDialog = None
self.oSpellChecker = None
self.oTokenizer = None
def _addWidget (self, name, wtype, x, y, w, h, **kwargs):
xWidget = self.xDialog.createInstance('com.sun.star.awt.UnoControl%sModel' % wtype)
xWidget.Name = name
xWidget.PositionX = x
xWidget.PositionY = y
xWidget.Width = w
|
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
@_waitPointer
def tagText (self, sWord, sAction=""):
if not sAction:
return
self.xProgressBar.ProgressValueMax = self._countParagraph()
self.xProgressBar.ProgressValue = 0
xCursor = self.xDocument.Text.createTextCursor()
#helpers.xray(xCursor)
xCursor.gotoStart(False)
xCursor.gotoEndOfParagraph(True)
sParagraph = xCursor.getString()
if sWord in sParagraph:
self._tagParagraph(sWord, xCursor, sAction)
self.xProgressBar.ProgressValue += 1
while xCursor.gotoNextParagraph(False):
xCursor.gotoEndOfParagraph(True)
sParagraph = xCursor.getString()
if sWord in sParagraph:
self._tagParagraph(sWord, xCursor, sAction)
self.xProgressBar.ProgressValue += 1
self.xProgressBar.ProgressValue = self.xProgressBar.ProgressValueMax
def _tagParagraph (self, sWord, xCursor, sAction):
xCursor.gotoStartOfParagraph(False)
while xCursor.gotoNextWord(False):
if xCursor.isStartOfWord():
xCursor.gotoEndOfWord(True)
if sWord == xCursor.getString():
if sAction == "underline":
xCursor.CharBackColor = hexToRBG("AA0000")
elif sAction == "nounderline":
xCursor.CharBackColor = hexToRBG("FFFFFF")
elif sAction == "accentuation":
xCursor.CharStyleName = "Emphasis"
elif sAction == "noaccentuation":
#xCursor.CharStyleName = "Default Style" # doesn’t work
xCursor.setPropertyToDefault("CharStyleName")
#g_ImplementationHelper = unohelper.ImplementationHelper()
#g_ImplementationHelper.addImplementation(Enumerator, 'net.grammalecte.enumerator', ('com.sun.star.task.Job',))
|
>
>
<
<
<
<
|
<
<
<
<
|
<
|
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
@_waitPointer
def tagText (self, sWord, sAction=""):
if not sAction:
return
self.xProgressBar.ProgressValueMax = self._countParagraph()
self.xProgressBar.ProgressValue = 0
if not self.oTokenizer:
self.oTokenizer = self.oSpellChecker.getTokenizer()
xCursor = self.xDocument.Text.createTextCursor()
xCursor.gotoStart(False)
self._tagParagraph(xCursor, sWord, sAction)
while xCursor.gotoNextParagraph(False):
self._tagParagraph(xCursor, sWord, sAction)
self.xProgressBar.ProgressValue = self.xProgressBar.ProgressValueMax
def _tagParagraph (self, xCursor, sWord, sAction):
xCursor.gotoEndOfParagraph(True)
sParagraph = xCursor.getString()
xCursor.gotoStartOfParagraph(False)
nPos = 0
for dToken in self.oTokenizer.genTokens(sParagraph):
if dToken["sValue"] == sWord:
xCursor.goRight(dToken["nStart"]-nPos, False) # start of token
nPos = dToken["nEnd"]
xCursor.goRight(nPos-dToken["nStart"], True) # end of token
if sAction == "underline":
xCursor.CharBackColor = hexToRBG("AA0000")
elif sAction == "nounderline":
xCursor.CharBackColor = hexToRBG("FFFFFF")
elif sAction == "accentuation":
xCursor.CharStyleName = "Emphasis"
elif sAction == "noaccentuation":
#xCursor.CharStyleName = "Default Style" # doesn’t work
xCursor.setPropertyToDefault("CharStyleName")
self.xProgressBar.ProgressValue += 1
#g_ImplementationHelper = unohelper.ImplementationHelper()
#g_ImplementationHelper.addImplementation(Enumerator, 'net.grammalecte.enumerator', ('com.sun.star.task.Job',))
|