Grammalecte  Diff

Differences From Artifact [f3ef6493bc]:

To Artifact [c3e413f4e7]:


1
2
3
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
32
33
34
35
36
# Helpers for LibreOffice extension

import os
import traceback


import uno

from com.sun.star.beans import PropertyValue
from com.sun.star.uno import RuntimeException as _rtex





















def xray (myObject):
    "XRay - API explorer"
    try:
        sm = uno.getComponentContext().ServiceManager
        mspf = sm.createInstanceWithContext("com.sun.star.script.provider.MasterScriptProviderFactory", uno.getComponentContext())
        scriptPro = mspf.createScriptProvider("")
        xScript = scriptPro.getScript("vnd.sun.star.script:XrayTool._Main.Xray?language=Basic&location=application")
        xScript.invoke((myObject,), (), ())
        return
    except:
        raise _rtex("\nBasic library Xray is not installed", uno.getComponentContext())


def mri (ctx, xTarget):
    "MRI - API Explorer"
    try:

        xMri = ctx.ServiceManager.createInstanceWithContext("mytools.Mri", ctx)
        xMri.inspect(xTarget)
    except:
        raise _rtex("\nPython extension MRI is not installed", uno.getComponentContext())


def getConfigSetting (sNodeConfig, bUpdate=False):
    "get a configuration node"
    # example: xNode = getConfigSetting("/org.openoffice.Office.Common/Path/Current", False)




>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|


|
|
|
|
|





|


>
|
|







1
2
3
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Helpers for LibreOffice extension

import os
import traceback
import subprocess

import uno

from com.sun.star.beans import PropertyValue
from com.sun.star.uno import RuntimeException as _rtex


def startConsole ():
    "open console from APSO extension"
    try:
        xContext = uno.getComponentContext()
        xContext.ServiceManager.createInstance("apso.python.script.organizer.impl")
        # now we can import apso_utils library
        from apso_utils import console
        console()
    except:
        try:
            xContext = uno.getComponentContext()
            xSvMgr = xContext.getServiceManager()
            xPathSettings = xSvMgr.createInstanceWithContext("com.sun.star.util.PathSettings", xContext)
            spPyInstallion = uno.fileUrlToSystemPath(xPathSettings.Module)
            subprocess.Popen(spPyInstallion + os.sep + "python")  # Start Python interactive Shell
        except:
            traceback.print_exc()


def xray (xObject):
    "XRay - API explorer"
    try:
        xSvMgr = uno.getComponentContext().ServiceManager
        xMSPF = xSvMgr.createInstanceWithContext("com.sun.star.script.provider.MasterScriptProviderFactory", uno.getComponentContext())
        xScriptProvider = xMSPF.createScriptProvider("")
        xScript = xScriptProvider.getScript("vnd.sun.star.script:XrayTool._Main.Xray?language=Basic&location=application")
        xScript.invoke((xObject,), (), ())
        return
    except:
        raise _rtex("\nBasic library Xray is not installed", uno.getComponentContext())


def mri (xObject):
    "MRI - API Explorer"
    try:
        xContext = uno.getComponentContext()
        xMri = xContext.ServiceManager.createInstanceWithContext("mytools.Mri", xContext)
        xMri.inspect(xObject)
    except:
        raise _rtex("\nPython extension MRI is not installed", uno.getComponentContext())


def getConfigSetting (sNodeConfig, bUpdate=False):
    "get a configuration node"
    # example: xNode = getConfigSetting("/org.openoffice.Office.Common/Path/Current", False)
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








def printServices (o):
    for s in o.getAvailableServiceNames():
        print(' > '+s)


def getWindowSize ():
    "return main window size"
    xCurCtx = uno.getComponentContext()
    xDesktop = xCurCtx.getServiceManager().createInstanceWithContext('com.sun.star.frame.Desktop', xCurCtx)
    xContainerWindow = xDesktop.getCurrentComponent().CurrentController.Frame.ContainerWindow
    xWindowSize = xContainerWindow.convertSizeToLogic(xContainerWindow.Size, uno.getConstantByName("com.sun.star.util.MeasureUnit.POINT"))
    #print(xContainerWindow.Size.Width, ">", xWindowSize.Width)
    #print(xContainerWindow.Size.Height, ">", xWindowSize.Height)
    xWindowSize.Width = xWindowSize.Width * 0.666
    xWindowSize.Height = xWindowSize.Height * 0.666
    return xWindowSize


def getAbsolutePathOf (sPath=""):
    xDefaultContext = uno.getComponentContext().ServiceManager.DefaultContext
    xPackageInfoProvider = xDefaultContext.getValueByName("/singletons/com.sun.star.deployment.PackageInformationProvider")
    sFullPath = xPackageInfoProvider.getPackageLocation("French.linguistic.resources.from.Dicollecte.by.OlivierR")
    if sPath and not sPath.startswith("/"):
        sPath = "/" + sPath
    sFullPath = sFullPath[8:] + sPath
    return os.path.abspath(sFullPath)















|
|

















>
>
>
>
>
>
>
>
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
def printServices (o):
    for s in o.getAvailableServiceNames():
        print(' > '+s)


def getWindowSize ():
    "return main window size"
    xContext = uno.getComponentContext()
    xDesktop = xContext.getServiceManager().createInstanceWithContext('com.sun.star.frame.Desktop', xContext)
    xContainerWindow = xDesktop.getCurrentComponent().CurrentController.Frame.ContainerWindow
    xWindowSize = xContainerWindow.convertSizeToLogic(xContainerWindow.Size, uno.getConstantByName("com.sun.star.util.MeasureUnit.POINT"))
    #print(xContainerWindow.Size.Width, ">", xWindowSize.Width)
    #print(xContainerWindow.Size.Height, ">", xWindowSize.Height)
    xWindowSize.Width = xWindowSize.Width * 0.666
    xWindowSize.Height = xWindowSize.Height * 0.666
    return xWindowSize


def getAbsolutePathOf (sPath=""):
    xDefaultContext = uno.getComponentContext().ServiceManager.DefaultContext
    xPackageInfoProvider = xDefaultContext.getValueByName("/singletons/com.sun.star.deployment.PackageInformationProvider")
    sFullPath = xPackageInfoProvider.getPackageLocation("French.linguistic.resources.from.Dicollecte.by.OlivierR")
    if sPath and not sPath.startswith("/"):
        sPath = "/" + sPath
    sFullPath = sFullPath[8:] + sPath
    return os.path.abspath(sFullPath)


def getProductNameAndVersion ():
    "returns tuple of software name and version"
    xSettings = getConfigSetting("org.openoffice.Setup/Product", False)
    sProdName = xSettings.getByName("ooName")
    sVersion = xSettings.getByName("ooSetupVersion")
    return (sProdName, sVersion)