Grammalecte  Check-in [6c8016e88a]

Overview
Comment:[lo] Enumerator: use tokenizer of Grammalecte instead of LO <gotoNextWord>
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | lo
Files: files | file ages | folders
SHA3-256: 6c8016e88a3561bf6b9ea2e42b2eb7f7c5b31b7753fe59f061a4d58b202dacf1
User & Date: olr on 2018-02-24 09:47:24
Other Links: manifest | tags
Context
2018-02-24
10:25
[lo] Enumerator: tag several words at once check-in: 8e05358b14 user: olr tags: lo, trunk
09:47
[lo] Enumerator: use tokenizer of Grammalecte instead of LO <gotoNextWord> check-in: 6c8016e88a user: olr tags: lo, trunk
08:20
[graphspell] spellchecker: new function getTokenizer() check-in: aae2892638 user: olr tags: graphspell, trunk
Changes

Modified gc_lang/fr/oxt/Lexicographer/Enumerator.py from [fb0c4a2aa0] to [40df986240].

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