Index: gc_lang/fr/oxt/DictOptions/LexiconEditor.py ================================================================== --- gc_lang/fr/oxt/DictOptions/LexiconEditor.py +++ gc_lang/fr/oxt/DictOptions/LexiconEditor.py @@ -68,11 +68,11 @@ 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) @@ -336,11 +336,11 @@ 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) @@ -347,11 +347,12 @@ #@_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)) + 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) @@ -364,20 +365,50 @@ 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 @@ -552,38 +583,8 @@ 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',)) Index: gc_lang/fr/oxt/DictOptions/SearchWords.py ================================================================== --- gc_lang/fr/oxt/DictOptions/SearchWords.py +++ gc_lang/fr/oxt/DictOptions/SearchWords.py @@ -80,13 +80,14 @@ for k, w in kwargs.items(): setattr(xGridModel, k, w) self.xDialog.insertByName(name, xGridModel) return xGridModel - def run (self, sLang): + 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 @@ -169,11 +170,11 @@ except: traceback.print_exc() def initSpellChecker (self): if not self.oSpellChecker: - self.oSpellChecker = sc.SpellChecker("fr", "fr.bdic", "", "", "") + self.oSpellChecker = sc.SpellChecker("fr", "fr.bdic", "", "", self.oPersonalDicJSON) @_waitPointer def searchSimilar (self): self.initSpellChecker() sWord = self.xWord.Text.strip()