Add documentation for application
This commit is contained in:
parent
bac62657f9
commit
79d44763f6
|
@ -9,6 +9,34 @@ Remember, always import library.
|
|||
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
|
||||
^^^^^^^^^^^
|
||||
|
||||
|
@ -110,6 +138,21 @@ With arguments.
|
|||
.. code-block:: python
|
||||
|
||||
path = '/home/mau/example.odt'
|
||||
args= {'Password': 'letmein'}
|
||||
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
|
||||
|
|
|
@ -8,6 +8,18 @@ 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:
|
||||
|
|
|
@ -9,8 +9,8 @@ Remember, always import library.
|
|||
import easymacro as app
|
||||
|
||||
|
||||
**Info from PC**
|
||||
^^^^^^^^^^^^^^^^
|
||||
Info from PC
|
||||
^^^^^^^^^^^^
|
||||
|
||||
* Operate system
|
||||
|
||||
|
@ -73,16 +73,16 @@ Remember, always import library.
|
|||
app.msgbox(app.IS_MAC)
|
||||
|
||||
|
||||
**Message box**
|
||||
^^^^^^^^^^^^^^^
|
||||
Message Box
|
||||
^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
app.msgbox(app.IS_WIN, 'My Macro')
|
||||
|
||||
|
||||
**Show warning**
|
||||
^^^^^^^^^^^^^^^^
|
||||
Show warning
|
||||
^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -91,8 +91,8 @@ Remember, always import library.
|
|||
app.warning(message, title)
|
||||
|
||||
|
||||
**Show error box**
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
Show error box
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -101,8 +101,8 @@ Remember, always import library.
|
|||
app.errorbox(message, title)
|
||||
|
||||
|
||||
**Make question**
|
||||
^^^^^^^^^^^^^^^^^
|
||||
Make question
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -112,8 +112,8 @@ Remember, always import library.
|
|||
app.msgbox(result)
|
||||
|
||||
|
||||
**InputBox**
|
||||
^^^^^^^^^^^^
|
||||
InputBox
|
||||
^^^^^^^^
|
||||
|
||||
* Normal data
|
||||
|
||||
|
@ -139,25 +139,8 @@ Remember, always import library.
|
|||
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**
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
Paths and files
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
* Get info path
|
||||
|
||||
|
@ -203,8 +186,8 @@ Or get information in a tuple
|
|||
app.debug(path)
|
||||
|
||||
|
||||
**Date and times**
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
Date and times
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
* Get today
|
||||
|
||||
|
@ -225,4 +208,94 @@ Or get information in a tuple
|
|||
app.msgbox(app.now(True))
|
||||
|
||||
|
||||
.. _MRI: https://github.com/hanya/MRI
|
||||
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)
|
||||
|
||||
data = app.data_to_dict(properties)
|
||||
|
||||
app.msgbox(data)
|
||||
|
||||
|
||||
Tuples or lists to dictionary
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
tuple_of_tuples = (
|
||||
('Hidden', True),
|
||||
('Password', 'letmein'),
|
||||
)
|
||||
data = app.data_to_dict(tuple_of_tuples)
|
||||
app.msgbox(data)
|
||||
|
||||
list_of_lists = [
|
||||
['Hidden', True],
|
||||
['Password', 'letmein'],
|
||||
]
|
||||
data = app.data_to_dict(list_of_lists)
|
||||
app.msgbox(data)
|
||||
|
||||
|
||||
Json
|
||||
^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
data = {
|
||||
'Hidden': True,
|
||||
'Password': 'letmein',
|
||||
}
|
||||
|
||||
json = app.json_dumps(data)
|
||||
|
||||
app.msgbox(json)
|
||||
|
||||
data = app.json_loads(json)
|
||||
|
||||
app.msgbox(data)
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
Tools for debug
|
||||
---------------
|
||||
|
||||
**INFO_DEBUG**
|
||||
^^^^^^^^^^^^^^
|
||||
INFO_DEBUG
|
||||
^^^^^^^^^^
|
||||
|
||||
Show info debug, show in message box.
|
||||
|
||||
|
@ -29,8 +29,8 @@ Show in shell.
|
|||
return
|
||||
|
||||
|
||||
**Log error**
|
||||
^^^^^^^^^^^^^
|
||||
Log error
|
||||
^^^^^^^^^
|
||||
|
||||
Show error message in shell.
|
||||
|
||||
|
@ -44,8 +44,8 @@ Show error message in shell.
|
|||
return
|
||||
|
||||
|
||||
**Log debug**
|
||||
^^^^^^^^^^^^^
|
||||
Log debug
|
||||
^^^^^^^^^
|
||||
|
||||
Show debug message in shell.
|
||||
|
||||
|
@ -59,8 +59,8 @@ Show debug message in shell.
|
|||
return
|
||||
|
||||
|
||||
**Log info**
|
||||
^^^^^^^^^^^^
|
||||
Log info
|
||||
^^^^^^^^
|
||||
|
||||
Show info message in shell.
|
||||
|
||||
|
@ -74,8 +74,8 @@ Show info message in shell.
|
|||
return
|
||||
|
||||
|
||||
**Log to file**
|
||||
^^^^^^^^^^^^^^^
|
||||
Log to file
|
||||
^^^^^^^^^^^
|
||||
|
||||
Save log to file, automatic add date and time.
|
||||
|
||||
|
@ -90,8 +90,8 @@ Save log to file, automatic add date and time.
|
|||
|
||||
|
||||
|
||||
**Message box**
|
||||
^^^^^^^^^^^^^^^
|
||||
Message box
|
||||
^^^^^^^^^^^
|
||||
|
||||
Show any data in message box
|
||||
|
||||
|
@ -115,8 +115,8 @@ Show any data in message box
|
|||
return
|
||||
|
||||
|
||||
**Catch exceptions**
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
Catch exceptions
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
Sometimes, for difficult errors, you can catch exceptions.
|
||||
|
||||
|
@ -132,8 +132,8 @@ Sometimes, for difficult errors, you can catch exceptions.
|
|||
And not, not used you this function in production.
|
||||
|
||||
|
||||
**Call MRI**
|
||||
^^^^^^^^^^^^
|
||||
Call MRI
|
||||
^^^^^^^^
|
||||
|
||||
`MRI`_ is the better extension for debug any object in LibreOffice, you need
|
||||
install before call it.
|
||||
|
|
|
@ -491,10 +491,10 @@ def json_loads(data):
|
|||
|
||||
|
||||
def data_to_dict(data):
|
||||
if isinstance(data, tuple) and isinstance(data[0], tuple):
|
||||
if isinstance(data, (tuple, list)) and isinstance(data[0], (tuple, list)):
|
||||
return _array_to_dict(data)
|
||||
|
||||
if isinstance(data, tuple) and isinstance(data[0], (PropertyValue, NamedValue)):
|
||||
if isinstance(data, (tuple, list)) and isinstance(data[0], (PropertyValue, NamedValue)):
|
||||
return _property_to_dict(data)
|
||||
return {}
|
||||
|
||||
|
@ -507,6 +507,8 @@ def _get_dispatch() -> Any:
|
|||
# ~ Used only if not exists in API
|
||||
def call_dispatch(frame: Any, url: str, args: dict={}) -> None:
|
||||
dispatch = _get_dispatch()
|
||||
if hasattr(frame, 'frame'):
|
||||
frame = frame.frame
|
||||
opt = dict_to_property(args)
|
||||
dispatch.executeDispatch(frame, url, '', 0, opt)
|
||||
return
|
||||
|
@ -585,7 +587,7 @@ def _call_macro(args: dict):
|
|||
|
||||
return result
|
||||
|
||||
|
||||
# ~ TODO
|
||||
def call_macro(args, in_thread=False):
|
||||
result = None
|
||||
if in_thread:
|
||||
|
|
Loading…
Reference in New Issue