From f15cebd20e82c9e25dae44bc427c5018ced33207 Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Thu, 3 Jun 2021 17:47:12 -0500 Subject: [PATCH] Add example for Draw --- .gitignore | 2 +- CHANGELOG | 4 + doc/source/index.rst | 1 + doc/source/main/00_tools.rst | 165 ----------------- doc/source/main/01_tools.rst | 261 ++++++++++++--------------- doc/source/main/02_tools.rst | 200 ++++++++++++++++++++ doc/source/main/03_examples_draw.rst | 17 ++ doc/source/main/easymacro.rst | 2 +- doc/source/main/examples.rst | 12 ++ doc/source/main/examples_base.rst | 11 ++ doc/source/main/examples_calc.rst | 11 ++ doc/source/main/examples_draw.rst | 27 +++ doc/source/main/examples_writer.rst | 11 ++ 13 files changed, 409 insertions(+), 315 deletions(-) delete mode 100644 doc/source/main/00_tools.rst create mode 100644 doc/source/main/02_tools.rst create mode 100644 doc/source/main/03_examples_draw.rst create mode 100644 doc/source/main/examples.rst create mode 100644 doc/source/main/examples_base.rst create mode 100644 doc/source/main/examples_calc.rst create mode 100644 doc/source/main/examples_draw.rst create mode 100644 doc/source/main/examples_writer.rst diff --git a/.gitignore b/.gitignore index 75753ff..c1981af 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ __pycache__/ conf.py files/ -docs/ +doc/build source/source/ # Virtualenv diff --git a/CHANGELOG b/CHANGELOG index 805fdcd..e93dc41 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +v 0.15.0 [-may-2021] + - Add autostyle for Writer tables + + v 0.14.0 [13-apr-2021] - Fix: Get paragraphs in Writer - Add support for data pilots diff --git a/doc/source/index.rst b/doc/source/index.rst index a4eee53..354b990 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -13,6 +13,7 @@ Welcome to ZAZ's documentation! main/intro main/config main/easymacro + main/examples Indices and tables diff --git a/doc/source/main/00_tools.rst b/doc/source/main/00_tools.rst deleted file mode 100644 index 3879da2..0000000 --- a/doc/source/main/00_tools.rst +++ /dev/null @@ -1,165 +0,0 @@ - -**easymacro.py** it's a library for easily develop macros en LibreOffice con -Python. It is an abstraction layer between the extensive and complex LibreOffice -API UNO and your code. - -Probably, your will be more happy if used it. :) - -You can used **easymacro.py** with any extension or directly in your macros. - - -1) Tools --------- - -1.1) For debug -^^^^^^^^^^^^^^ - -**INFO_DEBUG** -^^^^^^^^^^^^^^ - -Show info debug, show in message box. - -If you have any problem in your code, you can `open issue`_ in this project, -always copy the information of INFO_DEBUG in your ticket. - -.. code-block:: python - - import easymacro as app - - def info(): - app.msgbox(INFO_DEBUG) - return - -Show in shell. - -.. code-block:: python - - import easymacro as app - - def info(): - app.debug(INFO_DEBUG) - return - - -**Log error** -^^^^^^^^^^^^^ - -Show error message in shell. - -.. code-block:: python - - import easymacro as app - - def error(): - msg = 'My error 500' - app.error(msg) - return - - -**Log debug** -^^^^^^^^^^^^^ - -Show debug message in shell. - -.. code-block:: python - - import easymacro as app - - def error(): - msg = 'Verify this data...' - app.debug(msg) - return - - -**Log info** -^^^^^^^^^^^^ - -Show info message in shell. - -.. code-block:: python - - import easymacro as app - - def error(): - msg = 'Start process...' - app.info(msg) - return - - -**Log to file** -^^^^^^^^^^^^^^^ - -Save log to file, automatic add date and time. - -.. code-block:: python - - import easymacro as app - - def log(): - app.save_log('/home/mau/log.txt', 'PyUNO') - app.save_log('/home/mau/log.txt', app.INFO_DEBUG) - return - - - -**Message box** -^^^^^^^^^^^^^^^ - -Show any data in message box - -.. code-block:: python - - import easymacro as app - - def message(): - - msg = 'Please, save the planet' - app.msgbox(msg) - - msg = ('one', 2, 'three') - app.msgbox(msg) - - msg = {'name': 'Teresa'} - app.msgbox(msg) - - app.msgbox(app) - - return - - -**Catch exceptions** -^^^^^^^^^^^^^^^^^^^^ - -Sometimes, for difficult errors, you can catch exceptions. - -.. code-block:: python - - import easymacro as app - - @app.catch_exception - def test(): - r = 1 / 0 - return - -And not, not used you this function in production. - - -**Call MRI** -^^^^^^^^^^^^ - -`MRI`_ is the better extension for debug any object in LibreOffice, you need -install before call it. - - -.. code-block:: python - - import easymacro as app - - def error(): - obj = app.active - app.mri(obj) - return - - -.. _MRI: https://github.com/hanya/MRI -.. _open issue: https://git.cuates.net/elmau/zaz/issues diff --git a/doc/source/main/01_tools.rst b/doc/source/main/01_tools.rst index 946128f..3879da2 100644 --- a/doc/source/main/01_tools.rst +++ b/doc/source/main/01_tools.rst @@ -1,200 +1,165 @@ -1.2) Tools -^^^^^^^^^^ +**easymacro.py** it's a library for easily develop macros en LibreOffice con +Python. It is an abstraction layer between the extensive and complex LibreOffice +API UNO and your code. -Remember, always import library. +Probably, your will be more happy if used it. :) + +You can used **easymacro.py** with any extension or directly in your macros. + + +1) Tools +-------- + +1.1) For debug +^^^^^^^^^^^^^^ + +**INFO_DEBUG** +^^^^^^^^^^^^^^ + +Show info debug, show in message box. + +If you have any problem in your code, you can `open issue`_ in this project, +always copy the information of INFO_DEBUG in your ticket. .. code-block:: python import easymacro as app + def info(): + app.msgbox(INFO_DEBUG) + return -**Info from PC** -^^^^^^^^^^^^^^^^ - -* Operate system +Show in shell. .. code-block:: python - app.msgbox(app.OS) + import easymacro as app -* Current user + def info(): + app.debug(INFO_DEBUG) + return + + +**Log error** +^^^^^^^^^^^^^ + +Show error message in shell. .. code-block:: python - app.msgbox(app.USER) + import easymacro as app -* Name PC + def error(): + msg = 'My error 500' + app.error(msg) + return + + +**Log debug** +^^^^^^^^^^^^^ + +Show debug message in shell. .. code-block:: python - app.msgbox(app.PC) + import easymacro as app -* Name desktop, only GNU/Linux + def error(): + msg = 'Verify this data...' + app.debug(msg) + return + + +**Log info** +^^^^^^^^^^^^ + +Show info message in shell. .. code-block:: python - app.msgbox(app.DESKTOP) + import easymacro as app -* Language + def error(): + msg = 'Start process...' + app.info(msg) + return + + +**Log to file** +^^^^^^^^^^^^^^^ + +Save log to file, automatic add date and time. .. code-block:: python - app.msgbox(app.LANG) + import easymacro as app -* Language with variant + def log(): + app.save_log('/home/mau/log.txt', 'PyUNO') + app.save_log('/home/mau/log.txt', app.INFO_DEBUG) + return -.. code-block:: python - - app.msgbox(app.LANGUAGE) - -* Application name - -.. code-block:: python - - app.msgbox(app.NAME) - -* Application version - -.. code-block:: python - - app.msgbox(app.VERSION) - -* In Windows - -.. code-block:: python - - app.msgbox(app.IS_WIN) **Message box** ^^^^^^^^^^^^^^^ -.. code-block:: python - - app.msgbox(app.IS_WIN, 'My Macro') - - -**Show warning** -^^^^^^^^^^^^^^^^ +Show any data in message box .. code-block:: python - message = 'Caution, this action is dangerous' - title = 'My App' - app.warning(message, title) + import easymacro as app + + def message(): + + msg = 'Please, save the planet' + app.msgbox(msg) + + msg = ('one', 2, 'three') + app.msgbox(msg) + + msg = {'name': 'Teresa'} + app.msgbox(msg) + + app.msgbox(app) + + return -**Show error box** -^^^^^^^^^^^^^^^^^^ - -.. code-block:: python - - message = 'ERROR: Contact technical support' - title = 'My App' - app.errorbox(message, title) - - -**Make question** -^^^^^^^^^^^^^^^^^ - -.. code-block:: python - - message = 'Is easy Python?' - title = 'My App' - result = app.question(message, title) - app.msgbox(result) - - -**InputBox** -^^^^^^^^^^^^ - -* Normal data - -.. code-block:: python - - message = 'Type your name' - default = '' - title = 'My App' - - result = app.inputbox(message, default, title) - app.msgbox(result) - -* Private data - -.. code-block:: python - - message = 'Type your password' - default = '' - title = 'My App' - echochar = "*" - - result = app.inputbox(message, default, title, echochar) - app.msgbox(result) - - -**Create instances** +**Catch exceptions** ^^^^^^^^^^^^^^^^^^^^ -* Instances without context +Sometimes, for difficult errors, you can catch exceptions. .. code-block:: python - toolkit = app.create_instance("com.sun.star.awt.Toolkit") + import easymacro as app + + @app.catch_exception + def test(): + r = 1 / 0 + return + +And not, not used you this function in production. + + +**Call MRI** +^^^^^^^^^^^^ + +`MRI`_ is the better extension for debug any object in LibreOffice, you need +install before call it. -* Instances with context .. code-block:: python - service = 'com.sun.star.awt.DialogProvider2' - dialog = app.create_instance(service, True) + import easymacro as app - -**Paths and files** -^^^^^^^^^^^^^^^^^^^ - -* Get info path - -.. code-block:: python - - path = '/home/mau/myfile.ods' - p = app.paths(path) - - app.debug(p.path) - app.debug(p.file_name) - app.debug(p.name) - app.debug(p.ext) - app.debug(p.url) - -Or get information in a tuple - -.. code-block:: python - - path = '/home/mau/myfile.ods' - p = app.paths(path) - - app.debug(p.info) - -* Get path home - -.. code-block:: python - - path = app.paths.home - app.debug(path) - -* Get path documents - -.. code-block:: python - - path = app.paths.documents - app.debug(path) - -* Get path temp - -.. code-block:: python - - path = app.paths.temp_dir - app.debug(path) + def error(): + obj = app.active + app.mri(obj) + return .. _MRI: https://github.com/hanya/MRI +.. _open issue: https://git.cuates.net/elmau/zaz/issues diff --git a/doc/source/main/02_tools.rst b/doc/source/main/02_tools.rst new file mode 100644 index 0000000..946128f --- /dev/null +++ b/doc/source/main/02_tools.rst @@ -0,0 +1,200 @@ + +1.2) Tools +^^^^^^^^^^ + +Remember, always import library. + +.. code-block:: python + + import easymacro as app + + +**Info from PC** +^^^^^^^^^^^^^^^^ + +* Operate system + +.. code-block:: python + + app.msgbox(app.OS) + +* Current user + +.. code-block:: python + + app.msgbox(app.USER) + +* Name PC + +.. code-block:: python + + app.msgbox(app.PC) + +* Name desktop, only GNU/Linux + +.. code-block:: python + + app.msgbox(app.DESKTOP) + +* Language + +.. code-block:: python + + app.msgbox(app.LANG) + +* Language with variant + +.. code-block:: python + + app.msgbox(app.LANGUAGE) + +* Application name + +.. code-block:: python + + app.msgbox(app.NAME) + +* Application version + +.. code-block:: python + + app.msgbox(app.VERSION) + +* In Windows + +.. code-block:: python + + app.msgbox(app.IS_WIN) + + +**Message box** +^^^^^^^^^^^^^^^ + +.. code-block:: python + + app.msgbox(app.IS_WIN, 'My Macro') + + +**Show warning** +^^^^^^^^^^^^^^^^ + +.. code-block:: python + + message = 'Caution, this action is dangerous' + title = 'My App' + app.warning(message, title) + + +**Show error box** +^^^^^^^^^^^^^^^^^^ + +.. code-block:: python + + message = 'ERROR: Contact technical support' + title = 'My App' + app.errorbox(message, title) + + +**Make question** +^^^^^^^^^^^^^^^^^ + +.. code-block:: python + + message = 'Is easy Python?' + title = 'My App' + result = app.question(message, title) + app.msgbox(result) + + +**InputBox** +^^^^^^^^^^^^ + +* Normal data + +.. code-block:: python + + message = 'Type your name' + default = '' + title = 'My App' + + result = app.inputbox(message, default, title) + app.msgbox(result) + +* Private data + +.. code-block:: python + + message = 'Type your password' + default = '' + title = 'My App' + echochar = "*" + + result = app.inputbox(message, default, title, echochar) + app.msgbox(result) + + +**Create instances** +^^^^^^^^^^^^^^^^^^^^ + +* Instances without context + +.. code-block:: python + + toolkit = app.create_instance("com.sun.star.awt.Toolkit") + +* Instances with context + +.. code-block:: python + + service = 'com.sun.star.awt.DialogProvider2' + dialog = app.create_instance(service, True) + + +**Paths and files** +^^^^^^^^^^^^^^^^^^^ + +* Get info path + +.. code-block:: python + + path = '/home/mau/myfile.ods' + p = app.paths(path) + + app.debug(p.path) + app.debug(p.file_name) + app.debug(p.name) + app.debug(p.ext) + app.debug(p.url) + +Or get information in a tuple + +.. code-block:: python + + path = '/home/mau/myfile.ods' + p = app.paths(path) + + app.debug(p.info) + +* Get path home + +.. code-block:: python + + path = app.paths.home + app.debug(path) + +* Get path documents + +.. code-block:: python + + path = app.paths.documents + app.debug(path) + +* Get path temp + +.. code-block:: python + + path = app.paths.temp_dir + app.debug(path) + + +.. _MRI: https://github.com/hanya/MRI diff --git a/doc/source/main/03_examples_draw.rst b/doc/source/main/03_examples_draw.rst new file mode 100644 index 0000000..45a6ac0 --- /dev/null +++ b/doc/source/main/03_examples_draw.rst @@ -0,0 +1,17 @@ + +Examples for Draw +----------------- + +Save image +^^^^^^^^^^ + +.. code-block:: python + + def save_image(): + doc = app.docs.new('draw', {'Hidden': True}) + image = doc.paste() + path = '/home/mau/Pictures' + image.save(path) + doc.close() + app.msgbox('Image saved') + return diff --git a/doc/source/main/easymacro.rst b/doc/source/main/easymacro.rst index f8d5e9b..7133449 100644 --- a/doc/source/main/easymacro.rst +++ b/doc/source/main/easymacro.rst @@ -2,7 +2,7 @@ Library easymacro.py ==================== -.. include:: 00_tools.rst .. include:: 01_tools.rst +.. include:: 02_tools.rst diff --git a/doc/source/main/examples.rst b/doc/source/main/examples.rst new file mode 100644 index 0000000..604f031 --- /dev/null +++ b/doc/source/main/examples.rst @@ -0,0 +1,12 @@ + +Examples +======== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + examples_calc.rst + examples_writer.rst + examples_draw.rst + examples_base.rst diff --git a/doc/source/main/examples_base.rst b/doc/source/main/examples_base.rst new file mode 100644 index 0000000..a387145 --- /dev/null +++ b/doc/source/main/examples_base.rst @@ -0,0 +1,11 @@ + +Examples for Base +----------------- + +First +^^^^^ + +.. code-block:: python + + def _(): + return diff --git a/doc/source/main/examples_calc.rst b/doc/source/main/examples_calc.rst new file mode 100644 index 0000000..1547566 --- /dev/null +++ b/doc/source/main/examples_calc.rst @@ -0,0 +1,11 @@ + +Examples for Calc +----------------- + +First +^^^^^^^^^^ + +.. code-block:: python + + def _(): + return diff --git a/doc/source/main/examples_draw.rst b/doc/source/main/examples_draw.rst new file mode 100644 index 0000000..2c23f78 --- /dev/null +++ b/doc/source/main/examples_draw.rst @@ -0,0 +1,27 @@ + +Examples for Draw +----------------- + +Save image +^^^^^^^^^^ + +.. code-block:: python + + def save_image(): + # Target path + path = '/home/mau/Pictures' + + # Open new hidden Draw doc + doc = app.docs.new('draw', {'Hidden': True}) + + # Paste image from clipboard and return + image = doc.paste() + + # Save image + image.save(path) + + # Close document + doc.close() + + app.msgbox('Image saved') + return diff --git a/doc/source/main/examples_writer.rst b/doc/source/main/examples_writer.rst new file mode 100644 index 0000000..b46b71d --- /dev/null +++ b/doc/source/main/examples_writer.rst @@ -0,0 +1,11 @@ + +Examples for Writer +------------------- + +First +^^^^^ + +.. code-block:: python + + def _(): + return