Grammalecte  Diff

Differences From Artifact [e3eb9c5ac2]:

To Artifact [1b519e944b]:


52
53
54
55
56
57
58

59
60
61
62
63
64
65
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66







+







        self.xSvMgr = self.ctx.ServiceManager
        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
        # data
        self.sLemma = ""
        self.lGeneratedFlex = []
        # options node
        self.xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_grammalecte/Other/", True)

    def _addWidget (self, name, wtype, x, y, w, h, **kwargs):
        xWidget = self.xDialog.createInstance('com.sun.star.awt.UnoControl%sModel' % wtype)
        xWidget.Name = name
338
339
340
341
342
343
344
345
346


347
348
349
350
351
352
353
354


355
356
357


358
359

360
361
362
363
364
365


366
367
368


369
370

371
372
373
374

375
376
377

378
379
380
381


382
383
384
385
386
387
388
389
390
391
392
393
394
395


396
397
398
399

400
401
402
403
404

405
406
407
408
409
410


411
412
413
414



415
416

417
418
419
420


421
422
423
424
425
426

427
428
429
430
431
432
433
434
435
436


437
438
439
440
441
442
443
339
340
341
342
343
344
345


346
347
348
349
350
351
352
353


354
355
356


357
358
359

360
361
362
363
364


365
366
367


368
369
370

371
372
373
374

375
376
377

378
379
380


381
382
383
384
385
386
387
388
389
390
391
392
393
394


395
396
397
398
399

400
401
402
403
404

405
406
407
408
409


410
411
412



413
414
415
416

417
418
419


420
421
422
423
424
425
426

427
428
429
430
431
432
433
434
435


436
437
438
439
440
441
442
443
444







-
-
+
+






-
-
+
+

-
-
+
+

-
+




-
-
+
+

-
-
+
+

-
+



-
+


-
+


-
-
+
+












-
-
+
+



-
+




-
+




-
-
+
+

-
-
-
+
+
+

-
+


-
-
+
+





-
+








-
-
+
+







            if x.State:
                return x.HelpText
        return None

    @_waitPointer
    def updateGenWords (self):
        self.lGeneratedFlex = []
        sLemma = self.xLemma.Text.strip()
        if sLemma:
        self.sLemma = self.xLemma.Text.strip()
        if self.sLemma:
            if self._getRadioValue(self.xNA, self.xN, self.xA):
                # Substantif
                sPOS = self._getRadioValue(self.xNA, self.xN, self.xA)
                sGenderTag = self._getRadioValue(self.xSepi, self.xSmas, self.xSfem)
                if sGenderTag:
                    if self.xSs.State:
                        self.lGeneratedFlex.append((sLemma, sLemma, sPOS+sGenderTag+":s/*"))
                        self.lGeneratedFlex.append((sLemma+"s", sLemma, sPOS+sGenderTag+":p/*"))
                        self.lGeneratedFlex.append((self.sLemma, sPOS+sGenderTag+":s/*"))
                        self.lGeneratedFlex.append((self.sLemma+"s", sPOS+sGenderTag+":p/*"))
                    elif self.xSx.State:
                        self.lGeneratedFlex.append((sLemma, sLemma, sPOS+sGenderTag+":s/*"))
                        self.lGeneratedFlex.append((sLemma+"x", sLemma, sPOS+sGenderTag+":p/*"))
                        self.lGeneratedFlex.append((self.sLemma, sPOS+sGenderTag+":s/*"))
                        self.lGeneratedFlex.append((self.sLemma+"x", sPOS+sGenderTag+":p/*"))
                    elif self.xSinv.State:
                        self.lGeneratedFlex.append((sLemma, sLemma, sPOS+sGenderTag+":i/*"))
                        self.lGeneratedFlex.append((self.sLemma, sPOS+sGenderTag+":i/*"))
                    sLemma2 = self.xAltLemma.Text.strip()
                    if sLemma2 and self._getRadioValue(self.xNA2, self.xN2, self.xA2) and self._getRadioValue(self.xSepi2, self.xSmas2, self.xSfem2):
                        sTag2 = self._getRadioValue(self.xNA2, self.xN2, self.xA2) + self._getRadioValue(self.xSepi2, self.xSmas2, self.xSfem2)
                        if self.xSs2.State:
                            self.lGeneratedFlex.append((sLemma2, sLemma, sTag2+":s/*"))
                            self.lGeneratedFlex.append((sLemma2+"s", sLemma, sTag2+":p/*"))
                            self.lGeneratedFlex.append((sLemma2, sTag2+":s/*"))
                            self.lGeneratedFlex.append((sLemma2+"s", sTag2+":p/*"))
                        elif self.xSx2.State:
                            self.lGeneratedFlex.append((sLemma2, sLemma, sTag2+":s/*"))
                            self.lGeneratedFlex.append((sLemma2+"x", sLemma, sTag2+":p/*"))
                            self.lGeneratedFlex.append((sLemma2, sTag2+":s/*"))
                            self.lGeneratedFlex.append((sLemma2+"x", sTag2+":p/*"))
                        elif self.xSinv2.State:
                            self.lGeneratedFlex.append((sLemma2, sLemma, sTag2+":i/*"))
                            self.lGeneratedFlex.append((sLemma2, sTag2+":i/*"))
            elif self._getRadioValue(self.xM1, self.xM2, self.xMP):
                # Nom propre
                sPOS = self._getRadioValue(self.xM1, self.xM2, self.xMP)
                sLemma = sLemma[0:1].upper() + sLemma[1:];
                self.sLemma = self.sLemma[0:1].upper() + self.sLemma[1:];
                sGenderTag = self._getRadioValue(self.xMepi, self.xMmas, self.xMfem)
                if sGenderTag:
                    self.lGeneratedFlex.append((sLemma, sLemma, sPOS+sGenderTag+":i/*"))
                    self.lGeneratedFlex.append((self.sLemma, sPOS+sGenderTag+":i/*"))
            elif self.xV.State:
                # Verbe
                if sLemma.endswith(("er", "ir", "re")):
                    sLemma = sLemma.lower()
                if self.sLemma.endswith(("er", "ir", "re")):
                    self.sLemma = self.sLemma.lower()
                    c_i = "i"  if self.xV_i.State  else "_"
                    c_t = "t"  if self.xV_t.State  else "_"
                    c_n = "n"  if self.xV_n.State  else "_"
                    c_p = "p"  if self.xV_p.State  else "_"
                    c_m = "m"  if self.xV_m.State  else "_"
                    c_ae = "e"  if self.xV_ae.State  else "_"
                    c_aa = "a"  if self.xV_aa.State  else "_"
                    sVerbTag = c_i + c_t + c_n + c_p + c_m + c_ae + c_aa
                    if not sVerbTag.endswith("__") and not sVerbTag.startswith("____"):
                        sVerbPattern = self.xVpattern.Text.strip()
                        if not sVerbPattern:
                            # Utilisation du générateur de conjugaison
                            for sFlexion, sFlexTags in conjgen.conjugate(sLemma, sVerbTag, bool(self.xV_pp.State)):
                                self.lGeneratedFlex.append((sFlexion, sLemma, sFlexTags))
                            for sFlexion, sFlexTags in conjgen.conjugate(self.sLemma, sVerbTag, bool(self.xV_pp.State)):
                                self.lGeneratedFlex.append((sFlexion, sFlexTags))
                        else:
                            # copie du motif d’un autre verbe : utilisation du conjugueur
                            if conj.isVerb(sVerbPattern):
                                oVerb = conj.Verb(sLemma, sVerbPattern)
                                oVerb = conj.Verb(self.sLemma, sVerbPattern)
                                for sTag1, dFlex in oVerb.dConj.items():
                                    if sTag1 != ":Q":
                                        for sTag2, sConj in dFlex.items():
                                            if sTag2.startswith(":") and sConj:
                                                self.lGeneratedFlex.append((sConj, sLemma, ":V" + oVerb.cGroup + "_" + sVerbTag + sTag1 + sTag2))
                                                self.lGeneratedFlex.append((sConj, ":V" + oVerb.cGroup + "_" + sVerbTag + sTag1 + sTag2))
                                    else:
                                        # participes passés
                                        if dFlex[":Q3"]:
                                            if dFlex[":Q2"]:
                                                self.lGeneratedFlex.append((dFlex[":Q1"], sLemma, ":V" + oVerb.cGroup + "_" + sVerbTag + ":Q:A:m:s/*"))
                                                self.lGeneratedFlex.append((dFlex[":Q2"], sLemma, ":V" + oVerb.cGroup + "_" + sVerbTag + ":Q:A:m:p/*"))
                                                self.lGeneratedFlex.append((dFlex[":Q1"], ":V" + oVerb.cGroup + "_" + sVerbTag + ":Q:A:m:s/*"))
                                                self.lGeneratedFlex.append((dFlex[":Q2"], ":V" + oVerb.cGroup + "_" + sVerbTag + ":Q:A:m:p/*"))
                                            else:
                                                self.lGeneratedFlex.append((dFlex[":Q1"], sLemma, ":V" + oVerb.cGroup + "_" + sVerbTag + ":Q:A:m:i/*"))
                                            self.lGeneratedFlex.append((dFlex[":Q3"], sLemma, ":V" + oVerb.cGroup + "_" + sVerbTag + ":Q:A:f:s/*"))
                                            self.lGeneratedFlex.append((dFlex[":Q4"], sLemma, ":V" + oVerb.cGroup + "_" + sVerbTag + ":Q:A:f:p/*"))
                                                self.lGeneratedFlex.append((dFlex[":Q1"], ":V" + oVerb.cGroup + "_" + sVerbTag + ":Q:A:m:i/*"))
                                            self.lGeneratedFlex.append((dFlex[":Q3"], ":V" + oVerb.cGroup + "_" + sVerbTag + ":Q:A:f:s/*"))
                                            self.lGeneratedFlex.append((dFlex[":Q4"], ":V" + oVerb.cGroup + "_" + sVerbTag + ":Q:A:f:p/*"))
                                        else:
                                            self.lGeneratedFlex.append((dFlex[":Q1"], sLemma, ":V" + oVerb.cGroup + "_" + sVerbTag + ":Q:e:i/*"))
                                            self.lGeneratedFlex.append((dFlex[":Q1"], ":V" + oVerb.cGroup + "_" + sVerbTag + ":Q:e:i/*"))
            elif self.xW.State:
                # Adverbe
                sLemma = sLemma.lower();
                self.lGeneratedFlex.append((sLemma, sLemma, ":W/*"))
                self.sLemma = self.sLemma.lower();
                self.lGeneratedFlex.append((self.sLemma, ":W/*"))
            elif self.xX.State:
                # Autre
                sFlexion = self.xFlexion.Text.strip()
                sTags = self.xTags.Text.strip()
                if sFlexion and sTags.startswith(":"):
                    self.lGeneratedFlex.append((sFlexion, sLemma, sTags))
                    self.lGeneratedFlex.append((sFlexion, sTags))
        self._showGenWords()

    def _showGenWords (self):
        xGridDataModel = self.xGridModelNew.GridDataModel
        xGridDataModel.removeAllRows()
        if not self.lGeneratedFlex:
            self.xAdd.Enabled = False
            return
        for i, (sFlexion, sLemma, sTag) in enumerate(self.lGeneratedFlex):
            xGridDataModel.addRow(i, (sFlexion, sLemma, sTag))
        for i, (sFlexion, sTag) in enumerate(self.lGeneratedFlex):
            xGridDataModel.addRow(i, (sFlexion, sTag))
        self.xAdd.Enabled = True

    def _resetWidgets (self):
        self.xLemma.Text = ""
        self.xNA.State = False
        self.xN.State = False
        self.xA.State = False
482
483
484
485
486
487
488
489
490


491
492
493
494
495
496
497
483
484
485
486
487
488
489


490
491
492
493
494
495
496
497
498







-
-
+
+







    @_waitPointer
    def addToLexicon (self):
        self.xAdd.Enabled = False
        xGridDataModelNew = self.xGridModelNew.GridDataModel
        xGridDataModelLex = self.xGridModelLex.GridDataModel
        nStart = xGridDataModelLex.RowCount
        for i in range(xGridDataModelNew.RowCount):
            sFlexion, sLemma, sTag = xGridDataModelNew.getRowData(i)
            xGridDataModelLex.addRow(nStart + i, (sFlexion, sLemma, sTag))
            sFlexion, sTag = xGridDataModelNew.getRowData(i)
            xGridDataModelLex.addRow(nStart + i, (sFlexion, self.sLemma, sTag))
        self.xSave.Enabled = True
        self.xNumLex.Label = str(int(self.xNumLex.Label) + xGridDataModelNew.RowCount)
        self._resetWidgets()

    @_waitPointer
    def deleteSelectedEntries (self):
        # generated entries