master
a2nr 2023-02-20 07:51:46 +07:00
commit b7d16102eb
2 changed files with 50 additions and 0 deletions

21
coba.py Normal file
View File

@ -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

29
screen_io.py Normal file
View File

@ -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