Difference between revisions of "Python"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Python specific information for Extension creation)
(Hacking Around)
(20 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
{{Extensions}}
 
{{Extensions}}
 
[[image:Py-uno_128.png|PyUNO Logo]] [[image:Pyuno_logo_a.jpg]]  
 
[[image:Py-uno_128.png|PyUNO Logo]] [[image:Pyuno_logo_a.jpg]]  
=== News ===
 
Efforts on moving PyUNO to '''Python 2.5''' continue.  Liyuan is pushing this initiative and has [http://udk.openoffice.org/servlets/ReadMsg?listName=dev&msgNo=3704 commited the CWS] on the UDK mailing list.  The [[CWS]], however, is not ready, and was sent back on issue [http://www.openoffice.org/issues/show_bug.cgi?id=71327 71327].
 
  
=== Python and OpenOffice.org ===
+
=== Python and OpenOffice ===
OpenOffice.org ships with the python scripting language, version 2.3.4. This Python distribution comes with the [[Uno]] module, which connects the [[API|UNO API]] to the python scripting language.  To run this version of Python on Linux, you can go directly to the OpenOffice.org PATH.  And as one would expect with any distribution of Python, OOo-Python can be run from the command line as well.
+
Apache OpenOffice 4 ships with the Python scripting language, version 2.7. OpenOffice.org 3.1 and above shipped with Python version 2.6.1 and older OpenOffice.org releases shipped with Python version 2.3.4. This Python distribution via OpenOffice comes with the [[Uno]] module, which connects the [[API|UNO API]] to the python scripting language.  To run this version of Python on Linux, you can go directly to the OpenOffice PATH.  And as one would expect with any distribution of Python, AOO-Python can be run from the command line as well.
  
==== Where is the IDE ? ====
+
If you already have a separate Python installation, you can import the uno module (the Python-UNO bridge) to it using [http://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=36370&p=166783 these instructions].
OpenOffice.org's IDE doesn't support Python, so development has to be done from another editor that does.  Any volunteer for a binding is welcomed.
+
  
集成开发环境在哪?
+
If you already have a different version of Python installed on Windows, you can also access the [[API|UNO API]] using the [http://forum.openoffice.org//en/forum/viewtopic.php?f=45&t=36608&p=167909 COM bridge] instead of the Python bridge. Requires the [http://sourceforge.net/projects/pywin32/ add-on pywin32] module so Python can talk to COM. Note that while the UNO API is uniform, the implementation by the two bridges is slightly different, so the syntax required by each is also sometimes different.
  
OpenOffice.org的集成开发环境不支持Python,因此开发工作应该在其它的编辑器上完成,欢迎任何为绑定作贡献的志愿者。
+
==== Where is the IDE ? ====
 +
OpenOffice's IDE doesn't support Python, so development has to be done from another editor that does.  Any volunteer for a binding is welcomed. Here is a nice [http://pythonconquerstheuniverse.wordpress.com/category/the-python-debugger/ blog post] about using [http://www.vim.org VIM] a common Unix/Linux text editor configured in a way that acts like an IDE. Windows users can use [http://www.vim.org/download.php#pc Gvim] and [http://macvim.org/ MacVim] for OSX users.
  
 
==== Tips & Tricks ====
 
==== Tips & Tricks ====
  
Here is some useful information about using python in OOo.
+
Here is some useful information about using python in AOO.
  
 
===== Debug output =====
 
===== Debug output =====
Line 25: Line 23:
  
 
Have a look in  
 
Have a look in  
''/path/to/ooo/program/'''pythonscript.py'''''  
+
''/path/to/aoo/program/'''pythonscript.py'''''  
 
and replace  
 
and replace  
 
''LogLevel.use = LogLevel.'''NONE'''''
 
''LogLevel.use = LogLevel.'''NONE'''''
Line 44: Line 42:
  
 
=== Python specific information for Extension creation ===
 
=== Python specific information for Extension creation ===
To create extensions for python, it is important that you have enough familiarity with the UNO components, as well as with packaging your code for easy distribution through the ''OpenOffice.org package manager''.  Please check the tutorials to learn how to component-ize your code, and how to deploy remote scripting through a service implementation.
+
To create extensions for python, it is important that you have enough familiarity with the UNO components, as well as with packaging your code for easy distribution through the ''OpenOffice package manager''.  Please check the tutorials to learn how to component-ize your code, and how to deploy remote scripting through a service implementation.
  
 
To learn to run Python on Windows, visit [[Using Python on Windows| this link]] for more detailed information.
 
To learn to run Python on Windows, visit [[Using Python on Windows| this link]] for more detailed information.
  
=== Getting Started ===
+
{| align="center" cellspacing="0" cellpadding="0" style="border: 0px solid rgb(134, 194, 230);"
 +
|- valign="top"
 +
| style="width: 35%; padding-right: 15px;" | <div style="border-style: solid solid none; border-color: rgb(134, 194, 230) rgb(134, 194, 230) -moz-use-text-color; border-width: 1px 1px medium; padding: 5px; font-size: 120%; font-weight: bold; background-color: rgb(203, 222, 250);">Getting Started</div> <div style="border: 1px solid rgb(155, 192, 245); padding: 5px 5px 10px;">
 +
*[[Python/Python_Language_Binding|Python Language Binding]]
 +
*[[Python/Python_Loader|Python Loader]]
 
*[[Using Python on Windows]] - New to Python? Learn how to use python on Windows
 
*[[Using Python on Windows]] - New to Python? Learn how to use python on Windows
*[[Using Python on Linux]] - A must read for an overview on Python and OOo relations
+
*[[Using Python on Linux]] - A must read for an overview on Python and AOO relations
* [[pyUNO bridge]] - Official page of the PyUNO bridge at the [http://udk.openoffice.org/ UDK site]
+
* [[pyUNO bridge]] - Official page of the PyUNO bridge at the [http://udk.openoffice.org/ UDK site] - ([http://www.fatcow.com/edu/mathtex-be/ ''Belorussian translation''])
 
* [[Python as a macro language]] in OpenOffice.org 2.x - How to use the Python scripting framework
 
* [[Python as a macro language]] in OpenOffice.org 2.x - How to use the Python scripting framework
 +
* [[Python/Transfer_from_Basic_to_Python|Transfer from Basic to Python]]
 
* [http://lucasmanual.com/mywiki/OpenOffice PyUNO Manual] Lukasz created a pyUNO manual. '''new'''
 
* [http://lucasmanual.com/mywiki/OpenOffice PyUNO Manual] Lukasz created a pyUNO manual. '''new'''
 +
* [[SQLAlquemyPyUNO|SQLAlchemy and PyUNO]] connecting OpenOffice to any database
 
* [http://www.linuxjournal.com/content/starting-stopping-and-connecting-openoffice-python Starting/Stopping and connecting using Python] From Linux Journal
 
* [http://www.linuxjournal.com/content/starting-stopping-and-connecting-openoffice-python Starting/Stopping and connecting using Python] From Linux Journal
 
* Introduction on testing pyUNO programs with [[doctests]]
 
* Introduction on testing pyUNO programs with [[doctests]]
* Create a [http://codesnippets.services.openoffice.org/Office/Office.MessageBoxWithTheUNOBasedToolkit.snip dialog box] in PyUNO.
+
* Create a [[PythonDialogBox|dialog box]] in PyUNO.
* [http://codesnippets.services.openoffice.org/Office/Office.ConnectViaPipe.snip Connect to openoffice.org] from PyUNO
+
* [http://codesnippets.services.openoffice.org/Office/Office.ConnectViaPipe.snip Connect to Openoffice] from PyUNO
 
* [[PyUNO samples]] currently shipping with OpenOffice.org and the explanation.
 
* [[PyUNO samples]] currently shipping with OpenOffice.org and the explanation.
* Enhanced [http://www.oooforum.org/forum/viewtopic.phtml?p=257496#257496 Capitalized.py] script by ''The gray Cardinal'' at OOoforum.
+
* Enhanced [http://www.oooforum.org/forum/viewtopic.phtml?p=257496#257496 Capitalized.py] script by ''The gray Cardinal'' at the OpenOffice forum.
  
=== PyUNO Modules ===
+
| style="width: 35%; padding-right: 15px;" | <div style="border-style: solid solid none; border-color: rgb(134, 194, 230) rgb(134, 194, 230) -moz-use-text-color; border-width: 1px 1px medium; padding: 5px; font-size: 120%; font-weight: bold; background-color: rgb(203, 222, 250);">PYUNO Modules</div> <div style="border: 1px solid rgb(155, 192, 245); padding: 5px 5px 10px;">
 
*[[Danny's Python Modules]] - Collection guide from DannyB's modules.
 
*[[Danny's Python Modules]] - Collection guide from DannyB's modules.
 
*[[PrinttoWriter.py]] - This makes it easy and convenient to print a bunch of text into a Writer document.
 
*[[PrinttoWriter.py]] - This makes it easy and convenient to print a bunch of text into a Writer document.
*[http://www.oooforum.org/forum/viewtopic.phtml?t=8456 Developing Calc Functions in Python] - Learn how Python can be used to script your spreadsheets
+
*[[CalcFunctions]] - Learn how Python can be used to develop Calc functions in Python
*[http://www.oooforum.org/forum/viewtopic.phtml?p=56037#56037 Generating a Spreadsheet through Python] - Automatically generate new spreadsheets
+
*[[Python-Calc]] - Various scripts to deal with Calc
*[http://www.oooforum.org/forum/viewtopic.phtml?t=9115 Python container components]
+
*[[PythonContainers]] - Python container components
 
*[[PyUNOServer]] - The PyUNOServer is a script that works as an XML server for OpenOffice.org Calc
 
*[[PyUNOServer]] - The PyUNOServer is a script that works as an XML server for OpenOffice.org Calc
 
*[[calcParser]] - calcParser is a small parser using the native SAX utilities within the OpenOffice.org python
 
*[[calcParser]] - calcParser is a small parser using the native SAX utilities within the OpenOffice.org python
Line 72: Line 76:
 
*[[Bibliographic/Hints and Tips/OOoRISExport.py|OOoRISExport.py]] - Exports the bibliographic database in RIS format. Also [http://bibliographic.openoffice.org/files/documents/124/3078/RISImport.py RISImport.py]
 
*[[Bibliographic/Hints and Tips/OOoRISExport.py|OOoRISExport.py]] - Exports the bibliographic database in RIS format. Also [http://bibliographic.openoffice.org/files/documents/124/3078/RISImport.py RISImport.py]
 
*[[Zotero_Plugin |Zotero Plugin]] - The Zotero plugin provides citation and bibliographic table insertion and editing functions for Writer documents.
 
*[[Zotero_Plugin |Zotero Plugin]] - The Zotero plugin provides citation and bibliographic table insertion and editing functions for Writer documents.
 +
*[http://oosheet.hacklab.com.br/ OOSheet] - High level python library to develop spreadsheet macros without the complexity of Uno. Focuses on spreadsheets, but may be useful for other documents.
 +
|}
  
 
=== Hacking Around ===
 
=== Hacking Around ===
Line 77: Line 83:
 
*[http://www.oooforum.org/forum/viewtopic.phtml?p=38234#38234 Python component to parse XML] - Python is great to parse XML, PyUNO is also excellent when working with XML
 
*[http://www.oooforum.org/forum/viewtopic.phtml?p=38234#38234 Python component to parse XML] - Python is great to parse XML, PyUNO is also excellent when working with XML
 
*[[Example of Service in Python]] - Learn how to run Python as a service, this is useful for remote scripting.
 
*[[Example of Service in Python]] - Learn how to run Python as a service, this is useful for remote scripting.
*[http://www.oooforum.org/forum/viewtopic.phtml?p=76972#76972 Modify spreadsheet] - Example of storing and retrieving a custom attribute on a spreadsheet cell.
+
*[[CellCustomAtributes]] - Example of storing and retrieving a custom attribute on a spreadsheet cell.
 
*A simple [[daemon in Python]] - Learn how to run Python as a daemon
 
*A simple [[daemon in Python]] - Learn how to run Python as a daemon
 
*[[Loook.py]] - a simple Python tool that searches for text strings in OpenOffice.org.
 
*[[Loook.py]] - a simple Python tool that searches for text strings in OpenOffice.org.
 
*[[odt2txt.py]] - convert ODF to plain text using python (and convert the txt to html).
 
*[[odt2txt.py]] - convert ODF to plain text using python (and convert the txt to html).
  
=== Python rules OOo (by B. Bois) ===
+
=== Python rules OpenOffice (by B. Bois) ===
[[image:python_power_for_OOo.png|Python rules OOo :-)]]
+
[[image:python_power_for_OOo.png|Python rules OpenOffice :-)]]
  
  

Revision as of 02:55, 18 February 2015

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 -

PyUNO Logo Pyuno logo a.jpg

Python and OpenOffice

Apache OpenOffice 4 ships with the Python scripting language, version 2.7. OpenOffice.org 3.1 and above shipped with Python version 2.6.1 and older OpenOffice.org releases shipped with Python version 2.3.4. This Python distribution via OpenOffice comes with the Uno module, which connects the UNO API to the python scripting language. To run this version of Python on Linux, you can go directly to the OpenOffice PATH. And as one would expect with any distribution of Python, AOO-Python can be run from the command line as well.

If you already have a separate Python installation, you can import the uno module (the Python-UNO bridge) to it using these instructions.

If you already have a different version of Python installed on Windows, you can also access the UNO API using the COM bridge instead of the Python bridge. Requires the add-on pywin32 module so Python can talk to COM. Note that while the UNO API is uniform, the implementation by the two bridges is slightly different, so the syntax required by each is also sometimes different.

Where is the IDE ?

OpenOffice's IDE doesn't support Python, so development has to be done from another editor that does. Any volunteer for a binding is welcomed. Here is a nice blog post about using VIM a common Unix/Linux text editor configured in a way that acts like an IDE. Windows users can use Gvim and MacVim for OSX users.

Tips & Tricks

Here is some useful information about using python in AOO.

Debug output

If you launch a python script, any error will silently break the execution, making your extension hard to debug. To change this behaviour, one can change the LogLevel .

Have a look in /path/to/aoo/program/pythonscript.py and replace LogLevel.use = LogLevel.NONE with LogLevel.use = LogLevel.DEBUG .

There are also currently-undocumented environment variables that tell the pyUno bridge to log every call. Set the environment variable export PYUNO_LOGLEVEL=ARGS . The output may be a little hard to read, but helpful nonetheless.

Note that his applies only to Linux. For Windows, you need some more switches, and the output gets written to files (there is no stdout on windows :-( ).

There are still some error messages that won't appear in these logs; this will improve in the near future (cws pyunofixes4). Once the cws is integrated, I will document these switches on the official pyuno site.

Thanks to Joerg Budischewski .

Python specific information for Extension creation

To create extensions for python, it is important that you have enough familiarity with the UNO components, as well as with packaging your code for easy distribution through the OpenOffice package manager. Please check the tutorials to learn how to component-ize your code, and how to deploy remote scripting through a service implementation.

To learn to run Python on Windows, visit this link for more detailed information.

Getting Started
PYUNO Modules
  • Danny's Python Modules - Collection guide from DannyB's modules.
  • PrinttoWriter.py - This makes it easy and convenient to print a bunch of text into a Writer document.
  • CalcFunctions - Learn how Python can be used to develop Calc functions in Python
  • Python-Calc - Various scripts to deal with Calc
  • PythonContainers - Python container components
  • PyUNOServer - The PyUNOServer is a script that works as an XML server for OpenOffice.org Calc
  • calcParser - calcParser is a small parser using the native SAX utilities within the OpenOffice.org python
  • OoConfig - OoConfig is a Python extension that seeks to provide a configuration editing facility similar to Mozilla's about:config
  • OOoRISExport.py - Exports the bibliographic database in RIS format. Also RISImport.py
  • Zotero Plugin - The Zotero plugin provides citation and bibliographic table insertion and editing functions for Writer documents.
  • OOSheet - High level python library to develop spreadsheet macros without the complexity of Uno. Focuses on spreadsheets, but may be useful for other documents.

Hacking Around

Python rules OpenOffice (by B. Bois)

Python rules OpenOffice :-)
Views
Personal tools
Navigation
Tools