Grammalecte  Check-in [5cc5b32dc7]

Overview
Comment:[lo] lexicon editor: update
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | lo | multid
Files: files | file ages | folders
SHA3-256: 5cc5b32dc703a2e82da9e7d64b06b6a30d2698c3bbe5f2b1570cc51aa98ab6c4
User & Date: olr on 2018-02-28 15:29:01
Other Links: branch diff | manifest | tags
Context
2018-02-28
16:27
[lo] lexicon editor: update check-in: 00fe4c5157 user: olr tags: lo, multid
15:29
[lo] lexicon editor: update check-in: 5cc5b32dc7 user: olr tags: lo, multid
15:28
[graphspell][py] dawg: get JSON object instead of JSON string check-in: 1b8133065d user: olr tags: graphspell, multid
Changes

Modified gc_core/py/oxt/OptionsDialog.xcs from [412b78821f] to [3732fcdcec].

    17     17               ${xcs_options}
    18     18           </group>
    19     19   
    20     20           <group oor:name="o_${lang}">
    21     21               <info>
    22     22                   <desc>The data for one leaf.</desc>
    23     23               </info>
    24         -            <prop oor:name="graphspell" oor:type="xs:int"><value>1</value></prop>
    25         -            <prop oor:name="graphspellsugg" oor:type="xs:int"><value>1</value></prop>
    26         -            <prop oor:name="extended_dic" oor:type="xs:int"><value>0</value></prop>
    27         -            <prop oor:name="personal_dic" oor:type="xs:int"><value>1</value></prop>
           24  +            <prop oor:name="use_graphspell" oor:type="xs:int"><value>1</value></prop>
           25  +            <prop oor:name="use_graphspell_sugg" oor:type="xs:int"><value>1</value></prop>
           26  +            <prop oor:name="use_extended_dic" oor:type="xs:int"><value>0</value></prop>
           27  +            <prop oor:name="use_personal_dic" oor:type="xs:int"><value>1</value></prop>
           28  +            <prop oor:name="extended_dic" oor:type="xs:string"><value></value></prop>
           29  +            <prop oor:name="personal_dic" oor:type="xs:string"><value></value></prop>
    28     30           </group>
    29     31       </templates>
    30     32   
    31     33       <component>
    32     34           <group oor:name="Leaves">
    33     35               <node-ref oor:name="${lang}" oor:node-type="${lang}" />
    34     36           </group>

Modified gc_lang/fr/oxt/DictOptions/DictOptions.py from [0df543aa25] to [afd6778ebd].

   107    107           toolkit = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.ExtToolkit', self.ctx)
   108    108           self.xContainer.createPeer(toolkit, None)
   109    109           self.xContainer.execute()
   110    110   
   111    111       # XActionListener
   112    112       def actionPerformed (self, xActionEvent):
   113    113           try:
   114         -            xChild = self.xSettingNode.getByName("o_fr")
   115    114               if xActionEvent.ActionCommand == 'Apply':
   116         -                xChild.setPropertyValue("graphspell", self.xGraphspell.State)
   117         -                xChild.setPropertyValue("graphspellsugg", self.xGraphspellSugg.State)
          115  +                xChild = self.xSettingNode.getByName("o_fr")
          116  +                xChild.setPropertyValue("use_graphspell", self.xGraphspell.State)
          117  +                xChild.setPropertyValue("use_graphspell_sugg", self.xGraphspellSugg.State)
   118    118                   #xChild.setPropertyValue("extended_dic", self.xExtendedDic.State)
   119         -                xChild.setPropertyValue("personal_dic", self.xPersonalDic.State)
          119  +                xChild.setPropertyValue("use_personal_dic", self.xPersonalDic.State)
   120    120                   self.xSettingNode.commitChanges()
   121    121               elif xActionEvent.ActionCommand == "Import":
   122    122                   xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.SystemFilePicker', self.ctx)
   123    123                   xFilePicker.appendFilter("Supported files", "*.json; *.bdic")
   124    124                   #xFilePicker.setDisplayDirectory("")
   125    125                   #xFilePicker.setMultiSelectionMode(True)
   126    126                   nResult = xFilePicker.execute()
................................................................................
   141    141               dialog.run()
   142    142           except:
   143    143               traceback.print_exc()
   144    144   
   145    145       def _loadOptions (self):
   146    146           try:
   147    147               xChild = self.xSettingNode.getByName("o_fr")
   148         -            self.xGraphspell.State = xChild.getPropertyValue("graphspell")
   149         -            self.xGraphspellSugg.State = xChild.getPropertyValue("graphspellsugg")
          148  +            self.xGraphspell.State = xChild.getPropertyValue("use_graphspell")
          149  +            self.xGraphspellSugg.State = xChild.getPropertyValue("use_graphspell_sugg")
   150    150               #self.xExtendedDic.State = xChild.getPropertyValue("extended_dic")
   151         -            self.xPersonalDic.State = xChild.getPropertyValue("personal_dic")
          151  +            self.xPersonalDic.State = xChild.getPropertyValue("use_personal_dic")
   152    152           except:
   153    153               traceback.print_exc()
   154    154   
   155    155   
   156    156   #g_ImplementationHelper = unohelper.ImplementationHelper()
   157    157   #g_ImplementationHelper.addImplementation(DictOptions, 'net.grammalecte.graphspell.DictOptions', ('com.sun.star.task.Job',))

Modified gc_lang/fr/oxt/DictOptions/LexiconEditor.py from [34785f0710] to [3fd0784e8d].

     1      1   # Lexicon Editor
     2      2   # by Olivier R.
     3      3   # License: GPL 3
     4      4   
     5      5   import unohelper
     6      6   import uno
            7  +import json
     7      8   import re
     8      9   import traceback
     9     10   
    10     11   import helpers
    11     12   import lxe_strings
    12     13   import lxe_conj_data
    13     14   import grammalecte.graphspell as sc
    14     15   import grammalecte.graphspell.dawg as dawg
           16  +import grammalecte.graphspell.ibdawg as ibdawg
    15     17   import grammalecte.fr.conj as conj
    16     18   
    17     19   from com.sun.star.task import XJobExecutor
    18     20   from com.sun.star.awt import XActionListener
    19     21   from com.sun.star.awt import XKeyListener
    20     22   
    21     23   
................................................................................
    51     53           self.xDesktop = self.xSvMgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.ctx)
    52     54           self.xDocument = self.xDesktop.getCurrentComponent()
    53     55           self.xContainer = None
    54     56           self.xDialog = None
    55     57           self.oSpellChecker = None
    56     58           # data
    57     59           self.lGeneratedFlex = []
           60  +        # options node
           61  +        self.xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_grammalecte/Other/", True)
    58     62   
    59     63       def _addWidget (self, name, wtype, x, y, w, h, **kwargs):
    60     64           xWidget = self.xDialog.createInstance('com.sun.star.awt.UnoControl%sModel' % wtype)
    61     65           xWidget.Name = name
    62     66           xWidget.PositionX = x
    63     67           xWidget.PositionY = y
    64     68           xWidget.Width = w
................................................................................
    83     87               xColumnModel.addColumn(xCol)
    84     88           for k, w in kwargs.items():
    85     89               setattr(xGridModel, k, w)
    86     90           self.xDialog.insertByName(name, xGridModel)
    87     91           return xGridModel
    88     92   
    89     93       def run (self, sLang):
           94  +        # ui lang
    90     95           self.dUI = lxe_strings.getUI(sLang)
    91     96   
    92     97           # dialog
    93     98           self.xDialog = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel', self.ctx)
    94     99           self.xDialog.Width = 620
    95    100           self.xDialog.Height = 292
    96    101           self.xDialog.Title = self.dUI.get('title', "#title#")
................................................................................
   201    206   
   202    207           #### Generated words
   203    208           self._addWidget("gwords_section", 'FixedLine', nXB, nY1, 200, nHeight, Label = self.dUI.get("new_section", "#err"), FontDescriptor = xFDTitle)
   204    209           self.xGridModelNew = self._addGrid("list_grid_gwords", nXB, nY1+10, 200, 175, [
   205    210               {"Title": self.dUI.get("lex_flex", "#err"), "ColumnWidth": 65},
   206    211               {"Title": self.dUI.get("lex_lemma", "#err"), "ColumnWidth": 50},
   207    212               {"Title": self.dUI.get("lex_tags", "#err"), "ColumnWidth": 65}
   208         -        ])
          213  +        ], SelectionModel = uno.Enum("com.sun.star.view.SelectionType", "MULTI"))
   209    214           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)
   210    215           self.xDelete = self._addWidget('delete_button', 'Button', nXB+100, nY1+190, 100, 12, Label = self.dUI.get('delete_button', "#err"), FontDescriptor = xFDTitle, TextColor = 0x550000)
   211    216   
   212    217           nY2b = nY1 + 205
   213    218           # lexicon info section
   214    219           self._addWidget("lexicon_info_section", 'FixedLine', nXB, nY2b, 200, nHeight, Label = self.dUI.get("lexicon_info_section", "#err"), FontDescriptor = xFDTitle)
   215    220           self._addWidget("added_entries_label", 'FixedText', nXB, nY2b+10, 90, nHeight, Label = self.dUI.get("added_entries_label", "#err"))
   216    221           self._addWidget("deleted_entries_label", 'FixedText', nXB, nY2b+20, 90, nHeight, Label = self.dUI.get("deleted_entries_label", "#err"))
   217    222           self._addWidget("num_of_entries_label1", 'FixedText', nXB, nY2b+30, 90, nHeight, Label = self.dUI.get("num_of_entries_label", "#err"))
          223  +        self.xNumAdded = self._addWidget("added_entries", 'FixedText', nXB+90, nY2b+10, 50, nHeight, Label = "0")
          224  +        self.xNumDeleted = self._addWidget("deleted_entries", 'FixedText', nXB+90, nY2b+20, 50, nHeight, Label = "0")
          225  +        self.xNumLex = self._addWidget("num_of_entries1", 'FixedText', nXB+90, nY2b+30, 50, nHeight, Label = "0")
   218    226           self.xSave = self._addWidget('save_button', 'Button', nXB+150, nY2b+10, 50, 12, Label = self.dUI.get('save_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x005500)
   219    227           # dictionary section
   220    228           self._addWidget("dictionary_section", 'FixedLine', nXB, nY2b+45, 200, nHeight, Label = self.dUI.get("dictionary_section", "#err"), FontDescriptor = xFDTitle)
   221    229           self._addWidget("save_date_label", 'FixedText', nXB, nY2b+55, 90, nHeight, Label = self.dUI.get("save_date_label", "#err"))
   222    230           self._addWidget("num_of_entries_label2", 'FixedText', nXB, nY2b+65, 90, nHeight, Label = self.dUI.get("num_of_entries_label", "#err"))
   223         -        self.xExport = self._addWidget('export_button', 'Button', nXB+150, nY2b+55, 50, 12, Label = self.dUI.get('export_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x005500)
          231  +        self.xDateDic = self._addWidget("save_date", 'FixedText', nXB+90, nY2b+55, 50, nHeight, Label = "-")
          232  +        self.xNumDic = self._addWidget("num_of_entries2", 'FixedText', nXB+90, nY2b+65, 50, nHeight, Label = "0")
          233  +        #self.xExport = self._addWidget('export_button', 'Button', nXB+150, nY2b+55, 50, 12, Label = self.dUI.get('export_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x005500)
   224    234   
   225    235           #### Lexicon section
   226    236           self._addWidget("lexicon_section", 'FixedLine', nXC, nY1, 200, nHeight, Label = self.dUI.get("lexicon_section", "#err"), FontDescriptor = xFDTitle)
   227    237           self.xGridModelLex = self._addGrid("list_grid_lexicon", nXC, nY1+10, 200, 270, [
   228    238               {"Title": self.dUI.get("lex_flex", "#err"), "ColumnWidth": 65},
   229    239               {"Title": self.dUI.get("lex_lemma", "#err"), "ColumnWidth": 50},
   230    240               {"Title": self.dUI.get("lex_tags", "#err"), "ColumnWidth": 65}
   231         -        ])
          241  +        ], SelectionModel = uno.Enum("com.sun.star.view.SelectionType", "MULTI"))
          242  +
          243  +        self.loadLexicon()
   232    244   
   233    245           # container
   234    246           self.xContainer = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialog', self.ctx)
   235    247           self.xContainer.setModel(self.xDialog)
   236    248           self.xGridControlNew = self.xContainer.getControl('list_grid_gwords')
   237    249           self.xGridControlLex = self.xContainer.getControl('list_grid_lexicon')
   238    250           #helpers.xray(self.xContainer.getControl('lemma'))
................................................................................
   262    274           for sName in lNames:
   263    275               self.xContainer.getControl(sName).addActionListener(self)
   264    276               self.xContainer.getControl(sName).setActionCommand(sAction)
   265    277   
   266    278       # XActionListener
   267    279       def actionPerformed (self, xActionEvent):
   268    280           try:
   269         -            if xActionEvent.ActionCommand == "Add":
          281  +            if xActionEvent.ActionCommand == "Update":
          282  +                self.updateGenWords()
          283  +            elif xActionEvent.ActionCommand == "Add":
   270    284                   self.addToLexicon()
   271    285               elif xActionEvent.ActionCommand == "Delete":
   272         -                pass
          286  +                self.deleteSelectedEntries()
   273    287               elif xActionEvent.ActionCommand == "Save":
   274    288                   self.saveLexicon()
   275         -            elif xActionEvent.ActionCommand == "Update":
   276         -                self.updateGenWords()
          289  +            elif xActionEvent.ActionCommand == "Export":
          290  +                self.exportDictionary()
   277    291               elif xActionEvent.ActionCommand == "Close":
   278    292                   self.xContainer.endExecute()
   279    293           except:
   280    294               traceback.print_exc()
   281    295       
   282    296       # XKeyListener
   283    297       def keyPressed (self, xKeyEvent):
................................................................................
   291    305           try:
   292    306               xDialog = LexiconEditor(self.ctx)
   293    307               xDialog.run()
   294    308           except:
   295    309               traceback.print_exc()
   296    310   
   297    311       # Code
   298         -    @_waitPointer
          312  +    #@_waitPointer (don’t: strange behavior)
   299    313       def loadLexicon (self):
   300         -        pass
          314  +        xChild = self.xSettingNode.getByName("o_fr")
          315  +        sJSON = xChild.getPropertyValue("personal_dic")
          316  +        if sJSON != "":
          317  +            oIBDAWG = ibdawg.IBDAWG(json.loads(sJSON))
          318  +            xGridDataModel = self.xGridModelLex.GridDataModel
          319  +            for i, sLine in enumerate(oIBDAWG.select()):
          320  +                sFlexion, sLemma, sTag = sLine.split("\t")
          321  +                xGridDataModel.addRow(i, (sFlexion, sLemma, sTag))
          322  +            self.xNumAdded.Label = "0"
          323  +            self.xNumDeleted.Label = "0"
          324  +            self.xNumLex.Label = str(i)
          325  +            self.xNumDic.Label = str(i)
          326  +            self.xDateDic.Label = oIBDAWG.sDate
   301    327   
   302    328       @_waitPointer
   303    329       def saveLexicon (self):
   304    330           xGridDataModel = self.xGridModelLex.GridDataModel
   305    331           lEntry = []
   306    332           for i in range(xGridDataModel.RowCount):
   307    333               lEntry.append(xGridDataModel.getRowData(i))
   308    334           oDAWG = dawg.DAWG(lEntry, "S", "fr", "Français", "Dictionnaire personnel")
          335  +        oJSON = oDAWG.getBinaryAsJSON()
          336  +        xChild = self.xSettingNode.getByName("o_fr")
          337  +        xChild.setPropertyValue("personal_dic", json.dumps(oJSON, ensure_ascii=False))
          338  +        self.xSettingNode.commitChanges()
          339  +        self.xNumAdded.Label = "0"
          340  +        self.xNumDeleted.Label = "0"
          341  +        self.xNumLex.Label = str(oJSON["nEntry"])
          342  +        self.xNumDic.Label = str(oJSON["nEntry"])
          343  +        self.xDateDic.Label = oJSON["sDate"]
   309    344   
   310    345       def _getRadioValue (self, *args):
   311    346           for x in args:
   312    347               if x.State:
   313    348                   return x.HelpText
   314    349           return None
   315    350   
................................................................................
   490    525           xGridDataModelNew = self.xGridModelNew.GridDataModel
   491    526           xGridDataModelLex = self.xGridModelLex.GridDataModel
   492    527           nStart = xGridDataModelLex.RowCount
   493    528           for i in range(xGridDataModelNew.RowCount):
   494    529               sFlexion, sLemma, sTag = xGridDataModelNew.getRowData(i)
   495    530               xGridDataModelLex.addRow(nStart + i, (sFlexion, sLemma, sTag))
   496    531           self.xSave.Enabled = True
          532  +        self.xNumAdded.Label = str(int(self.xNumAdded.Label) + xGridDataModelNew.RowCount)
          533  +        self.xNumLex.Label = str(int(self.xNumLex.Label) + xGridDataModelNew.RowCount)
   497    534           self._resetWidgets()
   498    535   
   499    536       @_waitPointer
   500         -    def delete (self, xList):
   501         -        xGridDataModel = xList.GridDataModel
   502         -
          537  +    def deleteSelectedEntries (self):
          538  +        xGridDataModel = self.xGridModelNew.GridDataModel
          539  +        for i in self.xGridControlNew.getSelectedRows():
          540  +            xGridDataModel.removeRow(i)
          541  +        xGridDataModel = self.xGridModelLex.GridDataModel
          542  +        nSelectedEntries = len(self.xGridControlLex.getSelectedRows())
          543  +        for i in self.xGridControlLex.getSelectedRows():
          544  +            xGridDataModel.removeRow(i)
          545  +        self.xNumDeleted.Label = str(int(self.xNumDeleted.Label) + nSelectedEntries)
          546  +        self.xNumLex.Label = str(xGridDataModel.RowCount)
   503    547   
   504    548   
   505    549   #g_ImplementationHelper = unohelper.ImplementationHelper()
   506    550   #g_ImplementationHelper.addImplementation(LexiconEditor, 'net.grammalecte.LexiconEditor', ('com.sun.star.task.Job',))