Grammalecte  Check-in [885504d7e7]

Overview
Comment:[lo] text formatter: save options in LO profile
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | lo
Files: files | file ages | folders
SHA3-256: 885504d7e7d7eaed7462523ff71914c55a3d638fd2f53b6bb6fb90a4b571b08f
User & Date: olr on 2019-09-26 07:31:45
Other Links: manifest | tags
Context
2019-09-26
07:36
[lo] text formatter: remove useless options check-in: a34b24be81 user: olr tags: trunk, lo
07:31
[lo] text formatter: save options in LO profile check-in: 885504d7e7 user: olr tags: trunk, lo
2019-09-25
17:18
[fr] nr: confusion check-in: 6547ecddc9 user: olr tags: trunk, fr
Changes

Modified gc_core/py/oxt/OptionsDialog.xcs from [22cc8bb99e] to [ce33caf5a3].

30
31
32
33
34
35
36

37
38
39
40
41
42
43
            <prop oor:name="community_dic" oor:type="xs:string"><value></value></prop>
            <prop oor:name="personal_dic" oor:type="xs:string"><value></value></prop>
            <!-- graphic options -->
            <prop oor:name="line_multicolor" oor:type="xs:int"><value>1</value></prop>
            <prop oor:name="line_type" oor:type="xs:string"><value>BOLDWAVE</value></prop>
            <!-- misc options -->
            <prop oor:name="start_console" oor:type="xs:int"><value>0</value></prop>

        </group>
    </templates>

    <component>
        <group oor:name="Leaves">
            <node-ref oor:name="${lang}" oor:node-type="${lang}" />
        </group>







>







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
            <prop oor:name="community_dic" oor:type="xs:string"><value></value></prop>
            <prop oor:name="personal_dic" oor:type="xs:string"><value></value></prop>
            <!-- graphic options -->
            <prop oor:name="line_multicolor" oor:type="xs:int"><value>1</value></prop>
            <prop oor:name="line_type" oor:type="xs:string"><value>BOLDWAVE</value></prop>
            <!-- misc options -->
            <prop oor:name="start_console" oor:type="xs:int"><value>0</value></prop>
            <prop oor:name="tf_options" oor:type="xs:string"><value></value></prop>
        </group>
    </templates>

    <component>
        <group oor:name="Leaves">
            <node-ref oor:name="${lang}" oor:node-type="${lang}" />
        </group>

Modified gc_lang/fr/oxt/TextFormatter/TextFormatter.py from [53d806905a] to [3573b30804].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# -*- coding: utf8 -*-
# Text Formatter
# by Olivier R.
# License: MPL 2

import unohelper
import uno
import sys
import os
import traceback
import time

if sys.version_info.major == 3:
    import imp

import tf_strings
import tf_options
import tf_tabrep
import helpers


<






|
<


<
<
|








1
2
3
4
5
6
7

8
9


10
11
12
13
14
15
16
17

# Text Formatter
# by Olivier R.
# License: MPL 2

import unohelper
import uno


import traceback
import time


import json

import tf_strings
import tf_options
import tf_tabrep
import helpers


264
265
266
267
268
269
270

271
272
273
274
275
276
277
278
        #self.bsel = self._addWidget('bsel', 'CheckBox', x2, self.xDialog.Height-40, nWidth-55, nHeight, Label = self.dUI.get('bsel', "#err"))
        self.bapply = self._addWidget('apply', 'Button', self.xDialog.Width-55, self.xDialog.Height-19, 50, 15, Label = self.dUI.get('apply', "#err"), \
                                      FontDescriptor = xFD2, TextColor = 0x004400)
        self.binfo = self._addWidget('info', 'Button', self.xDialog.Width-15, 0, 10, 9, Label = self.dUI.get('info', "#err"), \
                                     HelpText = self.dUI.get('infotitle', "#err"), FontDescriptor = xFDsmall, TextColor = 0x444444)

        # load configuration

        self._loadConfig()

        ## container
        self.xContainer = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialog', self.ctx)
        self.xContainer.setModel(self.xDialog)
        self.xContainer.setVisible(False)
        self.xContainer.getControl('info').addActionListener(self)
        self.xContainer.getControl('info').setActionCommand('Info')







>
|







260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
        #self.bsel = self._addWidget('bsel', 'CheckBox', x2, self.xDialog.Height-40, nWidth-55, nHeight, Label = self.dUI.get('bsel', "#err"))
        self.bapply = self._addWidget('apply', 'Button', self.xDialog.Width-55, self.xDialog.Height-19, 50, 15, Label = self.dUI.get('apply', "#err"), \
                                      FontDescriptor = xFD2, TextColor = 0x004400)
        self.binfo = self._addWidget('info', 'Button', self.xDialog.Width-15, 0, 10, 9, Label = self.dUI.get('info', "#err"), \
                                     HelpText = self.dUI.get('infotitle', "#err"), FontDescriptor = xFDsmall, TextColor = 0x444444)

        # load configuration
        self.xGLOptionNode = helpers.getConfigSetting("/org.openoffice.Lightproof_${implname}/Other/", True)
        self._loadConfig("${lang}")

        ## container
        self.xContainer = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialog', self.ctx)
        self.xContainer.setModel(self.xDialog)
        self.xContainer.setVisible(False)
        self.xContainer.getControl('info').addActionListener(self)
        self.xContainer.getControl('info').setActionCommand('Info')
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
                else:
                    xDesktop = self.ctx.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", self.ctx)
                    xElem = xDesktop.getCurrentComponent()

                    # Writer
                    if True:
                        # no selection
                        self._saveConfig()
                        self._replaceAll(xElem)
                    else:
                        # modify selected text only
                        pass
                        #xSelecList = xDoc.getCurrentSelection()
                        #xSel = xSelecList.getByIndex(0)








|







304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
                else:
                    xDesktop = self.ctx.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", self.ctx)
                    xElem = xDesktop.getCurrentComponent()

                    # Writer
                    if True:
                        # no selection
                        self._saveConfig("${lang}")
                        self._replaceAll(xElem)
                    else:
                        # modify selected text only
                        pass
                        #xSelecList = xDoc.getCurrentSelection()
                        #xSel = xSelecList.getByIndex(0)

358
359
360
361
362
363
364
365
366
367
368

369
370

371
372
373

374
375

376
377
378

379
380
381
382
383

384
385

386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
                xWindow = xDoc.CurrentController.Frame.ContainerWindow
                MessageBox (xWindow, self.dUI.get('infomsg', "#err"), self.dUI.get('infotitle', "#err"))
            else:
                print("Wrong command: " + xActionEvent.ActionCommand)
        except:
            traceback.print_exc()

    def _loadConfig (self):
        try:
            if sys.version_info.major == 3:
                imp.reload(tf_options)

            else:
                reload(tf_options)

            self._setConfig(tf_options.dOpt)
        except:
            traceback.print_exc()


    def _setConfig (self, d):

        try:
            for key, val in d.items():
                w = getattr(self, key)

                w.State = val
                if key in self.dCheckboxWidgets:
                    self._switchCheckBox(w)
        except:
            raise


    def _saveConfig (self):

        try:
            # create options dictionary
            dOpt = {}
            for key, lWidget in self.dCheckboxWidgets.items():
                w = getattr(self, key)
                dOpt[w.Name] = w.State
                for w in lWidget:
                    dOpt[w.Name] = w.State
            # write file
            sExtPath = helpers.getAbsolutePathOf("/pythonpath/tf_options.py")
            if os.path.isfile(sExtPath):
                hOpt = open(sExtPath, "w")
                hOpt.write("dDefaultOpt = " + str(tf_options.dDefaultOpt) + "\n")
                hOpt.write("dOpt = " + str(dOpt))
                hOpt.close()
        except:
            traceback.print_exc()

    def _switchCheckBox (self, wGroupCheckbox):
        for w in self.dCheckboxWidgets.get(wGroupCheckbox.Name, []):
            w.Enabled = wGroupCheckbox.State








|

<
|
>
|
|
>
|


>

|
>
|
<
|
>
|
|
|
|
|
>

|
>



|
|



|
|
<
<
|
<
|







355
356
357
358
359
360
361
362
363

364
365
366
367
368
369
370
371
372
373
374
375
376

377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397


398

399
400
401
402
403
404
405
406
                xWindow = xDoc.CurrentController.Frame.ContainerWindow
                MessageBox (xWindow, self.dUI.get('infomsg', "#err"), self.dUI.get('infotitle', "#err"))
            else:
                print("Wrong command: " + xActionEvent.ActionCommand)
        except:
            traceback.print_exc()

    def _loadConfig (self, sLang):
        try:

            dOpt = tf_options.dDefaultOpt.copy()
            xChild = self.xGLOptionNode.getByName("o_"+sLang)
            sTFOptionsJSON = xChild.getPropertyValue("tf_options")
            if sTFOptionsJSON:
                dOpt.update(json.loads(sTFOptionsJSON))
            self._setConfig(dOpt)
        except:
            traceback.print_exc()
            self._setConfig(tf_options.dDefaultOpt)

    def _setConfig (self, dOpt):
        for sKey, val in dOpt.items():
            try:

                w = getattr(self, sKey)
                if w:
                    w.State = val
                    if sKey in self.dCheckboxWidgets:
                        self._switchCheckBox(w)
            except:
                traceback.print_exc()
                print("option", sKey, "not set.")

    def _saveConfig (self, sLang):
        "save options in LibreOffice profile"
        try:
            # create options dictionary
            dOpt = {}
            for sKey, lWidget in self.dCheckboxWidgets.items():
                w = getattr(self, sKey)
                dOpt[w.Name] = w.State
                for w in lWidget:
                    dOpt[w.Name] = w.State
            # save option to LO profile as JSON string
            xChild = self.xGLOptionNode.getByName("o_"+sLang)


            xChild.setPropertyValue("tf_options", json.dumps(dOpt))

            self.xGLOptionNode.commitChanges()
        except:
            traceback.print_exc()

    def _switchCheckBox (self, wGroupCheckbox):
        for w in self.dCheckboxWidgets.get(wGroupCheckbox.Name, []):
            w.Enabled = wGroupCheckbox.State

684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
        try:
            for sPattern, sRepl, bRegex, bCaseSensitive in tf_tabrep.dTableRepl[sList]:
                n += self._replaceText(xElem, sPattern, sRepl, bRegex, bCaseSensitive)
        except:
            print("# Error with "+sList)
            traceback.print_exc()
        return n


    def _replaceText (self, xElem, sPattern, sRepl, bRegex, bCaseSensitive=False):
        try:
            xRD = xElem.createReplaceDescriptor()
            xRD.SearchString = sPattern
            xRD.ReplaceString = sRepl
            xRD.SearchRegularExpression = bRegex







<







683
684
685
686
687
688
689

690
691
692
693
694
695
696
        try:
            for sPattern, sRepl, bRegex, bCaseSensitive in tf_tabrep.dTableRepl[sList]:
                n += self._replaceText(xElem, sPattern, sRepl, bRegex, bCaseSensitive)
        except:
            print("# Error with "+sList)
            traceback.print_exc()
        return n


    def _replaceText (self, xElem, sPattern, sRepl, bRegex, bCaseSensitive=False):
        try:
            xRD = xElem.createReplaceDescriptor()
            xRD.SearchString = sPattern
            xRD.ReplaceString = sRepl
            xRD.SearchRegularExpression = bRegex