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

⌈⌋ ⎇ branch:  PageTranslate


Artifact [2930d2ad82]

Artifact 2930d2ad82d3c043ff080652740c34b47369dfd7:

  • File pythonpath/unocompat.py — part of check-in [1956886c24] at 2022-10-14 12:56:59 on branch trunk — pylint whitespace etc. (user: mario size: 2046)

# 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()

# set properties when instantiating
def with_properties(obj, **kwargs):
    for key, value in kwargs.items():
        setattr(obj, key, value)
    return obj