LibreOffice plugin to pipe whole Writer documents through Google Translate, that ought to keep most of the page formatting.

⌈⌋ branch:  PageTranslate


Check-in [3f945d5495]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Move MessageBox() to unocompat (not actually used anymore, doesn't work in LO-dev-7.2 anyway), sys.excepthook doesn't suffice for dialog hookup. Add config btn_map{} for external tools from settings dialog.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3f945d5495a56436a3a87d1f36e13c1bed3ff422
User & Date: mario 2021-06-10 14:50:23
Context
2021-06-10
14:52
Notes about ArgosTranslate, CLI alternative check-in: b1b7271886 user: mario tags: trunk
14:50
Move MessageBox() to unocompat (not actually used anymore, doesn't work in LO-dev-7.2 anyway), sys.excepthook doesn't suffice for dialog hookup. Add config btn_map{} for external tools from settings dialog. check-in: 3f945d5495 user: mario tags: trunk
2021-06-06
20:49
Simplify Argos backend, conclude that it only works with distro-LibreOffice check-in: c4b8a7b58b user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Makefile.

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22




23
24
25
26
27
	unopkg remove vnd.include-once.pagetranslate
	unopkg add --log-file log.txt -s pagetranslate.oxt

version: # https://fossil.include-once.org/versionnum/
	which version  &&  version  --read pagetranslate.py  --incr  --write pagetranslate.py  --write description.xml  ||  true

oxt:
	zip pagetranslate.oxt -r META-INF pagetranslate.py *xcu *xcs *xdl *desc* icons pythonpath/ help NEWS

aoo:	version oxt
	#/opt/openoffice4/program/unopkg remove pagetranslate.oxt
	/opt/openoffice4/program/unopkg add pagetranslate.oxt
	# Shift+F1 for UNO names of widgets
	HELP_DEBUG=true /opt/openoffice4/program/soffice -writer
	
lo7:	version oxt
	/opt/libreoffice7.1/program/unopkg add pagetranslate.oxt
	/opt/libreoffice7.1/program/soffice --writer





xhp:
	make -C help/en/vnd.include-once.pagetranslate/

pip:
	make -C pythonpath







|











>
>
>
>





4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
	unopkg remove vnd.include-once.pagetranslate
	unopkg add --log-file log.txt -s pagetranslate.oxt

version: # https://fossil.include-once.org/versionnum/
	which version  &&  version  --read pagetranslate.py  --incr  --write pagetranslate.py  --write description.xml  ||  true

oxt:
	zip pagetranslate.oxt -9 -r META-INF pagetranslate.py *xcu *xcs *xdl *desc* icons pythonpath/ help NEWS -x '*/__pycache__/*'

aoo:	version oxt
	#/opt/openoffice4/program/unopkg remove pagetranslate.oxt
	/opt/openoffice4/program/unopkg add pagetranslate.oxt
	# Shift+F1 for UNO names of widgets
	HELP_DEBUG=true /opt/openoffice4/program/soffice -writer
	
lo7:	version oxt
	/opt/libreoffice7.1/program/unopkg add pagetranslate.oxt
	/opt/libreoffice7.1/program/soffice --writer

lo72:	version oxt
	/opt/libreofficedev7.2/program/unopkg add pagetranslate.oxt
	/opt/libreofficedev7.2/program/soffice --writer

xhp:
	make -C help/en/vnd.include-once.pagetranslate/

pip:
	make -C pythonpath

Changes to pagetranslate.py.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/python
# encoding: utf-8
# api: uno
# type: callback
# category: language
# title: PageTranslate
# description: Action button to get whole Writer document translated
# version: 1.9.43
# state: beta
# author: mario
# url: https://fossil.include-once.org/pagetranslate/
# depends: python:requests (>= 2.5), python:uno
# pack: *.py, pythonpath/*.py, META-INF/*, pkg-desc, *.x*, icons/*
# config:
#    { name: frames, type: bool, value: 0, description: traverse TextFrames }







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/python
# encoding: utf-8
# api: uno
# type: callback
# category: language
# title: PageTranslate
# description: Action button to get whole Writer document translated
# version: 1.9.74
# state: beta
# author: mario
# url: https://fossil.include-once.org/pagetranslate/
# depends: python:requests (>= 2.5), python:uno
# pack: *.py, pythonpath/*.py, META-INF/*, pkg-desc, *.x*, icons/*
# config:
#    { name: frames, type: bool, value: 0, description: traverse TextFrames }
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
76
77
78
# fully (only the Google Translate option is likely to).
#


# OpenOffice UNO bridge
import uno, unohelper
from com.sun.star.task import XJobExecutor
from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_RETRY_CANCEL, BUTTONS_ABORT_IGNORE_RETRY
from com.sun.star.awt.MessageBoxButtons import DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE
from com.sun.star.awt.MessageBoxType import MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
from unocompat import PropertyValue, XNamedAsEnumeration
from com.sun.star.awt import XActionListener, XContainerWindowEventHandler
from com.sun.star.lang import Locale, XServiceInfo, XInitialization
# sys modules
import os, sys
import string, json, re
from traceback import format_exc
from tempfile import gettempdir
# log file
import logging as log
log.basicConfig(filename='%s/pagetranslate-libreoffice.log'%gettempdir(), level=log.DEBUG)

# pythonpath/*.py modules
import httprequests
import translationbackends



# Office plugin
class pagetranslate(unohelper.Base, XJobExecutor):

    # defaults + config + command args
    params = dict(







<
<
<
|


|




|


>



|







47
48
49
50
51
52
53



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# fully (only the Google Translate option is likely to).
#


# OpenOffice UNO bridge
import uno, unohelper
from com.sun.star.task import XJobExecutor



from unocompat import PropertyValue, XNamedAsEnumeration, MessageBox
from com.sun.star.awt import XActionListener, XContainerWindowEventHandler
from com.sun.star.lang import Locale, XServiceInfo, XInitialization
# core modules
import os, sys
import string, json, re
from traceback import format_exc
from tempfile import gettempdir
# log setup
import logging as log
log.basicConfig(filename='%s/pagetranslate-libreoffice.log'%gettempdir(), level=log.DEBUG)
sys.excepthook = lambda *exc: log.critical(format_exc())
# pythonpath/*.py modules
import httprequests
import translationbackends
import pt_dialogs


# Office plugin
class pagetranslate(unohelper.Base, XJobExecutor):

    # defaults + config + command args
    params = dict(
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
        api_key = "",       # API key
        email = "",         # MyMemory email
        cmd = "translate-cli -o -f auto -t {lang} {text}",  # cli tool
        flag = "locale",    # default lang for secondary 🏴 button
    )
    t = None   #= translationbackends.google(self.params)


    # gets instantiated as XJobExecutor by LibreOffice
    def __init__(self, ctx):
        log.info("init")
        self.ctx = ctx
        self.desktop = self.ctx.ServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", self.ctx )
        self.document = self.desktop.getCurrentComponent()
        #self.dispatcher = self.ctx.ServiceManager.createInstanceWithContext("com.sun.star.frame.DispatchHelper", self.ctx)


    # invoked from toolbar button
    def trigger(self, args):
        log.info(".trigger(args=%s) invoked" % repr(args))
        try:
            # merge defaults from registry + params from args
            self.params["from"] = "auto"
            self.params.update(settings(self.ctx).read())
            self.params.update(self.argparse(args))
            if self.params.get("debug"):
                log.root.handlers[0].setLevel(log.DEBUG)
            if self.params.get("mode") == "mri":
                self.mri(self)
            if self.params.get("lang") == "flag":
                self.params["lang"] = self.params.get("flag", "locale")
            if self.params.get("lang") == "select" or self.params.get("from") == "select":
                import pt_dialogs
                self.params["from"], self.params["lang"] = pt_dialogs.langselect()
            if self.params.get("lang") in ("mri-debug", "mri", "debug"):
                return self.mri(self.document)
            log.info(repr(self.params))

            # Draw/Impress?
            log.debug(dir(self.document))







<








<


|












<







84
85
86
87
88
89
90

91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

114
115
116
117
118
119
120
        api_key = "",       # API key
        email = "",         # MyMemory email
        cmd = "translate-cli -o -f auto -t {lang} {text}",  # cli tool
        flag = "locale",    # default lang for secondary 🏴 button
    )
    t = None   #= translationbackends.google(self.params)


    # gets instantiated as XJobExecutor by LibreOffice
    def __init__(self, ctx):
        log.info("init")
        self.ctx = ctx
        self.desktop = self.ctx.ServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", self.ctx )
        self.document = self.desktop.getCurrentComponent()
        #self.dispatcher = self.ctx.ServiceManager.createInstanceWithContext("com.sun.star.frame.DispatchHelper", self.ctx)


    # invoked from toolbar button
    def trigger(self, args):
        log.info(".trigger(args='%s') invoked" % repr(args))
        try:
            # merge defaults from registry + params from args
            self.params["from"] = "auto"
            self.params.update(settings(self.ctx).read())
            self.params.update(self.argparse(args))
            if self.params.get("debug"):
                log.root.handlers[0].setLevel(log.DEBUG)
            if self.params.get("mode") == "mri":
                self.mri(self)
            if self.params.get("lang") == "flag":
                self.params["lang"] = self.params.get("flag", "locale")
            if self.params.get("lang") == "select" or self.params.get("from") == "select":

                self.params["from"], self.params["lang"] = pt_dialogs.langselect()
            if self.params.get("lang") in ("mri-debug", "mri", "debug"):
                return self.mri(self.document)
            log.info(repr(self.params))

            # Draw/Impress?
            log.debug(dir(self.document))
135
136
137
138
139
140
141
142
143

144
145
146
147





148
149
150
151

152
153
154
155
156
157
158
                return

            # else iterate over text snippets
            self.assign_t()
            tree = self.document.getText().createEnumeration()
            self.traverse(tree, slow=self.params.get("slow"))
            if self.params.get("frames"):
            	self.traverse(XNamedAsEnumeration(self.document.getTextFrames()))


        except Exception as exc:
            log.error(format_exc())
            try:
                import pt_dialogs





                pt_dialogs.exception(err=str(exc), exc=format_exc())
            except:
                self.MessageBox(format_exc(), MsgType=ERRORBOX)
        log.info("----")


    # map self.t.translate() implementation according to settings
    def assign_t(self):
        self.t = translationbackends.assign_service(self.params)
        log.info(self.t)
    
    # break up UNO service: url query string `.pagetranslate?page&lang=en`







|
<
>

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







130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146
147
148
149


150
151
152
153
154
155
156
157
                return

            # else iterate over text snippets
            self.assign_t()
            tree = self.document.getText().createEnumeration()
            self.traverse(tree, slow=self.params.get("slow"))
            if self.params.get("frames"):
                self.traverse(XNamedAsEnumeration(self.document.getTextFrames()))

        # show message box for errors from wherever
        except Exception as exc:
            self.exc(exc)
        finally:
            log.info("----")

    # central handler for errors
    def exc(self, exc, *a, **kw):
        dump = format_exc()
        log.error(dump)
        pt_dialogs.exception(err=str(exc), exc=dump)
        #except:


        #    MessageBox(self, dump)

    # map self.t.translate() implementation according to settings
    def assign_t(self):
        self.t = translationbackends.assign_service(self.params)
        log.info(self.t)
    
    # break up UNO service: url query string `.pagetranslate?page&lang=en`
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
            params["lang"] = self.getOoLocale()
        return params

    # debugging/introspection
    def mri(self, obj):
        mri = self.ctx.ServiceManager.createInstanceWithContext("mytools.Mri", self.ctx)
        mri.inspect(obj)


    #-- iterate over TextContent/TextTable nodes
    def traverse(self, tree, slow=0):
        log.info("TextDocument.Enumeration…")
        while tree.hasMoreElements():
            para = tree.nextElement()
            log.info(para)







<







165
166
167
168
169
170
171

172
173
174
175
176
177
178
            params["lang"] = self.getOoLocale()
        return params

    # debugging/introspection
    def mri(self, obj):
        mri = self.ctx.ServiceManager.createInstanceWithContext("mytools.Mri", self.ctx)
        mri.inspect(obj)


    #-- iterate over TextContent/TextTable nodes
    def traverse(self, tree, slow=0):
        log.info("TextDocument.Enumeration…")
        while tree.hasMoreElements():
            para = tree.nextElement()
            log.info(para)
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
            page = pages.getByIndex(pi)
            for si in range(0, page.getCount()):
                shape = page.getByIndex(si)
                if shape.supportsService("com.sun.star.drawing.TextShape"):
                    log.info(shape)
                    shape.Text.setString(self.t.translate(shape.Text.getString()))


    #-- TradutorLibreText (selection rewrite)
    def rewrite_selection(self, xTextRange):
        log.info("rewrite text selection")

        # Get selected text and language
        string = xTextRange.getString()
        if self.params["lang"] == "paragraph":







<







206
207
208
209
210
211
212

213
214
215
216
217
218
219
            page = pages.getByIndex(pi)
            for si in range(0, page.getCount()):
                shape = page.getByIndex(si)
                if shape.supportsService("com.sun.star.drawing.TextShape"):
                    log.info(shape)
                    shape.Text.setString(self.t.translate(shape.Text.getString()))


    #-- TradutorLibreText (selection rewrite)
    def rewrite_selection(self, xTextRange):
        log.info("rewrite text selection")

        # Get selected text and language
        string = xTextRange.getString()
        if self.params["lang"] == "paragraph":
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272




273
274
275
276
277
278
279

    # Langinfo=(com.sun.star.i18n.LanguageCountryInfo){ Language = (string)"de", LanguageDefaultName = (string)"German", Country = (string)"DE", CountryDefaultName = (string)"Germany", Variant = (string)"" }
    def getParaLang(self, xTextRange):
        Langinfo = self.LocaleData.getLanguageCountryInfo(xTextRange.CharLocale)
        log.info("Langinfo="+repr(Langinfo))
        return Langinfo

    # user notifications
    def MessageBox(self, MsgText, MsgTitle="", MsgType=MESSAGEBOX, MsgButtons=BUTTONS_OK):
        ParentWin = self.document.getCurrentController().Frame.ContainerWindow
        ctx = uno.getComponentContext()
        sm = ctx.ServiceManager
        sv = sm.createInstanceWithContext("com.sun.star.awt.Toolkit", ctx)
        myBox = sv.createMessageBox(ParentWin, MsgType, MsgButtons, MsgTitle, MsgText)
        return myBox.execute()


# XActionListener for callbacks
class action_listener(unohelper.Base, XActionListener):
    def __init__(self, cb):
        self.actionPerformed = cb

# Handler for settings-embedded DialogOptions.xdl window, and read/write access to our leaf in the office registry.
# (This is fairly generic/reusable, because it directly maps a dict to/from the dialog widgets.)
#
class settings(unohelper.Base, XContainerWindowEventHandler, XServiceInfo):
    impl_id = "vnd.include-once.OptionsPageTranslate"





    def __init__(self, ctx, *kargs):
        log.info("OptionsPageTranslate:settings.__init__()")
        self.access = self.updatemgr(ctx)
        log.debug(dir(self.access)) #→ ['AsProperty', 'ElementNames', 'ElementType', 'HierarchicalName', 'HierarchicalPropertySetInfo', 'ImplementationId', 'ImplementationName', 'Name', 'PendingChanges', 'Properties', 'PropertySetInfo', 'SupportedServiceNames', 'Types', 'addChangesListener', 'addContainerListener', 'addEventListener', 'addPropertiesChangeListener', 'addPropertyChangeListener', 'addVetoableChangeListener', 'api_key', 'api_key', 'commitChanges', 'composeHierarchicalName', 'debug', 'debug', 'deepl_api', 'deepl_api', 'deepl_web', 'deepl_web', 'dispose', 'firePropertiesChangeEvent', 'getAsProperty', 'getByHierarchicalName', 'getByName', 'getElementNames', 'getElementType', 'getExactName', 'getHierarchicalName', 'getHierarchicalPropertySetInfo', 'getHierarchicalPropertySetInfo', 'getHierarchicalPropertyValue', 'getHierarchicalPropertyValues', 'getImplementationId', 'getImplementationName', 'getName', 'getPendingChanges', 'getProperties', 'getPropertyByHierarchicalName', 'getPropertyByName', 'getPropertySetInfo', 'getPropertySetInfo', 'getPropertyValue', 'getPropertyValues', 'getSupportedServiceNames', 'getTypes', 'google', 'google', 'hasByHierarchicalName', 'hasByName', 'hasElements', 'hasPendingChanges', 'hasPropertyByHierarchicalName', 'hasPropertyByName', 'queryAdapter', 'queryInterface', 'removeChangesListener', 'removeContainerListener', 'removeEventListener', 'removePropertiesChangeListener', 'removePropertyChangeListener', 'removeVetoableChangeListener', 'replaceByHierarchicalName', 'replaceByName', 'setHierarchicalPropertyValue', 'setHierarchicalPropertyValues', 'setName', 'setPropertyValue', 'setPropertyValues', 'supportsService']

    # get handle on OpenOffice registry (read/write)







<
<
<
<
<
<
<
<
<











>
>
>
>







243
244
245
246
247
248
249









250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

    # Langinfo=(com.sun.star.i18n.LanguageCountryInfo){ Language = (string)"de", LanguageDefaultName = (string)"German", Country = (string)"DE", CountryDefaultName = (string)"Germany", Variant = (string)"" }
    def getParaLang(self, xTextRange):
        Langinfo = self.LocaleData.getLanguageCountryInfo(xTextRange.CharLocale)
        log.info("Langinfo="+repr(Langinfo))
        return Langinfo











# XActionListener for callbacks
class action_listener(unohelper.Base, XActionListener):
    def __init__(self, cb):
        self.actionPerformed = cb

# Handler for settings-embedded DialogOptions.xdl window, and read/write access to our leaf in the office registry.
# (This is fairly generic/reusable, because it directly maps a dict to/from the dialog widgets.)
#
class settings(unohelper.Base, XContainerWindowEventHandler, XServiceInfo):
    impl_id = "vnd.include-once.OptionsPageTranslate"
    btn_map = {
        "cfg_argos": "PYTHONPATH= argos-translate-gui &",
        "cfg_deps": "x-terminal-emulator -c 'pip install -U requests translate deep-translator argos-translate' &",
    }

    def __init__(self, ctx, *kargs):
        log.info("OptionsPageTranslate:settings.__init__()")
        self.access = self.updatemgr(ctx)
        log.debug(dir(self.access)) #→ ['AsProperty', 'ElementNames', 'ElementType', 'HierarchicalName', 'HierarchicalPropertySetInfo', 'ImplementationId', 'ImplementationName', 'Name', 'PendingChanges', 'Properties', 'PropertySetInfo', 'SupportedServiceNames', 'Types', 'addChangesListener', 'addContainerListener', 'addEventListener', 'addPropertiesChangeListener', 'addPropertyChangeListener', 'addVetoableChangeListener', 'api_key', 'api_key', 'commitChanges', 'composeHierarchicalName', 'debug', 'debug', 'deepl_api', 'deepl_api', 'deepl_web', 'deepl_web', 'dispose', 'firePropertiesChangeEvent', 'getAsProperty', 'getByHierarchicalName', 'getByName', 'getElementNames', 'getElementType', 'getExactName', 'getHierarchicalName', 'getHierarchicalPropertySetInfo', 'getHierarchicalPropertySetInfo', 'getHierarchicalPropertyValue', 'getHierarchicalPropertyValues', 'getImplementationId', 'getImplementationName', 'getName', 'getPendingChanges', 'getProperties', 'getPropertyByHierarchicalName', 'getPropertyByName', 'getPropertySetInfo', 'getPropertySetInfo', 'getPropertyValue', 'getPropertyValues', 'getSupportedServiceNames', 'getTypes', 'google', 'google', 'hasByHierarchicalName', 'hasByName', 'hasElements', 'hasPendingChanges', 'hasPropertyByHierarchicalName', 'hasPropertyByName', 'queryAdapter', 'queryInterface', 'removeChangesListener', 'removeContainerListener', 'removeEventListener', 'removePropertiesChangeListener', 'removePropertyChangeListener', 'removeVetoableChangeListener', 'replaceByHierarchicalName', 'replaceByName', 'setHierarchicalPropertyValue', 'setHierarchicalPropertyValues', 'setName', 'setPropertyValue', 'setPropertyValues', 'supportsService']

    # get handle on OpenOffice registry (read/write)
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
        log.debug("OptonsPageTranslate:settings.callHandlerMethod({}, {}, {})".format(repr(window), action, name))
        try:
            params = self.read()
            log.info(repr(params))
            # iterate over all dialog controls by name, and assign from/to config dict
            for name, cntrl in [(c.Model.Name, c) for c in window.getControls()]:
                log.info(name)
                if name == "cfg_argos":
                    #cntrl.setLabel("service:org.openoffice.comp.pyuno.pagetranslate?exec&cmd=argos-translate-gui")
                    cntrl.addActionListener(action_listener(lambda *x: os.system("PYTHONPATH= argos-translate-gui &")))
                    log.debug(sys.path)
                elif action == "initialize":
                    self.setControlValue(cntrl, params.get(name))
                elif action == "ok":
                    params[name] = self.getControlValue(cntrl)
            if action == "ok":
                self.write(params)
        except:







|
<
|
<







296
297
298
299
300
301
302
303

304

305
306
307
308
309
310
311
        log.debug("OptonsPageTranslate:settings.callHandlerMethod({}, {}, {})".format(repr(window), action, name))
        try:
            params = self.read()
            log.info(repr(params))
            # iterate over all dialog controls by name, and assign from/to config dict
            for name, cntrl in [(c.Model.Name, c) for c in window.getControls()]:
                log.info(name)
                if name in self.btn_map:

                    cntrl.addActionListener(action_listener(lambda *x: os.system(self.btn_map[name])))

                elif action == "initialize":
                    self.setControlValue(cntrl, params.get(name))
                elif action == "ok":
                    params[name] = self.getControlValue(cntrl)
            if action == "ok":
                self.write(params)
        except:

Changes to pythonpath/unocompat.py.

7
8
9
10
11
12
13



14
15
16
17
18
19
20
#
# Just the shorter `PropertyValue` for now.
# And a convenience wrapper for TextFrames, to match the iterator interface.
#

import uno, unohelper
from com.sun.star.beans import PropertyValue as UNO_PropertyValue




# AOO uno version doesn't have constructor with name/value params
def PropertyValue(Name="nodepath", Value=None):
    pv = UNO_PropertyValue()
    pv.Name = Name
    pv.Value = Value
    return pv







>
>
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
# Just the shorter `PropertyValue` for now.
# And a convenience wrapper for TextFrames, to match the iterator interface.
#

import uno, unohelper
from com.sun.star.beans import PropertyValue as UNO_PropertyValue
from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_RETRY_CANCEL, BUTTONS_ABORT_IGNORE_RETRY
from com.sun.star.awt.MessageBoxButtons import DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE
from com.sun.star.awt.MessageBoxType import MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX

# AOO uno version doesn't have constructor with name/value params
def PropertyValue(Name="nodepath", Value=None):
    pv = UNO_PropertyValue()
    pv.Name = Name
    pv.Value = Value
    return pv
32
33
34
35
36
37
38
39








            self.names = []

    def hasMoreElements(self):
        return len(self.names) > 0

    def nextElement(self):
        return self.elements.getByName(self.names.pop(0))
   















|
>
>
>
>
>
>
>
>
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
            self.names = []

    def hasMoreElements(self):
        return len(self.names) > 0

    def nextElement(self):
        return self.elements.getByName(self.names.pop(0))

# user notifications
def MessageBox(parent, MsgText, MsgTitle="", MsgType=MESSAGEBOX, MsgButtons=BUTTONS_OK):
    ParentWin = parent.document.getCurrentController().Frame.ContainerWindow
    ctx = uno.getComponentContext()
    sm = ctx.ServiceManager
    sv = sm.createInstanceWithContext("com.sun.star.awt.Toolkit", ctx)
    myBox = sv.createMessageBox(ParentWin, MsgType, MsgButtons, MsgTitle, MsgText)
    return myBox.execute()