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

⌈⌋ branch:  PageTranslate


Artifact [9668509ef9]

Artifact 9668509ef92e0175417fddae3d146ec8aef2d7db:

  • File pythonpath/unocompat.py — part of check-in [3f945d5495] at 2021-06-10 14:50:23 on branch trunk — 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. (user: mario size: 1887)

# encoding: utf-8
# api: uno
# type: functions
# version: 0.2
# title: UNO helper
# description: compatibility between LO and AOO
#
# 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

# faux XEnumerationAccesss for XNamedAccess
class XNamedAsEnumeration:
    names = []

    def __init__(self, elements):
        self.elements = elements
        self.names = elements.getElementNames()
        if type(self.names) is tuple:
            self.names = list(self.names)
        else:
            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()