From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- pyuno/demo/Addons.xcu | 36 +++++++++++ pyuno/demo/biblioaccess.py | 53 +++++++++++++++++ pyuno/demo/hello_world_comp.py | 60 +++++++++++++++++++ pyuno/demo/makefile.mk | 60 +++++++++++++++++++ pyuno/demo/ooextract.py | 129 ++++++++++++++++++++++++++++++++++++++++ pyuno/demo/pyunoenv.bat | 23 +++++++ pyuno/demo/pyunoenv.tcsh | 49 +++++++++++++++ pyuno/demo/swriter.py | 122 +++++++++++++++++++++++++++++++++++++ pyuno/demo/swritercomp.py | 128 +++++++++++++++++++++++++++++++++++++++ pyuno/demo/swritercompclient.py | 32 ++++++++++ 10 files changed, 692 insertions(+) create mode 100644 pyuno/demo/Addons.xcu create mode 100644 pyuno/demo/biblioaccess.py create mode 100644 pyuno/demo/hello_world_comp.py create mode 100644 pyuno/demo/makefile.mk create mode 100644 pyuno/demo/ooextract.py create mode 100644 pyuno/demo/pyunoenv.bat create mode 100644 pyuno/demo/pyunoenv.tcsh create mode 100644 pyuno/demo/swriter.py create mode 100644 pyuno/demo/swritercomp.py create mode 100644 pyuno/demo/swritercompclient.py (limited to 'pyuno/demo') diff --git a/pyuno/demo/Addons.xcu b/pyuno/demo/Addons.xcu new file mode 100644 index 000000000..59d2d1856 --- /dev/null +++ b/pyuno/demo/Addons.xcu @@ -0,0 +1,36 @@ + + + + + + + + + service:org.openoffice.comp.pyuno.demo.HelloWorld?insert + + + Insert Hello World + Insert Hello World + + + + + diff --git a/pyuno/demo/biblioaccess.py b/pyuno/demo/biblioaccess.py new file mode 100644 index 000000000..0e5d0b4c8 --- /dev/null +++ b/pyuno/demo/biblioaccess.py @@ -0,0 +1,53 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +import uno +from com.sun.star.sdb.CommandType import COMMAND + +def main(): + connectionString = "socket,host=localhost,port=2002" + + url = "uno:" + connectionString + ";urp;StarOffice.ComponentContext" + + localCtx = uno.getComponentContext() + localSmgr = localCtx.ServiceManager + resolver = localSmgr.createInstanceWithContext( + "com.sun.star.bridge.UnoUrlResolver", localCtx) + ctx = resolver.resolve(url) + smgr = ctx.ServiceManager + + rowset =smgr.createInstanceWithContext("com.sun.star.sdb.RowSet", ctx) + rowset.DataSourceName = "Bibliography" + rowset.CommandType = COMMAND + rowset.Command = "SELECT IDENTIFIER, AUTHOR FROM biblio" + + rowset.execute(); + + print("Identifier\tAuthor") + + id = rowset.findColumn("IDENTIFIER") + author = rowset.findColumn("AUTHOR") + while rowset.next(): + print(rowset.getString(id) + "\t" + repr(rowset.getString(author))) + + rowset.dispose(); + +main() + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/pyuno/demo/hello_world_comp.py b/pyuno/demo/hello_world_comp.py new file mode 100644 index 000000000..646a124a4 --- /dev/null +++ b/pyuno/demo/hello_world_comp.py @@ -0,0 +1,60 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +import uno +import unohelper + +from com.sun.star.task import XJobExecutor + +# implement a UNO component by deriving from the standard unohelper.Base class +# and from the interface(s) you want to implement. +class HelloWorldJob(unohelper.Base, XJobExecutor): + def __init__(self, ctx): + # store the component context for later use + self.ctx = ctx + + def trigger(self, args): + # note: args[0] == "HelloWorld", see below config settings + + # retrieve the desktop object + desktop = self.ctx.ServiceManager.createInstanceWithContext( + "com.sun.star.frame.Desktop", self.ctx) + + # get current document model + model = desktop.getCurrentComponent() + + # access the document's text property + text = model.Text + + # create a cursor + cursor = text.createTextCursor() + + # insert the text into the document + text.insertString(cursor, "Hello World", 0) + +# pythonloader looks for a static g_ImplementationHelper variable +g_ImplementationHelper = unohelper.ImplementationHelper() + +g_ImplementationHelper.addImplementation( \ + HelloWorldJob, # UNO object class + "org.openoffice.comp.pyuno.demo.HelloWorld", # implementation name + ("com.sun.star.task.Job",),) # list of implemented services + # (the only service) + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/pyuno/demo/makefile.mk b/pyuno/demo/makefile.mk new file mode 100644 index 000000000..11fe66f31 --- /dev/null +++ b/pyuno/demo/makefile.mk @@ -0,0 +1,60 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +PRJNAME=pyuno +PRJ=.. + +.INCLUDE : settings.mk +.INCLUDE : pyversion.mk + +ROOT=$(MISC)/pyuno-doc + +FILES=\ + $(ROOT)/python-bridge.html \ + $(ROOT)/customized_setup.png \ + $(ROOT)/mode_component.png \ + $(ROOT)/mode_ipc.png \ + $(ROOT)/modes.sxd \ + $(ROOT)/optional_components.png \ + $(ROOT)/samples/swriter.py \ + $(ROOT)/samples/swritercomp.py \ + $(ROOT)/samples/ooextract.py \ + $(ROOT)/samples/biblioaccess.py \ + $(ROOT)/samples/swritercompclient.py \ + $(ROOT)/samples/hello_world_pyuno.zip + + +$(MISC)/pyuno-doc.zip : dirs $(FILES) + -rm -f $@ + cd $(MISC) && zip -r pyuno-doc.zip pyuno-doc + +dirs .PHONY : + -mkdir $(ROOT) + -mkdir $(ROOT)/samples + +$(ROOT)/samples/hello_world_pyuno.zip : hello_world_comp.py Addons.xcu + -rm -f $@ + zip $@ hello_world_comp.py Addons.xcu + +$(ROOT)/samples/% : % + -rm -f $@ + $(COPY) $? $@ + +$(ROOT)/% : ../doc/% + -rm -f $@ + $(COPY) $? $@ diff --git a/pyuno/demo/ooextract.py b/pyuno/demo/ooextract.py new file mode 100644 index 000000000..d6cce94e8 --- /dev/null +++ b/pyuno/demo/ooextract.py @@ -0,0 +1,129 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +import getopt,sys +import uno +from unohelper import Base,systemPathToFileUrl, absolutize +from os import getcwd + +from com.sun.star.beans import PropertyValue +from com.sun.star.beans.PropertyState import DIRECT_VALUE +from com.sun.star.uno import Exception as UnoException +from com.sun.star.io import IOException,XInputStream, XOutputStream + +class OutputStream(Base, XOutputStream): + def __init__(self): + self.closed = 0 + + def closeOutput(self): + self.closed = 1 + + def writeBytes(self, seq): + sys.stdout.write(seq.value) + + def flush(self): + pass + +def main(): + retVal = 0 + doc = None + + try: + opts, args = getopt.getopt(sys.argv[1:], "hc:", ["help", "connection-string=", "html"]) + format = None + url = "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" + filterName = "Text (Encoded)" + for o, a in opts: + if o in ("-h", "--help"): + usage() + sys.exit() + if o in ("-c", "--connection-string"): + url = "uno:" + a + ";urp;StarOffice.ComponentContext" + if o == "--html": + filterName = "HTML (StarWriter)" + + print(filterName) + if not len(args): + usage() + sys.exit() + + ctxLocal = uno.getComponentContext() + smgrLocal = ctxLocal.ServiceManager + + resolver = smgrLocal.createInstanceWithContext( + "com.sun.star.bridge.UnoUrlResolver", ctxLocal) + ctx = resolver.resolve(url) + smgr = ctx.ServiceManager + + desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx) + + cwd = systemPathToFileUrl(getcwd()) + outProps = ( + PropertyValue("FilterName" , 0, filterName, 0), + PropertyValue("OutputStream", 0, OutputStream(), 0)) + inProps = PropertyValue("Hidden", 0 , True, 0), + for path in args: + try: + fileUrl = uno.absolutize(cwd, systemPathToFileUrl(path)) + doc = desktop.loadComponentFromURL(fileUrl , "_blank", 0, inProps) + + if not doc: + raise UnoException("Could not open stream for unknown reason", None) + + doc.storeToURL("private:stream", outProps) + except IOException as e: + sys.stderr.write("Error during conversion: " + e.Message + "\n") + retVal = 1 + except UnoException as e: + sys.stderr.write("Error (" + repr(e.__class__) + ") during conversion: " + e.Message + "\n") + retVal = 1 + if doc: + doc.dispose() + + except UnoException as e: + sys.stderr.write("Error (" + repr(e.__class__) + "): " + e.Message + "\n") + retVal = 1 + except getopt.GetoptError as e: + sys.stderr.write(str(e) + "\n") + usage() + retVal = 1 + + sys.exit(retVal) + +def usage(): + sys.stderr.write("usage: ooextract.py --help |\n"+ + " [-c | --connection-string=\n"+ + " file1 file2 ...\n"+ + "\n" + + "Extracts plain text from documents and prints it to stdout.\n" + + "Requires an OpenOffice.org instance to be running. The script and the\n"+ + "running OpenOffice.org instance must be able to access the file with\n"+ + "by the same system path.\n" + "\n"+ + "-c | --connection-string=\n" + + " The connection-string part of a UNO URL to where the\n" + + " the script should connect to in order to do the conversion.\n" + + " The strings defaults to socket,host=localhost,port=2002\n" + "--html \n" + " Instead of the text filter, the writer html filter is used\n" + ) + +main() + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/pyuno/demo/pyunoenv.bat b/pyuno/demo/pyunoenv.bat new file mode 100644 index 000000000..b38c61e73 --- /dev/null +++ b/pyuno/demo/pyunoenv.bat @@ -0,0 +1,23 @@ +rem +rem This file is part of the LibreOffice project. +rem +rem This Source Code Form is subject to the terms of the Mozilla Public +rem License, v. 2.0. If a copy of the MPL was not distributed with this +rem file, You can obtain one at http://mozilla.org/MPL/2.0/. +rem +rem This file incorporates work covered by the following license notice: +rem +rem Licensed to the Apache Software Foundation (ASF) under one or more +rem contributor license agreements. See the NOTICE file distributed +rem with this work for additional information regarding copyright +rem ownership. The ASF licenses this file to you under the Apache +rem License, Version 2.0 (the "License"); you may not use this file +rem except in compliance with the License. You may obtain a copy of +rem the License at http://www.apache.org/licenses/LICENSE-2.0 . +rem + +set OOOHOME= + +set PYTHONPATH=.;%OOOHOME%\program;%OOOHOME%\program\pydemo;%OOOHOME%\program\python-2.2.2;%PYTHONPATH% +set PATH=%OOOHOME%\program;%PYTHONHOME%;%OOOHOME%\program\python-2.2.2\bin;%PATH% + diff --git a/pyuno/demo/pyunoenv.tcsh b/pyuno/demo/pyunoenv.tcsh new file mode 100644 index 000000000..653d72a38 --- /dev/null +++ b/pyuno/demo/pyunoenv.tcsh @@ -0,0 +1,49 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +# the path to the office installation (e.g. /home/joe/OpenOffice.org1.1Beta) +setenv OOOHOME /src4/OpenOffice.org1.1Beta2 + +# don't modify anything beyond these lines +#--------------------------------------------- +setenv PYTHONHOME $OOOHOME/program/python + +if( ! $?LD_LIBRARY_PATH ) then + setenv LD_LIBRARY_PATH +endif + +if(! $?PYTHONPATH ) then + setenv PYTHONPATH +endif + +if( ! $?LD_LIBRARY_PATH ) then +setenv LD_LIBRARY_PATH +endif + +if( "$PYTHONPATH" != "" ) then + setenv PYTHONPATH $OOOHOME/program:$OOOHOME/program/pydemo:$OOOHOME/program/python/lib:$PYTHONPATH +else + setenv PYTHONPATH $OOOHOME/program:$OOOHOME/program/pydemo:$OOOHOME/program/python/lib +endif + +setenv LD_LIBRARY_PATH $OOOHOME/program:$LD_LIBRARY_PATH + +if( $?PYTHONHOME ) then +setenv PATH $PYTHONHOME/bin:$PATH +endif + +# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/pyuno/demo/swriter.py b/pyuno/demo/swriter.py new file mode 100644 index 000000000..90a53e826 --- /dev/null +++ b/pyuno/demo/swriter.py @@ -0,0 +1,122 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +# bootstrap uno component context +import uno +import unohelper + +from com.sun.star.lang import IllegalArgumentException + +# a UNO struct later needed to create a document +from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK +from com.sun.star.text.TextContentAnchorType import AS_CHARACTER +from com.sun.star.awt import Size + + +def insertTextIntoCell( table, cellName, text, color ): + tableText = table.getCellByName( cellName ) + cursor = tableText.createTextCursor() + cursor.setPropertyValue( "CharColor", color ) + tableText.setString( text ) + +localContext = uno.getComponentContext() + +resolver = localContext.ServiceManager.createInstanceWithContext( + "com.sun.star.bridge.UnoUrlResolver", localContext ) + +smgr = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" ) +remoteContext = smgr.getPropertyValue( "DefaultContext" ) + +#remoteContext = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) +#smgr = remoteContext.ServiceManager + +desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext) + +# open a writer document +doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () ) + +text = doc.Text +cursor = text.createTextCursor() +text.insertString( cursor, "The first line in the newly created text document.\n", 0 ) +text.insertString( cursor, "Now we are in the second line\n" , 0 ) + +# create a text table +table = doc.createInstance( "com.sun.star.text.TextTable" ) + +# with 4 rows and 4 columns +table.initialize(4, 4) + +text.insertTextContent( cursor, table, 0 ) +rows = table.Rows + +table.setPropertyValue( "BackTransparent", False ) +table.setPropertyValue( "BackColor", 13421823 ) +row = rows[0] +row.setPropertyValue( "BackTransparent", False ) +row.setPropertyValue( "BackColor", 6710932 ) + +textColor = 16777215 + +insertTextIntoCell( table, "A1", "FirstColumn", textColor ) +insertTextIntoCell( table, "B1", "SecondColumn", textColor ) +insertTextIntoCell( table, "C1", "ThirdColumn", textColor ) +insertTextIntoCell( table, "D1", "SUM", textColor ) + +table.getCellByName("A2").setValue(22.5) +table.getCellByName("B2").setValue(5615.3) +table.getCellByName("C2").setValue(-2315.7) +table.getCellByName("D2").setFormula("sum ") + +table.getCellByName("A3").setValue(21.5) +table.getCellByName("B3").setValue(615.3) +table.getCellByName("C3").setValue(-315.7) +table.getCellByName("D3").setFormula("sum ") + +table.getCellByName("A4").setValue(121.5) +table.getCellByName("B4").setValue(-615.3) +table.getCellByName("C4").setValue(415.7) +table.getCellByName("D4").setFormula("sum ") + + +cursor.setPropertyValue( "CharColor", 255 ) +cursor.setPropertyValue( "CharShadowed", True ) + +text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) +text.insertString( cursor, " This is a colored Text - blue with shadow\n" , 0 ) +text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) + +textFrame = doc.createInstance( "com.sun.star.text.TextFrame" ) +textFrame.setSize( Size(15000,400)) +textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER ) + + +text.insertTextContent( cursor, textFrame, 0 ) + +textInTextFrame = textFrame.getText() +cursorInTextFrame = textInTextFrame.createTextCursor() +textInTextFrame.insertString( cursorInTextFrame, "The first line in the newly created text frame.", 0 ) +textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the height of the rame raises.",0) +text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) + +cursor.setPropertyValue( "CharColor", 65536 ) +cursor.setPropertyValue( "CharShadowed", False ) + +text.insertString( cursor, " That's all for now!" , 0 ) + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/pyuno/demo/swritercomp.py b/pyuno/demo/swritercomp.py new file mode 100644 index 000000000..7c200cc7b --- /dev/null +++ b/pyuno/demo/swritercomp.py @@ -0,0 +1,128 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +# just a simple copy of the swriter.py demo, but implemented as a component. The advantage is, +# that the component may run within the office process which may give a performance improvement. + +import unohelper +import uno + +# a UNO struct later needed to create a document +from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK +from com.sun.star.text.TextContentAnchorType import AS_CHARACTER +from com.sun.star.awt import Size + +from com.sun.star.lang import XMain + +def insertTextIntoCell( table, cellName, text, color ): + tableText = table.getCellByName( cellName ) + cursor = tableText.createTextCursor() + cursor.setPropertyValue( "CharColor", color ) + tableText.setString( text ) + +# the UNO component +# implementing the interface com.sun.star.lang.XMain +# unohelper.Base implements the XTypeProvider interface +class SWriterComp(XMain,unohelper.Base): + def __init__( self, ctx ): + self.ctx = ctx + + # implementation for XMain.run( [in] sequence< any > ) + def run( self,args ): + ctx = self.ctx + smgr = ctx.ServiceManager + desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx) + + # open a writer document + doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () ) + + text = doc.Text + cursor = text.createTextCursor() + text.insertString( cursor, "The first line in the newly created text document.\n", 0 ) + text.insertString( cursor, "Now we are in the second line\n" , 0 ) + + # create a text table + table = doc.createInstance( "com.sun.star.text.TextTable" ) + + # with 4 rows and 4 columns + table.initialize( 4,4) + + text.insertTextContent( cursor, table, 0 ) + rows = table.Rows + + table.setPropertyValue( "BackTransparent", uno.Bool(0) ) + table.setPropertyValue( "BackColor", 13421823 ) + row = rows[0] + row.setPropertyValue( "BackTransparent", uno.Bool(0) ) + row.setPropertyValue( "BackColor", 6710932 ) + + textColor = 16777215 + + insertTextIntoCell( table, "A1", "FirstColumn", textColor ) + insertTextIntoCell( table, "B1", "SecondColumn", textColor ) + insertTextIntoCell( table, "C1", "ThirdColumn", textColor ) + insertTextIntoCell( table, "D1", "SUM", textColor ) + + table.getCellByName("A2").setValue(22.5) + table.getCellByName("B2").setValue(5615.3) + table.getCellByName("C2").setValue(-2315.7) + table.getCellByName("D2").setFormula("sum ") + + table.getCellByName("A3").setValue(21.5) + table.getCellByName("B3").setValue(615.3) + table.getCellByName("C3").setValue(-315.7) + table.getCellByName("D3").setFormula("sum ") + + table.getCellByName("A4").setValue(121.5) + table.getCellByName("B4").setValue(-615.3) + table.getCellByName("C4").setValue(415.7) + table.getCellByName("D4").setFormula("sum ") + + + cursor.setPropertyValue( "CharColor", 255 ) + cursor.setPropertyValue( "CharShadowed", uno.Bool(1) ) + + text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) + text.insertString( cursor, " This is a colored Text - blue with shadow\n" , 0 ) + text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) + + textFrame = doc.createInstance( "com.sun.star.text.TextFrame" ) + textFrame.setSize( Size(15000,400)) + textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER ) + + text.insertTextContent( cursor, textFrame, 0 ) + + textInTextFrame = textFrame.getText() + cursorInTextFrame = textInTextFrame.createTextCursor() + textInTextFrame.insertString( cursorInTextFrame, "The first line in the newly created text frame.", 0 ) + textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the height of the rame raises.",0) + text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) + + cursor.setPropertyValue( "CharColor", 65536 ) + cursor.setPropertyValue( "CharShadowed", uno.Bool(0) ) + + text.insertString( cursor, " That's all for now!" , 0 ) + return 0 + +# pythonloader looks for a static g_ImplementationHelper variable +g_ImplementationHelper = unohelper.ImplementationHelper() +g_ImplementationHelper.addImplementation( \ + SWriterComp,"org.openoffice.comp.pyuno.swriter",("org.openoffice.demo.SWriter",),) + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/pyuno/demo/swritercompclient.py b/pyuno/demo/swritercompclient.py new file mode 100644 index 000000000..c4d6cdbf6 --- /dev/null +++ b/pyuno/demo/swritercompclient.py @@ -0,0 +1,32 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +import uno + +localContext = uno.getComponentContext() +resolver = localContext.ServiceManager.createInstanceWithContext( + "com.sun.star.bridge.UnoUrlResolver", localContext ) +remoteContext = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) +remoteSmgr = remoteContext.ServiceManager + +pyComp = remoteSmgr.createInstanceWithContext( "org.openoffice.demo.SWriter" , remoteContext ) + +pyComp.run( (), ) + +# vim: set shiftwidth=4 softtabstop=4 expandtab: -- cgit v1.2.3