Grammalecte  Check-in [819d3a016f]

Overview
Comment:[lo] lexicon editor: search within personal dictionary
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | lo | multid
Files: files | file ages | folders
SHA3-256: 819d3a016fc6bd6eaef3a66c5af9dc1c83c868c84dd47892d5f5b98184691676
User & Date: olr on 2018-03-27 16:13:14
Other Links: branch diff | manifest | tags
Context
2018-03-27
16:51
[fx][tb][lo] lexical editor: tag p and q for verb generation check-in: 11a83392a7 user: olr tags: fx, lo, multid, tb
16:13
[lo] lexicon editor: search within personal dictionary check-in: 819d3a016f user: olr tags: lo, multid
16:12
[graphspell][bug] ibdawg: fix initialization with JSON object check-in: c0162510e5 user: olr tags: graphspell, multid
Changes

Modified gc_lang/fr/oxt/DictOptions/LexiconEditor.py from [b0ac6192f3] to [85224c07b2].

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
...
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
...
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378






























379
380
381
382
383
384
385
...
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
    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
        # 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):
................................................................................
            xDialog.run()
        except:
            traceback.print_exc()

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

    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 != "":

            oIBDAWG = ibdawg.IBDAWG(json.loads(sJSON))
            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

................................................................................
        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.xSettingNode.commitChanges()
            self.xNumDic.Label = str(oJSON["nEntry"])
            self.xDateDic.Label = oJSON["sDate"]
        else:
            xChild.setPropertyValue("personal_dic", "")
            self.xSettingNode.commitChanges()
            self.xNumDic.Label = "0"
            self.xDateDic.Label = self.dUI.get("void", "#err")































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

................................................................................
        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',))







|







 







|










>
|







 







|
|

|
|





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
...
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
...
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
...
581
582
583
584
585
586
587



588



























589
590
    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.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):
................................................................................
            xDialog.run()
        except:
            traceback.print_exc()

    # Code
    def launchSearchWords (self):
        xDialog = SearchWords.SearchWords(self.ctx)
        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(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

................................................................................
        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.xSettingNode.commitChanges()
            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

................................................................................
        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)
































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

Modified gc_lang/fr/oxt/DictOptions/SearchWords.py from [cd7d6b9804] to [fbd244567c].

78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
                setattr(xCol, k, w)
            xColumnModel.addColumn(xCol)
        for k, w in kwargs.items():
            setattr(xGridModel, k, w)
        self.xDialog.insertByName(name, xGridModel)
        return xGridModel

    def run (self, sLang):
        # ui lang
        self.dUI = sw_strings.getUI(sLang)


        # dialog
        self.xDialog = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel', self.ctx)
        self.xDialog.Width = 350
        self.xDialog.Height = 305
        self.xDialog.Title = self.dUI.get('title', "#title#")
        #xWindowSize = helpers.getWindowSize()
................................................................................
            elif xActionEvent.ActionCommand == "Close":
                self.xContainer.endExecute()
        except:
            traceback.print_exc()

    def initSpellChecker (self):
        if not self.oSpellChecker:
            self.oSpellChecker = sc.SpellChecker("fr", "fr.bdic", "", "", "")

    @_waitPointer
    def searchSimilar (self):
        self.initSpellChecker()
        sWord = self.xWord.Text.strip()
        if sWord:
            xGridDataModel = self.xGridModel.GridDataModel







|


>







 







|







78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
                setattr(xCol, k, w)
            xColumnModel.addColumn(xCol)
        for k, w in kwargs.items():
            setattr(xGridModel, k, w)
        self.xDialog.insertByName(name, xGridModel)
        return xGridModel

    def run (self, sLang, oPersonalDicJSON):
        # ui lang
        self.dUI = sw_strings.getUI(sLang)
        self.oPersonalDicJSON = oPersonalDicJSON

        # dialog
        self.xDialog = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel', self.ctx)
        self.xDialog.Width = 350
        self.xDialog.Height = 305
        self.xDialog.Title = self.dUI.get('title', "#title#")
        #xWindowSize = helpers.getWindowSize()
................................................................................
            elif xActionEvent.ActionCommand == "Close":
                self.xContainer.endExecute()
        except:
            traceback.print_exc()

    def initSpellChecker (self):
        if not self.oSpellChecker:
            self.oSpellChecker = sc.SpellChecker("fr", "fr.bdic", "", "", self.oPersonalDicJSON)

    @_waitPointer
    def searchSimilar (self):
        self.initSpellChecker()
        sWord = self.xWord.Text.strip()
        if sWord:
            xGridDataModel = self.xGridModel.GridDataModel