Grammalecte  Check-in [d5be21fa1a]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[lo] Enumerator of words: no more direct formatting, but navigation on words
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | lo
Files: files | file ages | folders
SHA3-256:d5be21fa1ab6f997bd1aea02af647c6000c643ef01e1db458b16de2484e1265e
User & Date: olr 2019-09-29 20:18:25
Context
2019-09-30
07:15
[fr] faux positif check-in: 65265d55cd user: olr tags: fr, trunk, v1.5.0
2019-09-29
20:18
[lo] Enumerator of words: no more direct formatting, but navigation on words check-in: d5be21fa1a user: olr tags: lo, trunk
14:04
[fr] faux positif check-in: 4b21b8f226 user: olr tags: fr, trunk
Changes

Changes to gc_lang/fr/oxt/Lexicographer/Enumerator.py.

   124    124           self._addWidget('count2_button', 'Button', nX+75, nY1+12, 70, 11, Label = self.dUI.get('count2_button', "#err"))
   125    125           self._addWidget('unknown_button', 'Button', nX+150, nY1+12, 70, 11, Label = self.dUI.get('unknown_button', "#err"))
   126    126           self.xGridModel = self._addGrid("list_grid", nX, nY1+25, nWidth, 181, \
   127    127               [ {"Title": self.dUI.get("words", "#err"), "ColumnWidth": 175}, {"Title": "Occurrences", "ColumnWidth": 45} ], \
   128    128               SelectionModel = uno.Enum("com.sun.star.view.SelectionType", "MULTI") \
   129    129           )
   130    130           self._addWidget('num_of_entries', 'FixedText', nX, nY1+210, 60, nHeight, Label = self.dUI.get('num_of_entries', "#err"), Align = 2)
   131         -        self.xNumWord = self._addWidget('num_of_entries_res', 'FixedText', nX+65, nY1+210, 30, nHeight, Label = "—")
   132         -        self._addWidget('tot_of_entries', 'FixedText', nX+100, nY1+210, 60, nHeight, Label = self.dUI.get('tot_of_entries', "#err"), Align = 2)
   133         -        self.xTotWord = self._addWidget('tot_of_entries_res', 'FixedText', nX+165, nY1+210, 30, nHeight, Label = "—")
          131  +        self.xNumWord = self._addWidget('num_of_entries_res', 'FixedText', nX+65, nY1+210, 25, nHeight, Label = "—")
          132  +        self._addWidget('tot_of_entries', 'FixedText', nX+90, nY1+210, 60, nHeight, Label = self.dUI.get('tot_of_entries', "#err"), Align = 2)
          133  +        self.xTotWord = self._addWidget('tot_of_entries_res', 'FixedText', nX+155, nY1+210, 30, nHeight, Label = "—")
          134  +        self.xSearch = self._addWidget('search_button', 'Button', nX+190, nY1+210, 30, nHeight, Label = ">>>", Enabled = False)
   134    135   
   135    136           # Tag
   136    137           # Note: the only way to group RadioButtons is to create them successively
   137         -        self._addWidget("dformat_section", 'FixedLine', nX, nY2, 90, nHeight, Label = self.dUI.get("dformat_section", "#err"), FontDescriptor = xFDTitle)
   138         -        self._addWidget("charstyle_section", 'FixedLine', nX+100, nY2, 90, nHeight, Label = self.dUI.get("charstyle_section", "#err"), FontDescriptor = xFDTitle)
   139         -        self.xUnderline = self._addWidget('underline', 'RadioButton', nX, nY2+12, 40, nHeight, Label = self.dUI.get('underline', "#err"))
   140         -        self.xNoUnderline = self._addWidget('nounderline', 'RadioButton', nX+50, nY2+12, 40, nHeight, Label = self.dUI.get('nounderline', "#err"))
   141         -        self.xAccent = self._addWidget('accentuation', 'RadioButton', nX+100, nY2+12, 50, nHeight, Label = self.dUI.get('accentuation', "#err"))
   142         -        self.xNoAccent = self._addWidget('noaccentuation', 'RadioButton', nX+155, nY2+12, 40, nHeight, Label = self.dUI.get('noaccentuation', "#err"))
          138  +        self._addWidget("charstyle_section", 'FixedLine', nX, nY2, 200, nHeight, Label = self.dUI.get("charstyle_section", "#err"), FontDescriptor = xFDTitle)
          139  +        self.xAccent = self._addWidget('emphasis', 'RadioButton', nX, nY2+12, 55, nHeight, Label = self.dUI.get('emphasis', "#err"))
          140  +        self.xStrongAccent = self._addWidget('strong_emphasis', 'RadioButton', nX+60, nY2+12, 70, nHeight, Label = self.dUI.get('strong_emphasis', "#err"))
          141  +        self.xNoAccent = self._addWidget('nostyle', 'RadioButton', nX+140, nY2+12, 45, nHeight, Label = self.dUI.get('nostyle', "#err"))
   143    142   
   144         -        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)
          143  +        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, Enabled=False)
   145    144   
   146    145           # Progress bar
   147    146           self.xProgressBar = self._addWidget('progress_bar', 'ProgressBar', nX, self.xDialog.Height-25, 160, 14)
   148    147           self.xProgressBar.ProgressValueMin = 0
   149    148           self.xProgressBar.ProgressValueMax = 1 # to calculate later
   150    149   
   151    150           # Close
................................................................................
   157    156           self.xGridControl = self.xContainer.getControl('list_grid')
   158    157           self.xContainer.getControl('count_button').addActionListener(self)
   159    158           self.xContainer.getControl('count_button').setActionCommand('Count')
   160    159           self.xContainer.getControl('count2_button').addActionListener(self)
   161    160           self.xContainer.getControl('count2_button').setActionCommand('CountByLemma')
   162    161           self.xContainer.getControl('unknown_button').addActionListener(self)
   163    162           self.xContainer.getControl('unknown_button').setActionCommand('UnknownWords')
          163  +        self.xContainer.getControl('search_button').addActionListener(self)
          164  +        self.xContainer.getControl('search_button').setActionCommand('Search')
   164    165           self.xContainer.getControl('tag_button').addActionListener(self)
   165    166           self.xContainer.getControl('tag_button').setActionCommand('Tag')
   166    167           self.xContainer.getControl('close_button').addActionListener(self)
   167    168           self.xContainer.getControl('close_button').setActionCommand('Close')
   168    169           self.xContainer.setVisible(True)    # True for non modal dialog
   169    170           xToolkit = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.ExtToolkit', self.ctx)
   170    171           self.xContainer.createPeer(xToolkit, None)
................................................................................
   172    173   
   173    174       # XActionListener
   174    175       def actionPerformed (self, xActionEvent):
   175    176           try:
   176    177               if xActionEvent.ActionCommand == "Count":
   177    178                   self.count(self.dUI.get("words", "#err"))
   178    179                   self.xTag.Enabled = True
          180  +                self.xSearch.Enabled = True
   179    181               elif xActionEvent.ActionCommand == "CountByLemma":
   180    182                   self.count(self.dUI.get("lemmas", "#err"), bByLemma=True)
   181    183                   self.xTag.Enabled = False
          184  +                self.xSearch.Enabled = False
   182    185               elif xActionEvent.ActionCommand == "UnknownWords":
   183    186                   self.count(self.dUI.get("unknown_words", "#err"), bOnlyUnknownWords=True)
   184    187                   self.xTag.Enabled = True
          188  +                self.xSearch.Enabled = True
          189  +            elif xActionEvent.ActionCommand == "Search":
          190  +                if not self.xGridControl.hasSelectedRows():
          191  +                    return
          192  +                lRow = self.xGridControl.getSelectedRows()
          193  +                aWord = set([ self.xGridModel.GridDataModel.getCellData(0, n)  for n in lRow ])
          194  +                self.gotoWord(aWord)
   185    195               elif xActionEvent.ActionCommand == "Tag":
   186    196                   if not self.xGridControl.hasSelectedRows():
   187    197                       return
   188    198                   lRow = self.xGridControl.getSelectedRows()
   189    199                   aWord = set([ self.xGridModel.GridDataModel.getCellData(0, n)  for n in lRow ])
   190    200                   sAction = ""
   191         -                if self.xUnderline.State:
   192         -                    sAction = "underline"
   193         -                elif self.xNoUnderline.State:
   194         -                    sAction = "nounderline"
   195         -                elif self.xAccent.State:
   196         -                    sAction = "accentuation"
          201  +                if self.xAccent.State:
          202  +                    sAction = "emphasis"
          203  +                elif self.xStrongAccent.State:
          204  +                    sAction = "strong_emphasis"
   197    205                   elif self.xNoAccent.State:
   198         -                    sAction = "noaccentuation"
          206  +                    sAction = "nostyle"
   199    207                   self.tagText(aWord, sAction)
   200    208               elif xActionEvent.ActionCommand == "Close":
   201    209                   self.xContainer.dispose()           # Non modal dialog
   202    210                   #self.xContainer.endExecute()       # Modal dialog
   203    211           except:
   204    212               traceback.print_exc()
   205    213   
................................................................................
   281    289           xCursor.gotoStartOfParagraph(False)
   282    290           nPos = 0
   283    291           for dToken in self.oTokenizer.genTokens(sParagraph):
   284    292               if dToken["sValue"] in aWord:
   285    293                   xCursor.goRight(dToken["nStart"]-nPos, False) # start of token
   286    294                   nPos = dToken["nEnd"]
   287    295                   xCursor.goRight(nPos-dToken["nStart"], True) # end of token
   288         -                if sAction == "underline":
   289         -                    xCursor.CharBackColor = hexToRBG("AA0000")
   290         -                elif sAction == "nounderline":
   291         -                    xCursor.CharBackColor = hexToRBG("FFFFFF")
   292         -                elif sAction == "accentuation":
          296  +                # if sAction == "underline":
          297  +                #     xCursor.CharBackColor = hexToRBG("AA0000")
          298  +                # elif sAction == "nounderline":
          299  +                #     xCursor.CharBackColor = hexToRBG("FFFFFF")
          300  +                if sAction == "emphasis":
   293    301                       xCursor.CharStyleName = "Emphasis"
   294         -                elif sAction == "noaccentuation":
          302  +                elif sAction == "strong_emphasis":
          303  +                    xCursor.CharStyleName = "Strong Emphasis"
          304  +                elif sAction == "nostyle":
   295    305                       #xCursor.CharStyleName = "Default Style"     # doesn’t work
   296    306                       xCursor.setPropertyToDefault("CharStyleName")
   297    307           self.xProgressBar.ProgressValue += 1
   298    308   
          309  +    @_waitPointer
          310  +    def gotoWord (self, aWord):
          311  +        try:
          312  +            if not aWord:
          313  +                return
          314  +            if not self.oTokenizer:
          315  +                self.oTokenizer = self.oSpellChecker.getTokenizer()
          316  +            xViewCursor = self.xDocument.CurrentController.ViewCursor
          317  +            if not xViewCursor.isCollapsed():
          318  +                xViewCursor.collapseToEnd()
          319  +            xRange = xViewCursor.getStart()
          320  +            xCursor = self.xDocument.Text.createTextCursor()
          321  +            xCursor.gotoRange(xRange, False)
          322  +            #xCursor.gotoEndOfWord(False)
          323  +            xCursor.gotoEndOfParagraph(True)
          324  +            sParagraph = xCursor.getString()
          325  +            xCursor.gotoRange(xRange, False)
          326  +            tPos = self._searchWordsInText(aWord, sParagraph)
          327  +            if not tPos:
          328  +                while xCursor.gotoNextParagraph(False):
          329  +                    xCursor.gotoEndOfParagraph(True)
          330  +                    sParagraph = xCursor.getString()
          331  +                    xCursor.gotoStartOfParagraph(False)
          332  +                    tPos = self._searchWordsInText(aWord, sParagraph)
          333  +                    if tPos:
          334  +                        break
          335  +            if not tPos:
          336  +                xCursor.gotoStart(False)
          337  +                xCursor.gotoEndOfParagraph(True)
          338  +                sParagraph = xCursor.getString()
          339  +                xCursor.gotoStartOfParagraph(True)
          340  +                tPos = self._searchWordsInText(aWord, sParagraph)
          341  +                while xCursor.gotoNextParagraph(False):
          342  +                    xCursor.gotoEndOfParagraph(True)
          343  +                    sParagraph = xCursor.getString()
          344  +                    xCursor.gotoStartOfParagraph(False)
          345  +                    tPos = self._searchWordsInText(aWord, sParagraph)
          346  +                    if tPos:
          347  +                        break
          348  +            if tPos:
          349  +                xCursor.goRight(tPos[0], False)
          350  +                xRange = xCursor.getStart()
          351  +                xViewCursor.gotoRange(xRange, False)
          352  +                xViewCursor.goRight(tPos[1], True)
          353  +        except:
          354  +            traceback.print_exc()
          355  +
          356  +    def _searchWordsInText (self, aWord, sText):
          357  +        for dToken in self.oTokenizer.genTokens(sText):
          358  +            if dToken["sValue"] in aWord:
          359  +                return (dToken["nStart"], dToken["nEnd"]-dToken["nStart"])
          360  +        return None
   299    361   
   300    362   #g_ImplementationHelper = unohelper.ImplementationHelper()
   301    363   #g_ImplementationHelper.addImplementation(Enumerator, 'net.grammalecte.enumerator', ('com.sun.star.task.Job',))

Changes to gc_lang/fr/oxt/Lexicographer/enum_strings.py.

     2      2       if sLang in dStrings:
     3      3           return dStrings[sLang]
     4      4       return dStrings["fr"]
     5      5   
     6      6   dStrings = {
     7      7       "fr": {
     8      8           "title": "Grammalecte · Recenseur de mots",
     9         -        
            9  +
    10     10           "list_section": "Énumération des occurrences",
    11     11           "count_button": "Compter tout",
    12     12           "count2_button": "Compter par lemme",
    13     13           "unknown_button": "Mots inconnus",
    14     14           "num_of_entries": "Nombre d’entrées :",
    15     15           "tot_of_entries": "Total des entrées :",
    16     16   
................................................................................
    18     18           "lemmas": "Lemmes",
    19     19           "unknown_words": "Mots inconnus",
    20     20   
    21     21           "dformat_section": "Formatage direct",
    22     22           "charstyle_section": "Style de caractères",
    23     23           "underline": "Surligner",
    24     24           "nounderline": "Effacer",
    25         -        "accentuation": "Accentuation",
    26         -        "noaccentuation": "Aucun",
           25  +        "emphasis": "Accentuation",
           26  +        "strong_emphasis": "Accentuation forte",
           27  +        "nostyle": "Aucun",
    27     28           "tag_button": "Taguer",
    28     29   
    29     30           "close_button": "Fermer",
    30     31       },
    31     32       "en": {
    32     33           "title": "Grammalecte · Enumerator of words",
    33     34   
................................................................................
    42     43           "lemmas": "Lemmas",
    43     44           "unknown_words": "Unknown words",
    44     45   
    45     46           "dformat_section": "Direct format",
    46     47           "charstyle_section": "Character style",
    47     48           "underline": "Underline",
    48     49           "nounderline": "Erase",
    49         -        "accentuation": "Accentuation",
    50         -        "noaccentuation": "None",
           50  +        "emphasis": "Emphasis",
           51  +        "strong_emphasis": "Strong emphasis",
           52  +        "nostyle": "None",
    51     53           "tag_button": "Tag",
    52     54   
    53     55           "close_button": "Close",
    54     56       },
    55     57   }