Added: incubator/ooo/ooo-site/trunk/content/udk/python/samples/ooextract.py
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/samples/ooextract.py?rev=1206906&view=auto
==============================================================================
--- incubator/ooo/ooo-site/trunk/content/udk/python/samples/ooextract.py (added)
+++ incubator/ooo/ooo-site/trunk/content/udk/python/samples/ooextract.py Sun
Nov 27 23:07:13 2011
@@ -0,0 +1,129 @@
+import getopt, sys
+import uno
+
+from unohelper import Base, systemPathToFileUrl, absolutize
+from os import getcwd
+from os.path import splitext
+from com.sun.star.beans import PropertyValue
+from com.sun.star.uno import Exception as UnoException
+from com.sun.star.io import IOException, 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
+ stdout = False
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "hc:",
+ ["help", "connection-string=" , "html", "pdf", "stdout" ])
+ url =
"uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
+ filterName = "Text (Encoded)"
+ extension = "txt"
+ 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)"
+ extension = "html"
+ if o == "--pdf":
+ filterName = "writer_pdf_Export"
+ extension = "pdf"
+ if o == "--stdout":
+ stdout = True
+
+ 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( "Overwrite" , 0, True , 0 ),
+ PropertyValue( "OutputStream", 0, OutputStream(), 0)
+ )
+
+ inProps = PropertyValue( "Hidden" , 0 , True, 0 ),
+ for path in args:
+ try:
+ fileUrl = absolutize( cwd, systemPathToFileUrl(path) )
+ doc = desktop.loadComponentFromURL( fileUrl , "_blank", 0,
inProps )
+
+ if not doc:
+ raise UnoException( "Couldn't open stream for unknown
reason", None )
+
+ if not stdout:
+ (dest, ext) = splitext(path)
+ dest = dest + "." + extension
+ destUrl = absolutize( cwd, systemPathToFileUrl(dest) )
+ sys.stderr.write(destUrl + "\n")
+ doc.storeToURL(destUrl, outProps)
+ else:
+ 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 | --stdout\n"+
+ " [-c <connection-string> |
--connection-string=<connection-string>\n"+
+ " [--html|--pdf]\n"+
+ " [--stdout]\n"+
+ " file1 file2 ...\n"+
+ "\n" +
+ "Extracts plain text from documents and prints it to a file
(unless --stdout is specified).\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. [ To have a listening
OpenOffice.org instance, just run:\n"+
+ "openoffice \"-accept=socket,host=localhost,port=2002;urp;\"
\n"
+ "\n"+
+ "--stdout \n" +
+ " Redirect output to stdout. Avoids writing to a file
directly\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"
+ "--pdf \n"
+ " Instead of the text filter, the pdf filter is
used\n"
+ )
+
+main()
Propchange: incubator/ooo/ooo-site/trunk/content/udk/python/samples/ooextract.py
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ooo/ooo-site/trunk/content/udk/python/samples/oomerge.py
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/samples/oomerge.py?rev=1206906&view=auto
==============================================================================
--- incubator/ooo/ooo-site/trunk/content/udk/python/samples/oomerge.py (added)
+++ incubator/ooo/ooo-site/trunk/content/udk/python/samples/oomerge.py Sun Nov
27 23:07:13 2011
@@ -0,0 +1,110 @@
+import getopt, sys
+import uno
+import os
+
+from os.path import isfile, join
+from os import getcwd
+from unohelper import systemPathToFileUrl, absolutize
+from com.sun.star.beans import PropertyValue
+from com.sun.star.style.BreakType import PAGE_BEFORE, PAGE_AFTER
+from com.sun.star.uno import Exception as UnoException, RuntimeException
+from com.sun.star.connection import NoConnectException
+from com.sun.star.lang import IllegalArgumentException
+from com.sun.star.io import IOException
+
+def usage():
+ sys.stderr.write( "usage: oomerge.py --help |\n"+
+ " [-c <connection-string> |
--connection-string=<connection-string>]\n"+
+ " [-o <outputfile> | --outfile=<outputfile>] \n"+
+ " file1 file2 ...\n"+
+ "\n" +
+ "Merges two or more documents into a single file, called
'output.swx' unless\n" +
+ "otherwise specified. It requires an OpenOffice.org instance
to be running.\n" +
+ "The script and the running OpenOffice.org instance must be
able to access the file with\n"+
+ "by the same system path.\n"
+ "[ To have a listening OpenOffice.org instance, just run:\n"+
+ "openoffice \"-accept=socket,host=localhost,port=2002;urp;\"
] \n"
+ "\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"
+ "-o <outputfile> | --outfile=<outputfile>\n" +
+ " The name of the output filename. \"output.swx\" if
not specified\n"
+ )
+
+def main():
+ retVal = 0
+ outputfile = "output.swx"
+
+ opts, args = getopt.getopt(sys.argv[1:], "hco:", ["help",
"connection-string=", "outfile" ])
+ url = "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
+
+ 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 in ("-o", "--outfile"):
+ outputfile = a
+
+ if not len( args ):
+ usage()
+ sys.exit()
+
+ try:
+ 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 )
+ except NoConnectException, e:
+ sys.stderr.write("OpenOffice process not found or not listening (" +
e.Message + ")\n")
+ sys.exit(1)
+ except IllegalArgumentException, e:
+ sys.stderr.write("The url is invalid ( " + e.Message + ")\n")
+ sys.exit(1)
+ except RuntimeException, e:
+ sys.stderr.write("An unknown error occured: " + e.Message + "\n")
+
+ cwd = systemPathToFileUrl( getcwd() )
+ destFile = absolutize( cwd, systemPathToFileUrl(outputfile) )
+ inProps = PropertyValue( "Hidden" , 0 , True, 0 ),
+
+ newdoc = desktop.loadComponentFromURL( "private:factory/swriter",
"_blank", 0, inProps )
+ text = newdoc.Text
+ cursor = text.createTextCursor()
+
+ for i in args:
+ if isfile(os.path.join(getcwd(), i)):
+ try:
+ fileUrl = absolutize( cwd, systemPathToFileUrl(i) )
+
+ print "Appending %s" % fileUrl
+ try:
+ cursor.gotoEnd(False)
+ cursor.BreakType = PAGE_BEFORE
+ cursor.insertDocumentFromURL(fileUrl, ())
+ except IOException, e:
+ sys.stderr.write("Error during opening ( " + e.Message +
")\n")
+ except IllegalArgumentException, e:
+ sys.stderr.write("The url is invalid ( " + e.Message +
")\n")
+
+ except IOException, e:
+ sys.stderr.write( "Error during opening: " + e.Message + "\n" )
+ except UnoException, e:
+ sys.stderr.write( "Error ("+repr(e.__class__)+") during
conversion:" +
+ e.Message + "\n" )
+ else:
+ raise IOException
+
+ print "%s merged into %s" % (args, destFile)
+ newdoc.storeAsURL(destFile, ())
+ newdoc.dispose()
+
+main()
Propchange: incubator/ooo/ooo-site/trunk/content/udk/python/samples/oomerge.py
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/ooo/ooo-site/trunk/content/udk/python/samples/python-tokencounter-calc-addin.oxt
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/samples/python-tokencounter-calc-addin.oxt?rev=1206906&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/samples/python-tokencounter-calc-addin.oxt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/ooo/ooo-site/trunk/content/udk/python/samples/swriter.py
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/samples/swriter.py?rev=1206906&view=auto
==============================================================================
--- incubator/ooo/ooo-site/trunk/content/udk/python/samples/swriter.py (added)
+++ incubator/ooo/ooo-site/trunk/content/udk/python/samples/swriter.py Sun Nov
27 23:07:13 2011
@@ -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 frame 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 )
+
Propchange: incubator/ooo/ooo-site/trunk/content/udk/python/samples/swriter.py
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ooo/ooo-site/trunk/content/udk/python/samples/swritercomp.py
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/samples/swritercomp.py?rev=1206906&view=auto
==============================================================================
--- incubator/ooo/ooo-site/trunk/content/udk/python/samples/swritercomp.py
(added)
+++ incubator/ooo/ooo-site/trunk/content/udk/python/samples/swritercomp.py Sun
Nov 27 23:07:13 2011
@@ -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 frame 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",),)
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/samples/swritercomp.py
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/ooo/ooo-site/trunk/content/udk/python/samples/swritercompclient.py
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/samples/swritercompclient.py?rev=1206906&view=auto
==============================================================================
---
incubator/ooo/ooo-site/trunk/content/udk/python/samples/swritercompclient.py
(added)
+++
incubator/ooo/ooo-site/trunk/content/udk/python/samples/swritercompclient.py
Sun Nov 27 23:07:13 2011
@@ -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( (), )
+
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/samples/swritercompclient.py
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/bilder.odp
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/bilder.odp?rev=1206906&view=auto
==============================================================================
(empty)
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/bilder.odp
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/dynamicDialog.py
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/dynamicDialog.py?rev=1206906&view=auto
==============================================================================
---
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/dynamicDialog.py
(added)
+++
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/dynamicDialog.py
Sun Nov 27 23:07:13 2011
@@ -0,0 +1,85 @@
+import uno
+import unohelper
+from com.sun.star.awt import XActionListener
+
+class MyActionListener( unohelper.Base, XActionListener ):
+ def __init__(self, labelControl, prefix ):
+ self.nCount = 0
+ self.labelControl = labelControl
+ self.prefix = prefix
+
+ def actionPerformed(self, actionEvent):
+ # increase click counter
+ self.nCount = self.nCount + 1;
+ self.labelControl.setText( self.prefix + str( self.nCount ) )
+
+# 'translated' from the developer's guide chapter 11.6
+def createDialog():
+ """Opens a dialog with a push button and a label, clicking the button
increases the label counter."""
+ try:
+ ctx = uno.getComponentContext()
+ smgr = ctx.ServiceManager
+
+ # create the dialog model and set the properties
+ dialogModel = smgr.createInstanceWithContext(
+ "com.sun.star.awt.UnoControlDialogModel", ctx)
+
+ dialogModel.PositionX = 100
+ dialogModel.PositionY = 100
+ dialogModel.Width = 150
+ dialogModel.Height = 100
+ dialogModel.Title = "Runtime Dialog Demo"
+
+ # create the button model and set the properties
+ buttonModel = dialogModel.createInstance(
+ "com.sun.star.awt.UnoControlButtonModel" )
+
+ buttonModel.PositionX = 50
+ buttonModel.PositionY = 30
+ buttonModel.Width = 50;
+ buttonModel.Height = 14;
+ buttonModel.Name = "myButtonName";
+ buttonModel.TabIndex = 0;
+ buttonModel.Label = "Click Me";
+
+ # create the label model and set the properties
+ labelModel = dialogModel.createInstance(
+ "com.sun.star.awt.UnoControlFixedTextModel" );
+
+ labelModel.PositionX = 40
+ labelModel.PositionY = 60
+ labelModel.Width = 100
+ labelModel.Height = 14
+ labelModel.Name = "myLabelName"
+ labelModel.TabIndex = 1
+ labelModel.Label = "Clicks "
+
+ # insert the control models into the dialog model
+ dialogModel.insertByName( "myButtonName", buttonModel);
+ dialogModel.insertByName( "myLabelName", labelModel);
+
+ # create the dialog control and set the model
+ controlContainer = smgr.createInstanceWithContext(
+ "com.sun.star.awt.UnoControlDialog", ctx);
+ controlContainer.setModel(dialogModel);
+
+ # add the action listener
+ controlContainer.getControl("myButtonName").addActionListener(
+ MyActionListener( controlContainer.getControl( "myLabelName" ),
labelModel.Label ))
+
+ # create a peer
+ toolkit = smgr.createInstanceWithContext(
+ "com.sun.star.awt.ExtToolkit", ctx);
+
+ controlContainer.setVisible(False);
+ controlContainer.createPeer(toolkit, None);
+
+ # execute it
+ controlContainer.execute()
+
+ # dispose the dialog
+ controlContainer.dispose()
+ except Exception,e:
+ print str(e)
+
+g_exportedScripts = createDialog,
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/dynamicDialog.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/dynamicDialog.py
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/index.html
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/index.html?rev=1206906&view=auto
==============================================================================
---
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/index.html
(added)
+++
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/index.html
Sun Nov 27 23:07:13 2011
@@ -0,0 +1,268 @@
+<html>
+<head> <title>OOo scripting framework and python</title></head>
+<h1>OpenOffice.org scripting framework and python</h1>
+<body>
+<a href="../python-bridge.html">Pyuno</a> supports the OOo scripting
framework, that
+is first shipped with OOo 2.0
+(precisely since OOo 1.9.m79 or OOo 2.0 beta).
+The current support is limited to the 'core' framework, meaning that execution
and
+assigning of macros via the standard Tools/Macro dialog works fine,
+but editing and debugging macros is not
+integrated in OpenOffice.org's UI (simply because of the lack of development
+resources). Use your favourite text editor to create and modify python
scripts.
+
+
+<h1>Script locations</h1>
+Scripts to be excuted in OpenOffice.org can be stored within the
+following locations:
+<p>
+<center><img src="macro_run_dlg.PNG"/></center>
+
+<ul>
+
+<li>OpenOffice.org's user directory
+<p>
+This is the standard place for self written python scripts.
+The script files are simply stored within the file system. On windows,
+the directory can typically be found in
+
+<table>
+<tr>
+<td>windows</td>
+<td><strong>C:\Documents and Settings\<current-user\>Application
Data\OpenOffice.org 2.0\user\Scripts\python</strong></td>
+</tr>
+<tr>
+<td> unix</td>
+<td><strong> ~/.openoffice.org.2.0/user/Scripts/python</strong></td>
+</tr>
+</table>
+Note, that the last <strong>python</strong> subdirectory may need to be created
+initially. Make sure, the python is completly written lowercase. You can add
arbitrary deeply
+nested subdirectories, the names of these directories are reflected in the UI.
+
+<p> <strong> Example:</strong>
+The <a href="dynamicDialog.py">dynamicDialog.py</a> file can simply be placed
in the above
+directory. Afterwards, open the Tools/Macros/Run macro dialog and navigate to
the position
+shown in the above picture. Click on <i>Run</i> to execute the python script,
which
+opens another dialog with a push button and a label field. Clicking the button
will increase
+the number within the label field. The dialog can be closed by pressing ESC.
+
+<li>OpenOffice.org's share directory
+<p>
+Scripts that shall be shared throughout all users of a concrete
+OpenOffice.org installation can be stored with the share directory.
+All
+default scripts coming with OpenOffice.org are located here. In general,
+this directory should not be used for script deployment (see later
+uno-packages).
+<p>
+
+The script files are simply stored within the file system. The
+directory can typically be found in
+<table>
+<tr>
+<td>windows</td>
+<td><strong>C:\Program Files\OpenOffice.org
2.0\share\Scripts\python</strong></td>
+</tr>
+<tr>
+<td> unix</td>
+<td><strong> ~/.openoffice.org.2.0/user/Scripts/python</strong></td>
+</tr>
+</table>
+
+<li>Embedded within an OpenOffice.org's document
+<p>
+An OpenOffice.org document is a zip-File, which contains different files.
+Python scripts within documents are stored in Scripts/python subdirectory.
+<p>
+If you want to ship your self written python scripts within a document,
+
+you should first develop your scripts in the (above mentioned) user directory
and
+then finally move the scripts into the document with your favourite zip tool.
However,
+note that you <strong>must reassign</strong> every binding you did before to
the
+script instances in the document. Ideally, you move away the scripts from the
user
+directory and do a regression test on the document's functionality.
+
+<p>
+After moving the script files into the document, you have to add some lines
+(<strong>boldly printed</strong>) to the
+<i>META-INF/manifest.xml</i> file:
+
+<table width="100%" bgcolor="silver"><tr><td><pre>
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest
1.0//EN" "Manifest.dtd">
+<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">
+ <manifest:file-entry
manifest:media-type="application/vnd.oasis.opendocument.text"
manifest:full-path="/"/>
+ <manifest:file-entry
manifest:media-type="application/vnd.sun.xml.ui.configuration"
manifest:full-path="Configurations2/"/>
+ <manifest:file-entry manifest:media-type=""
manifest:full-path="Pictures/"/>
+ <manifest:file-entry manifest:media-type="text/xml"
manifest:full-path="content.xml"/>
+ <manifest:file-entry :media-type="text/xml"
manifest:full-path="styles.xml"/>
+ <manifest:file-entry manifest:media-type="text/xml"
manifest:full-path="meta.xml"/>
+ <manifest:file-entry manifest:media-type=""
manifest:full-path="Thumbnails/thumbnail.png"/>
+ <manifest:file-entry manifest:media-type=""
manifest:full-path="Thumbnails/"/>
+ <manifest:file-entry manifest:media-type="text/xml"
manifest:full-path="settings.xml"/>
+<strong> <manifest:file-entry manifest:media-type=""
manifest:full-path="Scripts/python/push_me.py"/>
+ <manifest:file-entry manifest:media-type="application/binary"
manifest:full-path="Scripts/python/"/>
+ <manifest:file-entry manifest:media-type="application/binary"
manifest:full-path="Scripts/"/></strong>
+</manifest:manifest>
+</pre></td></tr></table>
+
+When you open the document afterwards, the OpenOffice.org's UI should warn you
about script content within the
+document (when this is not the case, you either have switched off the warning
in the options or you did
+something wrong).
+
+<p>
+<strong>Example:</strong>To see how it works, download <a
href="push_me_python4.odt">push_me_python4.odt</a>. The
+document contains a push button and a multi line edit control. Pressing the
button adds a new line with the current
+time stamp to the multi line edit control.
+
+
+</li>
+<li>Embedded within a uno-package in OpenOffice.org's user directory (read
only)
+<p>Often, distributing scripts in documents is not what you want (for instance
when you
+want to modify the application itself or you want to use the same scripts with
multiple
+documents ). Therefor you can place your scripts simply within uno-packages.
+
+<p>A uno-package is a zip-file. Its name <strong>must</strong> end with
<i>.pkg</i>, otherwise it does not work.
+file, where you must define the subdirectory (required!) that shall contain
scripts. For instance the sample
+<a href="pyhello2.uno.pkg">pyhello2.uno.pkg</a> has the following file
structure:
+
+<table width="100%" bgcolor="silver"><tr><td><pre>
+META-INF/
+META-INF/manifest.xml
+package/
+package/hallo.py
+</pre></td></tr></table>
+
+The <i>hallo.py</i> contains the scripts. How to write scripts is explained <a
href="#coding">below</a>. However,
+in order to make a script work within a uno package, you <strong>must</strong>
add some dummy code.
+<table width="100%" bgcolor="silver"><tr><td><pre>
+# ... here is the python script code
+
+# this must be added to every script file (the
+# name org.openoffice.script.DummyImplementationForPythonScripts should be
changed to something
+# different (must be unique within an office installation !)
+# --- faked component, dummy to allow registration with unopkg, no
functionality expected
+import unohelper
+g_ImplementationHelper = unohelper.ImplementationHelper()
+g_ImplementationHelper.addImplementation( \
+ None,"org.openoffice.script.DummyImplementationForPythonScripts", \
+ ("org.openoffice.script.DummyServiceForPythonScripts",),)
+</pre></td></tr></table>
+By default, every .py-file is interpreted as a <a
href="../python-bridge.html#components">UNO component</a>. Not
+having the above lines within the .py file would raise errors during
deployment.
+<p>
+
+The directory name (here package) can be choosen freely.
+A uno-package with a python script <strong>must</strong> contain a
META-INF/manifest.xml, which needs to
+point to the freely chosen directory name.
+
+<table width="100%" bgcolor="silver"><tr><td><pre>
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest
1.0//EN" "Manifest.dtd">
+<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">
+<manifest:file-entry
manifest:media-type="application/vnd.sun.star.framework-script"
manifest:full-path="<strong>package</strong>"/>
+</manifest:manifest>
+</pre></td></tr></table>
+
+Every user can add packages via the package manager (Tools/Package manager).
Note, that
+content within the package is by design <strong>readonly</strong>, it is
really a pure
+deployment, not a development mechanism. This might be the reason, why scripts
in packages
+cannot be viewed via Tools/Macros/Organize macros/Python dialog.
+</li>
+
+<li>Embedded within a uno-package in OpenOffice.org's share directory (read
only)
+<p> Packages can be added by an administrator to a complete OpenOffice.org
installation, so that every
+user can use run the macros located within the package. This can be done with
the <i>unopkg</i> tool.
+</li>
+</ul>
+
+<h1 id="coding">Script coding</h1>
+A python script within the OpenOffice.org's scripting framework is a function
+(introduced by the def keyword) within a .py file. For execution via the
+Tools/Macros/Run macro dialog, the script must have an empty argument list.
+For typical event listeners, the function must have exactly one argument
+(the event). In general, the number of arguments depend on the context
+where the function shall be used.
+
+Since OOo 2.4, you can use both unix and windows linefeeds, in earlier
+versions you must use use unix line feeds.
+
+<p>A single .py file
+may contain an arbitrary number of function definitions.
+By default, all function definitions are exported ( = shown in the macro
+selection dialog). As this may become tedious, exports can be limited to
+a smaller set of functions by having a global variable named
+<i>g_exportedScripts</i>, which is a tuple of function definitions.
+
+<p>Up to OOo2.4, .py files can only import python
+modules, which are within the python PYTHONPATH, by default this is just the
+python runtime and the uno bridge files. This means, that it cannot reference
+other python macro files. Since OOo2.4, you can use the mechanism
+described <a href="../python-bridge.html#multiple_source_files"> here</a>. Note
+that the main script file is reloaded after every change while the source
files in
+PYHTHONPATH get loaded only once and changes won't have any effect until
office restart.
+
+<p>Before executing the source code within the module, the global variable
+<i>XSCRIPTCONTEXT</i> is inserted as global variable within the module (this
variable
+also exists e.g. for javascript and beanshell, it is offered here for
consistency reasons).
+It has three members (<i>Document</i>,<i>Desktop</i> and
<i>ComponentContext</i>).
+
+<p>The comment of a function (introduced and ended by three ") is shown
as description
+in the macros' selection dialog.
+
+<p>The compiled python script files are not added to sys.modules. There may
exist multiple
+instances of the same module at the same time.
+
+<p>Example:
+<table width="100%" bgcolor="silver"><tr><td><pre>
+# HelloWorld python script for the scripting framework
+
+def HelloWorldPython( ):
+ """Prints the string 'Hello World(in Python)' into the current document"""
+ #get the doc from the scripting context which is made available to all
scripts
+ model = XSCRIPTCONTEXT.getDocument()
+ text = model.Text
+ cursor = text.createTextCursor()
+ text.insertString( cursor, "Hello World(in Python)", 0 )
+</pre></td></tr></table>
+
+
+
+
+<h1>Error handling and debugging</h1>
+Errors during compilation or execution of the scripts are passed as exceptions
to the scripting framework
+where possible. The scripting framework in general opens a popup box and
displays the message
+of the thrown exception.
+<p>However, sometimes this is not possible and an error gets silently ignored.
The user realizes these
+errors, when
+<ul>
+<li>his python script file does not appear where it is expected to be
+<li>the name of the script file appears, but it does not contain any scripts
+<li>only part of the script gets executed.
+</ul>
+You can get to know these problems by changing some flags in the
OpenOffice.org 2.0/program/pythonscript.py
+file :
+
+<table width="100%" bgcolor="silver"><tr><td><pre>
+# Configuration ----------------------------------------------------
+LogLevel.use = LogLevel.NONE # alternavly use LogLevel.ERROR or
LogLevel.DEBUG
+LOG_STDOUT = False # True, writes to stdout
+ # False, writes to
user/Scripts/python/log.txt
+ENABLE_EDIT_DIALOG=False # offers a minimal editor for
editing.
+</pre></td></tr></table>
+
+<p>Attaching a python debugger is currently not supported.
+
+<h1>Credits</h1>
+The python binding of the scripting framework is developed and maintained by
Joerg Budischewski in his spare time.
+Many, many thanks to Tomas O'Connor from Sun for his great support and his
code additions to the framework which
+made this binding possible. Please put low level questions about
+the binding to <a
href="mailto:[email protected]">[email protected]</a>. Questions
about the
+OpenOffice.org's API should be put to <a
href="mailto:[email protected]">[email protected]</a>.
+
+<h1>License</h1>
+This document is available under <a
href="http://www.openoffice.org/licenses/PDL.html">PDL</a> (Public
Documentation License).
+
+</body>
+</html>
\ No newline at end of file
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/index.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/index.html
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/macro_run_dlg.PNG
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/macro_run_dlg.PNG?rev=1206906&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/macro_run_dlg.PNG
------------------------------------------------------------------------------
svn:executable = *
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/macro_run_dlg.PNG
------------------------------------------------------------------------------
svn:mime-type = image/png
Added:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/makefile.mk
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/makefile.mk?rev=1206906&view=auto
==============================================================================
---
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/makefile.mk
(added)
+++
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/makefile.mk
Sun Nov 27 23:07:13 2011
@@ -0,0 +1,46 @@
+PRJNAME=pyuno
+PRJ=..$/..
+
+.INCLUDE : settings.mk
+.INCLUDE : pyversion.mk
+
+VERSION=0.1.0
+NAME=scriptrt4python-$(VERSION)
+ROOT=$(MISC)$/$(NAME)
+
+SAMPLE_NAME=hello-framework-python
+
+FILES=\
+ $(ROOT)$/runtime.py \
+ $(ROOT)$/Scripting.xcu
+
+target: $(MISC)$/$(NAME).zip $(MISC)$/$(SAMPLE_NAME).sxp
+
+
+$(MISC)$/$(SAMPLE_NAME).sxp : $(MISC)$/HelloFramework.py
$(MISC)$/parcel-descriptor.xml
+ rm -f $@
+ cd $(MISC) && zip -r $(SAMPLE_NAME).sxp HelloFramework.py
parcel-descriptor.xml
+
+$(MISC)$/$(NAME).zip: $(FILES)
+ -rm -f $@
+ cd $(MISC) && zip -r $(NAME).zip $(NAME)
+
+
+# $(ROOT)$/singleton.rdb : makefile.mk
+# -rm -f $@
+# regsingleton $@
drafts.com.sun.star.script.framework.theScriptRuntimeForPython=drafts.com.sun.star.script.framework.runtime.ScriptRuntimeForPython
+
+
+$(ROOT)$/% : %
+ -$(MKDIRHIER) $(@:d)
+ -rm -f $@
+ cat $< > $@
+
+
+$(MISC)$/parcel-descriptor.xml : parcel-descriptor.xml
+ -rm -f $@
+ cat $< > $@
+
+$(MISC)$/HelloFramework.py : HelloFramework.py
+ -rm -f $@
+ cat $< > $@
Added:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/push_me_python4.odt
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/push_me_python4.odt?rev=1206906&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/push_me_python4.odt
------------------------------------------------------------------------------
svn:executable = *
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/push_me_python4.odt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/pyhello2.uno.pkg
URL:
http://svn.apache.org/viewvc/incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/pyhello2.uno.pkg?rev=1206906&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/pyhello2.uno.pkg
------------------------------------------------------------------------------
svn:executable = *
Propchange:
incubator/ooo/ooo-site/trunk/content/udk/python/scriptingframework/pyhello2.uno.pkg
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream