Grammalecte  Check-in [8e05358b14]

Overview
Comment:[lo] Enumerator: tag several words at once
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | lo
Files: files | file ages | folders
SHA3-256: 8e05358b14cfe8ed9cf457908013679947153c85859f317811dfa04cff980b14
User & Date: olr on 2018-02-24 10:25:18
Other Links: manifest | tags
Context
2018-02-24
12:45
[lo] Enumerator: change title comment check-in: 015284c8bd user: olr tags: lo, trunk
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
Changes

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

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21







-








import helpers
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)
    b = int(sHexa[4:], 16)
    return (r & 255) << 16 | (g & 255) << 8 | (b & 255)
120
121
122
123
124
125
126
127
128
129



130

131
132
133
134
135
136
137
119
120
121
122
123
124
125



126
127
128

129
130
131
132
133
134
135
136







-
-
-
+
+
+
-
+







        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, 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}
        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 = "—")
        
        # Tag
        # Note: the only way to group RadioButtons is to create them successively
180
181
182
183
184
185
186
187

188
189

190

191
192
193
194
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
179
180
181
182
183
184
185

186

187
188

189


190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206







-
+
-

+
-
+
-
-









-
+







            elif xActionEvent.ActionCommand == "CountByLemma":
                self.count(self.dUI.get("lemmas", "#err"), bByLemma=True)
                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 not self.xGridControl.hasSelectedRows():
                if nRow == -1:
                    return
                lRow = self.xGridControl.getSelectedRows()
                sWord = self.xGridModel.GridDataModel.getCellData(0, nRow)
                aWord = set([ self.xGridModel.GridDataModel.getCellData(0, n)  for n in lRow ])
                if not sWord:
                    return
                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()
    
    # XJobExecutor
    def trigger (self, args):
259
260
261
262
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
256
257
258
259
260
261
262

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







-
+








-
+

-
+


-
+





-
+







            i += 1
            nTotOccur += w
        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()
        xCursor.gotoStart(False)
        self._tagParagraph(xCursor, sWord, sAction)
        self._tagParagraph(xCursor, aWord, sAction)
        while xCursor.gotoNextParagraph(False):
            self._tagParagraph(xCursor, sWord, sAction)
            self._tagParagraph(xCursor, aWord, sAction)
        self.xProgressBar.ProgressValue = self.xProgressBar.ProgressValueMax

    def _tagParagraph (self, xCursor, sWord, sAction):
    def _tagParagraph (self, xCursor, aWord, sAction):
        xCursor.gotoEndOfParagraph(True)
        sParagraph = xCursor.getString()
        xCursor.gotoStartOfParagraph(False)
        nPos = 0
        for dToken in self.oTokenizer.genTokens(sParagraph):
            if dToken["sValue"] == sWord:
            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")