Grammalecte  Diff

Differences From Artifact [b0ac6192f3]:

To Artifact [85224c07b2]:


66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80







-
+







    def __init__ (self, ctx):
        self.ctx = ctx
        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
        self.oPersonalDicJSON = 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):
334
335
336
337
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
334
335
336
337
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







-
+










+
-
+
















-
-
+
+

-
-
+
+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







            xDialog.run()
        except:
            traceback.print_exc()

    # Code
    def launchSearchWords (self):
        xDialog = SearchWords.SearchWords(self.ctx)
        xDialog.run(self.sLang)
        xDialog.run(self.sLang, self.oPersonalDicJSON)

    def launchTagsInfo (self):
        xDialog = TagsInfo.TagsInfo(self.ctx)
        xDialog.run(self.sLang)

    #@_waitPointer (don’t: strange behavior)
    def loadLexicon (self):
        xChild = self.xSettingNode.getByName("o_fr")
        sJSON = xChild.getPropertyValue("personal_dic")
        if sJSON != "":
            self.oPersonalDicJSON = json.loads(sJSON)
            oIBDAWG = ibdawg.IBDAWG(json.loads(sJSON))
            oIBDAWG = ibdawg.IBDAWG(self.oPersonalDicJSON)
            xGridDataModel = self.xGridModelLex.GridDataModel
            for i, aEntry in enumerate(oIBDAWG.select()):
                xGridDataModel.addRow(i, aEntry)
            self.xNumLex.Label = str(i)
            self.xNumDic.Label = str(i)
            self.xDateDic.Label = oIBDAWG.sDate

    @_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")
            oJSON = oDAWG.getBinaryAsJSON()
            xChild.setPropertyValue("personal_dic", json.dumps(oJSON, ensure_ascii=False))
            self.oPersonalDicJSON = oDAWG.getBinaryAsJSON()
            xChild.setPropertyValue("personal_dic", json.dumps(self.oPersonalDicJSON, ensure_ascii=False))
            self.xSettingNode.commitChanges()
            self.xNumDic.Label = str(oJSON["nEntry"])
            self.xDateDic.Label = oJSON["sDate"]
            self.xNumDic.Label = str(self.oPersonalDicJSON["nEntry"])
            self.xDateDic.Label = self.oPersonalDicJSON["sDate"]
        else:
            xChild.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")
            xChild = self.xSettingNode.getByName("o_fr")
            sJSON = xChild.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")
        except:
            sMessage = traceback.format_exc()
        MessageBox(self.xDocument, sMessage, self.dUI.get('export_title', "#err"))

        # FilePicker doesn’t work at all…
        #xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.SystemFilePicker', self.ctx)
        #xFilePicker.appendFilter("Supported files", "*.json; *.bdic")
        #xFilePicker.setDisplayDirectory("")
        #xFilePicker.setMultiSelectionMode(True)
        #nResult = xFilePicker.execute()
        #if nResult == 1:
            #pass
            #lFile = xFilePicker.getSelectedFiles()
            #lFile = xFilePicker.getFiles()

    @_waitPointer
    def importDictionary (self):
        pass

    def _getRadioValue (self, *args):
        for x in args:
            if x.State:
                return x.HelpText
        return None

550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
581
582
583
584
585
586
587



588



























589
590







-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


        nSelectedEntries = len(self.xGridControlLex.getSelectedRows())
        for i in self.xGridControlLex.getSelectedRows():
            if i < xGridDataModel.RowCount:
                xGridDataModel.removeRow(i)
        self.xGridControlLex.deselectAllRows()
        self.xNumLex.Label = str(xGridDataModel.RowCount)

    @_waitPointer
    def importDictionary (self):
        pass

    def exportDictionary (self):
        try:
            spfExported = os.path.join(os.environ['USERPROFILE'], "fr.personal.json")
            xChild = self.xSettingNode.getByName("o_fr")
            sJSON = xChild.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")
        except:
            sMessage = traceback.format_exc()
        MessageBox(self.xDocument, sMessage, self.dUI.get('export_title', "#err"))

        # FilePicker doesn’t work at all…
        #xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.SystemFilePicker', self.ctx)
        #xFilePicker.appendFilter("Supported files", "*.json; *.bdic")
        #xFilePicker.setDisplayDirectory("")
        #xFilePicker.setMultiSelectionMode(True)
        #nResult = xFilePicker.execute()
        #if nResult == 1:
            #pass
            #lFile = xFilePicker.getSelectedFiles()
            #lFile = xFilePicker.getFiles()


#g_ImplementationHelper = unohelper.ImplementationHelper()
#g_ImplementationHelper.addImplementation(LexiconEditor, 'net.grammalecte.LexiconEditor', ('com.sun.star.task.Job',))