Difference between revisions of "Using Python on Windows"
(Add description about recent installer) |
|||
Line 2: | Line 2: | ||
===Introduction to Python on OOo=== | ===Introduction to Python on OOo=== | ||
− | You need | + | You need {{AOo}} installed with its Python-UNO bridge. |
If you do not customize the installation, Python-UNO bridge is installed as default on recent version. | If you do not customize the installation, Python-UNO bridge is installed as default on recent version. | ||
− | Install | + | Install {{AOo}}. 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 | + | If you already have {{AOo}} installed, then go into your AOo 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 | + | In order to use the python-uno bridge, the python code must run from the Python that comes with {{AOo}}. 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 | + | If you want an interactive Python command shell right now, go into your {{AOo}}\program subfolder and run the batch file named ''python.bat''. You get a python shell. You can then use the statement Code: |
import uno | import uno | ||
− | You can now connect to any | + | You can now connect to any {{AOo}} that will accept a remote UNO connection. |
− | I suppose that leads us to the next issue.... Configuring | + | I suppose that leads us to the next issue.... Configuring {{AOo}} 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 | + | 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 {{AOo}} to listen for uno connections. |
Therefore, the two ways to use Python are... | Therefore, the two ways to use Python are... | ||
− | * Outside of | + | * Outside of {{AOo}} -- with a remote uno connection. |
− | * Inside of | + | * Inside of {{AOo}} -- as an installed component. |
Approach 1 is the quick and easy way to write and debug code. | Approach 1 is the quick and easy way to write and debug code. | ||
Line 27: | Line 27: | ||
Approach 2 is a great way to _deliver_ finished code to a user. | Approach 2 is a great way to _deliver_ finished code to a user. | ||
− | See this for more information about the Python-UNO bridge in | + | See this for more information about the Python-UNO bridge in {{AOo}}. |
http://udk.openoffice.org/python/python-bridge.html | http://udk.openoffice.org/python/python-bridge.html | ||
− | ===Configuring | + | ===Configuring {{AOo}} to listen for UNO connections=== |
− | If you write programs in Java or Python and run them external to | + | If you write programs in Java or Python and run them external to {{AOo}}, then you need to configure {{AOo}} to listen for a uno connection. |
− | It is possible to run your program on computer A, and connect to computer B which is running | + | It is possible to run your program on computer A, and connect to computer B which is running {{AOo}}, and have your program at A manipulate the {{AOo}} 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 {{AOo}} -- but it should work the same way. |
In the past, it was necessary to either | In the past, it was necessary to either | ||
− | * launch | + | * launch {{AOo}} with a special parameter to make it listen |
− | * hand edit one of | + | * hand edit one of {{AOo}}'s configuration files |
Both of the above options I explained here previously. | Both of the above options I explained here previously. | ||
Line 48: | Line 48: | ||
http://www.oooforum.org/forum/viewtopic.php?t=3754 | http://www.oooforum.org/forum/viewtopic.php?t=3754 | ||
− | My '''UnoConnectionListener document''' can be obtained from OOoMacros.org. | + | My '''UnoConnectionListener document''' can be obtained from OOoMacros.org. |
− | + | ||
− | + | ||
http://sourceforge.net/project/showfiles.php?group_id=87718&package_id=100069 | 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 | + | 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 {{AOo}}. Re-launch {{AOo}} 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. |
[[Category:Extensions]] | [[Category:Extensions]] | ||
[[Category:Python]] | [[Category:Python]] |
Revision as of 16:05, 26 November 2020
OOo Extensions project
Please view the wiki usage guidelines
|
---|
Categories: Pages: |
Extensions on the main site |
Extensions in other languages: |
Introduction to Python on OOo
You need Apache OpenOffice installed with its Python-UNO bridge.
If you do not customize the installation, Python-UNO bridge is installed as default on recent version. Install Apache OpenOffice. 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 Apache OpenOffice installed, then go into your AOo 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 Apache OpenOffice. 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 Apache OpenOffice\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 Apache OpenOffice that will accept a remote UNO connection.
I suppose that leads us to the next issue.... Configuring Apache OpenOffice 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 Apache OpenOffice to listen for uno connections.
Therefore, the two ways to use Python are...
- Outside of Apache OpenOffice -- with a remote uno connection.
- Inside of Apache OpenOffice -- 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 Apache OpenOffice. http://udk.openoffice.org/python/python-bridge.html
Configuring Apache OpenOffice to listen for UNO connections
If you write programs in Java or Python and run them external to Apache OpenOffice, then you need to configure Apache OpenOffice to listen for a uno connection.
It is possible to run your program on computer A, and connect to computer B which is running Apache OpenOffice, and have your program at A manipulate the Apache OpenOffice 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 Apache OpenOffice -- but it should work the same way.
In the past, it was necessary to either
- launch Apache OpenOffice with a special parameter to make it listen
- hand edit one of Apache OpenOffice'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://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 Apache OpenOffice. Re-launch Apache OpenOffice 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.