Grammalecte  Diff

Differences From Artifact [2bb83eccad]:

To Artifact [8be9d56e0e]:


72
73
74
75
76
77
78

79
80
81
82
83
84
85
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86







+







        self.xDialog = None
        self.oPersonalDicJSON = None
        # data
        self.sLemma = ""
        self.lGeneratedFlex = []
        # options node
        self.xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_grammalecte/Other/", True)
        self.xOptionNode = self.xSettingNode.getByName("o_fr")

    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
        xWidget.PositionY = y
        xWidget.Width = w
347
348
349
350
351
352
353
354
355

356
357
358
359
360
361
362
348
349
350
351
352
353
354


355
356
357
358
359
360
361
362







-
-
+







        xDialog = TagsInfo.TagsInfo(self.ctx)
        xDialog.run(self.sLang)

    #@_waitPointer (don’t: strange behavior when dialog is not finished)
    def loadLexicon (self):
        xGridDataModel = self.xGridModelLex.GridDataModel
        xGridDataModel.removeAllRows()
        xChild = self.xSettingNode.getByName("o_fr")
        sJSON = xChild.getPropertyValue("personal_dic")        
        sJSON = self.xOptionNode.getPropertyValue("personal_dic")        
        if sJSON:
            try:
                self.oPersonalDicJSON = json.loads(sJSON)
                oIBDAWG = ibdawg.IBDAWG(self.oPersonalDicJSON)
                for i, aEntry in enumerate(oIBDAWG.select()):
                    xGridDataModel.addRow(i, aEntry)
                self.xNumLex.Label = str(i)
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
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







-
+
-
-
+
+











-



-
+




-
+






-
+
-
-
+







            with open(spfImported, "r", encoding="utf-8") as hDst:
                sJSON = hDst.read()
                try:
                    sTest = json.loads(sJSON)
                except:
                    sMessage = self.dUI.get('wrong_json', "#err_msg: %s") % spfImported
                    MessageBox(self.xDocument, sMessage, self.dUI.get('import_title', "#err"), ERRORBOX)
                else:
                else:            
                    xChild = self.xSettingNode.getByName("o_fr")
                    xChild.setPropertyValue("personal_dic", sJSON)
                    self.xOptionNode.setPropertyValue("personal_dic", sJSON)
                    self.xSettingNode.commitChanges()
                    self.loadLexicon()
        else:
            sMessage = self.dUI.get('file_not_found', "#err_msg: %s") % spfImported
            MessageBox(self.xDocument, sMessage, self.dUI.get('import_title', "#err"), ERRORBOX)

    @_waitPointer
    def saveLexicon (self):
        xGridDataModel = self.xGridModelLex.GridDataModel
        lEntry = []
        for i in range(xGridDataModel.RowCount):
            lEntry.append(xGridDataModel.getRowData(i))
        xChild = self.xSettingNode.getByName("o_fr")
        if lEntry:
            oDAWG = dawg.DAWG(lEntry, "S", "fr", "Français", "Dictionnaire personnel")
            self.oPersonalDicJSON = oDAWG.getBinaryAsJSON()
            xChild.setPropertyValue("personal_dic", json.dumps(self.oPersonalDicJSON, ensure_ascii=False))
            self.xOptionNode.setPropertyValue("personal_dic", json.dumps(self.oPersonalDicJSON, ensure_ascii=False))
            self.xSettingNode.commitChanges()
            self.xNumDic.Label = str(self.oPersonalDicJSON["nEntry"])
            self.xDateDic.Label = self.oPersonalDicJSON["sDate"]
        else:
            xChild.setPropertyValue("personal_dic", "")
            self.xOptionNode.setPropertyValue("personal_dic", "")
            self.xSettingNode.commitChanges()
            self.xNumDic.Label = "0"
            self.xDateDic.Label = self.dUI.get("void", "#err")

    def exportDictionary (self):
        try:
            spfExported = os.path.join(os.environ['USERPROFILE'], "fr.personal.json")
            spfExported = os.path.join(os.environ['USERPROFILE'], "fr.personal.json")    
            xChild = self.xSettingNode.getByName("o_fr")
            sJSON = xChild.getPropertyValue("personal_dic")
            sJSON = self.xOptionNode.getPropertyValue("personal_dic")
            if sJSON:
                with open(spfExported, "w", encoding="utf-8") as hDst:
                    hDst.write(sJSON)
                sMessage = self.dUI.get('export_message', "#err_msg: %s") % spfExported
            else:
                sMessage = self.dUI.get('empty_dictionary', "#err")
            MessageBox(self.xDocument, sMessage, self.dUI.get('export_title', "#err"))