Doc for install

This commit is contained in:
El Mau 2022-02-23 22:49:43 -06:00
parent 7b18c1a8ab
commit 796257d444
8 changed files with 302 additions and 9 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
__pycache__
*.pyc
build/

20
docs/Makefile Normal file
View File

@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

35
docs/make.bat Normal file
View File

@ -0,0 +1,35 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd

View File

@ -0,0 +1,48 @@
Installation
============
Clone repository
----------------
Clone repository in your favorite folder projects.
.. code-block:: console
git clone https://git.cuates.net/elmau/easymacro
and copy library into `pythonpath` in your macros.
.. code-block:: console
/home/USER/.config/libreoffice/4/user/Scripts/python/pythonpath/easymacro.py
Test
----
In your favorite macros file, for example:
.. code-block:: console
vim /home/USER/.config/libreoffice/4/user/Scripts/python/mymacros.py
copy this code:
.. code-block:: python
import easymacro as app
def main():
app.msgbox(app.INFO_DEBUG)
return
and execute from LibreOffice, if you see similar next info, great!
.. image:: _static/images/01_install_01.png
|
you are ready for develop with **easymacro**.
Happy develop!

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

53
docs/source/conf.py Normal file
View File

@ -0,0 +1,53 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'easymacro'
copyright = '2022, El Mau'
author = 'El Mau'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
# ~ html_theme = 'alabaster'
html_theme = 'sphinx_book_theme'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

32
docs/source/index.rst Normal file
View File

@ -0,0 +1,32 @@
.. easymacro documentation master file, created by
sphinx-quickstart on Tue Feb 22 16:10:57 2022.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to easymacro's documentation!
=====================================
**easymacro** 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** with any extension or directly in your macros.
.. note::
This project is under active development.
.. toctree::
:maxdepth: 2
:caption: Contents:
01_install
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

View File

@ -18,6 +18,7 @@
# ~ along with easymacro. If not, see <https://www.gnu.org/licenses/>.
import datetime
import getpass
import logging
import os
@ -26,16 +27,17 @@ import socket
import subprocess
import sys
import time
import traceback
from functools import wraps
from pprint import pprint
from typing import Any
import uno
from com.sun.star.awt import MessageBoxButtons as MSG_BUTTONS
from com.sun.star.awt.MessageBoxResults import YES
from com.sun.star.beans import PropertyValue
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
LOG_DATE = '%d/%m/%Y %H:%M:%S'
logging.addLevelName(logging.ERROR, '\033[1;41mERROR\033[1;0m')
@ -52,6 +54,8 @@ PC = platform.node()
USER = getpass.getuser()
IS_WIN = OS == 'Windows'
IS_MAC = OS == 'Darwin'
_info_debug = f"Python: {sys.version}\n\n{platform.platform()}\n\n" + '\n'.join(sys.path)
@ -62,14 +66,56 @@ CTX = uno.getComponentContext()
SM = CTX.getServiceManager()
def debug(*args):
def debug(*args) -> None:
"""
Show messages debug
Parameters:
args (list): iterable messages for show
"""
data = [str(a) for a in args]
log.debug('\t'.join(data))
return
def error(info):
log.error(info)
def error(message: Any) -> None:
"""
Show message error
Parameters:
message (Any): message show error
"""
log.error(message)
return
def info(*args) -> None:
"""
Show messages info
Parameters:
args (list): iterable messages for show
"""
data = [str(a) for a in args]
log.info('\t'.join(data))
return
def save_log(path: str, data: Any) -> None:
"""
Save data in file, data append to end
Parameters:
path (str): path to save
data (Any): any info data
"""
with open(path, 'a') as f:
f.write(f'{str(now())[:19]} - ')
pprint(data, stream=f)
return
@ -102,14 +148,72 @@ def get_app_config(node_name: str, key: str='', update: bool=False):
# Get info LibO
NAME = get_app_config('org.openoffice.Setup/Product', 'ooName')
NAME = TITLE = get_app_config('org.openoffice.Setup/Product', 'ooName')
VERSION = get_app_config('org.openoffice.Setup/Product','ooSetupVersion')
LANGUAGE = get_app_config('org.openoffice.Setup/L10N/', 'ooLocale')
LANG = LANGUAGE.split('-')[0]
INFO_DEBUG = f"{NAME} v{VERSION} {LANGUAGE}\n\n{_info_debug}"
node = '/org.openoffice.Office.Calc/Calculate/Other/Date'
year = get_app_config(node, 'YY')
month = get_app_config(node, 'MM')
day = get_app_config(node, 'DD')
DATE_OFFSET = datetime.date(year, month, day).toordinal()
def msgbox(message: Any, title: str=TITLE, buttons=MSG_BUTTONS.BUTTONS_OK, type_msg: str='infobox') -> Any:
""" Create message box
type_msg: infobox, warningbox, errorbox, querybox, messbox
http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1awt_1_1XMessageBoxFactory.html
"""
toolkit = create_instance('com.sun.star.awt.Toolkit')
parent = toolkit.getDesktopWindow()
box = toolkit.createMessageBox(parent, type_msg, buttons, title, str(message))
return box.execute()
def question(message: Any, title: str=TITLE) -> Any:
result = msgbox(message, title, MSG_BUTTONS.BUTTONS_YES_NO, 'querybox')
return result == YES
def warning(message: Any, title: str=TITLE) -> Any:
return msgbox(message, title, type_msg='warningbox')
def errorbox(message: Any, title: str=TITLE) -> Any:
return msgbox(message, title, type_msg='errorbox')
def mri(obj: Any) -> None:
"""
Inspect object with MRI Extension
"""
m = create_instance('mytools.Mri')
if m is None:
msg = 'Extension MRI not found'
error(msg)
return
if hasattr(obj, 'obj'):
obj = obj.obj
m.inspect(obj)
return
def catch_exception(f):
@wraps(f)
def func(*args, **kwargs):
try:
return f(*args, **kwargs)
except Exception as e:
name = f.__name__
if IS_WIN:
msgbox(traceback.format_exc())
log.error(name, exc_info=True)
return func
class LOServer(object):
HOST = 'localhost'