Index: gc_lang/fr/oxt/Lexicographer/Enumerator.py ================================================================== --- gc_lang/fr/oxt/Lexicographer/Enumerator.py +++ gc_lang/fr/oxt/Lexicographer/Enumerator.py @@ -1,6 +1,6 @@ -# Dictionary Options +# Enumerator of Words # by Olivier R. # License: MPL 2 import unohelper import uno @@ -10,11 +10,10 @@ import enum_strings import grammalecte.graphspell as sc from com.sun.star.task import XJobExecutor from com.sun.star.awt import XActionListener -from com.sun.star.beans import PropertyValue def hexToRBG (sHexa): r = int(sHexa[:2], 16) g = int(sHexa[2:4], 16) @@ -54,10 +53,11 @@ 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 @@ -118,17 +118,17 @@ nWidth = self.xDialog.Width - 20 nHeight = 10 # List self._addWidget("list_section", 'FixedLine', nX, nY1, nWidth, nHeight, Label = self.dUI.get("list_section", "#err"), FontDescriptor = xFDTitle) - self._addWidget('count_button', 'Button', nX, nY1+12, 70, 10, Label = self.dUI.get('count_button', "#err")) - self._addWidget('count2_button', 'Button', nX+75, nY1+12, 70, 10, Label = self.dUI.get('count2_button', "#err")) - self._addWidget('unknown_button', 'Button', nX+150, nY1+12, 70, 10, Label = self.dUI.get('unknown_button', "#err")) - self.xGridModel = self._addGrid("list_grid", nX, nY1+25, nWidth, 180, [ - {"Title": self.dUI.get("words", "#err"), "ColumnWidth": 175}, - {"Title": "Occurrences", "ColumnWidth": 45} - ]) + self._addWidget('count_button', 'Button', nX, nY1+12, 70, 11, Label = self.dUI.get('count_button', "#err")) + self._addWidget('count2_button', 'Button', nX+75, nY1+12, 70, 11, Label = self.dUI.get('count2_button', "#err")) + self._addWidget('unknown_button', 'Button', nX+150, nY1+12, 70, 11, Label = self.dUI.get('unknown_button', "#err")) + self.xGridModel = self._addGrid("list_grid", nX, nY1+25, nWidth, 181, \ + [ {"Title": self.dUI.get("words", "#err"), "ColumnWidth": 175}, {"Title": "Occurrences", "ColumnWidth": 45} ], \ + SelectionModel = uno.Enum("com.sun.star.view.SelectionType", "MULTI") \ + ) self._addWidget('num_of_entries', 'FixedText', nX, nY1+210, 60, nHeight, Label = self.dUI.get('num_of_entries', "#err"), Align = 2) self.xNumWord = self._addWidget('num_of_entries_res', 'FixedText', nX+65, nY1+210, 30, nHeight, Label = "—") self._addWidget('tot_of_entries', 'FixedText', nX+100, nY1+210, 60, nHeight, Label = self.dUI.get('tot_of_entries', "#err"), Align = 2) self.xTotWord = self._addWidget('tot_of_entries_res', 'FixedText', nX+165, nY1+210, 30, nHeight, Label = "—") @@ -144,11 +144,11 @@ self.xTag = self._addWidget('tag_button', 'Button', self.xDialog.Width-40, nY2+10, 30, 11, Label = self.dUI.get('tag_button', "#err"), FontDescriptor = xFDTitle, TextColor = 0x005500) # Progress bar self.xProgressBar = self._addWidget('progress_bar', 'ProgressBar', nX, self.xDialog.Height-25, 160, 14) self.xProgressBar.ProgressValueMin = 0 - self.xProgressBar.ProgressValueMax = 1 # to calculate + self.xProgressBar.ProgressValueMax = 1 # to calculate later # Close self._addWidget('close_button', 'Button', self.xDialog.Width-60, self.xDialog.Height-25, 50, 14, Label = self.dUI.get('close_button', "#err"), FontDescriptor = xFDTitle, TextColor = 0x550000) # container @@ -181,26 +181,24 @@ self.xTag.Enabled = False elif xActionEvent.ActionCommand == "UnknownWords": self.count(self.dUI.get("unknown_words", "#err"), bOnlyUnknownWords=True) self.xTag.Enabled = True elif xActionEvent.ActionCommand == "Tag": - nRow = self.xGridControl.getCurrentRow() - if nRow == -1: + if not self.xGridControl.hasSelectedRows(): return - sWord = self.xGridModel.GridDataModel.getCellData(0, nRow) - if not sWord: - return + lRow = self.xGridControl.getSelectedRows() + aWord = set([ self.xGridModel.GridDataModel.getCellData(0, n) for n in lRow ]) sAction = "" if self.xUnderline.State: sAction = "underline" elif self.xNoUnderline.State: sAction = "nounderline" elif self.xAccent.State: sAction = "accentuation" elif self.xNoAccent.State: sAction = "noaccentuation" - self.tagText(sWord, sAction) + self.tagText(aWord, sAction) elif xActionEvent.ActionCommand == "Close": self.xContainer.endExecute() except: traceback.print_exc() @@ -260,45 +258,43 @@ self.xProgressBar.ProgressValue = self.xProgressBar.ProgressValueMax self.xNumWord.Label = str(i) self.xTotWord.Label = nTotOccur @_waitPointer - def tagText (self, sWord, sAction=""): + def tagText (self, aWord, 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() - #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 + self._tagParagraph(xCursor, aWord, sAction) while xCursor.gotoNextParagraph(False): - xCursor.gotoEndOfParagraph(True) - sParagraph = xCursor.getString() - if sWord in sParagraph: - self._tagParagraph(sWord, xCursor, sAction) - self.xProgressBar.ProgressValue += 1 + self._tagParagraph(xCursor, aWord, sAction) self.xProgressBar.ProgressValue = self.xProgressBar.ProgressValueMax - def _tagParagraph (self, sWord, xCursor, sAction): + def _tagParagraph (self, xCursor, aWord, sAction): + xCursor.gotoEndOfParagraph(True) + sParagraph = xCursor.getString() 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") + nPos = 0 + for dToken in self.oTokenizer.genTokens(sParagraph): + if dToken["sValue"] in aWord: + 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',)) Index: gc_lang/fr/oxt/Lexicographer/enum_strings.py ================================================================== --- gc_lang/fr/oxt/Lexicographer/enum_strings.py +++ gc_lang/fr/oxt/Lexicographer/enum_strings.py @@ -5,11 +5,11 @@ dStrings = { "fr": { "title": "Grammalecte · Recenseur de mots", - "list_section": "Calcul des occurrences des mots", + "list_section": "Énumération des occurrences", "count_button": "Compter tout", "count2_button": "Compter par lemme", "unknown_button": "Mots inconnus", "num_of_entries": "Nombre d’entrées :", "tot_of_entries": "Total des entrées :", @@ -27,13 +27,13 @@ "tag_button": "Taguer", "close_button": "Fermer", }, "en": { - "title": "Grammalecte · Enumerator of Words", + "title": "Grammalecte · Enumerator of words", - "list_section": "Words", + "list_section": "Occurrences enumeration", "count_button": "Count all", "count2_button": "Count by lemma", "unknown_button": "Unknown words", "num_of_entries": "Number of entries:", "tot_of_entries": "Total of words:", Index: gc_lang/fr/rules.grx ================================================================== --- gc_lang/fr/rules.grx +++ gc_lang/fr/rules.grx @@ -2307,12 +2307,12 @@ TEST: __ocr__ {{Us}} arrive demain. # il / i1 / if / 11 -__[i]/ocr(ocr_il_ils3)__ - [i1][1f]s? +__[s]/ocr(ocr_il_ils3)__ + [iI1][1f]s? <<- not \0.endswith("s") ->> Il|il # Erreur de numérisation ? <<- __else__ ->> Ils|ils # Erreur de numérisation ? TEST: __ocr__ {{i1s}} en savent beaucoup trop pour leur propre bien. Index: graphspell-js/spellchecker.js ================================================================== --- graphspell-js/spellchecker.js +++ graphspell-js/spellchecker.js @@ -68,10 +68,17 @@ this.oTokenizer = new tokenizer.Tokenizer(this.sLangCode); } else { this.oTokenizer = new Tokenizer(this.sLangCode); } } + + getTokenizer () { + if (!this.oTokenizer) { + this.loadTokenizer(); + } + return this.oTokenizer; + } setMainDictionary (dictionary) { // returns true if the dictionary is loaded this.oMainDic = this._loadDictionary(dictionary); return Boolean(this.oMainDic); Index: graphspell/spellchecker.py ================================================================== --- graphspell/spellchecker.py +++ graphspell/spellchecker.py @@ -46,10 +46,15 @@ return None def loadTokenizer (self): self.oTokenizer = tokenizer.Tokenizer(self.sLangCode) + def getTokenizer (self): + if not self.oTokenizer: + self.loadTokenizer() + return self.oTokenizer + def setMainDictionary (self, sfDictionary): "returns True if the dictionary is loaded" self.oMainDic = self._loadDictionary(sfDictionary) return bool(self.oMainDic)