summaryrefslogtreecommitdiff
path: root/pyuno/demo
diff options
context:
space:
mode:
Diffstat (limited to 'pyuno/demo')
-rw-r--r--pyuno/demo/Addons.xcu21
-rw-r--r--pyuno/demo/biblioaccess.py35
-rw-r--r--pyuno/demo/hello_world_comp.py40
-rw-r--r--pyuno/demo/makefile.mk229
-rw-r--r--pyuno/demo/ooextract.py109
-rw-r--r--pyuno/demo/pyunoenv.bat6
-rw-r--r--pyuno/demo/pyunoenv.tcsh25
-rw-r--r--pyuno/demo/swriter.py105
-rw-r--r--pyuno/demo/swritercomp.py112
-rw-r--r--pyuno/demo/swritercompclient.py13
10 files changed, 695 insertions, 0 deletions
diff --git a/pyuno/demo/Addons.xcu b/pyuno/demo/Addons.xcu
new file mode 100644
index 000000000000..75ec5188e6d0
--- /dev/null
+++ b/pyuno/demo/Addons.xcu
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<oor:node xmlns:oor="http://openoffice.org/2001/registry"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ oor:name="Addons" oor:package="org.openoffice.Office">
+<node oor:name="AddonUI">
+ <node oor:name="AddonMenu">
+ <node oor:name="org.openoffice.comp.pyuno.demo.HelloWorld" oor:op="replace">
+ <prop oor:name="URL" oor:type="xs:string">
+ <value>service:org.openoffice.comp.pyuno.demo.HelloWorld?insert</value>
+ </prop>
+ <prop oor:name="ImageIdentifier" oor:type="xs:string">
+ <value>private:image/3216</value>
+ </prop>
+ <prop oor:name="Title" oor:type="xs:string">
+ <value xml:lang="x-no-translate">Insert Hello World</value>
+ <value xml:lang="en-US">Insert Hello World</value>
+ </prop>
+ </node>
+ </node>
+</node>
+</oor:node>
diff --git a/pyuno/demo/biblioaccess.py b/pyuno/demo/biblioaccess.py
new file mode 100644
index 000000000000..ac9cf64044ad
--- /dev/null
+++ b/pyuno/demo/biblioaccess.py
@@ -0,0 +1,35 @@
+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()
diff --git a/pyuno/demo/hello_world_comp.py b/pyuno/demo/hello_world_comp.py
new file mode 100644
index 000000000000..a9bc488853ec
--- /dev/null
+++ b/pyuno/demo/hello_world_comp.py
@@ -0,0 +1,40 @@
+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", # implemenation name
+ ("com.sun.star.task.Job",),) # list of implemented services
+ # (the only service)
diff --git a/pyuno/demo/makefile.mk b/pyuno/demo/makefile.mk
new file mode 100644
index 000000000000..f328ac5a6ddc
--- /dev/null
+++ b/pyuno/demo/makefile.mk
@@ -0,0 +1,229 @@
+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 $@
+ cat $? > $@
+
+$(ROOT)$/% : ..$/doc$/%
+ -rm -f $@
+ cat $? > $@
+
+#VERSION=0.9.4
+#PYDIRNAME=python-$(PYVERSION)
+#.IF "$(GUI)"=="WNT"
+#INISUFFIX=.ini
+#BATCHSUFFIX=.bat
+#ENVSUFFIX=.bat
+#PLATFORM=win32
+#EXESUFFIX=.exe
+#PACKSUFFIX=.zip
+#MYCOPY=copy
+#DOLLAR_SIGN=$$
+#.ELSE
+#DOLLAR_SIGN=\$$
+#PACKSUFFIX=.tar.gz
+#MYCOPY=cp
+#BATCHSUFFIX=.sh
+#ENVSUFFIX=.tcsh
+#INISUFFIX=rc
+#PYUNOMODULE=$(DESTROOT)$/program$/pyuno$(DLLPOST)
+#PYTHONLIBRARY=$(DESTROOT)$/program$/$(DLLPRE)python$(DLLPOST).$(PYVERSION)
+#PYRUNTIMELINK=$(DESTROOT)$/program$/python
+#PYRUNTIMELIBLINK1=$(DESTROOT)$/program$/libpython.so.2
+#PYRUNTIMELIBLINK2=$(DESTROOT)$/program$/libpython.so
+#
+#.IF "$(OS)$(CPU)"=="SOLARISS"
+#PLATFORM=solaris-sparc
+#.ELIF "$(OS)$(CPU)"=="SOLARISI"
+#PLATFORM=solaris-x86
+#.ELIF "$(OS)$(CPU)"=="LINUXI"
+#PLATFORM=linux-x86
+#.ELIF "$(OS)$(CPU)"=="LINUXP"
+#PLATFORM=linux-ppc
+#.ELSE
+#error please add your platform
+#.ENDIF
+#
+#.ENDIF
+#
+#DESTROOT=$(BIN)$/root
+#
+#FINDDIRS=$(subst,/,$/ $(shell +cd $(SOLARLIBDIR)$/python && $(FIND) . -type d))
+#FINDLIBFILES=$(subst,/,$/ $(shell +cd $(SOLARLIBDIR)$/python && $(FIND) . -type f))
+#
+#PYRUNTIME_DIRS=\
+# $(DESTROOT) \
+# $(DESTROOT)$/program \
+# $(DESTROOT)$/program/pydemo \
+# $(DESTROOT)$/program$/$(PYDIRNAME) \
+# $(DESTROOT)$/program$/$(PYDIRNAME)$/bin \
+# $(DESTROOT)$/program$/$(PYDIRNAME)$/lib \
+# $(foreach,i,$(FINDDIRS) $(DESTROOT)$/program$/$(PYDIRNAME)$/lib$/$(i))
+#
+#
+#FILES=\
+# $(DESTROOT)$/program$/$(DLLPRE)pyuno$(DLLPOST) \
+# $(DESTROOT)$/program$/pythonloader.uno$(DLLPOST) \
+# $(DESTROOT)$/program$/pyuno$(INISUFFIX) \
+# $(DESTROOT)$/program$/uno.py \
+# $(DESTROOT)$/program$/unohelper.py \
+# $(DESTROOT)$/program$/pythonloader.py \
+# $(DESTROOT)$/program$/pyuno_setup$(BATCHSUFFIX) \
+# $(DESTROOT)$/program$/regcomp$(EXESUFFIX) \
+# $(DESTROOT)$/program$/pyunoenv$(ENVSUFFIX) \
+# $(DESTROOT)$/program$/pydemo$/biblioaccess.py \
+# $(DESTROOT)$/program$/pydemo$/ooextract.py \
+# $(DESTROOT)$/program$/pydemo$/swriter.py \
+# $(DESTROOT)$/program$/pydemo$/swritercomp.py \
+# $(DESTROOT)$/program$/pydemo$/swritercompclient.py \
+# $(DESTROOT)$/program$/pydemo$/swritercompclient.py \
+# $(DESTROOT)$/program$/pydemo$/python-bridge.html \
+# $(PYUNOMODULE) \
+# $(PYTHONLIBRARY) \
+# $(DESTROOT)$/program$/$(PYDIRNAME)$/bin$/python$(EXESUFFIX) \
+# $(foreach,i,$(FINDLIBFILES) $(DESTROOT)$/program$/$(PYDIRNAME)$/lib$/$(i)) \
+# $(PYRUNTIMELINK) \
+# $(PYRUNTIMELIBLINK1) \
+# $(PYRUNTIMELIBLINK2)
+#
+#
+#
+#$(BIN)$/pyuno-$(PLATFORM)-$(PYVERSION)$(PACKSUFFIX) : makefile.mk dirs $(FILES)
+# -rm $@
+#.IF "$(GUI)"=="WNT"
+# +cd $(DESTROOT) && zip -r ..$/pyuno-$(PLATFORM)-$(VERSION)$(PACKSUFFIX) program
+#.ELSE
+# $(FIND) $(DESTROOT) -name '*.so' | xargs strip
+# cd $(DESTROOT) && tar -cO program | gzip - > ..$/pyuno-$(PLATFORM)-$(VERSION)$(PACKSUFFIX)
+#.ENDIF
+#
+#
+#dirs .PHONY:
+# -mkdir $(PYRUNTIME_DIRS)
+#
+## Some symbolic links for unix
+#.IF "$(GUI)" == "UNX"
+#$(PYRUNTIMELINK) : makefile.mk
+# -rm -f $@
+# cd $(DESTROOT)$/program && ln -s $(PYDIRNAME) python
+#
+#$(PYRUNTIMELIBLINK1) : makefile.mk
+# -rm -f $@
+# cd $(DESTROOT)$/program && ln -s $(DLLPRE)python$(DLLPOST).$(PYVERSION) $(DLLPRE)python$(DLLPOST).$(PYMAJOR)
+#
+#$(PYRUNTIMELIBLINK2) : makefile.mk
+# -rm -f $@
+# cd $(DESTROOT)$/program && ln -s $(DLLPRE)python$(DLLPOST).$(PYVERSION) $(DLLPRE)python$(DLLPOST)
+#.ENDIF
+#
+#$(DESTROOT)$/program$/regcomp$(EXESUFFIX) : $(SOLARBINDIR)$/regcomp$(EXESUFFIX)
+# cp $? $@
+#.IF "$(GUI)" == "UNX"
+# strip $@
+# chmod +x $@
+#.ENDIF
+#
+#
+#$(DESTROOT)$/program$/pyunoenv$(ENVSUFFIX) : pyunoenv$(ENVSUFFIX)
+# -rm -f $@
+# cat $? > $@
+#
+#$(DESTROOT)$/program$/$(DLLPRE)pyuno$(DLLPOST) : $(DLLDEST)$/$(DLLPRE)pyuno$(DLLPOST)
+# cp $? $@
+#
+#$(DESTROOT)$/program$/pyuno_setup$(BATCHSUFFIX) : makefile.mk
+# -rm -f $@
+#.IF "$(GUI)"!="WNT"
+# echo #\!/bin/sh >> $@
+# chmod +x $@
+#.ENDIF
+# echo regcomp -register -r services.rdb -c pythonloader.uno >>$@
+## echo "$(MYCOPY) applicat.rdb pydemo$/applicat.rdb" >> $@
+# echo regcomp -register -br types.rdb -br services.rdb -r services.rdb -c vnd.openoffice.pymodule:swritercomp -l com.sun.star.loader.Python >>$@
+#
+#$(DESTROOT)$/program$/$(DLLPRE)python$(DLLPOST).$(PYVERSION) : $(SOLARLIBDIR)$/$(DLLPRE)python$(DLLPOST).$(PYVERSION)
+# cp $? $@
+#
+#$(DESTROOT)$/program$/pythonloader.uno$(DLLPOST) : $(DLLDEST)$/pythonloader.uno$(DLLPOST)
+# cp $? $@
+#
+#$(DESTROOT)$/program$/%.py : $(DLLDEST)$/%.py
+# cp $? $@
+#
+#.IF "$(GUI)" == "UNX"
+#$(DESTROOT)$/program$/pyuno$(DLLPOST) : $(DLLDEST)$/pyuno$(DLLPOST)
+# cp $? $@
+#.ENDIF
+#
+#$(DESTROOT)$/program$/pydemo$/%.py : %.py
+# -rm -f $@
+# cat $? > $@
+#
+#$(DESTROOT)$/program$/pyuno$(INISUFFIX) : makefile.mk
+# -rm -f $@ $(DESTROOT)$/program$/pyuno.tmp
+# echo UNO_TYPES=$(DOLLAR_SIGN)PYUNOLIBDIR/types.rdb > $(DESTROOT)$/program$/pyuno.tmp
+# echo UNO_SERVICES=$(DOLLAR_SIGN)PYUNOLIBDIR/services.rdb >> $(DESTROOT)$/program$/pyuno.tmp
+# mv $(DESTROOT)$/program$/pyuno.tmp $@
+#
+#$(DESTROOT)$/program$/pydemo$/python-bridge.html : ..$/doc$/python-bridge.html
+# -rm -f $@
+# cat $? > $@
+#
+#
+# $(DESTROOT)$/program$/$(PYDIRNAME)$/lib$/%.so : $(SOLARLIBDIR)$/python$/%.so
+# -rm -f $@
+# cat $? > $@
+# strip $@
+#
+#$(DESTROOT)$/program$/$(PYDIRNAME)$/lib$/% : $(SOLARLIBDIR)$/python$/%
+# -rm -f $@
+# cat $? > $@
+#
+#
+#$(DESTROOT)$/program$/$(PYDIRNAME)$/bin$/python$(EXESUFFIX) : $(SOLARBINDIR)$/python$(EXESUFFIX)
+# -rm -f $@
+# cat $? > $@
+#.IF "$(GUI)" == "UNX"
+# strip $@
+# chmod +x $@
+#.ENDIF
+#
+#
+#
+#
+# \ No newline at end of file
diff --git a/pyuno/demo/ooextract.py b/pyuno/demo/ooextract.py
new file mode 100644
index 000000000000..057fa04964eb
--- /dev/null
+++ b/pyuno/demo/ooextract.py
@@ -0,0 +1,109 @@
+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( "Couldn't open stream for unknown reason", None )
+
+ doc.storeToURL("private:stream",outProps)
+ except IOException, e:
+ sys.stderr.write( "Error during conversion: " + e.Message + "\n" )
+ retVal = 1
+ except UnoException, e:
+ sys.stderr.write( "Error ("+repr(e.__class__)+") during conversion:" + e.Message + "\n" )
+ retVal = 1
+ if doc:
+ doc.dispose()
+
+ except UnoException, e:
+ sys.stderr.write( "Error ("+repr(e.__class__)+") :" + e.Message + "\n" )
+ retVal = 1
+ except getopt.GetoptError,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> | --connection-string=<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> | --connection-string=<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()
diff --git a/pyuno/demo/pyunoenv.bat b/pyuno/demo/pyunoenv.bat
new file mode 100644
index 000000000000..1a8239992a4b
--- /dev/null
+++ b/pyuno/demo/pyunoenv.bat
@@ -0,0 +1,6 @@
+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 000000000000..1a831996325f
--- /dev/null
+++ b/pyuno/demo/pyunoenv.tcsh
@@ -0,0 +1,25 @@
+# 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
+
+setenv PYTHONPATH .:$OOOHOME/program:$OOOHOME/program/pydemo:$OOOHOME/program/python/lib:$PYTHONPATH
+setenv LD_LIBRARY_PATH $OOOHOME/program:$LD_LIBRARY_PATH
+
+if( $?PYTHONHOME ) then
+setenv PATH $PYTHONHOME/bin:$PATH
+endif
diff --git a/pyuno/demo/swriter.py b/pyuno/demo/swriter.py
new file mode 100644
index 000000000000..05ab332fd382
--- /dev/null
+++ b/pyuno/demo/swriter.py
@@ -0,0 +1,105 @@
+
+# bootstrap uno component context
+import uno
+import unohelper
+
+
+# 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", uno.Bool(0) )
+table.setPropertyValue( "BackColor", 13421823 )
+row = rows.getByIndex(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 )
+
+values = ( (22.5,21.5,121.5),
+ (5615.3,615.3,-615.3),
+ (-2315.7,315.7,415.7) )
+table.getCellByName("A2").setValue(22.5)
+table.getCellByName("B2").setValue(5615.3)
+table.getCellByName("C2").setValue(-2315.7)
+table.getCellByName("D2").setFormula("sum <A2:C2>")
+
+table.getCellByName("A3").setValue(21.5)
+table.getCellByName("B3").setValue(615.3)
+table.getCellByName("C3").setValue(-315.7)
+table.getCellByName("D3").setFormula("sum <A3:C3>")
+
+table.getCellByName("A4").setValue(121.5)
+table.getCellByName("B4").setValue(-615.3)
+table.getCellByName("C4").setValue(415.7)
+table.getCellByName("D4").setFormula("sum <A4:C4>")
+
+
+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 )
+
diff --git a/pyuno/demo/swritercomp.py b/pyuno/demo/swritercomp.py
new file mode 100644
index 000000000000..6f8f30607bd2
--- /dev/null
+++ b/pyuno/demo/swritercomp.py
@@ -0,0 +1,112 @@
+# 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.getByIndex(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 )
+
+ values = ( (22.5,21.5,121.5),
+ (5615.3,615.3,-615.3),
+ (-2315.7,315.7,415.7) )
+ table.getCellByName("A2").setValue(22.5)
+ table.getCellByName("B2").setValue(5615.3)
+ table.getCellByName("C2").setValue(-2315.7)
+ table.getCellByName("D2").setFormula("sum <A2:C2>")
+
+ table.getCellByName("A3").setValue(21.5)
+ table.getCellByName("B3").setValue(615.3)
+ table.getCellByName("C3").setValue(-315.7)
+ table.getCellByName("D3").setFormula("sum <A3:C3>")
+
+ table.getCellByName("A4").setValue(121.5)
+ table.getCellByName("B4").setValue(-615.3)
+ table.getCellByName("C4").setValue(415.7)
+ table.getCellByName("D4").setFormula("sum <A4:C4>")
+
+
+ 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",),)
diff --git a/pyuno/demo/swritercompclient.py b/pyuno/demo/swritercompclient.py
new file mode 100644
index 000000000000..1076a69eb9b6
--- /dev/null
+++ b/pyuno/demo/swritercompclient.py
@@ -0,0 +1,13 @@
+# instantiating
+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( (), )
+