Grammalecte  Check-in [819d3a016f]

Overview
Comment:[lo] lexicon editor: search within personal dictionary
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | lo | multid
Files: files | file ages | folders
SHA3-256: 819d3a016fc6bd6eaef3a66c5af9dc1c83c868c84dd47892d5f5b98184691676
User & Date: olr on 2018-03-27 16:13:14
Other Links: branch diff | manifest | tags
Context
2018-03-27
16:51
[fx][tb][lo] lexical editor: tag p and q for verb generation check-in: 11a83392a7 user: olr tags: fx, lo, multid, tb
16:13
[lo] lexicon editor: search within personal dictionary check-in: 819d3a016f user: olr tags: lo, multid
16:12
[graphspell][bug] ibdawg: fix initialization with JSON object check-in: c0162510e5 user: olr tags: graphspell, multid
Changes

Modified gc_lang/fr/oxt/DictOptions/LexiconEditor.py from [b0ac6192f3] to [85224c07b2].

    66     66       def __init__ (self, ctx):
    67     67           self.ctx = ctx
    68     68           self.xSvMgr = self.ctx.ServiceManager
    69     69           self.xDesktop = self.xSvMgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.ctx)
    70     70           self.xDocument = self.xDesktop.getCurrentComponent()
    71     71           self.xContainer = None
    72     72           self.xDialog = None
    73         -        self.oSpellChecker = None
           73  +        self.oPersonalDicJSON = None
    74     74           # data
    75     75           self.sLemma = ""
    76     76           self.lGeneratedFlex = []
    77     77           # options node
    78     78           self.xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_grammalecte/Other/", True)
    79     79   
    80     80       def _addWidget (self, name, wtype, x, y, w, h, **kwargs):
................................................................................
   334    334               xDialog.run()
   335    335           except:
   336    336               traceback.print_exc()
   337    337   
   338    338       # Code
   339    339       def launchSearchWords (self):
   340    340           xDialog = SearchWords.SearchWords(self.ctx)
   341         -        xDialog.run(self.sLang)
          341  +        xDialog.run(self.sLang, self.oPersonalDicJSON)
   342    342   
   343    343       def launchTagsInfo (self):
   344    344           xDialog = TagsInfo.TagsInfo(self.ctx)
   345    345           xDialog.run(self.sLang)
   346    346   
   347    347       #@_waitPointer (don’t: strange behavior)
   348    348       def loadLexicon (self):
   349    349           xChild = self.xSettingNode.getByName("o_fr")
   350    350           sJSON = xChild.getPropertyValue("personal_dic")
   351    351           if sJSON != "":
   352         -            oIBDAWG = ibdawg.IBDAWG(json.loads(sJSON))
          352  +            self.oPersonalDicJSON = json.loads(sJSON)
          353  +            oIBDAWG = ibdawg.IBDAWG(self.oPersonalDicJSON)
   353    354               xGridDataModel = self.xGridModelLex.GridDataModel
   354    355               for i, aEntry in enumerate(oIBDAWG.select()):
   355    356                   xGridDataModel.addRow(i, aEntry)
   356    357               self.xNumLex.Label = str(i)
   357    358               self.xNumDic.Label = str(i)
   358    359               self.xDateDic.Label = oIBDAWG.sDate
   359    360   
................................................................................
   362    363           xGridDataModel = self.xGridModelLex.GridDataModel
   363    364           lEntry = []
   364    365           for i in range(xGridDataModel.RowCount):
   365    366               lEntry.append(xGridDataModel.getRowData(i))
   366    367           xChild = self.xSettingNode.getByName("o_fr")
   367    368           if lEntry:
   368    369               oDAWG = dawg.DAWG(lEntry, "S", "fr", "Français", "Dictionnaire personnel")
   369         -            oJSON = oDAWG.getBinaryAsJSON()
   370         -            xChild.setPropertyValue("personal_dic", json.dumps(oJSON, ensure_ascii=False))
          370  +            self.oPersonalDicJSON = oDAWG.getBinaryAsJSON()
          371  +            xChild.setPropertyValue("personal_dic", json.dumps(self.oPersonalDicJSON, ensure_ascii=False))
   371    372               self.xSettingNode.commitChanges()
   372         -            self.xNumDic.Label = str(oJSON["nEntry"])
   373         -            self.xDateDic.Label = oJSON["sDate"]
          373  +            self.xNumDic.Label = str(self.oPersonalDicJSON["nEntry"])
          374  +            self.xDateDic.Label = self.oPersonalDicJSON["sDate"]
   374    375           else:
   375    376               xChild.setPropertyValue("personal_dic", "")
   376    377               self.xSettingNode.commitChanges()
   377    378               self.xNumDic.Label = "0"
   378    379               self.xDateDic.Label = self.dUI.get("void", "#err")
          380  +
          381  +    def exportDictionary (self):
          382  +        try:
          383  +            spfExported = os.path.join(os.environ['USERPROFILE'], "fr.personal.json")
          384  +            xChild = self.xSettingNode.getByName("o_fr")
          385  +            sJSON = xChild.getPropertyValue("personal_dic")
          386  +            if sJSON:
          387  +                with open(spfExported, "w", encoding="utf-8") as hDst:
          388  +                    hDst.write(sJSON)
          389  +                sMessage = self.dUI.get('export_message', "#err_msg: %s") % spfExported
          390  +            else:
          391  +                sMessage = self.dUI.get('empty_dictionary', "#err")
          392  +        except:
          393  +            sMessage = traceback.format_exc()
          394  +        MessageBox(self.xDocument, sMessage, self.dUI.get('export_title', "#err"))
          395  +
          396  +        # FilePicker doesn’t work at all…
          397  +        #xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.SystemFilePicker', self.ctx)
          398  +        #xFilePicker.appendFilter("Supported files", "*.json; *.bdic")
          399  +        #xFilePicker.setDisplayDirectory("")
          400  +        #xFilePicker.setMultiSelectionMode(True)
          401  +        #nResult = xFilePicker.execute()
          402  +        #if nResult == 1:
          403  +            #pass
          404  +            #lFile = xFilePicker.getSelectedFiles()
          405  +            #lFile = xFilePicker.getFiles()
          406  +
          407  +    @_waitPointer
          408  +    def importDictionary (self):
          409  +        pass
   379    410   
   380    411       def _getRadioValue (self, *args):
   381    412           for x in args:
   382    413               if x.State:
   383    414                   return x.HelpText
   384    415           return None
   385    416   
................................................................................
   550    581           nSelectedEntries = len(self.xGridControlLex.getSelectedRows())
   551    582           for i in self.xGridControlLex.getSelectedRows():
   552    583               if i < xGridDataModel.RowCount:
   553    584                   xGridDataModel.removeRow(i)
   554    585           self.xGridControlLex.deselectAllRows()
   555    586           self.xNumLex.Label = str(xGridDataModel.RowCount)
   556    587   
   557         -    @_waitPointer
   558         -    def importDictionary (self):
   559         -        pass
   560         -
   561         -    def exportDictionary (self):
   562         -        try:
   563         -            spfExported = os.path.join(os.environ['USERPROFILE'], "fr.personal.json")
   564         -            xChild = self.xSettingNode.getByName("o_fr")
   565         -            sJSON = xChild.getPropertyValue("personal_dic")
   566         -            if sJSON:
   567         -                with open(spfExported, "w", encoding="utf-8") as hDst:
   568         -                    hDst.write(sJSON)
   569         -                sMessage = self.dUI.get('export_message', "#err_msg: %s") % spfExported
   570         -            else:
   571         -                sMessage = self.dUI.get('empty_dictionary', "#err")
   572         -        except:
   573         -            sMessage = traceback.format_exc()
   574         -        MessageBox(self.xDocument, sMessage, self.dUI.get('export_title', "#err"))
   575         -
   576         -        # FilePicker doesn’t work at all…
   577         -        #xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.SystemFilePicker', self.ctx)
   578         -        #xFilePicker.appendFilter("Supported files", "*.json; *.bdic")
   579         -        #xFilePicker.setDisplayDirectory("")
   580         -        #xFilePicker.setMultiSelectionMode(True)
   581         -        #nResult = xFilePicker.execute()
   582         -        #if nResult == 1:
   583         -            #pass
   584         -            #lFile = xFilePicker.getSelectedFiles()
   585         -            #lFile = xFilePicker.getFiles()
   586         -
   587    588   
   588    589   #g_ImplementationHelper = unohelper.ImplementationHelper()
   589    590   #g_ImplementationHelper.addImplementation(LexiconEditor, 'net.grammalecte.LexiconEditor', ('com.sun.star.task.Job',))

Modified gc_lang/fr/oxt/DictOptions/SearchWords.py from [cd7d6b9804] to [fbd244567c].

    78     78                   setattr(xCol, k, w)
    79     79               xColumnModel.addColumn(xCol)
    80     80           for k, w in kwargs.items():
    81     81               setattr(xGridModel, k, w)
    82     82           self.xDialog.insertByName(name, xGridModel)
    83     83           return xGridModel
    84     84   
    85         -    def run (self, sLang):
           85  +    def run (self, sLang, oPersonalDicJSON):
    86     86           # ui lang
    87     87           self.dUI = sw_strings.getUI(sLang)
           88  +        self.oPersonalDicJSON = oPersonalDicJSON
    88     89   
    89     90           # dialog
    90     91           self.xDialog = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel', self.ctx)
    91     92           self.xDialog.Width = 350
    92     93           self.xDialog.Height = 305
    93     94           self.xDialog.Title = self.dUI.get('title', "#title#")
    94     95           #xWindowSize = helpers.getWindowSize()
................................................................................
   167    168               elif xActionEvent.ActionCommand == "Close":
   168    169                   self.xContainer.endExecute()
   169    170           except:
   170    171               traceback.print_exc()
   171    172   
   172    173       def initSpellChecker (self):
   173    174           if not self.oSpellChecker:
   174         -            self.oSpellChecker = sc.SpellChecker("fr", "fr.bdic", "", "", "")
          175  +            self.oSpellChecker = sc.SpellChecker("fr", "fr.bdic", "", "", self.oPersonalDicJSON)
   175    176   
   176    177       @_waitPointer
   177    178       def searchSimilar (self):
   178    179           self.initSpellChecker()
   179    180           sWord = self.xWord.Text.strip()
   180    181           if sWord:
   181    182               xGridDataModel = self.xGridModel.GridDataModel