Grammalecte  Check-in [d03e3c0ed1]

Overview
Comment:[lo] lexicon editor: export dictionary (sigh: file picker doesn’t work at all)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | lo | multid
Files: files | file ages | folders
SHA3-256: d03e3c0ed1ecfd844b15faffc3032ce03544b3fbb6b349a81f1d17b16d5d670d
User & Date: olr on 2018-03-27 14:48:23
Other Links: branch diff | manifest | tags
Context
2018-03-27
15:13
[fx][tb][lo] lexicon editor: participe passé invariable check-in: 86b963906e user: olr tags: fx, lo, multid, tb
14:48
[lo] lexicon editor: export dictionary (sigh: file picker doesn’t work at all) check-in: d03e3c0ed1 user: olr tags: lo, multid
13:01
[lo] lexical editor: wait pointers check-in: 3a15f6b206 user: olr tags: lo, multid
Changes

Modified gc_lang/fr/oxt/DictOptions/LexiconEditor.py from [07ba5d540c] to [d7c0b13323].

     2      2   # by Olivier R.
     3      3   # License: MPL 2
     4      4   
     5      5   import unohelper
     6      6   import uno
     7      7   import json
     8      8   import re
            9  +import os
     9     10   import traceback
    10     11   
    11     12   import helpers
    12     13   import lxe_strings
    13     14   import grammalecte.graphspell as sc
    14     15   import grammalecte.graphspell.dawg as dawg
    15     16   import grammalecte.graphspell.ibdawg as ibdawg
................................................................................
    18     19   
    19     20   import SearchWords
    20     21   import TagsInfo
    21     22   
    22     23   from com.sun.star.task import XJobExecutor
    23     24   from com.sun.star.awt import XActionListener
    24     25   from com.sun.star.awt import XKeyListener
           26  +
           27  +from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK
           28  +# BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_RETRY_CANCEL, BUTTONS_ABORT_IGNORE_RETRY
           29  +# DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE
           30  +from com.sun.star.awt.MessageBoxType import INFOBOX # MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
           31  +
           32  +def MessageBox (xDocument, sMsg, sTitle, nBoxType=INFOBOX, nBoxButtons=BUTTONS_OK):
           33  +    xParentWin = xDocument.CurrentController.Frame.ContainerWindow
           34  +    ctx = uno.getComponentContext()
           35  +    xToolkit = ctx.ServiceManager.createInstanceWithContext("com.sun.star.awt.Toolkit", ctx) 
           36  +    xMsgBox = xToolkit.createMessageBox(xParentWin, nBoxType, nBoxButtons, sTitle, sMsg)
           37  +    return xMsgBox.execute()
    25     38   
    26     39   
    27     40   def _waitPointer (funcDecorated):
    28     41       def wrapper (*args, **kwargs):
    29     42           # self is the first parameter if the decorator is applied on a object
    30     43           self = args[0]
    31     44           # before
................................................................................
   259    272           self.xContainer.getControl('information_button').setActionCommand('TagsInfo')
   260    273           self.xContainer.getControl('add_button').addActionListener(self)
   261    274           self.xContainer.getControl('add_button').setActionCommand('Add')
   262    275           self.xContainer.getControl('delete_button').addActionListener(self)
   263    276           self.xContainer.getControl('delete_button').setActionCommand('Delete')
   264    277           self.xContainer.getControl('save_button').addActionListener(self)
   265    278           self.xContainer.getControl('save_button').setActionCommand('Save')
          279  +        self.xContainer.getControl('export_button').addActionListener(self)
          280  +        self.xContainer.getControl('export_button').setActionCommand('Export')
   266    281           self.xContainer.getControl('close_button').addActionListener(self)
   267    282           self.xContainer.getControl('close_button').setActionCommand('Close')
   268    283           self.xContainer.setVisible(False)
   269    284           xToolkit = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.ExtToolkit', self.ctx)
   270    285           self.xContainer.createPeer(xToolkit, None)
   271    286           self.xContainer.execute()
   272    287   
................................................................................
   294    309                   self.deleteSelectedEntries()
   295    310               elif xActionEvent.ActionCommand == "Save":
   296    311                   self.saveLexicon()
   297    312               elif xActionEvent.ActionCommand == "Import":
   298    313                   self.importDictionary()
   299    314               elif xActionEvent.ActionCommand == "Export":
   300    315                   self.exportDictionary()
          316  +            elif xActionEvent.ActionCommand == 'Info':
          317  +                pass
   301    318               elif xActionEvent.ActionCommand == "Close":
   302    319                   self.xContainer.endExecute()
   303    320           except:
   304    321               traceback.print_exc()
   305    322       
   306    323       # XKeyListener
   307    324       def keyPressed (self, xKeyEvent):
................................................................................
   537    554           self.xGridControlLex.deselectAllRows()
   538    555           self.xNumLex.Label = str(xGridDataModel.RowCount)
   539    556   
   540    557       @_waitPointer
   541    558       def importDictionary (self):
   542    559           pass
   543    560   
   544         -    @_waitPointer
   545    561       def exportDictionary (self):
   546         -        xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.SystemFilePicker', self.ctx)
   547         -        xFilePicker.appendFilter("Supported files", "*.json; *.bdic")
          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")
   548    579           #xFilePicker.setDisplayDirectory("")
   549    580           #xFilePicker.setMultiSelectionMode(True)
   550         -        nResult = xFilePicker.execute()
   551         -        if nResult == 1:
   552         -            pass
          581  +        #nResult = xFilePicker.execute()
          582  +        #if nResult == 1:
          583  +            #pass
   553    584               #lFile = xFilePicker.getSelectedFiles()
   554    585               #lFile = xFilePicker.getFiles()
   555    586   
   556    587   
   557    588   #g_ImplementationHelper = unohelper.ImplementationHelper()
   558    589   #g_ImplementationHelper.addImplementation(LexiconEditor, 'net.grammalecte.LexiconEditor', ('com.sun.star.task.Job',))

Modified gc_lang/fr/oxt/DictOptions/lxe_strings.py from [95dfd605af] to [d20d6fd400].

    65     65           "save_button": "Enregistrer",
    66     66   
    67     67           # Dictionary
    68     68           "dictionary_section": "Dictionnaire personnel",
    69     69           "save_date_label": "Date d’enregistrement :",
    70     70           "num_of_entries_label": "Nombre d’entrées :",
    71     71           "export_button": "Exporter",
           72  +        "export_title": "Exportation du dictionnaire",
           73  +        "export_message": "Fichier exporté : ‹%s>",
           74  +        "empty_dictionary": "Le dictionnaire est vide. Aucun fichier créé.",
    72     75           "void": "[néant]",
    73     76   
    74     77           #
    75     78           "close_button": "Fermer",
    76     79       },
    77     80       # Traduction délibérément limitée
    78     81       "en": {
    79     82           "title": "Grammalecte · Lexicon editor",
    80     83           
    81     84           "close_button": "Close",
    82     85       },
    83     86   }