OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

FYI...How to use OOo with Python on Windows

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Jan 07, 2004 10:45 am    Post subject: FYI...How to use OOo with Python on Windows Reply with quote

Danny's Guide to setting up Python for OpenOffice.org on Windows
================================================================

Revision: 2004-01-07-01


Here are some useful messages I've written about Python in the past.
http://www.oooforum.org/forum/viewtopic.php?p=13501#13501
http://www.oooforum.org/forum/viewtopic.php?t=3451
http://www.oooforum.org/forum/viewtopic.php?t=4368
http://www.oooforum.org/forum/viewtopic.php?t=4772



Introduction to Python on OOo
=============================

You need OpenOffice.org installed with its Python-UNO bridge.

Install OpenOffice.org. If you are installing it for the first time, then be sure to do a Custom install and install the Python-UNO bridge under Optional Components.

If you already have OpenOffice.org installed, then go into your OOo folder and run Setup. Pick Modify, click Next. Under Optional Components, be sure to install the Python-UNO bridge.

In order to use the python-uno bridge, the python code must run from the Python that comes with OOo 1.1.0. There is apparently some issue with the standard C library. The Python 2.2.2 that comes with OOo has been compiled using the StdCLib that OOo uses rather than the one that python would normally be compiled with.

If you want an interactive Python command shell right now, go into your OOo\program subfolder and run the batch file named "python.bat". You get a python shell. You can then use the statement
Code:
import uno

You can now connect to any OOo that will accept a remote UNO connection.

I suppose that leads us to the next issue.... Configuring OOo to listen for UNO connections.

It is also possible to write a component in Python and install it into the office. It is my understanding (but I have not tried yet) that when you do this you do NOT need to configure OOo to listen for uno connections.

Therefore, the two ways to use Python are...
1. Outside of OOo -- with a remote uno connection.
2. Inside of OOo as an installed component.

Approach 1 is the quick and easy way to write and debug code.

Approach 2 is a great way to _deliver_ finished code to a user.

See this for more information about the Python-UNO bridge in OOo.
http://udk.openoffice.org/python/python-bridge.html



Configuring OOo to listen for UNO connections
=============================================

If you write programs in Java or Python and run them external to OOo, then you need to configure OOo to listen for a uno connection.

It is possible to run your program on computer A, and connect to computer B which is running OOo, and have your program at A manipulate the OOo running on B. In fact, A and B can even be running different operating systems. I have done this personally using Java. With Python, I have only run my program on the same computer as OOo -- but it should work the same way.

In the past, it was necessary to either
1. launch OOo with a special parameter to make it listen
2. hand edit one of OOo's configuration files

Both of the above options I explained here previously.
http://www.oooforum.org/forum/viewtopic.php?p=12370#12370
You can hand edit an XML file for version 1.0 of OOo, or an XCU file for version 1.1 of OOo (the current version).

Later, I developed a macro to do this editing and announced it here.
http://www.oooforum.org/forum/viewtopic.php?t=3754

My UnoConnectionListener document can be obtained from OOoMacros.org.

http://ooomacros.org/files.php?type=macro#UNOConnectionListener

http://sourceforge.net/project/showfiles.php?group_id=87718&package_id=100069

Just download the document. Open it. Configure text boxes to taste. (Read the text of the above post if necessary.) Then click a button. Quit OOo. Re-launch OOo and it should henceforth (until you reconfigure it again) always listen for Uno connections. You can configure it to listen to connections only from localhost, or from any other computer.




An example Python program
=========================

For your immediate gratification, I'll provide a simple working program.

Code:
import uno

# The following is a subset of my Python library.


# The ServiceManager of the running OOo.
# It is cached in a global variable.
oServiceManager = False

def getServiceManager( cHost="localhost", cPort="8100" ):
    """Get the ServiceManager from the running OpenOffice.org.
        Then retain it in the global variable oServiceManager for future use.
    """
    global oServiceManager
    if not oServiceManager:
        # Get the uno component context from the PyUNO runtime
        oLocalContext = uno.getComponentContext()
       
        # Create the UnoUrlResolver on the Python side.
        oLocalResolver = oLocalContext.ServiceManager.createInstanceWithContext(
                                    "com.sun.star.bridge.UnoUrlResolver", oLocalContext )
       
        # Connect to the running OpenOffice.org and get its context.
        oContext = oLocalResolver.resolve( "uno:socket,host=" + cHost + ",port=" + cPort + ";urp;StarOffice.ComponentContext" )
       
        # Get the ServiceManager object
        oServiceManager = oContext.ServiceManager
    return oServiceManager




# This is the same as ServiceManager.createInstance( ... )
def createUnoService( cClass ):
    """A handy way to create a global objects within the running OOo.
    """
    oServiceManager = getServiceManager()
    oObj = oServiceManager.createInstance( cClass )
    return oObj




# The Desktop object.
# It is cached in a global variable.
oDesktop = False

def getDesktop():
    """An easy way to obtain the Desktop object from a running OOo.
    """
    global oDesktop
    if not oDesktop:
        oDesktop = createUnoService( "com.sun.star.frame.Desktop" )
    return oDesktop



# The CoreReflection object.
# It is cached in a global variable.
oCoreReflection = False

def getCoreReflection():
    global oCoreReflection
    if not oCoreReflection:
        oCoreReflection = createUnoService( "com.sun.star.reflection.CoreReflection" )
    return oCoreReflection



def createUnoStruct( cTypeName ):
    """Create a UNO struct and return it.
    """
    oCoreReflection = getCoreReflection()

    # Get the IDL class for the type name
    oXIdlClass = oCoreReflection.forName( cTypeName )

    # Create the struct.
    oReturnValue, oStruct = oXIdlClass.createObject( None )

    return oStruct



def makePropertyValue( cName=None, uValue=None, nHandle=None, nState=None ):
    """Create a com.sun.star.beans.PropertyValue struct and return it.
    """
    oPropertyValue = createUnoStruct( "com.sun.star.beans.PropertyValue" )

    if cName != None:
        oPropertyValue.Name = cName
    if uValue != None:
        oPropertyValue.Value = uValue
    if nHandle != None:
        oPropertyValue.Handle = nHandle
    if nState != None:
        oPropertyValue.State = nState

    return oPropertyValue




#------------------------------------------------------------
#   Shape functions
#------------------------------------------------------------



def makeRectangleShape( oDrawDoc, oPosition=None, oSize=None ):
    """Create a new RectangleShape with an optional position and size."""
    oShape = makeShape( oDrawDoc, "com.sun.star.drawing.RectangleShape", oPosition, oSize )
    return oShape


def makeEllipseShape( oDrawDoc, oPosition=None, oSize=None ):
    """Create a new EllipseShape with an optional position and size."""
    oShape = makeShape( oDrawDoc, "com.sun.star.drawing.EllipseShape", oPosition, oSize )
    return oShape


def makeLineShape( oDrawDoc, oPosition=None, oSize=None ):
    """Create a new LineShape with an optional position and size."""
    oShape = makeShape( oDrawDoc, "com.sun.star.drawing.LineShape", oPosition, oSize )
    return oShape


def makeTextShape( oDrawDoc, oPosition=None, oSize=None ):
    """Create a new TextShape with an optional position and size."""
    oShape = makeShape( oDrawDoc, "com.sun.star.drawing.TextShape", oPosition, oSize )
    return oShape


def makePoint( nX, nY ):
    """Create a com.sun.star.awt.Point struct."""
    oPoint = createUnoStruct( "com.sun.star.awt.Point" )
    oPoint.X = nX
    oPoint.Y = nY
    return oPoint


def makeSize( nWidth, nHeight ):
    """Create a com.sun.star.awt.Size struct."""
    oSize = createUnoStruct( "com.sun.star.awt.Size" )
    oSize.Width = nWidth
    oSize.Height = nHeight
    return oSize


def findShapeByName( oShapes, cShapeName ):
    """Find a named shape within an XShapes interface.
    oShapes can be a drawing page, which supports the XShapes interface.
    Thus, you can find a named shape within a draw page, or within a grouped shape,
     or within a selection of sseveral shapes.
    """
    nNumShapes = oShapes.getCount()
    for i in range( nNumShapes ):
        oShape = oShapes.getByIndex( i )
        cTheShapeName = oShape.getName()
        if cTheShapeName == cShapeName:
            return oShape
    return None


def makeShape( oDrawDoc, cShapeClassName, oPosition=None, oSize=None ):
    """Create a new shape of the specified class.
    Position and size arguments are optional.
    """
    oShape = oDrawDoc.createInstance( cShapeClassName )

    if oPosition != None:
        oShape.Position = oPosition
    if oSize != None:
        oShape.Size = oSize

    return oShape





#------------------------------------------------------------
#   Color manipulation
#------------------------------------------------------------


def rgbColor( nRed, nGreen, nBlue ):
    """Return an integer which repsents a color.
    The color is specified in RGB notation.
    Each of nRed, nGreen and nBlue must be a number from 0 to 255.
    """
    return (int( nRed ) & 255) << 16 | (int( nGreen ) & 255) << 8 | (int( nBlue ) & 255)



def redColor( nColor ):
    """Return the Red component of a color as an integer from 0 to 255.
    nColor is an integer representing a color.
    This function is complimentary to the rgbColor function.
    """
    return (int( nColor ) >> 16) & 255


def greenColor( nColor ):
    """Return the Green component of a color as an integer from 0 to 255.
    nColor is an integer representing a color.
    This function is complimentary to the rgbColor function.
    """
    return (int( nColor ) >> 8) & 255


def blueColor( nColor ):
    """Return the Blue component of a color as an integer from 0 to 255.
    nColor is an integer representing a color.
    This function is complimentary to the rgbColor function.
    """
    return int( nColor ) & 255




# Create a new drawing.
oDrawDoc = getDesktop().loadComponentFromURL( "private:factory/sdraw", "_blank", 0, () )
# Get its first page.
oDrawPage = oDrawDoc.getDrawPages().getByIndex( 0 )

# Create a new shape.
oShape = makeRectangleShape( oDrawDoc, makePoint( 2000, 2000 ), makeSize( 3000, 5000 ) )
# Add shape to the page.
oDrawPage.add( oShape )



The above program creates a drawing with a rectangle.

The above code contains a SUBSET of my library which I use everyday. The functions in this library very closely minic the functions that I've posted here in Basic before.

Let's look at the last four lines in particular....

This line...
Code:
oDrawDoc = getDesktop().loadComponentFromURL( "private:factory/sdraw", "_blank", 0, () )

is almost EXACTLY like the same line I use in Basic all the time...
Code:
oDrawDoc = StarDesktop.loadComponentFromURL( "private:factory/sdraw", "_blank", 0, Array() )

In Basic, StarDesktop is a global variable. In python, my function getDesktop() returns the desktop object. The first time you call it, it gets the service manager, establishes a connection, etc., and then gets the desktop object. After that, it returns a cached copy of the desktop object.

This next line...
Code:
oDrawPage = oDrawDoc.getDrawPages().getByIndex( 0 )

Is identical character for character to the same line I use in Basic all the time.

The next line...
Code:
oShape = makeRectangleShape( oDrawDoc, makePoint( 2000, 2000 ), makeSize( 3000, 5000 ) )

Is also identical, other than that in Basic I capitalize the words "MakeRectangleShape", "MakeSize", "MakePoint", "MakePropertyValue", etc.

The last line...
Code:
oDrawPage.add( oShape )

is again identical to the same line I use in Basic all the time.


Just for grins, I thew in a few extra functions....
rgbColor()
redColor()
greenColor()
blueColor()

These functions are very similar to Basic's built in RGB(), Red(), Green() and Blue() functions.





How to run the example program

==============================

Copy the example program above into a text file. Name it Example.py. Place this file into your....

C:\Program Files\OpenOffice.org1.1.0\program\python-core-2.2.2

folder.

Make sure OOo is running, and configured to listen for an UNO connection on port 8100 from localhost. (Procedure previously described.)

Run the "python.bat" script that is in your OOo\program folder. You should get an interactive python command shell.

Type the command...

import Example

The above Example.py program should be executed, creating a new drawing with a single rectangle in it.





How to set up Python IDLE on Windows
====================================

If you are on Windows, and want to work with OOo on Python, it is very useful to be able to use Python's GUI IDE called IDLE.

In order to do this, you will need...
1. OpenOffice.org 1.1.0 installed with its Python-UNO bridge
2. Standard Python 2.2 (not 2.3, or latest, but version 2.2)


Install OOo 1.1.0 with the python uno bridge, as described previously.

Download the standard Python 2.2 distribution. (I am using 2.2.3.) Do NOT get Python 2.3. You need a similar version of Python to what is included with OOo so that the IDLE gui development environment is compatible.

What we will do is run OOo's python 2.2.2, but make it also run the IDLE from the standard python distribution.

Install standard Python 2.2. Mine is installed in...

C:\Python22


Now, write a batch file. It doesn't matter where you put this batch file, because it uses fully qualified pathnames.

Here is the batch file I use. You will need to adjust the pathnames to taste.



Code:
@echo off

rem ----------
rem   Adjust these environment variables to taste.
rem ----------

set OOoPath=C:\Program Files\OpenOffice.org1.1.0

set DannysPythonMods=C:\Danny\Danny's Python\Modules

set Python22Path=C:\Python22



rem ----------

set OOoProg=%OOoPath%\program


set PATH=%OOoProg%;%PATH%

set PYTHONPATH=

Set PYTHONPATH=%PYTHONPATH%;%DannysPythonMods%

set PYTHONPATH=%PYTHONPATH%;%Python22Path%
set PYTHONPATH=%PYTHONPATH%;%Python22Path%\DLLs
set PYTHONPATH=%PYTHONPATH%;%Python22Path%\lib
set PYTHONPATH=%PYTHONPATH%;%Python22Path%\lib\lib-tk
set PYTHONPATH=%PYTHONPATH%;%Python22Path%\lib\site-packages
set PYTHONPATH=%PYTHONPATH%;%Python22Path%\Tools\idle

set PYTHONPATH=%PYTHONPATH%;%OOoProg%
set PYTHONPATH=%PYTHONPATH%;%OOoProg%\python-core-2.2.2\lib

set PYTHONHOME=%OOoProg%\python-core-2.2.2



CD "%OOoProg%"

"%OOoProg%\python-core-2.2.2\bin\python.exe" "%Python22Path%\Tools\idle\idle.py" %1 %2 %3 %4 %5 %6 %7 %8 %9



The variable "DannysPythonMods" points to a folder where my own personal Python modules are kept, including many for OOo, and many for other purposes, such as HSB color conversion which have use outside of OOo.


You must copy the "tcl" folder from your regular Python2.2 installation into the OOo\program\python-core-2.2.2 folder. In my case, I copy the folder...

C:\Python22\tcl

and make the copy be...

C:\Program Files\OpenOffice.org1.1.0\program\python-core-2.2.2\tcl


Now run the batch file. You should get the Python IDLE gui development environment.

If people use python much in the future, maybe I can start posting more Python code than Basic code. It is unfortunante that Basic is so much easier to access than the hoops (in this document) that you have to jump through to use Python with OOo.

Setting up Python with OOo on Linux is very similar to what I've described here.

Good luck.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
dfrench
Moderator
Moderator


Joined: 03 Mar 2003
Posts: 1605
Location: Wellington, New Zealand

PostPosted: Wed Jan 07, 2004 11:57 am    Post subject: Reply with quote

Great stuff presented in one convenient package, Thanks.
Quote:
Do NOT get Python 2.3. You need a similar version of Python to what is included with OOo so that the IDLE gui development environment is compatible.
In principle, should we be working to an approach that allows the Python and OOoinstallations to be independent with the bridging code handling the compatibility between versions rather that being limited to whatever version of Python that OpenOffice is prepared to distribute?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Jan 07, 2004 2:21 pm    Post subject: Reply with quote

This would really be a question for whoever wrote the python uno bridge.

I can only guess, but here is my educated guess.

I believe that PyUno bridge is implemented as a DLL (windows, or .so on Linux). The DLL includes various OOo code. Python has a mechanism by which you can call extensions written in C. (I know it exists, but that is about all I know.)

I would conjecture that a python extension, running within python, accesses the DLL containing OOo code. Some incompatibility exists between the two compiled object codes. Therefore you must use the Python that comes with OOo.

Here is what I would really much rather see.

I would rather see a PyUno bridge implemented in 100% pure python. This code would connect to the OOo's port 8100 (or whatever) and communicate using the binary urp protocol, which is fully documented. (What does urp stand for? Uno remote p----something?)

This implementation approach is both harder, and easier.

It has the benefits that the PyUno bridge could be used with any distribution of python, on any platform, from any vendor or distributor. Your program runs completely outside of OOo -- even perhaps on a different computer.

The drawback is the same thing. Your program runs outside of OOo. OOo must be configured to listen for uno connections. (Easier now with my macro to configure OOo. I remember the ordeal this was when I wrote my Maze Generator program in Java.)

You would still be restricted to using OOo's python for components that you install into the office -- which is okay by me.

This, of course, necessarily means two completely different implementations of a PyUno bridge. The existing one to support internal OOo components. And a new one written in pure python.

I may have some facts wrong. Even if all facts are correct, my speculation may just be plain wrong.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Wed Jun 16, 2004 9:50 pm    Post subject: Reply with quote

First of all:
An excellent post, thank you very much Danny.
After some time fiddling around with the bare commandline (for quite some time I must say) of the OOo Python core I decided to use my Python IDE following your instructions.

I have got two things to add to your documentation:
1.) Users on Windows that are new to Python should download the win32 extension package which has a very neat IDE called PythonWin. The nicest feature - and why I actually use it - is that it has a tooltip like you have in VB6 where you can see which parameters every function or method has and it even shows you explanatory text to every call you do (before you close the parenthesis). Besides that you can fold your code structure. So if you're new to Python and you're running on Windows I would strongly recommend this IDE.
And these tooltips even pop up for your own modules that you import or other custom modules.

2.)
Code:
It is possible to run your program on computer A, and connect to computer B which is running OOo, and have your program at A manipulate the OOo running on B. In fact, A and B can even be running different operating systems. I have done this personally using Java. With Python, I have only run my program on the same computer as OOo -- but it should work the same way.

I have tested this and yes it works.
_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Jan 08, 2005 9:27 am    Post subject: Reply with quote

Some cross references.....
http://www.oooforum.org/forum/viewtopic.php?p=60941#60941
http://www.oooforum.org/forum/viewtopic.php?p=12904#12904
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Mar 19, 2005 9:51 am    Post subject: Reply with quote

Here are updated instructions for

  • how to use the interactive IDLE development tool
  • in conjunction with OOo 2.0's private Python which works with UNO
  • on Windows

Linux users should be able to adapt this technique.

Using IDLE allows you to interactively use Python code to develop and debug python code that drives OOo via. its API. This is a very productive way to tinker with and experiment with the OOo's API using Python.

OOo comes with Python 2.3. This article describes how to make OOo's private python use the IDLE from a standard Python 2.3 installation.

Download and install Python 2.3. (I am using the python 2.3 released 29-Jul-2003) I install this to the default suggested location C:\Python23

Now from your C:\Python23, copy the "tcl" folder into your OOo's python. On my system, I copied the folder
C:\Python23\tcl
to the folder
C:\Program Files\OpenOffice.org 1.9.79\program\python-core-2.3.4\tcl

Now create the following BAT file. You can create this anywhere on your system.
Code:
@echo off

rem ----------
rem   Adjust these environment variables to taste.
rem ----------

rem set OOoPath=C:\Program Files\OpenOffice.org 1.9.79
set OOoPath=C:\progra~1\openof~1.79

set DannysPythonMods=C:\Danny\Danny's Python\Modules

set Python23Path=C:\Python23


rem     Be sure to copy the C:\Python\tcl folder to
rem      OOo's python top level folder, so that OOo's python
rem      has "bin", "lib", and "tcl".


rem ----------
rem     It should not be necessary to adjust any of the following,
rem      with the exception of the possibility that OOo's python
rem      might no longer be 2.3.4.
rem ----------

set OOoProg=%OOoPath%\program


set PATH=%OOoProg%;%PATH%

set PYTHONPATH=

Set PYTHONPATH=%PYTHONPATH%;%DannysPythonMods%

set PYTHONPATH=%PYTHONPATH%;%Python23Path%
set PYTHONPATH=%PYTHONPATH%;%Python23Path%\DLLs
set PYTHONPATH=%PYTHONPATH%;%Python23Path%\lib
set PYTHONPATH=%PYTHONPATH%;%Python23Path%\lib\lib-tk
set PYTHONPATH=%PYTHONPATH%;%Python23Path%\lib\site-packages
set PYTHONPATH=%PYTHONPATH%;%Python23Path%\lib\idlelib
rem set PYTHONPATH=%PYTHONPATH%;%Python23Path%\Tools\idle

set PYTHONPATH=%PYTHONPATH%;%OOoProg%
set PYTHONPATH=%PYTHONPATH%;%OOoProg%\python-core-2.3.4\lib

set PYTHONHOME=%OOoProg%\python-core-2.3.4



CD "%OOoProg%"

"%OOoProg%\python-core-2.3.4\bin\python.exe" "%Python23Path%\Lib\idlelib\idle.pyw" %1 %2 %3 %4 %5 %6 %7 %8 %9


Notice the line that says....
Code:
set DannysPythonMods=C:\Danny\Danny's Python\Modules

and where that variable is used
Code:
Set PYTHONPATH=%PYTHONPATH%;%DannysPythonMods%

The purpose of these lines are to make my entire body of python module works available to the combined OOo python + IDLE. You can adjust this to taste so that your own python modules are included.

Thus, from within IDLE, I can simply type....
Code:
import Danny.OOo.OOoLib
import Danny.OOo.DrawLib
import Danny.OOo.DialogLib

etc. (Notice my collection of Python modules over here. Well, this is some of my python modules, the OOo related ones.)

Once this BAT file is created, you simply run it. A pythin IDLE window soon appears on your screen. You should first test that you can
Code:
import uno
import unohelper

to be sure that you are running OOo's private python. If that works, then here is an example program that you can try.

See also...
http://udk.openoffice.org/python/scriptingframework/index.html
http://udk.openoffice.org/python/python-bridge.html
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Apr 23, 2005 9:23 am    Post subject: Reply with quote

Some more cross references.....

A lot of introductory information / answers about OOo UNO and Python
http://www.oooforum.org/forum/viewtopic.phtml?p=75468#75468

Danny's Python Modules
http://www.oooforum.org/forum/viewtopic.phtml?t=14409
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Paphiopedilum
Newbie
Newbie


Joined: 12 Mar 2007
Posts: 2

PostPosted: Mon Mar 12, 2007 6:28 pm    Post subject: Reply with quote

Now that it's a few years down the road, I have Python 2.5 and OpenOffice 2.1. Does OpenOffice still need to be configured to listen for UNO connections? What's the status of this? I'm lost and frustrated, because I can't find comprehensive, up-to-date instructions. I'm grateful for everything I've found so far, but I don't want to spend hours using a method that has become obsolete with newer releases of OO and Python.
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Tue Mar 13, 2007 11:01 am    Post subject: Reply with quote

Paphiopedilum wrote:
Does OpenOffice still need to be configured to listen for UNO connections?

No and yes:
- No, if you use the new Bootstrap Conncetion Mode: http://api.openoffice.org/docs/DevelopersGuide/FirstSteps/FirstSteps.xhtml#1_3_4_First_Contact
- Yes, if you use the Listening Mode: http://api.openoffice.org/docs/DevelopersGuide/ProfUNO/ProfUNO.xhtml#1_3_1_1_Starting_OpenOffice.org_in_Listening_Mode

Paphiopedilum wrote:
I'm lost and frustrated, because I can't find comprehensive, up-to-date instructions.

It's all in the OOo Developer's Guide. Although it shows most stuff in Java...

Regards
hol.sten
Back to top
View user's profile Send private message
Paphiopedilum
Newbie
Newbie


Joined: 12 Mar 2007
Posts: 2

PostPosted: Tue Mar 13, 2007 3:32 pm    Post subject: Reply with quote

Thank you for the link. This is obviously targeted toward developers, though. What I'm trying find is a place where it says, "If you want to write Python code that interacts with OpenOffice, here is what you need to do." I do not understand most of the concepts that the API Developer Manual is trying to explain.

I had heard that Python could be used to automate OpenOffice tasks, in much the same way Visual Basic can be used to automate Microsoft Office tasks. I'm talking about snippets of code that can be written within the *Office application, tested out right then and there, and edited right there within a handy window.

Unfortunately, it looks to me like even if I go through all the pain of configuring UNO, I'm only going to be able to write code in a text editor or IDLE, put it somewhere particular, and then tell OpenOffice where to get that add-in. I'm not going to have the ability to toggle back and forth between the code I'm writing and the spreadsheet it's acting on.

I'm learning Visual Basic rapidly right now, sitting at work just messing around with the Visual Basic Editor. I wanted something that simple to use. I am realizing now that what I wanted does not exist yet, but I at least wanted to ask around before I gave up and went back to Visual Basic. (I already took a class in Java, hate the language, hate Sun's Java-looking OpenOffice Basic, and I'm not going to use either.)
Back to top
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Wed Mar 14, 2007 12:20 am    Post subject: Reply with quote

Paphiopedilum wrote:
Unfortunately, it looks to me like even if I go through all the pain of configuring UNO, I'm only going to be able to write code in a text editor or IDLE, put it somewhere particular, and then tell OpenOffice where to get that add-in. I'm not going to have the ability to toggle back and forth between the code I'm writing and the spreadsheet it's acting on.

That's correct.

Paphiopedilum wrote:
I'm learning Visual Basic rapidly right now, sitting at work just messing around with the Visual Basic Editor. I wanted something that simple to use. I am realizing now that what I wanted does not exist yet, but I at least wanted to ask around before I gave up and went back to Visual Basic. (I already took a class in Java, hate the language, hate Sun's Java-looking OpenOffice Basic, and I'm not going to use either.)

Seems you don't understand things, here.
Programming OpenOffice.org with Visual Basic is only possible through COM. If you are expecting auto-completion when writing instructions for OpenOffice, you will be disappointed. There is none.
OpenOffice Basic is different from Java. What you are considering as Java-looking is probably the instructions to access OpenOffice.org API. By the way, it is simpler in Basic than in Java.
Anyway, using Visual Basic or OOoBasic, or Java or any other programming language you will not escape the OpenOffice API. And this is the tricky part : you have to learn by reading docs and snippets. Any notion of VBA for Word or Excel will be of little use, you will have to learn again.
Back to top
View user's profile Send private message Visit poster's website
Mark B
Super User
Super User


Joined: 16 Feb 2007
Posts: 852
Location: Lincolnshire, UK

PostPosted: Wed Mar 14, 2007 12:46 am    Post subject: Reply with quote

B Marcelly wrote:
Any notion of VBA for Word or Excel will be of little use, you will have to learn again.


That's not altogether true - there is an ongoing project to introduce VBA interoperability into OOo ( http://wiki.services.openoffice.org/wiki/VBA ), and the Novell version of OOo comes with this already enabled.

I'm not recommending that everyone install this (I use it because it comes as part of the OS I use - SUSE LInix 10.1), however if VBA is important to you then this is one possible solution.

Mark
_________________
Mark B's Articles
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group