Start doc for API
This commit is contained in:
parent
796257d444
commit
3e0fb188e2
|
@ -1,4 +1,5 @@
|
||||||
__pycache__
|
__pycache__
|
||||||
*.pyc
|
*.pyc
|
||||||
build/
|
build/
|
||||||
|
*.bk
|
||||||
|
|
||||||
|
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
|
@ -0,0 +1,7 @@
|
||||||
|
API
|
||||||
|
===
|
||||||
|
|
||||||
|
.. autosummary::
|
||||||
|
:toctree: generated
|
||||||
|
|
||||||
|
easymacro
|
|
@ -10,9 +10,9 @@
|
||||||
# add these directories to sys.path here. If the directory is relative to the
|
# 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.
|
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||||
#
|
#
|
||||||
# import os
|
import os
|
||||||
# import sys
|
import sys
|
||||||
# sys.path.insert(0, os.path.abspath('.'))
|
sys.path.insert(0, os.path.abspath('../../source'))
|
||||||
|
|
||||||
|
|
||||||
# -- Project information -----------------------------------------------------
|
# -- Project information -----------------------------------------------------
|
||||||
|
@ -20,6 +20,7 @@
|
||||||
project = 'easymacro'
|
project = 'easymacro'
|
||||||
copyright = '2022, El Mau'
|
copyright = '2022, El Mau'
|
||||||
author = 'El Mau'
|
author = 'El Mau'
|
||||||
|
release = '0.1.0'
|
||||||
|
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------------
|
# -- General configuration ---------------------------------------------------
|
||||||
|
@ -28,6 +29,8 @@ author = 'El Mau'
|
||||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||||
# ones.
|
# ones.
|
||||||
extensions = [
|
extensions = [
|
||||||
|
'sphinx.ext.autodoc',
|
||||||
|
'sphinx.ext.autosummary',
|
||||||
]
|
]
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
# Add any paths that contain templates here, relative to this directory.
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
easymacro module
|
||||||
|
================
|
||||||
|
|
||||||
|
.. automodule:: easymacro
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,52 @@
|
||||||
|
easymacro
|
||||||
|
=========
|
||||||
|
|
||||||
|
.. automodule:: easymacro
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.. rubric:: Functions
|
||||||
|
|
||||||
|
.. autosummary::
|
||||||
|
|
||||||
|
catch_exception
|
||||||
|
create_instance
|
||||||
|
debug
|
||||||
|
error
|
||||||
|
errorbox
|
||||||
|
get_app_config
|
||||||
|
info
|
||||||
|
mri
|
||||||
|
msgbox
|
||||||
|
now
|
||||||
|
question
|
||||||
|
save_log
|
||||||
|
set_app_config
|
||||||
|
today
|
||||||
|
warning
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.. rubric:: Classes
|
||||||
|
|
||||||
|
.. autosummary::
|
||||||
|
|
||||||
|
LOServer
|
||||||
|
MBT
|
||||||
|
MessageBoxType
|
||||||
|
commands
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,8 @@ You can used **easymacro** with any extension or directly in your macros.
|
||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
:caption: Contents:
|
:caption: Contents:
|
||||||
|
|
||||||
01_install
|
install
|
||||||
|
api
|
||||||
|
|
||||||
|
|
||||||
Indices and tables
|
Indices and tables
|
||||||
|
|
|
@ -38,7 +38,7 @@ copy this code:
|
||||||
|
|
||||||
and execute from LibreOffice, if you see similar next info, great!
|
and execute from LibreOffice, if you see similar next info, great!
|
||||||
|
|
||||||
.. image:: _static/images/01_install_01.png
|
.. image:: _static/images/install_01.png
|
||||||
|
|
||||||
|
|
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
source
|
||||||
|
======
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 4
|
||||||
|
|
||||||
|
easymacro
|
|
@ -38,6 +38,7 @@ from com.sun.star.awt import MessageBoxButtons as MSG_BUTTONS
|
||||||
from com.sun.star.awt.MessageBoxResults import YES
|
from com.sun.star.awt.MessageBoxResults import YES
|
||||||
from com.sun.star.beans import PropertyValue
|
from com.sun.star.beans import PropertyValue
|
||||||
|
|
||||||
|
|
||||||
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
|
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
|
||||||
LOG_DATE = '%d/%m/%Y %H:%M:%S'
|
LOG_DATE = '%d/%m/%Y %H:%M:%S'
|
||||||
logging.addLevelName(logging.ERROR, '\033[1;41mERROR\033[1;0m')
|
logging.addLevelName(logging.ERROR, '\033[1;41mERROR\033[1;0m')
|
||||||
|
@ -66,51 +67,55 @@ CTX = uno.getComponentContext()
|
||||||
SM = CTX.getServiceManager()
|
SM = CTX.getServiceManager()
|
||||||
|
|
||||||
|
|
||||||
def debug(*args) -> None:
|
# UNO Enum
|
||||||
"""
|
class MessageBoxType():
|
||||||
Show messages debug
|
from com.sun.star.awt.MessageBoxType \
|
||||||
|
import MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
|
||||||
|
MBT = MessageBoxType
|
||||||
|
|
||||||
Parameters:
|
|
||||||
args (list): iterable messages for show
|
def debug(*messages) -> None:
|
||||||
|
"""Show messages debug
|
||||||
|
|
||||||
|
:param messages: List of messages to debug
|
||||||
|
:type messages: list[Any]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = [str(a) for a in args]
|
data = [str(m) for m in messages]
|
||||||
log.debug('\t'.join(data))
|
log.debug('\t'.join(data))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def error(message: Any) -> None:
|
def error(message: Any) -> None:
|
||||||
"""
|
"""Show message error
|
||||||
Show message error
|
|
||||||
|
|
||||||
Parameters:
|
:param message: The message error
|
||||||
message (Any): message show error
|
:type message: Any
|
||||||
"""
|
"""
|
||||||
|
|
||||||
log.error(message)
|
log.error(message)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def info(*args) -> None:
|
def info(*messages) -> None:
|
||||||
"""
|
"""Show messages info
|
||||||
Show messages info
|
|
||||||
|
|
||||||
Parameters:
|
:param messages: List of messages to debug
|
||||||
args (list): iterable messages for show
|
:type messages: list[Any]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = [str(a) for a in args]
|
data = [str(m) for m in messages]
|
||||||
log.info('\t'.join(data))
|
log.info('\t'.join(data))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def save_log(path: str, data: Any) -> None:
|
def save_log(path: str, data: Any) -> None:
|
||||||
"""
|
"""Save data in file, data append to end and automatic add current time.
|
||||||
Save data in file, data append to end
|
|
||||||
|
|
||||||
Parameters:
|
:param path: Path to save log
|
||||||
path (str): path to save
|
:type path: str
|
||||||
data (Any): any info data
|
:param data: Data to save in file log
|
||||||
|
:type data: Any
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with open(path, 'a') as f:
|
with open(path, 'a') as f:
|
||||||
|
@ -119,32 +124,111 @@ def save_log(path: str, data: Any) -> None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def create_instance(name: str, with_context: bool=False, args: Any=None) -> Any:
|
def create_instance(name: str, with_context: bool=False, argument: Any=None) -> Any:
|
||||||
|
"""Create a service instance
|
||||||
|
|
||||||
|
:param name: Name of service
|
||||||
|
:type name: str
|
||||||
|
:param with_context: If used context
|
||||||
|
:type with_context: bool
|
||||||
|
:param argument: If needed some argument
|
||||||
|
:type argument: Any
|
||||||
|
:return: PyUno instance
|
||||||
|
:rtype: PyUno Object
|
||||||
|
"""
|
||||||
|
|
||||||
if with_context:
|
if with_context:
|
||||||
instance = SM.createInstanceWithContext(name, CTX)
|
instance = SM.createInstanceWithContext(name, CTX)
|
||||||
elif args:
|
elif argument:
|
||||||
instance = SM.createInstanceWithArguments(name, (args,))
|
instance = SM.createInstanceWithArguments(name, (argument,))
|
||||||
else:
|
else:
|
||||||
instance = SM.createInstance(name)
|
instance = SM.createInstance(name)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
def get_app_config(node_name: str, key: str='', update: bool=False):
|
def get_app_config(node_name: str, key: str='') -> Any:
|
||||||
|
"""Get any key from any node from LibreOffice configuration.
|
||||||
|
|
||||||
|
:param node_name: Name of node
|
||||||
|
:type name: str
|
||||||
|
:param key: Name of key
|
||||||
|
:type key: str
|
||||||
|
:return: Any value
|
||||||
|
:rtype: Any
|
||||||
|
|
||||||
|
`See Api ConfigurationProvider <https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1configuration_1_1ConfigurationProvider.html>`_
|
||||||
|
"""
|
||||||
|
|
||||||
name = 'com.sun.star.configuration.ConfigurationProvider'
|
name = 'com.sun.star.configuration.ConfigurationProvider'
|
||||||
service = 'com.sun.star.configuration.ConfigurationAccess'
|
service = 'com.sun.star.configuration.ConfigurationAccess'
|
||||||
if update:
|
|
||||||
service = 'com.sun.star.configuration.ConfigurationUpdateAccess'
|
|
||||||
cp = create_instance(name, True)
|
cp = create_instance(name, True)
|
||||||
node = PropertyValue(Name='nodepath', Value=node_name)
|
node = PropertyValue(Name='nodepath', Value=node_name)
|
||||||
|
value = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ca = cp.createInstanceWithArguments(service, (node,))
|
value = cp.createInstanceWithArguments(service, (node,))
|
||||||
if ca and not key:
|
if value and value.hasByName(key):
|
||||||
return ca
|
value = value.getPropertyValue(key)
|
||||||
if ca and ca.hasByName(key):
|
|
||||||
return ca.getPropertyValue(key)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error(e)
|
error(e)
|
||||||
return ''
|
value = ''
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def set_app_config(node_name: str, key: str, new_value: Any) -> Any:
|
||||||
|
result = True
|
||||||
|
current_value = ''
|
||||||
|
name = 'com.sun.star.configuration.ConfigurationProvider'
|
||||||
|
service = 'com.sun.star.configuration.ConfigurationUpdateAccess'
|
||||||
|
cp = create_instance(name, True)
|
||||||
|
node = PropertyValue(Name='nodepath', Value=node_name)
|
||||||
|
update = cp.createInstanceWithArguments(service, (node,))
|
||||||
|
|
||||||
|
try:
|
||||||
|
current_value = update.getPropertyValue(key)
|
||||||
|
update.setPropertyValue(key, new_value)
|
||||||
|
update.commitChanges()
|
||||||
|
except Exception as e:
|
||||||
|
error(e)
|
||||||
|
if update.hasByName(key) and current_value:
|
||||||
|
update.setPropertyValue(key, current_value)
|
||||||
|
update.commitChanges()
|
||||||
|
result = False
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def _set_app_command(command: str, disable: bool):
|
||||||
|
NEW_NODE_NAME = f'zaz_disable_command_{command.lower()}'
|
||||||
|
name = 'com.sun.star.configuration.ConfigurationProvider'
|
||||||
|
service = 'com.sun.star.configuration.ConfigurationUpdateAccess'
|
||||||
|
node_name = '/org.openoffice.Office.Commands/Execute/Disabled'
|
||||||
|
|
||||||
|
cp = create_instance(name, True)
|
||||||
|
node = PropertyValue(Name='nodepath', Value=node_name)
|
||||||
|
update = cp.createInstanceWithArguments(service, (node,))
|
||||||
|
|
||||||
|
if disable:
|
||||||
|
new_node = update.createInstanceWithArguments(())
|
||||||
|
new_node.setPropertyValue('Command', command)
|
||||||
|
update.insertByName(NEW_NODE_NAME, new_node)
|
||||||
|
else:
|
||||||
|
update.removeByName(NEW_NODE_NAME)
|
||||||
|
update.commitChanges()
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class commands():
|
||||||
|
# ~ https://wiki.documentfoundation.org/Development/DispatchCommands
|
||||||
|
def __init__(self, command):
|
||||||
|
self._command = command
|
||||||
|
def disable(self):
|
||||||
|
return _set_app_command(self._command, True)
|
||||||
|
def enabled(self):
|
||||||
|
return _set_app_command(self._command, False)
|
||||||
|
|
||||||
|
|
||||||
# Get info LibO
|
# Get info LibO
|
||||||
|
@ -162,35 +246,16 @@ day = get_app_config(node, 'DD')
|
||||||
DATE_OFFSET = datetime.date(year, month, day).toordinal()
|
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:
|
def mri(obj: Any) -> None:
|
||||||
|
"""Inspect object with MRI Extension
|
||||||
|
|
||||||
|
:param obj: Any pyUno object
|
||||||
|
:type obj: Any
|
||||||
|
|
||||||
|
`See MRI <https://github.com/hanya/MRI/releases>`_
|
||||||
"""
|
"""
|
||||||
Inspect object with MRI Extension
|
|
||||||
"""
|
mri = create_instance('mytools.Mri')
|
||||||
m = create_instance('mytools.Mri')
|
|
||||||
if m is None:
|
if m is None:
|
||||||
msg = 'Extension MRI not found'
|
msg = 'Extension MRI not found'
|
||||||
error(msg)
|
error(msg)
|
||||||
|
@ -198,11 +263,17 @@ def mri(obj: Any) -> None:
|
||||||
|
|
||||||
if hasattr(obj, 'obj'):
|
if hasattr(obj, 'obj'):
|
||||||
obj = obj.obj
|
obj = obj.obj
|
||||||
m.inspect(obj)
|
mri.inspect(obj)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def catch_exception(f):
|
def catch_exception(f):
|
||||||
|
"""Catch exception for any function
|
||||||
|
|
||||||
|
:param f: Any Python function
|
||||||
|
:type f: Function instance
|
||||||
|
"""
|
||||||
|
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def func(*args, **kwargs):
|
def func(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
@ -215,6 +286,91 @@ def catch_exception(f):
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
|
def msgbox(message: Any, title: str=TITLE, buttons=MSG_BUTTONS.BUTTONS_OK, \
|
||||||
|
type_message_box=MessageBoxType.INFOBOX) -> Any:
|
||||||
|
"""Create message box
|
||||||
|
|
||||||
|
:param message: Any type message, all is converted to string.
|
||||||
|
:type message: Any
|
||||||
|
:param title: The title for message box
|
||||||
|
:type title: str
|
||||||
|
:param buttons: A combination of `com::sun::star::awt::MessageBoxButtons <https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1awt_1_1MessageBoxButtons.html>`_
|
||||||
|
:type buttons: long
|
||||||
|
:param type_message_box: The `message box type <https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1awt.html#ad249d76933bdf54c35f4eaf51a5b7965>`_
|
||||||
|
:type type_message_box: enum
|
||||||
|
:return: Instance MessageBox
|
||||||
|
:rtype: pyUno
|
||||||
|
|
||||||
|
`See Api XMessageBoxFactory <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_message_box, buttons, title, str(message))
|
||||||
|
return box.execute()
|
||||||
|
|
||||||
|
|
||||||
|
def question(message: str, title: str=TITLE) -> Any:
|
||||||
|
"""Create message box question, show buttons YES and NO
|
||||||
|
|
||||||
|
:param message: Message question
|
||||||
|
:type message: str
|
||||||
|
:param title: The title for message box
|
||||||
|
:type title: str
|
||||||
|
:return: True if user click YES and False if click NO
|
||||||
|
:rtype: bool
|
||||||
|
"""
|
||||||
|
|
||||||
|
result = msgbox(message, title, MSG_BUTTONS.BUTTONS_YES_NO, MessageBoxType.QUERYBOX)
|
||||||
|
return result == YES
|
||||||
|
|
||||||
|
|
||||||
|
def warning(message: Any, title: str=TITLE) -> Any:
|
||||||
|
"""Create message box with icon warning
|
||||||
|
|
||||||
|
:param message: Any type message, all is converted to string.
|
||||||
|
:type message: Any
|
||||||
|
:param title: The title for message box
|
||||||
|
:type title: str
|
||||||
|
:return: Instance MessageBox
|
||||||
|
:rtype: pyUno
|
||||||
|
"""
|
||||||
|
|
||||||
|
return msgbox(message, title, type_message_box=MessageBoxType.WARNINGBOX)
|
||||||
|
|
||||||
|
|
||||||
|
def errorbox(message: Any, title: str=TITLE) -> Any:
|
||||||
|
"""Create message box with icon error
|
||||||
|
|
||||||
|
:param message: Any type message, all is converted to string.
|
||||||
|
:type message: Any
|
||||||
|
:param title: The title for message box
|
||||||
|
:type title: str
|
||||||
|
:return: Instance MessageBox
|
||||||
|
:rtype: pyUno
|
||||||
|
"""
|
||||||
|
|
||||||
|
return msgbox(message, title, type_message_box=MessageBoxType.ERRORBOX)
|
||||||
|
|
||||||
|
|
||||||
|
def now():
|
||||||
|
"""Current local date and time
|
||||||
|
|
||||||
|
:return: Return the current local date and time
|
||||||
|
:rtype: datetime
|
||||||
|
"""
|
||||||
|
return datetime.datetime.now()
|
||||||
|
|
||||||
|
|
||||||
|
def today():
|
||||||
|
"""Current local date
|
||||||
|
|
||||||
|
:return: Return the current local date
|
||||||
|
:rtype: date
|
||||||
|
"""
|
||||||
|
return datetime.date.today()
|
||||||
|
|
||||||
|
|
||||||
class LOServer(object):
|
class LOServer(object):
|
||||||
HOST = 'localhost'
|
HOST = 'localhost'
|
||||||
PORT = '8100'
|
PORT = '8100'
|
||||||
|
|
Loading…
Reference in New Issue