Add build folder

This commit is contained in:
Mauricio Baeza 2021-06-25 22:55:52 -05:00
parent 327dd76291
commit fa781d3da1
80 changed files with 22273 additions and 1 deletions

1
.gitignore vendored
View File

@ -5,7 +5,6 @@ __pycache__/
conf.py
files/
doc/build
source/source/
# Virtualenv

4
doc/build/.buildinfo vendored Normal file
View File

@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 9dc485243b09862a9e5c34c02e1c395f
tags: 645f666f9bcd5a90fca523b33c5a78b7

BIN
doc/build/.doctrees/environment.pickle vendored Normal file

Binary file not shown.

BIN
doc/build/.doctrees/es/index.doctree vendored Normal file

Binary file not shown.

BIN
doc/build/.doctrees/index.doctree vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
doc/build/.doctrees/main/base.doctree vendored Normal file

Binary file not shown.

BIN
doc/build/.doctrees/main/calc.doctree vendored Normal file

Binary file not shown.

BIN
doc/build/.doctrees/main/config.doctree vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
doc/build/.doctrees/main/email.doctree vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
doc/build/.doctrees/main/intro.doctree vendored Normal file

Binary file not shown.

BIN
doc/build/.doctrees/main/path.doctree vendored Normal file

Binary file not shown.

BIN
doc/build/.doctrees/main/paths.doctree vendored Normal file

Binary file not shown.

BIN
doc/build/.doctrees/main/tools.doctree vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
doc/build/.doctrees/main/writer.doctree vendored Normal file

Binary file not shown.

24
doc/build/_sources/index.rst.txt vendored Normal file
View File

@ -0,0 +1,24 @@
.. ZAZ documentation master file, created by
sphinx-quickstart on Thu Feb 4 22:28:30 2021.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to ZAZ's documentation!
===============================
.. toctree::
:maxdepth: 2
:caption: Contents:
main/intro
main/config
main/easymacro
main/examples
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

View File

@ -0,0 +1,158 @@
Application
-----------
Remember, always import library.
.. code-block:: python
import easymacro as app
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)
* Get desktop
.. code-block:: python
desktop1 = app.create_instance('com.sun.star.frame.Desktop', True)
# ~ or
desktop2 = app.get_desktop()
app.msgbox(desktop1 == desktop2)
Current doc
^^^^^^^^^^^
.. code-block:: python
doc = app.active
app.msgbox(doc.title)
Iter docs
^^^^^^^^^
.. code-block:: python
for doc in app.docs:
app.msgbox(doc.title)
Count
^^^^^
.. code-block:: python
count = len(app.docs)
app.msgbox(count)
Get by name
^^^^^^^^^^^
.. code-block:: python
name = 'MyDoc.ods'
if name in app.docs:
doc = app.docs[name]
app.msgbox(doc.title)
New
^^^
For default create new Calc document.
.. code-block:: python
doc = app.docs.new()
app.msgbox(doc.type)
For new Writer document.
.. code-block:: python
doc = app.docs.new('writer')
app.msgbox(doc.type)
With arguments.
.. code-block:: python
args= {'Hidden': True}
doc = app.docs.new('writer', args)
msg = f'{doc.type} - {doc.title}'
app.msgbox(msg)
doc.visible = True
Other documents.
.. code-block:: python
doc = app.docs.new('draw')
app.msgbox(doc.type)
doc = app.docs.new('impress')
app.msgbox(doc.type)
Open
^^^^
.. code-block:: python
path = '/home/mau/MyDoc.ods'
doc = app.docs.open(path)
While LibreOffice support format, you can open arbitrary file.
.. code-block:: python
path = '/home/mau/example.xlsx'
doc = app.docs.open(path)
With arguments.
.. code-block:: python
path = '/home/mau/example.odt'
args = {'Password': 'letmein'}
doc = app.docs.open(path, args)
Call dispatch
^^^^^^^^^^^^^
You can call any `dispatch command`_ used only if property or method no exists in original object or in `easymacro.py`
.. code-block:: python
doc = app.active
command = '.uno:Gallery'
app.call_dispatch(doc, command)
.. _dispatch command: https://wiki.documentfoundation.org/Development/DispatchCommands

20
doc/build/_sources/main/base.rst.txt vendored Normal file
View File

@ -0,0 +1,20 @@
Base
----
Remember, always import library.
.. code-block:: python
import easymacro as app
New database
^^^^^^^^^^^^
.. code-block:: python
path = '/home/mau/db.odb'
db = app.doc.connect(path)
app.msgbox(db.type)

27
doc/build/_sources/main/calc.rst.txt vendored Normal file
View File

@ -0,0 +1,27 @@
Calc
----
Remember, always import library.
.. code-block:: python
import easymacro as app
Current doc
^^^^^^^^^^^
.. code-block:: python
doc = app.active
app.msgbox(doc.type)
Active sheet
^^^^^^^^^^^^
.. code-block:: python
sheet = app.active_sheet
app.msgbox(sheet.name)

399
doc/build/_sources/main/config.rst.txt vendored Normal file
View File

@ -0,0 +1,399 @@
Configuration
=============
* Create new extension:
``./zaz.py -new -t ~/projects -n MyGreatExtension``
* Move to new folder:
``cd ~/projects/MyGreatExtension``
* Edit file ``conf.py``
``vim conf.py``
Parameters
----------
**Configure correctly this options, before you start code your extension.**
Only modify this options.
Type extension
^^^^^^^^^^^^^^
**TYPE_EXTENSION**
The type extension that you want develop.
* Integer
* 1 = Normal extension
* 2 = New components
* 3 = Calc addin
Example:
.. code-block:: python
TYPE_EXTENSION = 1
Version
^^^^^^^
**VERSION**
* String
* The current version of extension, look: `Semantic Versioning`_
Example:
.. code-block:: python
VERSION = '0.1.0'
Name
^^^^
**NAME**
* String
* Your extension name, not used spaces.
Example:
.. code-block:: python
NAME = 'MyGreatExtension'
ID extension
^^^^^^^^^^^^
The internal name for extension.
**ID**
* String
* Should be unique, used URL inverse
Example:
.. code-block:: python
ID = 'org.yourname.extensionname'
Locales
^^^^^^^
If your extension will be multi-language (recommended)
**USE_LOCALES**
* Bool
Example:
.. code-block:: python
USE_LOCALES = True
Domain for locales
^^^^^^^^^^^^^^^^^^
The base name for generate files POT
**DOMAIN**
* String
Example:
.. code-block:: python
DOMAIN = 'base'
Path pyGetText
^^^^^^^^^^^^^^
Absolute path for tool `pygettext.py` for generate POT.
**PATH_PYGETTEXT**
* String
Example:
.. code-block:: python
PATH_PYGETTEXT = '/usr/lib/python3.9/Tools/i18n/pygettext.py'
Author
^^^^^^
Your information like author, one or more languages. This information is displayed in the extension manager.
**PUBLISHER**
* Dictionary
Example:
.. code-block:: python
PUBLISHER = {
'en': {'text': 'Your name', 'link': 'https://your.page'},
'es': {'text': 'Tu nombre', 'link': 'https://elmau.net'},
}
Extension icon
^^^^^^^^^^^^^^
Path relative or absolute to extension logo. Show in extension manager.
**ICON**
* String
Example:
.. code-block:: python
ICON='images/logo.png'
License
^^^^^^^
The license for your extension, please, used free license.
**LICENSE**
* String
Example:
.. code-block:: python
LICENSE_EN = f"""This file is part of {NAME}.
{NAME} is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
{NAME} is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with {NAME}. If not, see <https://www.gnu.org/licenses/>.
"""
LICENSE_ES = LICENSE_EN
Information
^^^^^^^^^^^
Information of extension: Display name, description and license to displayed when install.
**INFO**
* Dictionary
Example:
.. code-block:: python
INFO = {
'en': {
'display_name': 'Test Macro',
'description': 'My great extension',
'license': LICENSE_EN,
},
'es': {
'display_name': 'Macro de Prueba',
'description': 'Mi gran extensión',
'license': LICENSE_ES,
},
}
Parent menu
^^^^^^^^^^^
Only for normal extension (`TYPE_EXTENSION = 1`), where add extension menu, only two possible values: **AddonMenu** or **OfficeMenuBar**
**PARENT**
* String
* **AddonMenu**: Show in menu Tools->Add-Ons
* **OfficeMenuBar**: Show in LibreOffice menu
Example:
.. code-block:: python
PARENT = 'OfficeMenuBar'
Main menu
^^^^^^^^^
Only for normal extension (`TYPE_EXTENSION = 1`) and only if parent menu is `OfficeMenuBar`. Can be multi language.
**MENU_MAIN**
* Dictionary
Example:
.. code-block:: python
MENU_MAIN = {
'en': 'My Extension',
'es': 'Mi Extensión',
}
Menus
^^^^^
Each menu for show in parent menu.
**MENUS**
* Tuple of dictionaries
* **title** = Label showed, can be multi language.
* **argument** = Argument to pass to extension, not use spaces.
* **context** = In what applications show, if is blank, show in all.
* **icon** = Icon to add, the icon should be in format BMP. The name should be NAME_16.bmp or NAME_26.bmp. Set only NAME in this property.
* **toolbar** = It is True, add to new toolbar too, used same icon.
* **shortcut** = Shortcut keyboard for this menu. For `Shift+Ctrl+Alt+T` used: `T_SHIFT_MOD1_MOD2`
Example:
.. code-block:: python
MENUS = (
{
'title': {'en': 'Option 1', 'es': 'Opción 1'},
'argument': 'option1',
'context': 'calc,writer',
'icon': 'icon',
'toolbar': True,
'shortcut': 'T_SHIFT_MOD1_MOD2',
},
)
Functions
^^^^^^^^^
Only for Add-in extension (`TYPE_EXTENSION = 2`). Can be multi language.
The key of dictionary, is the same name of your function. Used exactly you used in your code.
**FUNCTIONS**
* Dictionary of dictionaries
* **displayname** = Show in function wizard, multi language.
* **description** = Show in function wizard, multi language.
* **parameters** = Each parameters in your function.
* **key** = Is the exactly name for parameter in your code function.
* **displayname** = Show in function wizard, multi language.
* **description** = Show in function wizard, multi language.
Example:
.. code-block:: python
FUNCTIONS = {
'test': {
'displayname': {'en': 'test', 'es': 'prueba'},
'description': {'en': 'My test', 'es': 'Mi prueba'},
'parameters': {
'value': {
'displayname': {'en': 'value', 'es': 'valor'},
'description': {'en': 'The value', 'es': 'El valor'},
},
},
},
}
Default program
^^^^^^^^^^^^^^^
Optional. Open automatically when install and test.
**PROGRAM**
* String
* --calc
* --writer
* --draw
* --impress
Example:
.. code-block:: python
PROGRAM = '--calc'
File test
^^^^^^^^^
Optional. Open automatically when install and test.
* String
Example:
.. code-block:: python
FILE_TEST = '/home/mau/example.ods'
Paths
^^^^^
Paths for install and test. `idlc`, `include` and `remerge` only used en `TYPE_EXTENSION` 2 or 3. `idlc` and path `include` is installed with LibreOffice SDK.
**PATHS**
* Dictionary
* **idlc** for generate files urd.
* **include** path with files idl.
* **remerge** for generate files rdb.
* **soffice** for open LibreOffice.
* **install** for install extension.
Example:
.. code-block:: python
PATHS = {
'idlc': '/usr/lib/libreoffice/sdk/bin/idlc',
'include': '/usr/share/idl/libreoffice',
'regmerge': '/usr/lib/libreoffice/program/regmerge',
'soffice': ('soffice', PROGRAM, FILE_TEST),
'install': ('unopkg', 'add', '-v', '-f', '-s'),
}
.. _Semantic Versioning: https://semver.org/

View File

@ -0,0 +1,34 @@
Library easymacro.py
====================
**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.
**IMPORTANT**: Majority objects are custom objects, you can always get original UNO object with property `obj`
.. code-block:: python
doc = app.active
app.msgbox(doc)
app.msgbox(doc.obj)
.. toctree::
:maxdepth: 2
:caption: Contents:
tools_for_debug.rst
tools.rst
paths.rst
email.rst
application.rst
calc.rst
writer.rst
base.rst

20
doc/build/_sources/main/email.rst.txt vendored Normal file
View File

@ -0,0 +1,20 @@
Email
-----
Remember, always import library.
.. code-block:: python
import easymacro as app
Send email
^^^^^^^^^^
.. code-block:: python
app.msgbox(app.OS)
.. _cryptography: https://github.com/pyca/cryptography

View File

@ -0,0 +1,15 @@
Examples
========
Examples of macros used in production.
.. toctree::
:maxdepth: 2
:caption: Contents:
examples_app.rst
examples_calc.rst
examples_writer.rst
examples_draw.rst
examples_base.rst

View File

@ -0,0 +1,47 @@
For Application
---------------
Make custom menu
^^^^^^^^^^^^^^^^
Macro example in library ``mymacros``
.. code-block:: python
def show_info_debug():
app.msgbox(app.INFO_DEBUG)
return
Insert custom menu in menu Tools in Calc.
.. code-block:: python
def insert_menu_in_calc():
menus = app.menus['calc']
data = {
'Label': 'My Macros',
'CommandURL': 'zaz.my.macros',
'Index': 0,
'Submenu': [
{
'Label': 'Show info debug',
'CommandURL': {'library': 'mymacros', 'name': 'show_info_debug'},
'ShortCut': 'Ctrl+Shift+Alt+M'
},
],
}
menus.insert('Tools', data)
return
Delete menu
^^^^^^^^^^^
.. code-block:: python
def delete_menu():
menus = app.menus['calc']
menus.remove('Tools', 'zaz.my.macros')
return

View File

@ -0,0 +1,100 @@
For Base
--------
You need install ``peewee``
``pip install -U peewee``
Create table
^^^^^^^^^^^^
.. code-block:: python
import easymacro as app
from peewee import *
database_proxy = DatabaseProxy()
class BaseModel(Model):
class Meta:
database = database_proxy
legacy_table_names = False
class Contacts(BaseModel):
id = IdentityField()
name = CharField()
born = app.BaseDateField(null=True)
def create_table():
path = '/home/mau/test.odb'
if app.paths.exists(path):
db = app.docs.connect(path)
else:
db = app.docs.new('base', {'path': path})
tables = [Contacts]
db.initialize(database_proxy, tables)
return
Insert data
^^^^^^^^^^^
.. code-block:: python
def base_insert_data():
path = '/home/mau/test.odb'
db = app.docs.connect(path)
db.initialize(database_proxy)
rows = (
dict(name = 'Ingrid Bergman', born=app.dates.date(2001, 1, 1)),
dict(name = 'Sofia Loren', born=app.dates.date(2002, 2, 2)),
dict(name = 'Kim Novak', born=app.dates.date(2003, 3, 3)),
dict(name = 'Jane Fonda', born=app.dates.date(2004, 4, 4)),
dict(name = 'Marion Cotillar', born=app.dates.date(2005, 5, 5)),
)
for row in rows:
Contactos.insert(**row).execute()
return
Select data
^^^^^^^^^^^
.. code-block:: python
def base_select_data():
path = '/home/mau/test.odb'
db = app.docs.connect(path)
db.initialize(database_proxy)
query = Contactos.select()
rows = db.get_query(query).tuples
for row in rows:
print(row)
rows = db.get_query(query).dicts
for row in rows:
print(row)
return
You can get tuples or dict::
(1, 'Ingrid Bergman', datetime.date(2001, 1, 1))
(2, 'Sofia Loren', datetime.date(2002, 2, 2))
(3, 'Kim Novak', datetime.date(2003, 3, 3))
(4, 'Jane Fonda', datetime.date(2004, 4, 4))
(5, 'Marion Cotillar', datetime.date(2005, 5, 5))
{'id': 1, 'name': 'Ingrid Bergman', 'born': datetime.date(2001, 1, 1)}
{'id': 2, 'name': 'Sofia Loren', 'born': datetime.date(2002, 2, 2)}
{'id': 3, 'name': 'Kim Novak', 'born': datetime.date(2003, 3, 3)}
{'id': 4, 'name': 'Jane Fonda', 'born': datetime.date(2004, 4, 4)}
{'id': 5, 'name': 'Marion Cotillar', 'born': datetime.date(2005, 5, 5)}

View File

@ -0,0 +1,23 @@
For Calc
--------
Data to cell
^^^^^^^^^^^^
Automatic calculate size range.
.. code-block:: python
def calc_data_to_cell():
sheet = app.active_sheet
data = (
('Month', 'Total'),
('January', 100),
('February', 200),
('March', 300),
('April', 400),
('May', 500),
)
sheet['A1'].data = data
return

View File

@ -0,0 +1,27 @@
For Draw
-----------------
Save image from clipboard
^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
def save_image_from_clipboard():
# 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

View File

@ -0,0 +1,14 @@
For Writer
-------------------
Set autostyle in table
^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
def writer_table_set_style():
doc = app.active
table = doc.tables[0]
table.style = 'Academic'
return

86
doc/build/_sources/main/intro.rst.txt vendored Normal file
View File

@ -0,0 +1,86 @@
Introduction
============
Overview
--------
ZAZ is a script for rapid develop extensions and macros for `LibreOffice`_, in
`Python`_ of course.
With ZAZ, you can create:
* Extensions for final user
* New components for used from Basic
* AddIn, new functions for Calc
Requirements
------------
* Python 3.7+
* LibreOffice 7.0+ with support for macros Python
* LibreOffice SDK, for new components and Add-In
In:
* ArchLinux
* ``sudo pacman -S libreoffice-fresh-sdk``
* Ubuntu 20.04+
* ``sudo apt install libreoffice-script-provider-python libreoffice-dev``
Installation
------------
* Clone this repository (recommended) or download it.
``git clone https://git.cuates.net/elmau/zaz.git``
* Move to.
``cd zaz/source``
* Start new extension.
``./zaz.py -new -t ~/projects -n MyFirstExtension``
My first extension
------------------
* Move to:
``cd ~/projects/MyFirstExtension``
* Create:
``python zaz.py -c``::
↪ python zaz.py -c
04/02/2021 23:07:50 - INFO - Created directories...
04/02/2021 23:07:50 - INFO - Created files...
04/02/2021 23:07:50 - INFO - Don't forget generate DOMAIN.pot for locales
04/02/2021 23:07:50 - INFO - New extension: MyFirstExtension make successfully...
Now, you can install and test: zaz.py -i
* Install and test:
``python zaz.py -i``::
↪ python zaz.py -i
04/02/2021 23:11:40 - INFO - Don't forget generate DOMAIN.pot for locales
04/02/2021 23:11:40 - INFO - Compress OXT extension...
04/02/2021 23:11:40 - INFO - Extension OXT created successfully...
Copying: MyFirstExtension_v0.1.0.oxt
unopkg done.
04/02/2021 23:11:41 - INFO - Install extension successfully...
04/02/2021 23:11:41 - INFO - Start LibreOffice...
04/02/2021 23:11:53 - INFO - Extension make successfully...
.. _LibreOffice: https://libreoffice.org
.. _Python: https://python.org

449
doc/build/_sources/main/paths.rst.txt vendored Normal file
View File

@ -0,0 +1,449 @@
Paths and files
---------------
Remember, always import library.
.. code-block:: python
import easymacro as app
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.size)
app.debug(p.url)
Or get information in a tuple
.. code-block:: python
path = '/home/mau/myfile.ods'
p = app.paths(path)
app.msgbox(p.info)
Exists path
^^^^^^^^^^^
.. code-block:: python
path = '/home/mau/test'
app.msgbox(app.paths.exists(path))
Path is file
^^^^^^^^^^^^
.. code-block:: python
path = '/home/mau/myfile.ott'
app.msgbox(app.paths.is_file(path))
Path is dir
^^^^^^^^^^^
.. code-block:: python
path = '/home/mau'
app.msgbox(app.paths.is_dir(path))
Get path home
^^^^^^^^^^^^^
.. code-block:: python
path = app.paths.home
app.msgbox(path)
Get path documents
^^^^^^^^^^^^^^^^^^
* Configurate in LibreOffice Paths
.. code-block:: python
path = app.paths.documents
app.msgbox(path)
Get path temp
^^^^^^^^^^^^^
.. code-block:: python
path = app.paths.temp_dir
app.msgbox(path)
Get path from LibreOffice configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* Default get path documents.
.. code-block:: python
path = app.paths.config()
app.msgbox(path)
* All options in `API XPathSettings`_
.. code-block:: python
path = app.paths.config('Config')
app.msgbox(path)
Get path executable python
^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
path_python = app.paths.python
app.msgbox(path_python)
Save and read text data
^^^^^^^^^^^^^^^^^^^^^^^
* Default encoding is UTF8
.. code-block:: python
data = """Do you want to know who you are? Don't ask. Act!
Action will delineate and define you.
Thomas Jefferson
"""
path = '/home/mau/temp.txt'
app.paths.save(path, data)
data = app.paths.read(path)
app.msgbox(data)
* Change encoding
.. code-block:: python
app.paths.save(path, data, 'iso-8859-1')
Save and read binary data
^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
data = b'Binary data'
path = '/home/mau/temp.bin'
app.paths.save_bin(path, data)
data = app.paths.read_bin(path)
app.msgbox(data)
Join paths
^^^^^^^^^^
.. code-block:: python
path_home = app.paths.home
file_name = 'test.ods'
path = app.paths.join(path_home, file_name)
app.msgbox(path)
Get a temporal path
^^^^^^^^^^^^^^^^^^^
.. code-block:: python
path_temp = app.paths.tmp()
app.msgbox(path_temp)
* Get with extension.
.. code-block:: python
path_temp = app.paths.tmp('.txt')
app.msgbox(path_temp)
* Save data in a temporal path
.. code-block:: python
data = """He who receives an idea from me,
receives instruction himself without lessening mine;
as he who lights his taper at mine,
receives light without darkening me.
Thomas Jefferson
"""
path_tmp = app.paths.save_tmp(data)
app.msgbox(path_tmp)
Get a temporal dir
^^^^^^^^^^^^^^^^^^
* All content and directory is deleted when exit context.
.. code-block:: python
data = """Do you want to know who you are? Don't ask. Act!
Action will delineate and define you.
Thomas Jefferson
"""
with app.paths.dir_tmp() as dt:
app.debug(app.paths.exists(dt))
path = app.paths.join(dt, 'test.txt')
app.paths.save(path, data)
app.debug(app.paths.exists(dt))
Get path for save
^^^^^^^^^^^^^^^^^
* Default open in user documents.
.. code-block:: python
path = app.paths.get()
app.msgbox(path)
* Open in other path.
.. code-block:: python
path_tmp = app.paths.temp_dir
path = app.paths.get(path_tmp)
app.msgbox(path)
* Add one filter
.. code-block:: python
path = app.paths.get(filters='xml')
app.msgbox(path)
* Add multiple filters
.. code-block:: python
path = app.paths.get(filters='xml,txt')
Select directory
^^^^^^^^^^^^^^^^
* Default open in user documents.
.. code-block:: python
path_dir = app.paths.get_dir()
app.msgbox(path_dir)
* Open in other path.
.. code-block:: python
path_tmp = app.paths.temp_dir
path_dir = app.paths.get_dir(path_tmp)
app.msgbox(path_dir)
Get path exists file
^^^^^^^^^^^^^^^^^^^^
* Default open in user documents.
.. code-block:: python
path_file = app.paths.get_file()
app.msgbox(path_file)
* Change init dir.
.. code-block:: python
path = '/home/mau'
path_file = app.paths.get_file(path)
app.msgbox(path_file)
* Add filter or filters.
.. code-block:: python
path_file = app.paths.get_file(filters='ods')
# or
path_file = app.paths.get_file(filters='ods,odt')
* Can select multiple files.
.. code-block:: python
path_file = app.paths.get_file(multiple=True)
Replace extension
^^^^^^^^^^^^^^^^^
.. code-block:: python
path = '/home/mau/myFile.ods'
path_new = app.paths.replace_ext(path, 'pdf')
app.msgbox(path_new)
Path in format URL <-> System
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
path = '/home/mau/myFile.ods'
path_url = app.paths.to_url(path)
app.msgbox(path_url)
path = app.paths.to_system(path_url)
app.msgbox(path)
Delete files and directories
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**CAUTION**: Delete files and directories immediately, always confirm this action.
.. code-block:: python
path = '/home/mau/temp.bin'
result = app.paths.kill(path)
app.msgbox(result)
* Delete directory and all content.
.. code-block:: python
path = '/home/mau/safe_for_delete'
result = app.paths.kill(path)
app.msgbox(result)
Get files
^^^^^^^^^
This method use library `pathlib`
* Get files not recursively
.. code-block:: python
path = '/home/mau/Documents'
files = app.paths.files(path)
for f in files:
app.debug(f)
* Add filter
.. code-block:: python
files = app.paths.files(path, '*.pdf')
* Get from this directory and all subdirectories, recursively
.. code-block:: python
files = app.paths.files(path, '**/*.pdf')
This method use `os.walk`
* Get content files recursively
.. code-block:: python
path = '/home/mau/Documents'
files = app.paths.walk(path)
for f in files:
app.debug(f)
* Add filters
.. code-block:: python
files = app.paths.walk(path, 'ods')
# or filters
files = app.paths.walk(path, 'ods|odt')
Get directories
^^^^^^^^^^^^^^^
This method use library `pathlib`
* Get directories in path not recursively
.. code-block:: python
path = '/home/mau/Documents'
folders = app.paths.dirs(path)
for f in folders:
app.debug(f)
This method use `os.walk`
* Get directories in path recursively
.. code-block:: python
path = '/home/mau/Documents'
folders = app.paths.walk_dirs(path)
for f in folders:
app.debug(f)
* Get info in a tuple (ID_FOLDER, ID_PARENT, NAME)
.. code-block:: python
path = '/home/mau/Documents'
folders = app.paths.walk_dirs(path, True)
for f in folders:
app.debug(f)
Get install path from id extension
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
id_ext = 'net.elmau.zaz.EasyMacro'
path = app.paths.from_id(id_ext)
app.debug(path)
.. code-block:: bash
24/06/2021 21:47:29 - DEBUG - /home/mau/.config/libreoffice/4/user/uno_packages/cache/uno_packages/lu20665x29msz.tmp_/ZAZEasyMacro_v0.1.0.oxt
.. _API XPathSettings: http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1util_1_1XPathSettings.html

511
doc/build/_sources/main/tools.rst.txt vendored Normal file
View File

@ -0,0 +1,511 @@
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)
* In Mac
.. code-block:: python
app.msgbox(app.IS_MAC)
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)
Date and times
^^^^^^^^^^^^^^
* Get today
.. code-block:: python
app.msgbox(app.today())
* Get now
.. code-block:: python
app.msgbox(app.now())
* Get now only time
.. code-block:: python
app.msgbox(app.now(True))
* Get `epoch time`_
.. code-block:: python
app.msgbox(app.get_epoch())
* Simple measure time
.. code-block:: python
app.start()
app.sleep(5)
seconds = app.end(True)
app.msgbox(seconds)
Thread
^^^^^^
You can execute any macro in thread
* Normal execution
.. code-block:: python
def show_time(seconds):
app.sleep(seconds)
app.msgbox(app.NAME)
return
def main(args=None):
show_time(5)
app.msgbox('Finish...')
return
* Run in thread
.. code-block:: python
@app.run_in_thread
def show_time(seconds):
app.sleep(seconds)
app.msgbox(app.NAME)
return
def main(args=None):
show_time(5)
app.msgbox('Finish...')
return
Dictionary <-> properties
^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
args = {
'Hidden': True,
'Password': 'letmein',
}
properties = app.dict_to_property(args)
app.msgbox(properties)