Difference between revisions of "Using Python on Windows"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{Extensions}}
 
{{Extensions}}
===Introduction to Python on OOo===  
+
===Introduction to Python on {{AOo}}===  
  
 
You need {{AOo}} installed with its Python-UNO bridge.  
 
You need {{AOo}} installed with its Python-UNO bridge.  
Line 9: Line 9:
 
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.  
 
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 {{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.  
+
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 {{AOo}} has been compiled using the StdCLib that {{AOo}} 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 {{AOo}}\program subfolder and run the batch file named ''python.bat''. You get a python shell. You can then use the statement Code:
 
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:
 +
<syntaxhighlight lang="python">
 
   import uno
 
   import uno
 +
</syntaxhighlight>
 
You can now connect to any {{AOo}} that will accept a remote UNO connection.  
 
You can now connect to any {{AOo}} that will accept a remote UNO connection.  
  
I suppose that leads us to the next issue.... Configuring {{AOo}} to listen for UNO connections.  
+
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 {{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 {{AOo}} to listen for uno connections.  
Line 28: Line 30:
  
 
See this for more information about the Python-UNO bridge in {{AOo}}.  
 
See this for more information about the Python-UNO bridge in {{AOo}}.  
http://udk.openoffice.org/python/python-bridge.html
+
https://www.openoffice.org/udk/python/python-bridge.html
  
 
===Configuring {{AOo}} to listen for UNO connections===
 
===Configuring {{AOo}} to listen for UNO connections===
Line 41: Line 43:
  
 
Both of the above options I explained here previously.  
 
Both of the above options I explained here previously.  
http://www.oooforum.org/forum/viewtopic.php?p=12370#12370  
+
https://web.archive.org/web/20111007035201/http://www.oooforum.org/forum/viewtopic.phtml?p=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).  
+
You can hand edit an XML file for version 1.0 of OpenOffice.org, or an XCU file for version 1.1 of OpenOffice.org.  
  
 
Later, I developed a macro to do this editing and announced it here.  
 
Later, I developed a macro to do this editing and announced it here.  
http://www.oooforum.org/forum/viewtopic.php?t=3754  
+
https://web.archive.org/web/20121205124008/http://www.oooforum.org/forum/viewtopic.phtml?t=3754  
  
My '''UnoConnectionListener document''' can be obtained from OOoMacros.org.   
+
My '''UnoConnectionListener document''' can be obtained from OpenOffice.org Macros on Sourceforge.   
  
http://sourceforge.net/project/showfiles.php?group_id=87718&package_id=100069  
+
https://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 {{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.
 
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]]

Latest revision as of 12:35, 3 February 2021

OOo Extensions project

Please view the wiki usage guidelines
before contributing.

Categories:

Pages:

Extensions on the main site

Extensions in other languages:
ES - FR - IT - JA - NL - OC -

Introduction to Python on Apache OpenOffice

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 Apache OpenOffice 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 Apache OpenOffice has been compiled using the StdCLib that Apache OpenOffice 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. https://www.openoffice.org/udk/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. https://web.archive.org/web/20111007035201/http://www.oooforum.org/forum/viewtopic.phtml?p=12370

You can hand edit an XML file for version 1.0 of OpenOffice.org, or an XCU file for version 1.1 of OpenOffice.org.

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

My UnoConnectionListener document can be obtained from OpenOffice.org Macros on Sourceforge.

https://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.

Personal tools