Python Guide - Introduction

From The Document Foundation Wiki
Jump to: navigation, search
This page is a translated version of the page Macros/Python Guide/Introduction and the translation is 50% complete.

Outdated translations are marked like this.


Return to Index

Other languages:
English • ‎español • ‎français • ‎italiano


Introduction

¿Que es PyUNO?

LibreOffice tiene soporte para crear macros en varios lenguajes interpretados, uno de ellos es Python. PyUNO es el componente que nos da acceso a la Interfaz de programación de aplicaciones (IPA o API de aquí en adelante por sus siglas del inglés Application Programming Interface) de LibreOffice con Python.

Probar el soporte para Python

Abre LibreOffice Writer y ve al menú Herramientas ▸ Macros ▸ Organizar macros ▸ Python... Si no ves esta opción, probablemente no tengas instalado el soporte para macros Python.

Sigue la siguiente secuencia dentro del cuadro de diálogo Macros de Pyhon.

  1. Selecciona y expande la rama Macros de LibreOffice
  2. Selecciona y expande la subrama HelloWorld
  3. Selecciona la macro HelloWorldPython
  4. Da un clic en el botón de comando Ejecutar

Si ves el siguiente resultado...

Hello World (in Python)

tienes todo listo para empezar.

Requerimientos previos

No se requieren conocimientos previos de programación pero si del uso de LibreOffice. Este no es un curso de Libreoffice, si no del desarrollo de macros con Python.

Inside a document

    • Any ODF file, really is a ZIP file, you can extract this file like extract normally this type files. In the root, create folder
      Scripts/python/
      and copy inside any python file, for example:
      mymacros.py
    • You should see.
 myfile
 |   ...
 ├── META-INF
 │   └── manifest.xml
 ├── Scripts
 │   └── python
 │       └── mymacros.py
 ...
  • Edit file manifest.xml into folder META-INF and add lines, just before tag close </manifest:manifest>
 <manifest:file-entry manifest:full-path="Scripts/python/mymacros.py" manifest:media-type="" />
 <manifest:file-entry manifest:full-path="Scripts/python/" manifest:media-type="application/binary" />
 <manifest:file-entry manifest:full-path="Scripts/" manifest:media-type="application/binary" />
  • The final file should see like:
   <?xml version="1.0" encoding="UTF-8"?>
   <manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0">
    <manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.spreadsheet"/>
    <manifest:file-entry manifest:full-path="Thumbnails/thumbnail.png" manifest:media-type="image/png"/>
    <manifest:file-entry manifest:full-path="settings.xml" manifest:media-type="text/xml"/>
    <manifest:file-entry manifest:full-path="manifest.rdf" manifest:media-type="application/rdf+xml"/>
    <manifest:file-entry manifest:full-path="Configurations2/" manifest:media-type="application/vnd.sun.xml.ui.configuration"/>
    <manifest:file-entry manifest:full-path="meta.xml" manifest:media-type="text/xml"/>
    <manifest:file-entry manifest:full-path="styles.xml" manifest:media-type="text/xml"/>
    <manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/>
    <manifest:file-entry manifest:full-path="Scripts/python/mymacros.py" manifest:media-type="" />
    <manifest:file-entry manifest:full-path="Scripts/python/" manifest:media-type="application/binary" />
    <manifest:file-entry manifest:full-path="Scripts/" manifest:media-type="application/binary" />
   </manifest:manifest>
  • Now, zip the complete folder again. Caution, not zip extern folder, zip the content of folder


Return to Index