1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
+
|
# Lexicon Editor
# by Olivier R.
# License: MPL 2
import unohelper
import uno
import json
import re
import os
import traceback
import platform
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
|
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
|
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
-
+
|
lFile = xFilePicker.getFiles()
#print(lFile)
#MessageBox(self.xDocument, "File(s): " + str(lFile), "DEBUG", INFOBOX)
spfImported = lFile[0][5:].lstrip("/") # remove file://
if platform.system() != "Windows":
spfImported = "/" + spfImported
except:
spfImported = os.path.join(os.path.expanduser("~"), "fr.personal.json") # workaround
spfImported = os.path.join(os.path.expanduser("~"), "fr.__personal__.json") # workaround
if spfImported and os.path.isfile(spfImported):
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
|
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
-
+
|
@_waitPointer
def saveLexicon (self):
xGridDataModel = self.xGridModelLex.GridDataModel
lEntry = []
for i in range(xGridDataModel.RowCount):
lEntry.append(xGridDataModel.getRowData(i))
if lEntry:
oDAWG = dawg.DAWG(lEntry, "S", "fr", "Français", "fr.personal", "Dictionnaire personnel")
oDAWG = dawg.DAWG(lEntry, "S", "fr", "Français", "fr.__personal__", "Dictionnaire personnel")
self.oPersonalDicJSON = oDAWG.getBinaryAsJSON()
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:
self.xOptionNode.setPropertyValue("personal_dic", "")
|