init
commit
b7d16102eb
|
@ -0,0 +1,21 @@
|
|||
import sys
|
||||
def PythonVersion(*args):
|
||||
"""Prints the Python version into the current document"""
|
||||
#get the doc from the scripting context which is made available to all scripts
|
||||
desktop = XSCRIPTCONTEXT.getDesktop()
|
||||
model = desktop.getCurrentComponent()
|
||||
#check whether there's already an opened document. Otherwise, create a new one
|
||||
if not hasattr(model, "Sheets"):
|
||||
model = desktop.loadComponentFromURL(
|
||||
"private:factory/scalc","_blank", 0, () )
|
||||
#get the XText interface
|
||||
sheet = model.Sheets.getByIndex(0)
|
||||
#create an XTextRange at the end of the document
|
||||
tRange = sheet.getCellRangeByName("C4")
|
||||
#and set the string
|
||||
tRange.String = "The Python version is %s.%s.%s" % sys.version_info[:3]
|
||||
#do the same for the python executable path
|
||||
tRange = sheet.getCellRangeByName("C5")
|
||||
tRange.String = sys.executable
|
||||
return None
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
def MsgBox(prompt: str, buttons=0, title='LibreOffice') -> int:
|
||||
""" Displays a dialog box containing a message and returns a value."""
|
||||
xScript = _getScript("_MsgBox")
|
||||
res = xScript.invoke((prompt,buttons,title), (), ())
|
||||
return res[0]
|
||||
|
||||
def InputBox(prompt: str, title='LibreOffice', defaultValue='') -> str:
|
||||
""" Displays a prompt in a dialog box at which the user can enter text."""
|
||||
xScript = _getScript("_InputBox")
|
||||
res = xScript.invoke((prompt,title,defaultValue), (), ())
|
||||
return res[0]
|
||||
|
||||
def Print(message: str):
|
||||
"""Outputs the specified strings or numeric expressions in a dialog box."""
|
||||
xScript = _getScript("_Print")
|
||||
xScript.invoke((message,), (), ())
|
||||
|
||||
import uno
|
||||
from com.sun.star.script.provider import XScript
|
||||
def _getScript(script: str, library='Standard', module='uiScripts') -> XScript:
|
||||
sm = uno.getComponentContext().ServiceManager
|
||||
mspf = sm.createInstanceWithContext("com.sun.star.script.provider.MasterScriptProviderFactory", uno.getComponentContext())
|
||||
scriptPro = mspf.createScriptProvider("")
|
||||
scriptName = "vnd.sun.star.script:"+library+"."+module+"."+script+"?language=Basic&location=application"
|
||||
xScript = scriptPro.getScript(scriptName)
|
||||
return xScript
|
Loading…
Reference in New Issue