Index: gc_lang/fr/oxt/DictOptions/LexiconEditor.py ================================================================== --- gc_lang/fr/oxt/DictOptions/LexiconEditor.py +++ gc_lang/fr/oxt/DictOptions/LexiconEditor.py @@ -25,11 +25,11 @@ from com.sun.star.awt import XKeyListener from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK # BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_RETRY_CANCEL, BUTTONS_ABORT_IGNORE_RETRY # DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE -from com.sun.star.awt.MessageBoxType import INFOBOX # MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX +from com.sun.star.awt.MessageBoxType import INFOBOX, ERRORBOX # MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX def MessageBox (xDocument, sMsg, sTitle, nBoxType=INFOBOX, nBoxButtons=BUTTONS_OK): xParentWin = xDocument.CurrentController.Frame.ContainerWindow ctx = uno.getComponentContext() xToolkit = ctx.ServiceManager.createInstanceWithContext("com.sun.star.awt.Toolkit", ctx) @@ -153,11 +153,12 @@ 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 = 0x000055) + self.xImport = self._addWidget('import_button', 'Button', self.xDialog.Width-90, nY0, 40, 12, Label = self.dUI.get('import_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x000055) + self.xExport = self._addWidget('export_button', 'Button', self.xDialog.Width-50, nY0, 40, 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, 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) @@ -274,10 +275,12 @@ 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('import_button').addActionListener(self) + self.xContainer.getControl('import_button').setActionCommand('Import') self.xContainer.getControl('export_button').addActionListener(self) self.xContainer.getControl('export_button').setActionCommand('Export') self.xContainer.getControl('close_button').addActionListener(self) self.xContainer.getControl('close_button').setActionCommand('Close') self.xContainer.setVisible(False) @@ -342,23 +345,52 @@ def launchTagsInfo (self): xDialog = TagsInfo.TagsInfo(self.ctx) xDialog.run(self.sLang) - #@_waitPointer (don’t: strange behavior) + #@_waitPointer (don’t: strange behavior when dialog is not finished) def loadLexicon (self): + xGridDataModel = self.xGridModelLex.GridDataModel + xGridDataModel.removeAllRows() 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 + sJSON = xChild.getPropertyValue("personal_dic") + if sJSON: + try: + self.oPersonalDicJSON = json.loads(sJSON) + oIBDAWG = ibdawg.IBDAWG(self.oPersonalDicJSON) + 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 + except: + sMessage = self.dUI.get('not_loaded', "#err") + sMessage += traceback.format_exc() + MessageBox(self.xDocument, sMessage, self.dUI.get('load_title', "#err"), ERRORBOX) + else: + self.xNumLex.Label = 0 + self.xNumDic.Label = 0 + self.xDateDic.Label = self.dUI.get("void", "#err") + + @_waitPointer + def importDictionary (self): + spfImported = os.path.join(os.environ['USERPROFILE'], "fr.personal.json") + if 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 + MessageBox(self.xDocument, sMessage, self.dUI.get('import_title', "#err"), ERRORBOX) + else: + xChild = self.xSettingNode.getByName("o_fr") + xChild.setPropertyValue("personal_dic", sJSON) + self.loadLexicon() + else: + sMessage = self.dUI.get('file_not_found', "#err_msg: %s") % spfImported + MessageBox(self.xDocument, sMessage, self.dUI.get('import_title', "#err"), ERRORBOX) @_waitPointer def saveLexicon (self): xGridDataModel = self.xGridModelLex.GridDataModel lEntry = [] @@ -387,13 +419,14 @@ 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") + MessageBox(self.xDocument, sMessage, self.dUI.get('export_title', "#err")) except: sMessage = traceback.format_exc() - MessageBox(self.xDocument, sMessage, self.dUI.get('export_title', "#err")) + MessageBox(self.xDocument, sMessage, self.dUI.get('export_title', "#err"), ERRORBOX) # 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("") @@ -402,14 +435,10 @@ #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 Index: gc_lang/fr/oxt/DictOptions/lxe_strings.py ================================================================== --- gc_lang/fr/oxt/DictOptions/lxe_strings.py +++ gc_lang/fr/oxt/DictOptions/lxe_strings.py @@ -66,14 +66,20 @@ # Dictionary "dictionary_section": "Dictionnaire personnel", "save_date_label": "Date d’enregistrement :", "num_of_entries_label": "Nombre d’entrées :", + "import_button": "Importer", + "import_title": "Importation du dictionnaire", "export_button": "Exporter", "export_title": "Exportation du dictionnaire", "export_message": "Fichier exporté : ‹%s›", "empty_dictionary": "Le dictionnaire est vide. Aucun fichier créé.", + "file_not_found": "Le fichier ‹%s› ne semble pas exister.", + "wrong_json": "Le fichier ‹%s› n’est pas un fichier JSON valide.", + "load_title": "Chargement du dictionnaire.", + "not_loaded": "Le fichier n’a pas pu être chargé.\n", "void": "[néant]", # Close button "close_button": "Fermer",