Index: gc_core/py/oxt/OptionsDialog.xcs ================================================================== --- gc_core/py/oxt/OptionsDialog.xcs +++ gc_core/py/oxt/OptionsDialog.xcs @@ -19,14 +19,16 @@ The data for one leaf. - 1 - 1 - 0 - 1 + 1 + 1 + 0 + 1 + + Index: gc_lang/fr/oxt/DictOptions/DictOptions.py ================================================================== --- gc_lang/fr/oxt/DictOptions/DictOptions.py +++ gc_lang/fr/oxt/DictOptions/DictOptions.py @@ -109,16 +109,16 @@ self.xContainer.execute() # XActionListener def actionPerformed (self, xActionEvent): try: - xChild = self.xSettingNode.getByName("o_fr") if xActionEvent.ActionCommand == 'Apply': - xChild.setPropertyValue("graphspell", self.xGraphspell.State) - xChild.setPropertyValue("graphspellsugg", self.xGraphspellSugg.State) + xChild = self.xSettingNode.getByName("o_fr") + xChild.setPropertyValue("use_graphspell", self.xGraphspell.State) + xChild.setPropertyValue("use_graphspell_sugg", self.xGraphspellSugg.State) #xChild.setPropertyValue("extended_dic", self.xExtendedDic.State) - xChild.setPropertyValue("personal_dic", self.xPersonalDic.State) + xChild.setPropertyValue("use_personal_dic", self.xPersonalDic.State) self.xSettingNode.commitChanges() elif xActionEvent.ActionCommand == "Import": xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.SystemFilePicker', self.ctx) xFilePicker.appendFilter("Supported files", "*.json; *.bdic") #xFilePicker.setDisplayDirectory("") @@ -143,15 +143,15 @@ traceback.print_exc() def _loadOptions (self): try: xChild = self.xSettingNode.getByName("o_fr") - self.xGraphspell.State = xChild.getPropertyValue("graphspell") - self.xGraphspellSugg.State = xChild.getPropertyValue("graphspellsugg") + self.xGraphspell.State = xChild.getPropertyValue("use_graphspell") + self.xGraphspellSugg.State = xChild.getPropertyValue("use_graphspell_sugg") #self.xExtendedDic.State = xChild.getPropertyValue("extended_dic") - self.xPersonalDic.State = xChild.getPropertyValue("personal_dic") + self.xPersonalDic.State = xChild.getPropertyValue("use_personal_dic") except: traceback.print_exc() #g_ImplementationHelper = unohelper.ImplementationHelper() #g_ImplementationHelper.addImplementation(DictOptions, 'net.grammalecte.graphspell.DictOptions', ('com.sun.star.task.Job',)) Index: gc_lang/fr/oxt/DictOptions/LexiconEditor.py ================================================================== --- gc_lang/fr/oxt/DictOptions/LexiconEditor.py +++ gc_lang/fr/oxt/DictOptions/LexiconEditor.py @@ -2,18 +2,20 @@ # by Olivier R. # License: GPL 3 import unohelper import uno +import json import re import traceback import helpers import lxe_strings import lxe_conj_data import grammalecte.graphspell as sc import grammalecte.graphspell.dawg as dawg +import grammalecte.graphspell.ibdawg as ibdawg import grammalecte.fr.conj as conj from com.sun.star.task import XJobExecutor from com.sun.star.awt import XActionListener from com.sun.star.awt import XKeyListener @@ -53,10 +55,12 @@ self.xContainer = None self.xDialog = None self.oSpellChecker = None # data self.lGeneratedFlex = [] + # options node + self.xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_grammalecte/Other/", True) def _addWidget (self, name, wtype, x, y, w, h, **kwargs): xWidget = self.xDialog.createInstance('com.sun.star.awt.UnoControl%sModel' % wtype) xWidget.Name = name xWidget.PositionX = x @@ -85,10 +89,11 @@ setattr(xGridModel, k, w) self.xDialog.insertByName(name, xGridModel) return xGridModel def run (self, sLang): + # ui lang self.dUI = lxe_strings.getUI(sLang) # dialog self.xDialog = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel', self.ctx) self.xDialog.Width = 620 @@ -203,34 +208,41 @@ self._addWidget("gwords_section", 'FixedLine', nXB, nY1, 200, nHeight, Label = self.dUI.get("new_section", "#err"), FontDescriptor = xFDTitle) self.xGridModelNew = self._addGrid("list_grid_gwords", nXB, nY1+10, 200, 175, [ {"Title": self.dUI.get("lex_flex", "#err"), "ColumnWidth": 65}, {"Title": self.dUI.get("lex_lemma", "#err"), "ColumnWidth": 50}, {"Title": self.dUI.get("lex_tags", "#err"), "ColumnWidth": 65} - ]) + ], SelectionModel = uno.Enum("com.sun.star.view.SelectionType", "MULTI")) self.xAdd = self._addWidget('add_button', 'Button', nXB, nY1+190, 95, 12, Label = self.dUI.get('add_button', "#err"), FontDescriptor = xFDTitle, TextColor = 0x005500, Enabled = False) self.xDelete = self._addWidget('delete_button', 'Button', nXB+100, nY1+190, 100, 12, Label = self.dUI.get('delete_button', "#err"), FontDescriptor = xFDTitle, TextColor = 0x550000) nY2b = nY1 + 205 # lexicon info section self._addWidget("lexicon_info_section", 'FixedLine', nXB, nY2b, 200, nHeight, Label = self.dUI.get("lexicon_info_section", "#err"), FontDescriptor = xFDTitle) self._addWidget("added_entries_label", 'FixedText', nXB, nY2b+10, 90, nHeight, Label = self.dUI.get("added_entries_label", "#err")) self._addWidget("deleted_entries_label", 'FixedText', nXB, nY2b+20, 90, nHeight, Label = self.dUI.get("deleted_entries_label", "#err")) self._addWidget("num_of_entries_label1", 'FixedText', nXB, nY2b+30, 90, nHeight, Label = self.dUI.get("num_of_entries_label", "#err")) + self.xNumAdded = self._addWidget("added_entries", 'FixedText', nXB+90, nY2b+10, 50, nHeight, Label = "0") + self.xNumDeleted = self._addWidget("deleted_entries", 'FixedText', nXB+90, nY2b+20, 50, nHeight, Label = "0") + self.xNumLex = self._addWidget("num_of_entries1", 'FixedText', nXB+90, nY2b+30, 50, nHeight, Label = "0") self.xSave = self._addWidget('save_button', 'Button', nXB+150, nY2b+10, 50, 12, Label = self.dUI.get('save_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x005500) # dictionary section self._addWidget("dictionary_section", 'FixedLine', nXB, nY2b+45, 200, nHeight, Label = self.dUI.get("dictionary_section", "#err"), FontDescriptor = xFDTitle) self._addWidget("save_date_label", 'FixedText', nXB, nY2b+55, 90, nHeight, Label = self.dUI.get("save_date_label", "#err")) self._addWidget("num_of_entries_label2", 'FixedText', nXB, nY2b+65, 90, nHeight, Label = self.dUI.get("num_of_entries_label", "#err")) - self.xExport = self._addWidget('export_button', 'Button', nXB+150, nY2b+55, 50, 12, Label = self.dUI.get('export_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x005500) + self.xDateDic = self._addWidget("save_date", 'FixedText', nXB+90, nY2b+55, 50, nHeight, Label = "-") + self.xNumDic = self._addWidget("num_of_entries2", 'FixedText', nXB+90, nY2b+65, 50, nHeight, Label = "0") + #self.xExport = self._addWidget('export_button', 'Button', nXB+150, nY2b+55, 50, 12, Label = self.dUI.get('export_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x005500) #### Lexicon section self._addWidget("lexicon_section", 'FixedLine', nXC, nY1, 200, nHeight, Label = self.dUI.get("lexicon_section", "#err"), FontDescriptor = xFDTitle) self.xGridModelLex = self._addGrid("list_grid_lexicon", nXC, nY1+10, 200, 270, [ {"Title": self.dUI.get("lex_flex", "#err"), "ColumnWidth": 65}, {"Title": self.dUI.get("lex_lemma", "#err"), "ColumnWidth": 50}, {"Title": self.dUI.get("lex_tags", "#err"), "ColumnWidth": 65} - ]) + ], SelectionModel = uno.Enum("com.sun.star.view.SelectionType", "MULTI")) + + self.loadLexicon() # container self.xContainer = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialog', self.ctx) self.xContainer.setModel(self.xDialog) self.xGridControlNew = self.xContainer.getControl('list_grid_gwords') @@ -264,18 +276,20 @@ self.xContainer.getControl(sName).setActionCommand(sAction) # XActionListener def actionPerformed (self, xActionEvent): try: - if xActionEvent.ActionCommand == "Add": + if xActionEvent.ActionCommand == "Update": + self.updateGenWords() + elif xActionEvent.ActionCommand == "Add": self.addToLexicon() elif xActionEvent.ActionCommand == "Delete": - pass + self.deleteSelectedEntries() elif xActionEvent.ActionCommand == "Save": self.saveLexicon() - elif xActionEvent.ActionCommand == "Update": - self.updateGenWords() + elif xActionEvent.ActionCommand == "Export": + self.exportDictionary() elif xActionEvent.ActionCommand == "Close": self.xContainer.endExecute() except: traceback.print_exc() @@ -293,21 +307,42 @@ xDialog.run() except: traceback.print_exc() # Code - @_waitPointer + #@_waitPointer (don’t: strange behavior) def loadLexicon (self): - pass + 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()): + sFlexion, sLemma, sTag = sLine.split("\t") + xGridDataModel.addRow(i, (sFlexion, sLemma, sTag)) + self.xNumAdded.Label = "0" + self.xNumDeleted.Label = "0" + self.xNumLex.Label = str(i) + self.xNumDic.Label = str(i) + self.xDateDic.Label = oIBDAWG.sDate @_waitPointer def saveLexicon (self): xGridDataModel = self.xGridModelLex.GridDataModel lEntry = [] for i in range(xGridDataModel.RowCount): lEntry.append(xGridDataModel.getRowData(i)) oDAWG = dawg.DAWG(lEntry, "S", "fr", "Français", "Dictionnaire personnel") + oJSON = oDAWG.getBinaryAsJSON() + xChild = self.xSettingNode.getByName("o_fr") + xChild.setPropertyValue("personal_dic", json.dumps(oJSON, ensure_ascii=False)) + self.xSettingNode.commitChanges() + self.xNumAdded.Label = "0" + self.xNumDeleted.Label = "0" + self.xNumLex.Label = str(oJSON["nEntry"]) + self.xNumDic.Label = str(oJSON["nEntry"]) + self.xDateDic.Label = oJSON["sDate"] def _getRadioValue (self, *args): for x in args: if x.State: return x.HelpText @@ -492,15 +527,24 @@ nStart = xGridDataModelLex.RowCount for i in range(xGridDataModelNew.RowCount): sFlexion, sLemma, sTag = xGridDataModelNew.getRowData(i) xGridDataModelLex.addRow(nStart + i, (sFlexion, sLemma, sTag)) self.xSave.Enabled = True + self.xNumAdded.Label = str(int(self.xNumAdded.Label) + xGridDataModelNew.RowCount) + self.xNumLex.Label = str(int(self.xNumLex.Label) + xGridDataModelNew.RowCount) self._resetWidgets() @_waitPointer - def delete (self, xList): - xGridDataModel = xList.GridDataModel - + def deleteSelectedEntries (self): + xGridDataModel = self.xGridModelNew.GridDataModel + for i in self.xGridControlNew.getSelectedRows(): + xGridDataModel.removeRow(i) + xGridDataModel = self.xGridModelLex.GridDataModel + nSelectedEntries = len(self.xGridControlLex.getSelectedRows()) + for i in self.xGridControlLex.getSelectedRows(): + xGridDataModel.removeRow(i) + self.xNumDeleted.Label = str(int(self.xNumDeleted.Label) + nSelectedEntries) + self.xNumLex.Label = str(xGridDataModel.RowCount) #g_ImplementationHelper = unohelper.ImplementationHelper() #g_ImplementationHelper.addImplementation(LexiconEditor, 'net.grammalecte.LexiconEditor', ('com.sun.star.task.Job',))