zaz/doc/build/_sources/main/application.rst.txt

159 lines
2.3 KiB
ReStructuredText

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