Grammalecte  Diff

Differences From Artifact [9c50f96337]:

To Artifact [07ba5d540c]:


1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17



18
19
20
21
22
23
24
1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


-
+














+
+
+







# Lexicon Editor
# by Olivier R.
# License: GPL 3
# License: MPL 2

import unohelper
import uno
import json
import re
import traceback

import helpers
import lxe_strings
import grammalecte.graphspell as sc
import grammalecte.graphspell.dawg as dawg
import grammalecte.graphspell.ibdawg as ibdawg
import grammalecte.fr.conj as conj
import grammalecte.fr.conj_generator as conjgen

import SearchWords
import TagsInfo

from com.sun.star.task import XJobExecutor
from com.sun.star.awt import XActionListener
from com.sun.star.awt import XKeyListener


def _waitPointer (funcDecorated):
89
90
91
92
93
94
95

96
97
98
99
100
101
102
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106







+







        for k, w in kwargs.items():
            setattr(xGridModel, k, w)
        self.xDialog.insertByName(name, xGridModel)
        return xGridModel

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

        # dialog
        self.xDialog = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel', self.ctx)
        self.xDialog.Width = 570
        self.xDialog.Height = 305
        self.xDialog.Title = self.dUI.get('title', "#title#")
134
135
136
137
138
139
140
141

142
143
144
145



146
147
148
149
150
151
152
138
139
140
141
142
143
144

145
146
147
148

149
150
151
152
153
154
155
156
157
158







-
+



-
+
+
+








        #### Dictionary section
        self._addWidget("dictionary_section", 'FixedLine', nX1, nY0, 180, nHeight, Label = self.dUI.get("dictionary_section", "#err"), FontDescriptor = xFDTitle, TextColor = 0x000088)
        self._addWidget("save_date_label", 'FixedText', nXB, nY0+2, 80, nHeight, Label = self.dUI.get("save_date_label", "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x000088)
        self._addWidget("num_of_entries_label2", 'FixedText', nXC, nY0+2, 65, nHeight, Label = self.dUI.get("num_of_entries_label", "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x000088)
        self.xDateDic = self._addWidget("save_date", 'FixedText', nXB+85, nY0+2, 75, nHeight, Label = self.dUI.get("void", "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x000088)
        self.xNumDic = self._addWidget("num_of_entries2", 'FixedText', nXC+70, nY0+2, 45, nHeight, Label = "0", FontDescriptor = xFDSubTitle, TextColor = 0x000088)
        self.xExport = self._addWidget('export_button', 'Button', nXC+150, nY0, 50, 12, Label = self.dUI.get('export_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x005500)
        self.xExport = self._addWidget('export_button', 'Button', nXC+150, nY0, 50, 12, Label = self.dUI.get('export_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x000055)

        #### Add word
        self._addWidget("add_section", 'FixedLine', nX1, nY1, 180, nHeight, Label = self.dUI.get("add_section", "#err"), FontDescriptor = xFDTitle)
        self.xLemma = self._addWidget('lemma', 'Edit', nX1, nY1+10, 120, 14, FontDescriptor = xFDTitle)
        self.xLemma = self._addWidget('lemma', 'Edit', nX1, nY1+10, 110, 14, FontDescriptor = xFDTitle)
        self._addWidget('search_button', 'Button', nX1+115, nY1+11, 45, 12, Label = self.dUI.get('search_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x555500)
        self._addWidget('information_button', 'Button', nX1+165, nY1+11, 15, 12, Label = self.dUI.get('information_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x555500)

        # Radio buttons: main POS tag
        # Note: the only way to group RadioButtons is to create them successively
        self.xNA = self._addWidget('nom_adj', 'RadioButton', nX1, nY2+12, 60, nHeight, Label = self.dUI.get("nom_adj", "#err"), HelpText = ":N:A")
        self.xN = self._addWidget('nom', 'RadioButton', nX1, nY2+22, 60, nHeight, Label = self.dUI.get("nom", "#err"), HelpText = ":N")
        self.xA = self._addWidget('adj', 'RadioButton', nX1, nY2+32, 60, nHeight, Label = self.dUI.get("adj", "#err"), HelpText = ":A")
        self.xM1 = self._addWidget('M1', 'RadioButton', nX1, nY3+12, 60, nHeight, Label = self.dUI.get("M1", "#err"), HelpText = ":M1")
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
169
170
171
172
173
174
175

176
177
178
179
180
181
182
183







-
+







        self.xSfem = self._addWidget('Sfem', 'RadioButton', nX1+65, nY2+32, 50, nHeight, Label = self.dUI.get("fem", "#err"), HelpText = ":f")
        self._addWidget("fl_sep1", 'FixedLine', nX1, nY2, 1, nHeight)
        self.xSs = self._addWidget('Ss', 'RadioButton', nX1+120, nY2+12, 50, nHeight, Label = self.dUI.get("-s", "#err"), HelpText = "·s")
        self.xSx = self._addWidget('Sx', 'RadioButton', nX1+120, nY2+22, 50, nHeight, Label = self.dUI.get("-x", "#err"), HelpText = "·x")
        self.xSinv = self._addWidget('Sinv', 'RadioButton', nX1+120, nY2+32, 50, nHeight, Label = self.dUI.get("inv", "#err"), HelpText = ":i")

        self._addWidget("alt_lemma_label", 'FixedLine', nX1+10, nY2+42, 170, nHeight, Label = self.dUI.get("alt_lemma", "#err"))
        self.xAltLemma = self._addWidget('alt_lemma', 'Edit', nX1+10, nY2+52, 120, nHeight)
        self.xAltLemma = self._addWidget('alt_lemma', 'Edit', nX1+10, nY2+52, 110, nHeight)
        self.xNA2 = self._addWidget('nom_adj2', 'RadioButton', nX1+10, nY2+65, 60, nHeight, Label = self.dUI.get("nom_adj", "#err"), HelpText = ":N:A")
        self.xN2 = self._addWidget('nom2', 'RadioButton', nX1+10, nY2+75, 60, nHeight, Label = self.dUI.get("nom", "#err"), HelpText = ":N")
        self.xA2 = self._addWidget('adj2', 'RadioButton', nX1+10, nY2+85, 60, nHeight, Label = self.dUI.get("adj", "#err"), HelpText = ":A")
        self._addWidget("fl_sep2", 'FixedLine', nX1, nY2, 1, nHeight)
        self.xSepi2 = self._addWidget('Sepi2', 'RadioButton', nX1+75, nY2+65, 50, nHeight, Label = self.dUI.get("epi", "#err"), HelpText = ":e")
        self.xSmas2 = self._addWidget('Smas2', 'RadioButton', nX1+75, nY2+75, 50, nHeight, Label = self.dUI.get("mas", "#err"), HelpText = ":m")
        self.xSfem2 = self._addWidget('Sfem2', 'RadioButton', nX1+75, nY2+85, 50, nHeight, Label = self.dUI.get("fem", "#err"), HelpText = ":f")
243
244
245
246
247
248
249




250
251
252
253
254
255
256
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266







+
+
+
+







        self.xGridControlLex = self.xContainer.getControl('list_grid_lexicon')
        #helpers.xray(self.xContainer.getControl('lemma'))
        self._createKeyListeners(['lemma', 'alt_lemma', "v_pattern", 'flexion', 'tags'], "Update")
        self._createActionListeners(['nom_adj', 'nom', 'adj', 'M1', 'M2', 'MP', 'verb', 'adv', 'other', \
                                     'Sepi', 'Smas', 'Sfem', 'Ss', 'Sx', 'Sinv', 'nom_adj2', 'nom2', 'adj2', \
                                     'Sepi2', 'Smas2', 'Sfem2', 'Ss2', 'Sx2', 'Sinv2', 'Mepi', 'Mmas', 'Mfem', \
                                     'v_i', 'v_t', 'v_n', 'v_p', 'v_m', 'v_ae', 'v_aa', 'v_pp'], "Update")
        self.xContainer.getControl('search_button').addActionListener(self)
        self.xContainer.getControl('search_button').setActionCommand('SearchWords')
        self.xContainer.getControl('information_button').addActionListener(self)
        self.xContainer.getControl('information_button').setActionCommand('TagsInfo')
        self.xContainer.getControl('add_button').addActionListener(self)
        self.xContainer.getControl('add_button').setActionCommand('Add')
        self.xContainer.getControl('delete_button').addActionListener(self)
        self.xContainer.getControl('delete_button').setActionCommand('Delete')
        self.xContainer.getControl('save_button').addActionListener(self)
        self.xContainer.getControl('save_button').setActionCommand('Save')
        self.xContainer.getControl('close_button').addActionListener(self)
270
271
272
273
274
275
276




277
278
279
280
281
282
283
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297







+
+
+
+







            self.xContainer.getControl(sName).setActionCommand(sAction)

    # XActionListener
    def actionPerformed (self, xActionEvent):
        try:
            if xActionEvent.ActionCommand == "Update":
                self.updateGenWords()
            elif xActionEvent.ActionCommand == "SearchWords":
                self.launchSearchWords()
            elif xActionEvent.ActionCommand == "TagsInfo":
                self.launchTagsInfo()
            elif xActionEvent.ActionCommand == "Add":
                self.addToLexicon()
            elif xActionEvent.ActionCommand == "Delete":
                self.deleteSelectedEntries()
            elif xActionEvent.ActionCommand == "Save":
                self.saveLexicon()
            elif xActionEvent.ActionCommand == "Import":
301
302
303
304
305
306
307








308
309
310
311
312
313
314
315

316
317

318
319
320
321
322
323
324
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336

337


338
339
340
341
342
343
344
345







+
+
+
+
+
+
+
+







-
+
-
-
+







        try:
            xDialog = LexiconEditor(self.ctx)
            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, sLine in enumerate(oIBDAWG.select()):
            for i, aEntry in enumerate(oIBDAWG.select()):
                sFlexion, sLemma, sTag = sLine.split("\t")
                xGridDataModel.addRow(i, (sFlexion, sLemma, sTag))
                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