Grammalecte  Check-in [a491e075e0]

Overview
Comment:[lo][fr] remove old and useless file
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fr | lo
Files: files | file ages | folders
SHA3-256: a491e075e04b680d59cfbbe78f65888b768aa4812009a93b6895289d64e5e9c9
User & Date: olr on 2021-01-29 15:06:16
Other Links: manifest | tags
Context
2021-01-29
16:07
[fx] prevent code checker warning check-in: 56d5c851ec user: olr tags: fx, trunk
15:06
[lo][fr] remove old and useless file check-in: a491e075e0 user: olr tags: fr, lo, trunk
15:00
[server] update bottle.py check-in: dfc463e07d user: olr tags: server, trunk
Changes

Deleted gc_lang/fr/dictionnaire/_templates/ooo/DictionarySwitcher.save.py version [8b30bb88f9].

     1         -# -*- coding: utf8 -*-
     2         -# French Dictionary Switcher
     3         -# by Olivier R.
     4         -# License: MPL 2
     5         -
     6         -import unohelper
     7         -import uno
     8         -import sys
     9         -import re
    10         -#import os.path
    11         -
    12         -from com.sun.star.task import XJobExecutor
    13         -from com.sun.star.awt import XActionListener
    14         -from com.sun.star.awt import WindowDescriptor
    15         -from com.sun.star.awt.WindowClass import MODALTOP
    16         -from com.sun.star.awt.VclWindowPeerAttribute import OK, OK_CANCEL, YES_NO, YES_NO_CANCEL, RETRY_CANCEL, DEF_OK, DEF_CANCEL, DEF_RETRY, DEF_YES, DEF_NO
    17         -from com.sun.star.beans import PropertyValue
    18         -
    19         -# XRay - API explorer
    20         -from com.sun.star.uno import RuntimeException as _rtex
    21         -
    22         -def xray(myObject):
    23         -    try:
    24         -        sm = uno.getComponentContext().ServiceManager
    25         -        mspf = sm.createInstanceWithContext("com.sun.star.script.provider.MasterScriptProviderFactory", uno.getComponentContext())
    26         -        scriptPro = mspf.createScriptProvider("")
    27         -        xScript = scriptPro.getScript("vnd.sun.star.script:XrayTool._Main.Xray?language=Basic&location=application")
    28         -        xScript.invoke((myObject,), (), ())
    29         -        return
    30         -    except:
    31         -        raise _rtex("\nBasic library Xray is not installed", uno.getComponentContext())
    32         -# END Xray
    33         -
    34         -DEBUG = False
    35         -
    36         -if DEBUG and sys.platform.startswith('win'):
    37         -    import codecs
    38         -    sys.stdout = codecs.open("C:\_multidict_stdout.txt", "w", "utf-8")
    39         -
    40         -def handleException (ctx=None):
    41         -    import traceback
    42         -    '''Display exception in a message dialog'''
    43         -    s = '\n'.join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
    44         -    if not sys.platform.startswith('win'):
    45         -        # also print trace on stdout/stderr on non-Windows platform
    46         -        traceback.print_exc()
    47         -    else:
    48         -        # no default stdout/stderr on Windows
    49         -        print(s)
    50         -    
    51         -    if not ctx:
    52         -        return
    53         -    xSvMgr = ctx.ServiceManager
    54         -    xDesktop = xSvMgr.createInstanceWithContext('com.sun.star.frame.Desktop', ctx)
    55         -    xDoc = xDesktop.getCurrentComponent()
    56         -    xWindow = xDoc.CurrentController.Frame.ContainerWindow
    57         -    MessageBox(xWindow, s, 'Exception', 'errorbox')
    58         -
    59         -    
    60         -def MessageBox (xParentWin, sMsg, sTitle, sBoxType="messbox", MsgButtons=OK):
    61         -    if sBoxType not in ("messbox", "infobox", "errorbox", "warningbox", "querybox"):
    62         -        sBoxType = "messbox"
    63         -
    64         -    # window properties
    65         -    aDescriptor = WindowDescriptor()
    66         -    aDescriptor.Type = MODALTOP
    67         -    aDescriptor.WindowServiceName = sBoxType
    68         -    aDescriptor.ParentIndex = -1
    69         -    aDescriptor.Parent = xParentWin
    70         -    #aDescriptor.Bounds = Rectangle()
    71         -    aDescriptor.WindowAttributes = MsgButtons
    72         -
    73         -    xTK = xParentWin.getToolkit()
    74         -    msgbox = xTK.createWindow(aDescriptor)
    75         -    msgbox.setMessageText(sMsg)
    76         -    msgbox.setCaptionText(sTitle)
    77         -
    78         -    return msgbox.execute()
    79         -
    80         -LABELDICT = { "moderne": u"Moderne", "classique": u"Classique", "reforme1990": u"Réforme 1990", "toutesvariantes": u"Toutes variantes" }
    81         -
    82         -class FrenchDictionarySwitcher (unohelper.Base, XActionListener, XJobExecutor):
    83         -    def __init__ (self, ctx):
    84         -        self.ctx = ctx
    85         -        self.xSvMgr = self.ctx.ServiceManager
    86         -        self.container = None
    87         -        self.dialog = None
    88         -        self.xRB_m = None
    89         -        self.xRB_c = None
    90         -        self.xRB_r = None
    91         -        self.xRB_f = None
    92         -        self.sCurrentDic = ''
    93         -        self.sSelectedDic = ''
    94         -
    95         -    def addWidget (self, name, wtype, x, y, w, h, **kwargs):
    96         -        widget = self.dialog.createInstance('com.sun.star.awt.UnoControl%sModel' % wtype)
    97         -        widget.Name = name
    98         -        widget.PositionX = x
    99         -        widget.PositionY = y
   100         -        widget.Width = w
   101         -        widget.Height = h
   102         -        for k, w in kwargs.items():
   103         -            setattr(widget, k, w)
   104         -        self.dialog.insertByName(name, widget)
   105         -        return widget
   106         -
   107         -    def run (self):
   108         -        # what is the current dictionary
   109         -        xSettings = getConfigSetting("/org.openoffice.Office.Linguistic/ServiceManager/Dictionaries/HunSpellDic_fr", True)
   110         -        xLocations = xSettings.getByName("Locations")
   111         -        m = re.search(r"fr-(\w*)\.(?:dic|aff)", xLocations[0])
   112         -        self.sCurrentDic = m.group(1)
   113         -    
   114         -        # dialog
   115         -        self.dialog = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel', self.ctx)
   116         -        self.dialog.Width = 200
   117         -        self.dialog.Height = 280
   118         -        self.dialog.Title = u"Orthographe française"
   119         -        
   120         -        # blabla
   121         -        sSubTitle = u"Choisissez un dictionnaire"
   122         -        sDicLabel_m = u"“Moderne”"
   123         -        sDicDescr_m = u"Ce dictionnaire propose l’orthographe telle qu’elle est écrite aujourd’hui le plus couramment. C’est le dictionnaire recommandé si le français n’est pas votre langue maternelle ou si vous ne désirez qu’une seule graphie correcte par mot."
   124         -        sDicLabel_c = u"“Classique” (recommandé)"
   125         -        sDicDescr_c = u"Il s’agit du dictionnaire “Moderne”, avec des graphies classiques en sus, certaines encore communément utilisées, d’autres désuètes. C’est le dictionnaire recommandé si le français est votre langue maternelle."
   126         -        sDicLabel_r = u"“Réforme 1990”"
   127         -        sDicDescr_r = u"Avec ce dictionnaire, seule l’orthographe réformée est reconnue. Attendu que bon nombre de graphies réformées sont considérées comme erronées par beaucoup, ce dictionnaire est déconseillé. Les graphies passées dans l’usage sont déjà incluses dans le dictionnaire “Moderne”."
   128         -        sDicLabel_t = u"“Toutes variantes”"
   129         -        sDicDescr_t = u"Ce dictionnaire contient les variantes graphiques, classiques, réformées, ainsi que d’autres plus rares encore. Ce dictionnaire est déconseillé à ceux qui ne connaissent pas très bien la langue française."
   130         -        
   131         -        # widgets
   132         -        padding = 10
   133         -        hspace = 60
   134         -        posY1 = 20; posY2 = posY1 + hspace; posY3 = posY2 + hspace; posY4 = posY3 + hspace; posY5 = posY4 + hspace;
   135         -        wwidth = 170
   136         -        wheight = 20
   137         -        wwidthdescr = 170
   138         -        wheightdescr = 40
   139         -        
   140         -        xFD1 = uno.createUnoStruct("com.sun.star.awt.FontDescriptor")
   141         -        xFD1.Height = 12
   142         -        xFD1.Name = "Verdana"
   143         -        
   144         -        xFD2 = uno.createUnoStruct("com.sun.star.awt.FontDescriptor")
   145         -        xFD2.Height = 11
   146         -        xFD2.Name = "Verdana"
   147         -        
   148         -        gbm = self.addWidget('groupbox', 'GroupBox', 5, 5, 190, 250, Label = sSubTitle, FontDescriptor = xFD1)
   149         -        
   150         -        # Note: the only way to group RadioButtons is to create them successively
   151         -        rbm_m = self.addWidget('rb-moderne', 'RadioButton', padding, posY1, wwidth, wheight, Label = sDicLabel_m, FontDescriptor = xFD2)
   152         -        self.xRB_m = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlRadioButton', self.ctx)
   153         -        self.xRB_m.setModel(rbm_m)
   154         -        rbm_c = self.addWidget('rb-classique', 'RadioButton', padding, posY2, wwidth, wheight, Label = sDicLabel_c, FontDescriptor = xFD2)
   155         -        self.xRB_c = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlRadioButton', self.ctx)
   156         -        self.xRB_c.setModel(rbm_c)
   157         -        rbm_r = self.addWidget('rb-reforme1990', 'RadioButton', padding, posY3, wwidth, wheight, Label = sDicLabel_r, FontDescriptor = xFD2)
   158         -        self.xRB_r = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlRadioButton', self.ctx)
   159         -        self.xRB_r.setModel(rbm_r)
   160         -        rbm_t = self.addWidget('rb-toutesvariantes', 'RadioButton', padding, posY4, wwidth, wheight, Label = sDicLabel_t, FontDescriptor = xFD2)
   161         -        self.xRB_t = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlRadioButton', self.ctx)
   162         -        self.xRB_t.setModel(rbm_t)
   163         -        
   164         -        label_m = self.addWidget('label_m', 'FixedText', 20, posY1+10, wwidthdescr, wheightdescr, Label = sDicDescr_m, MultiLine = True)
   165         -        label_c = self.addWidget('label_c', 'FixedText', 20, posY2+10, wwidthdescr, wheightdescr, Label = sDicDescr_c, MultiLine = True)
   166         -        label_r = self.addWidget('label_r', 'FixedText', 20, posY3+10, wwidthdescr, wheightdescr, Label = sDicDescr_r, MultiLine = True)
   167         -        label_t = self.addWidget('label_t', 'FixedText', 20, posY4+10, wwidthdescr, wheightdescr, Label = sDicDescr_t, MultiLine = True)
   168         -        
   169         -        self.setRadioButton(self.sCurrentDic)
   170         -        
   171         -        button = self.addWidget('select', 'Button', padding+50, posY5, 80, 14, Label = 'Utiliser ce dictionnaire')
   172         -        
   173         -        # container
   174         -        self.container = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialog', self.ctx)
   175         -        self.container.setModel(self.dialog)
   176         -        self.container.getControl('select').addActionListener(self)
   177         -#         if self.sCurrentDic != "moderne":
   178         -#             self.container.getControl('rb-moderne').addActionListener(self)
   179         -#         if self.sCurrentDic != "classique":
   180         -#             self.container.getControl('rb-classique').addActionListener(self)
   181         -#         if self.sCurrentDic != "reforme1990":
   182         -#             self.container.getControl('rb-reforme1990').addActionListener(self)
   183         -#         if self.sCurrentDic != "toutesvariantes":
   184         -#             self.container.getControl('rb-toutesvariantes').addActionListener(self)
   185         -        self.container.setVisible(False)
   186         -        toolkit = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.ExtToolkit', self.ctx)
   187         -        self.container.createPeer(toolkit, None)
   188         -        self.container.execute()
   189         -    
   190         -    def setRadioButton (self, sDic):
   191         -        if sDic == 'moderne':
   192         -            self.xRB_m.setState(True)
   193         -        elif sDic == 'classique':
   194         -            self.xRB_c.setState(True)
   195         -        elif sDic == 'reforme1990':
   196         -            self.xRB_r.setState(True)
   197         -        elif sDic == 'toutesvariantes':
   198         -            self.xRB_t.setState(True)
   199         -        else:
   200         -            pass
   201         -        
   202         -    def actionPerformed (self, actionEvent):
   203         -        try:
   204         -            if self.xRB_m.getState():
   205         -                self.sSelectedDic = 'moderne'
   206         -            elif self.xRB_c.getState():
   207         -                self.sSelectedDic = 'classique'
   208         -            elif self.xRB_r.getState():
   209         -                self.sSelectedDic = 'reforme1990'
   210         -            elif self.xRB_t.getState():
   211         -                self.sSelectedDic = 'toutesvariantes'
   212         -            else:
   213         -                # no dictionary selected
   214         -                pass
   215         -            self.container.endExecute()
   216         -        except:
   217         -            handleException(self.ctx)
   218         -    
   219         -    def trigger (self, args):
   220         -        try:
   221         -            dialog = FrenchDictionarySwitcher(self.ctx)
   222         -            dialog.run()
   223         -            
   224         -            if dialog.sSelectedDic and dialog.sCurrentDic != dialog.sSelectedDic:
   225         -                xSvMgr = uno.getComponentContext().ServiceManager
   226         -                xDesktop = xSvMgr.createInstanceWithContext('com.sun.star.frame.Desktop', self.ctx)
   227         -                xDoc = xDesktop.getCurrentComponent()
   228         -                xWindow = xDoc.CurrentController.Frame.ContainerWindow
   229         -                
   230         -                if dialog.sCurrentDic:
   231         -                    # Modify the registry
   232         -                    xSettings = getConfigSetting("/org.openoffice.Office.Linguistic/ServiceManager/Dictionaries/HunSpellDic_fr", True)
   233         -                    xLocations = xSettings.getByName("Locations")
   234         -                    v1 = xLocations[0].replace(dialog.sCurrentDic, dialog.sSelectedDic)
   235         -                    v2 = xLocations[1].replace(dialog.sCurrentDic, dialog.sSelectedDic)
   236         -                    #xSettings.replaceByName("Locations", xLocations)  # ERROR, see line below
   237         -                    uno.invoke(xSettings, "replaceByName", ("Locations", uno.Any("[]string", (v1, v2))))
   238         -                    xSettings.commitChanges()
   239         -                    # message box
   240         -                    sMsg = u"Vous avez choisi un nouveau dictionnaire\northographique pour la langue française.\n\n“%s” ⇒ “%s”\n\nFermez le logiciel (y compris le démarrage rapide)\net relancez-le." % (LABELDICT[dialog.sCurrentDic], LABELDICT[dialog.sSelectedDic])
   241         -                    MessageBox(xWindow, sMsg, u"Sélection d’un nouveau dictionnaire", "infobox")
   242         -                    
   243         -
   244         -#                     # get package location (URL of this extension)
   245         -#                     xCompCtx = uno.getComponentContext()
   246         -#                     xPackageInformationProvider = xCompCtx.getByName("/singletons/com.sun.star.deployment.PackageInformationProvider")
   247         -#                     sURL = xPackageInformationProvider.getPackageLocation("French.linguistic.resources.from.Dicollecte.by.OlivierR")
   248         -#                     sDstFile = sURL + '/dictionaries.xcu'
   249         -#                     sDstFile = sDstFile.replace('file:///', '').replace('%20', ' ')
   250         -#                     sDstFile = os.path.normpath(sDstFile)
   251         -#                     sTplFile = sDstFile + '.tpl.xml'
   252         -#                     
   253         -#                     # rewrite dictionaries.xcu
   254         -#                     if os.path.isfile(sTplFile) and os.path.isfile(sDstFile):
   255         -#                         with open(sTplFile, 'r') as hFile:
   256         -#                             content = hFile.read()
   257         -#                         hFile.close()
   258         -#                         content = content.replace('{{dictionaryName}}', dialog.sSelectedDic)
   259         -#                         with open(sDstFile, 'w') as hFile:
   260         -#                             hFile.write(content)
   261         -#                         hFile.close()
   262         -#                     else:
   263         -#                         sErrMsg = ""
   264         -#                         if not os.path.isfile(sTplFile):
   265         -#                             sErrMsg += u"File not found: %s\n" % sTplFile
   266         -#                         if not os.path.isfile(sDstFile):
   267         -#                             sErrMsg += u"File not found: %s\n" % sDstFile
   268         -#                         if sErrMsg:
   269         -#                             MessageBox(xWindow, sErrMsg, "ERROR", "error")
   270         -                else:
   271         -                    MessageBox(xWindow, u"Couldn’t retrieve informations\nabout the current dictionary.", "ERROR", "errorbox")
   272         -                
   273         -#                 xSpellChecker = xSvMgr.createInstanceWithContext('com.sun.star.linguistic2.SpellChecker', self.ctx)
   274         -#                 xLocale = uno.createUnoStruct('com.sun.star.lang.Locale')
   275         -#                 xLocale.Language = "fr"
   276         -#                 xLocale.Country = "FR"
   277         -#                 l = xSpellChecker.getSupportedServiceNames()
   278         -#                 MessageBox(xWindow, " ".join(l), "DEBUG", "infobox")
   279         -        except:
   280         -            handleException(self.ctx)
   281         -
   282         -
   283         -def getConfigSetting (sNodeConfig, bForUpdate):
   284         -    if bForUpdate:
   285         -        sService = "com.sun.star.configuration.ConfigurationUpdateAccess"
   286         -    else:
   287         -        sService = "com.sun.star.configuration.ConfigurationAccess"
   288         -    
   289         -    xConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
   290         -    
   291         -    xPropertyValue = PropertyValue()
   292         -    xPropertyValue.Name = "nodepath"
   293         -    xPropertyValue.Value = sNodeConfig
   294         -    
   295         -    xSettings = xConfigProvider.createInstanceWithArguments(sService, (xPropertyValue,))
   296         -    return xSettings
   297         -
   298         -def createUnoService (serviceName):
   299         -    xSvMgr = uno.getComponentContext().ServiceManager
   300         -    return xSvMgr.createInstanceWithContext(serviceName, uno.getComponentContext())
   301         -
   302         -
   303         -g_ImplementationHelper = unohelper.ImplementationHelper()
   304         -g_ImplementationHelper.addImplementation(FrenchDictionarySwitcher, 'dicollecte.FrenchDictionarySwitcher', ('com.sun.star.task.Job',))