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      8   
     9      9   import helpers
    10     10   import enum_strings
    11     11   import grammalecte.graphspell as sc
    12     12   
    13     13   from com.sun.star.task import XJobExecutor
    14     14   from com.sun.star.awt import XActionListener
    15         -from com.sun.star.beans import PropertyValue
    16     15   
    17     16   
    18     17   def hexToRBG (sHexa):
    19     18       r = int(sHexa[:2], 16)
    20     19       g = int(sHexa[2:4], 16)
    21     20       b = int(sHexa[4:], 16)
    22     21       return (r & 255) << 16 | (g & 255) << 8 | (b & 255)
................................................................................
   120    119           nHeight = 10
   121    120   
   122    121           # List
   123    122           self._addWidget("list_section", 'FixedLine', nX, nY1, nWidth, nHeight, Label = self.dUI.get("list_section", "#err"), FontDescriptor = xFDTitle)
   124    123           self._addWidget('count_button', 'Button', nX, nY1+12, 70, 11, Label = self.dUI.get('count_button', "#err"))
   125    124           self._addWidget('count2_button', 'Button', nX+75, nY1+12, 70, 11, Label = self.dUI.get('count2_button', "#err"))
   126    125           self._addWidget('unknown_button', 'Button', nX+150, nY1+12, 70, 11, Label = self.dUI.get('unknown_button', "#err"))
   127         -        self.xGridModel = self._addGrid("list_grid", nX, nY1+25, nWidth, 181, [
   128         -            {"Title": self.dUI.get("words", "#err"), "ColumnWidth": 175},
   129         -            {"Title": "Occurrences", "ColumnWidth": 45}
   130         -        ])
          126  +        self.xGridModel = self._addGrid("list_grid", nX, nY1+25, nWidth, 181, \
          127  +            [ {"Title": self.dUI.get("words", "#err"), "ColumnWidth": 175}, {"Title": "Occurrences", "ColumnWidth": 45} ], \
          128  +            SelectionModel = uno.Enum("com.sun.star.view.SelectionType", "MULTI") \
          129  +        )
   131    130           self._addWidget('num_of_entries', 'FixedText', nX, nY1+210, 60, nHeight, Label = self.dUI.get('num_of_entries', "#err"), Align = 2)
   132    131           self.xNumWord = self._addWidget('num_of_entries_res', 'FixedText', nX+65, nY1+210, 30, nHeight, Label = "—")
   133    132           self._addWidget('tot_of_entries', 'FixedText', nX+100, nY1+210, 60, nHeight, Label = self.dUI.get('tot_of_entries', "#err"), Align = 2)
   134    133           self.xTotWord = self._addWidget('tot_of_entries_res', 'FixedText', nX+165, nY1+210, 30, nHeight, Label = "—")
   135    134           
   136    135           # Tag
   137    136           # Note: the only way to group RadioButtons is to create them successively
................................................................................
   180    179               elif xActionEvent.ActionCommand == "CountByLemma":
   181    180                   self.count(self.dUI.get("lemmas", "#err"), bByLemma=True)
   182    181                   self.xTag.Enabled = False
   183    182               elif xActionEvent.ActionCommand == "UnknownWords":
   184    183                   self.count(self.dUI.get("unknown_words", "#err"), bOnlyUnknownWords=True)
   185    184                   self.xTag.Enabled = True
   186    185               elif xActionEvent.ActionCommand == "Tag":
   187         -                nRow = self.xGridControl.getCurrentRow()
   188         -                if nRow == -1:
          186  +                if not self.xGridControl.hasSelectedRows():
   189    187                       return
   190         -                sWord = self.xGridModel.GridDataModel.getCellData(0, nRow)
   191         -                if not sWord:
   192         -                    return
          188  +                lRow = self.xGridControl.getSelectedRows()
          189  +                aWord = set([ self.xGridModel.GridDataModel.getCellData(0, n)  for n in lRow ])
   193    190                   sAction = ""
   194    191                   if self.xUnderline.State:
   195    192                       sAction = "underline"
   196    193                   elif self.xNoUnderline.State:
   197    194                       sAction = "nounderline"
   198    195                   elif self.xAccent.State:
   199    196                       sAction = "accentuation"
   200    197                   elif self.xNoAccent.State:
   201    198                       sAction = "noaccentuation"
   202         -                self.tagText(sWord, sAction)
          199  +                self.tagText(aWord, sAction)
   203    200               elif xActionEvent.ActionCommand == "Close":
   204    201                   self.xContainer.endExecute()
   205    202           except:
   206    203               traceback.print_exc()
   207    204       
   208    205       # XJobExecutor
   209    206       def trigger (self, args):
................................................................................
   259    256               i += 1
   260    257               nTotOccur += w
   261    258           self.xProgressBar.ProgressValue = self.xProgressBar.ProgressValueMax
   262    259           self.xNumWord.Label = str(i)
   263    260           self.xTotWord.Label = nTotOccur
   264    261   
   265    262       @_waitPointer
   266         -    def tagText (self, sWord, sAction=""):
          263  +    def tagText (self, aWord, sAction=""):
   267    264           if not sAction:
   268    265               return
   269    266           self.xProgressBar.ProgressValueMax = self._countParagraph()
   270    267           self.xProgressBar.ProgressValue = 0
   271    268           if not self.oTokenizer:
   272    269               self.oTokenizer = self.oSpellChecker.getTokenizer()
   273    270           xCursor = self.xDocument.Text.createTextCursor()
   274    271           xCursor.gotoStart(False)
   275         -        self._tagParagraph(xCursor, sWord, sAction)
          272  +        self._tagParagraph(xCursor, aWord, sAction)
   276    273           while xCursor.gotoNextParagraph(False):
   277         -            self._tagParagraph(xCursor, sWord, sAction)
          274  +            self._tagParagraph(xCursor, aWord, sAction)
   278    275           self.xProgressBar.ProgressValue = self.xProgressBar.ProgressValueMax
   279    276   
   280         -    def _tagParagraph (self, xCursor, sWord, sAction):
          277  +    def _tagParagraph (self, xCursor, aWord, sAction):
   281    278           xCursor.gotoEndOfParagraph(True)
   282    279           sParagraph = xCursor.getString()
   283    280           xCursor.gotoStartOfParagraph(False)
   284    281           nPos = 0
   285    282           for dToken in self.oTokenizer.genTokens(sParagraph):
   286         -            if dToken["sValue"] == sWord:
          283  +            if dToken["sValue"] in aWord:
   287    284                   xCursor.goRight(dToken["nStart"]-nPos, False) # start of token
   288    285                   nPos = dToken["nEnd"]
   289    286                   xCursor.goRight(nPos-dToken["nStart"], True) # end of token
   290    287                   if sAction == "underline":
   291    288                       xCursor.CharBackColor = hexToRBG("AA0000")
   292    289                   elif sAction == "nounderline":
   293    290                       xCursor.CharBackColor = hexToRBG("FFFFFF")