Update doc

This commit is contained in:
Mauricio Baeza 2021-07-01 22:41:20 -05:00
commit 9f2c0999aa
35 changed files with 1567 additions and 1965 deletions

View File

@ -1,3 +1,7 @@
v 0.16.1 [01-jul-2021]
- Change property is_connected in db
- Update doc
v 0.16.0 [20-jun-2021]
- Add connection for postgres and mariadb
- Fix in call macro Basic

View File

@ -18,10 +18,12 @@ LibreOffice SDK 7.0+
#### but, don't make the mistake of many of *thinking only in gratis software* that so much damage has done to **Free Software**.
This extension have a cost of maintenance of 10 euros every year.
This extension have a cost of maintenance of 1 euros every year.
BCH: `qztd3l00xle5tffdqvh2snvadkuau2ml0uqm4n875d`
MONERO: `48ygK6NuuNAfwWfeAbeK8YP2ryPqxMAsUZBnfAhaHVkoHZ48JRYiQKKFd5GFMmaytyUpfxnyA95pWavjRgPUuKv1TUTvhkd`
BTC: `3FhiXcXmAesmQzrNEngjHFnvaJRhU1AGWV`
ETH: `0x61a4f614a30ff686445751ed8328b82b77ecfc69`
@ -33,8 +35,6 @@ You have others cryptos, welcome too!
## Extensions develop with ZAZ
* https://gitlab.com/mauriciobaeza/zaz-barcode
* https://gitlab.com/mauriciobaeza/zaz-favorite
* https://gitlab.com/mauriciobaeza/zaz-easymacro
* https://gitlab.com/mauriciobaeza/zaz-pip
* https://gitlab.com/mauriciobaeza/zaz-inspect
* https://git.cuates.net/elmau/zaz-pip
* https://git.cuates.net/elmau/zaz-favorites
* https://git.cuates.net/elmau/zaz-functions

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.

View File

@ -14,6 +14,7 @@ Welcome to ZAZ's documentation!
main/config
main/easymacro
main/examples
main/apendixes
Indices and tables

View File

@ -0,0 +1,46 @@
Apendixes
---------
Remember, always import library.
.. code-block:: python
import easymacro as app
Get all filters in Calc sheet
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* Fields in filter
.. code-block:: python
'Finalized': False,
'UIName': 'EPS - Encapsulated PostScript',
'UserData': <ByteSequence instance 'b'''>,
'TemplateName': '',
'Enabled': True,
'Mandatory': False,
'Name': 'impress_eps_Export',
'FilterService': '',
'Type': 'eps_Encapsulated_PostScript',
'UIComponent': 'com.sun.star.svtools.SvFilterOptionsDialog',
'Flags': 1090,
'FileFormatVersion': 0,
'DocumentService': 'com.sun.star.presentation.PresentationDocument',
'UINames': {
'en-US': 'EPS - Encapsulated PostScript',
'es': 'EPS - PostScript encapsulado'}
.. code-block:: python
filters = app.get_filters()
headers = (('DocumentService', 'UIName', 'Name', 'Type'),)
data = [(f['DocumentService'], f['UIName'], f['Name'], f['Type'])
for f in filters]
doc = app.docs.new()
doc[0]['A1'].data = headers
doc[0]['A2'].data = data

View File

@ -75,6 +75,16 @@ Get by name
app.msgbox(doc.title)
If contain
^^^^^^^^^^
.. code-block:: python
result = 'myfile.ods' in app.docs
app.msgbox(result)
New
^^^
@ -142,6 +152,90 @@ With arguments.
doc = app.docs.open(path, args)
Save
^^^^
.. code-block:: python
path = '/home/mau/myfile.ods'
doc = app.docs.new()
doc.save(path)
* If previously open and modify any file.
.. code-block:: python
doc.save()
* Open exists file and save with other name.
.. code-block:: python
path = '/home/mau/myfile.ods'
doc = app.docs.open(path)
new_path = '/srv/mau/other_name.ods'
doc.save(new_path)
Close
^^^^^
.. code-block:: python
doc = app.docs.new()
app.msgbox(doc.title)
doc.close()
To PDF
^^^^^^
* Save in path
.. code-block:: python
doc = app.active
path = '/home/mau/test.pdf'
doc.to_pdf(path)
* Save in memory
.. code-block:: python
doc = app.active
pdf = doc.to_pdf()
Export
^^^^^^
Fonst
^^^^^
* Get all fonts
.. code-block:: python
fonts = app.get_fonts()
for f in fonts:
print(f'Name: {f.Name} - StyleName: {f.StyleName}')
Filters
^^^^^^^
* Get all `support filters`_
.. code-block:: python
filters = app.get_filters()
ds = []
for f in filters:
data = f"UI Name: {f['UIName']} - Name: {f['Name']} - Type: {f['Type']}"
app.debug(data)
Call dispatch
^^^^^^^^^^^^^
@ -154,5 +248,17 @@ You can call any `dispatch command`_ used only if property or method no exists i
app.call_dispatch(doc, command)
Properties
^^^^^^^^^^
Title
~~~~~
.. code-block:: python
doc = app.active
app.msgbox(doc.title)
.. _dispatch command: https://wiki.documentfoundation.org/Development/DispatchCommands
.. _support filters: https://help.libreoffice.org/latest/en-US/text/shared/guide/convertfilters.html

View File

@ -9,12 +9,103 @@ Remember, always import library.
import easymacro as app
**IMPORTANT:** Always save your config the more security way possible.
Send email
^^^^^^^^^^
.. code-block:: python
app.msgbox(app.OS)
from conf import PASSWORD
SERVER = dict(
server = 'mail.server.net' ,
port = 495,
ssl = True,
user = 'no-responder@noexiste.mx',
password = PASSWORD,
)
body = "Hello Ingrid\n\nWho are you?\n\nBest regards"
message = dict(
to = 'ingrid.bergman@love.you',
subject = 'I love you',
body = body,
)
app.send_email(SERVER, message)
* We can use fields `cc`, `bcc` too and send to more than one address emails.
.. code-block:: python
to = 'mail1@correo.com,mail2@correo.com,mail3@correo.com'
cc = 'other@correo.com'
bcc = 'hidden@correo.com'
* We can send too more than one message.
.. code-block:: python
message1 = dict(
to = 'ingrid.bergman@email.net',
subject = 'I love you',
body = "Hello Ingrid\n\nWho are you?\n\nBest regards",
)
message2 = dict(
to = 'sophia.loren@email.net',
subject = 'I love you',
body = "Hello Sophia\n\nWho are you?\n\nBest regards",
)
messages = (message1, message2)
app.send_email(SERVER, messages)
.. code-block:: bash
30/06/2021 13:43:23 - DEBUG - Connect to: mail.gandi.net
30/06/2021 13:43:24 - DEBUG - Email sent...
30/06/2021 13:43:26 - DEBUG - Email sent...
30/06/2021 13:43:26 - DEBUG - Close connection...
* Send with attachment
.. code-block:: python
files = '/home/mau/file.epub'
message = dict(
to = 'ingrid.bergman@email.net',
subject = 'I love you',
body = "Hello Ingrid\n\nWho are you?\n\nBest regards",
files = files,
)
* Send more than one file.
.. code-block:: python
files = (
'/home/mau/file1.epub',
'/home/mau/file2.epub',
)
* If your client email used `mbox` format, we can save in any path into your email client configuration.
.. code-block:: python
path_save = '/home/mau/.thunderbird/7iznrbyw.default/Mail/Local Folders/LibreOffice'
message = dict(
to = 'ingrid.bergman@email.net',
subject = 'I love you',
body = "Hello Ingrid\n\nWho are you?\n\nBest regards",
path = path_save
)
app.send_email(SERVER, message)
* All emails always send in other thread.
.. _cryptography: https://github.com/pyca/cryptography

View File

@ -432,7 +432,7 @@ This method use `os.walk`
app.debug(f)
Get install path from id extension
Get install path extension from id
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
@ -446,4 +446,169 @@ Get install path from id extension
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
Verify if application exists
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
app_name = 'nosoffice'
app.msgbox(app.paths.exists_app(app_name))
app_name = 'soffice'
app.msgbox(app.paths.exists_app(app_name))
Open any type file
^^^^^^^^^^^^^^^^^^
Open with default application in OS.
.. code-block:: python
path = '/home/mau/Downloads/file.pdf'
app.paths.open(path)
path = '/home/mau/Projects/libre_office/zaz/doc/build/index.html'
app.paths.open(path)
Save and read json
^^^^^^^^^^^^^^^^^^
.. code-block:: python
path = '/home/mau/data.json'
data = {
'type': 'calc',
'name': 'myfile.ods',
}
app.paths.to_json(path, data)
data = app.paths.from_json(path)
app.msgbox(data)
Save and read csv
^^^^^^^^^^^^^^^^^
You can used the same way that `python csv`_
.. code-block:: python
path = '/home/mau/data.csv'
data = (
(1, 'one', app.now()),
(2, 'two', app.now()),
(3, 'three', app.now()),
)
app.paths.to_csv(path, data)
data = app.paths.from_csv(path)
app.msgbox(data)
Zip, unzip
^^^^^^^^^^
For default, save in the same directory with the same name + `.zip`
* Zip file
.. code-block:: python
source = '/home/mau/logo.svg'
path_zip = app.paths.zip(source)
app.debug(path_zip)
* Zip directory
.. code-block:: python
source = '/home/mau/test'
path_zip = app.paths.zip(source)
app.debug(path_zip)
* Set target
.. code-block:: python
source = '/home/mau/logo.svg'
target = '/home/mau/myfile.zip'
path_zip = app.paths.zip(source, target)
app.debug(path_zip)
* Read content of zip
.. code-block:: python
path_zip = '/home/mau/test.zip'
names = app.paths.zip_content(path_zip)
for n in names:
app.debug(n)
* Unzip in the same directory
.. code-block:: python
path_zip = '/home/mau/test.zip'
app.paths.unzip(path_zip)
* Unzip in other directory
.. code-block:: python
path_zip = '/home/mau/test.zip'
target = '/srv/mau'
app.paths.unzip(path_zip, target)
* Extract one or more files
.. code-block:: python
path_zip = '/home/mau/test.zip'
members = 'calc.ods'
app.paths.unzip(path_zip, members=members)
# or
members = ('calc.ods', 'subdir/file.md')
* Merge zips
.. code-block:: python
zips = (
'/home/mau/test.zip',
'/home/mau/pictures.zip',
)
target = '/srv/mau/file.zip'
result = app.paths.merge_zip(target, zips)
app.msgbox(result)
Copy files
^^^^^^^^^^
Copy with the same name
.. code-block:: python
path = '/home/mau/image.png'
target = '/home/mau/Pictures'
path_new = app.paths.copy(path, target)
app.msgbox(path_new)
Copy with other name
.. code-block:: python
path = '/home/mau/image.png'
target = '/home/mau/Pictures'
new_name = 'other_name.png'
path_new = app.paths.copy(path, target, name)
app.msgbox(path_new)
.. _API XPathSettings: http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1util_1_1XPathSettings.html
.. _python csv: https://docs.python.org/3.7/library/csv.html

View File

@ -505,7 +505,28 @@ Simple url open
For more complex case, you can used `requests`_ or `httpx`_
Color
^^^^^
Look colors that you can used in `web colors`_
.. code-block:: python
color_name = 'darkblue'
color = app.get_color(color_name)
app.msgbox(color)
color_rgb = (125, 200, 10)
color = app.get_color(color_rgb)
app.msgbox(color)
color_html = '#008080'
color = app.get_color(color_html)
app.msgbox(color)
.. _epoch time: https://en.wikipedia.org/wiki/Unix_time
.. _cryptography: https://github.com/pyca/cryptography
.. _requests: https://docs.python-requests.org
.. _httpx: https://www.python-httpx.org/
.. _web colors: https://en.wikipedia.org/wiki/Web_colors

View File

@ -60,6 +60,7 @@
<li class="toctree-l1"><a class="reference internal" href="main/config.html">Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="main/easymacro.html">Library easymacro.py</a></li>
<li class="toctree-l1"><a class="reference internal" href="main/examples.html">Examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="main/apendixes.html">Apendixes</a></li>
</ul>
<div class="relations">

View File

@ -67,6 +67,10 @@
<li class="toctree-l2"><a class="reference internal" href="main/examples_base.html">For Base</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="main/apendixes.html">Apendixes</a><ul>
<li class="toctree-l2"><a class="reference internal" href="main/apendixes.html#get-all-filters-in-calc-sheet">Get all filters in Calc sheet</a></li>
</ul>
</li>
</ul>
</div>
</section>
@ -102,6 +106,7 @@
<li class="toctree-l1"><a class="reference internal" href="main/config.html">Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="main/easymacro.html">Library easymacro.py</a></li>
<li class="toctree-l1"><a class="reference internal" href="main/examples.html">Examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="main/apendixes.html">Apendixes</a></li>
</ul>
<div class="relations">

152
doc/build/main/apendixes.html vendored Normal file
View File

@ -0,0 +1,152 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Apendixes &#8212; ZAZ documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/alabaster.css" />
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="prev" title="For Base" href="examples_base.html" />
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head><body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="apendixes">
<h1>Apendixes<a class="headerlink" href="#apendixes" title="Permalink to this headline"></a></h1>
<p>Remember, always import library.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">easymacro</span> <span class="k">as</span> <span class="nn">app</span>
</pre></div>
</div>
<section id="get-all-filters-in-calc-sheet">
<h2>Get all filters in Calc sheet<a class="headerlink" href="#get-all-filters-in-calc-sheet" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p>Fields in filter</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="s1">&#39;Finalized&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
<span class="s1">&#39;UIName&#39;</span><span class="p">:</span> <span class="s1">&#39;EPS - Encapsulated PostScript&#39;</span><span class="p">,</span>
<span class="s1">&#39;UserData&#39;</span><span class="p">:</span> <span class="o">&lt;</span><span class="n">ByteSequence</span> <span class="n">instance</span> <span class="s1">&#39;b&#39;&#39;&#39;</span><span class="o">&gt;</span><span class="p">,</span>
<span class="s1">&#39;TemplateName&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
<span class="s1">&#39;Enabled&#39;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
<span class="s1">&#39;Mandatory&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
<span class="s1">&#39;Name&#39;</span><span class="p">:</span> <span class="s1">&#39;impress_eps_Export&#39;</span><span class="p">,</span>
<span class="s1">&#39;FilterService&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
<span class="s1">&#39;Type&#39;</span><span class="p">:</span> <span class="s1">&#39;eps_Encapsulated_PostScript&#39;</span><span class="p">,</span>
<span class="s1">&#39;UIComponent&#39;</span><span class="p">:</span> <span class="s1">&#39;com.sun.star.svtools.SvFilterOptionsDialog&#39;</span><span class="p">,</span>
<span class="s1">&#39;Flags&#39;</span><span class="p">:</span> <span class="mi">1090</span><span class="p">,</span>
<span class="s1">&#39;FileFormatVersion&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="s1">&#39;DocumentService&#39;</span><span class="p">:</span> <span class="s1">&#39;com.sun.star.presentation.PresentationDocument&#39;</span><span class="p">,</span>
<span class="s1">&#39;UINames&#39;</span><span class="p">:</span> <span class="p">{</span>
<span class="s1">&#39;en-US&#39;</span><span class="p">:</span> <span class="s1">&#39;EPS - Encapsulated PostScript&#39;</span><span class="p">,</span>
<span class="s1">&#39;es&#39;</span><span class="p">:</span> <span class="s1">&#39;EPS - PostScript encapsulado&#39;</span><span class="p">}</span>
</pre></div>
</div>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">filters</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">get_filters</span><span class="p">()</span>
<span class="n">headers</span> <span class="o">=</span> <span class="p">((</span><span class="s1">&#39;DocumentService&#39;</span><span class="p">,</span> <span class="s1">&#39;UIName&#39;</span><span class="p">,</span> <span class="s1">&#39;Name&#39;</span><span class="p">,</span> <span class="s1">&#39;Type&#39;</span><span class="p">),)</span>
<span class="n">data</span> <span class="o">=</span> <span class="p">[(</span><span class="n">f</span><span class="p">[</span><span class="s1">&#39;DocumentService&#39;</span><span class="p">],</span> <span class="n">f</span><span class="p">[</span><span class="s1">&#39;UIName&#39;</span><span class="p">],</span> <span class="n">f</span><span class="p">[</span><span class="s1">&#39;Name&#39;</span><span class="p">],</span> <span class="n">f</span><span class="p">[</span><span class="s1">&#39;Type&#39;</span><span class="p">])</span>
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">filters</span><span class="p">]</span>
<span class="n">doc</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">docs</span><span class="o">.</span><span class="n">new</span><span class="p">()</span>
<span class="n">doc</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;A1&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">headers</span>
<span class="n">doc</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;A2&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>
</pre></div>
</div>
</section>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="../index.html">ZAZ</a></h1>
<h3>Navigation</h3>
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="intro.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="config.html">Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="easymacro.html">Library easymacro.py</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Apendixes</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#get-all-filters-in-calc-sheet">Get all filters in Calc sheet</a></li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="../index.html">Documentation overview</a><ul>
<li>Previous: <a href="examples_base.html" title="previous chapter">For Base</a></li>
</ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2021, Mauricio Baeza.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 4.0.2</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
|
<a href="../_sources/main/apendixes.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>

View File

@ -95,6 +95,13 @@
</pre></div>
</div>
</section>
<section id="if-contain">
<h2>If contain<a class="headerlink" href="#if-contain" title="Permalink to this headline"></a></h2>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">result</span> <span class="o">=</span> <span class="s1">&#39;myfile.ods&#39;</span> <span class="ow">in</span> <span class="n">app</span><span class="o">.</span><span class="n">docs</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="new">
<h2>New<a class="headerlink" href="#new" title="Permalink to this headline"></a></h2>
<p>For default create new Calc document.</p>
@ -142,6 +149,82 @@
</pre></div>
</div>
</section>
<section id="save">
<h2>Save<a class="headerlink" href="#save" title="Permalink to this headline"></a></h2>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/myfile.ods&#39;</span>
<span class="n">doc</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">docs</span><span class="o">.</span><span class="n">new</span><span class="p">()</span>
<span class="n">doc</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>If previously open and modify any file.</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">doc</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</pre></div>
</div>
<ul class="simple">
<li><p>Open exists file and save with other name.</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/myfile.ods&#39;</span>
<span class="n">doc</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">docs</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
<span class="n">new_path</span> <span class="o">=</span> <span class="s1">&#39;/srv/mau/other_name.ods&#39;</span>
<span class="n">doc</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">new_path</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="close">
<h2>Close<a class="headerlink" href="#close" title="Permalink to this headline"></a></h2>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">doc</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">docs</span><span class="o">.</span><span class="n">new</span><span class="p">()</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">doc</span><span class="o">.</span><span class="n">title</span><span class="p">)</span>
<span class="n">doc</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</section>
<section id="to-pdf">
<h2>To PDF<a class="headerlink" href="#to-pdf" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p>Save in path</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">doc</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">active</span>
<span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/test.pdf&#39;</span>
<span class="n">doc</span><span class="o">.</span><span class="n">to_pdf</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>Save in memory</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">doc</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">active</span>
<span class="n">pdf</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">to_pdf</span><span class="p">()</span>
</pre></div>
</div>
</section>
<section id="export">
<h2>Export<a class="headerlink" href="#export" title="Permalink to this headline"></a></h2>
</section>
<section id="fonst">
<h2>Fonst<a class="headerlink" href="#fonst" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p>Get all fonts</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">fonts</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">get_fonts</span><span class="p">()</span>
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">fonts</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;Name: </span><span class="si">{</span><span class="n">f</span><span class="o">.</span><span class="n">Name</span><span class="si">}</span><span class="s1"> - StyleName: </span><span class="si">{</span><span class="n">f</span><span class="o">.</span><span class="n">StyleName</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="filters">
<h2>Filters<a class="headerlink" href="#filters" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p>Get all <a class="reference external" href="https://help.libreoffice.org/latest/en-US/text/shared/guide/convertfilters.html">support filters</a></p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">filters</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">get_filters</span><span class="p">()</span>
<span class="n">ds</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">filters</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;UI Name: </span><span class="si">{</span><span class="n">f</span><span class="p">[</span><span class="s1">&#39;UIName&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2"> - Name: </span><span class="si">{</span><span class="n">f</span><span class="p">[</span><span class="s1">&#39;Name&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2"> - Type: </span><span class="si">{</span><span class="n">f</span><span class="p">[</span><span class="s1">&#39;Type&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">&quot;</span>
<span class="n">app</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="call-dispatch">
<h2>Call dispatch<a class="headerlink" href="#call-dispatch" title="Permalink to this headline"></a></h2>
<p>You can call any <a class="reference external" href="https://wiki.documentfoundation.org/Development/DispatchCommands">dispatch command</a> used only if property or method no exists in original object or in <cite>easymacro.py</cite></p>
@ -151,6 +234,16 @@
</pre></div>
</div>
</section>
<section id="properties">
<h2>Properties<a class="headerlink" href="#properties" title="Permalink to this headline"></a></h2>
<section id="title">
<h3>Title<a class="headerlink" href="#title" title="Permalink to this headline"></a></h3>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">doc</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">active</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">doc</span><span class="o">.</span><span class="n">title</span><span class="p">)</span>
</pre></div>
</div>
</section>
</section>
</section>

View File

@ -80,6 +80,7 @@
<li class="toctree-l2"><a class="reference internal" href="tools.html#render-string">Render string</a></li>
<li class="toctree-l2"><a class="reference internal" href="tools.html#encrypt-decrypt">Encrypt decrypt</a></li>
<li class="toctree-l2"><a class="reference internal" href="tools.html#simple-url-open">Simple url open</a></li>
<li class="toctree-l2"><a class="reference internal" href="tools.html#color">Color</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="paths.html">Paths and files</a><ul>
@ -105,7 +106,13 @@
<li class="toctree-l2"><a class="reference internal" href="paths.html#delete-files-and-directories">Delete files and directories</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#get-files">Get files</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#get-directories">Get directories</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#get-install-path-from-id-extension">Get install path from id extension</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#get-install-path-extension-from-id">Get install path extension from id</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#verify-if-application-exists">Verify if application exists</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#open-any-type-file">Open any type file</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#save-and-read-json">Save and read json</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#save-and-read-csv">Save and read csv</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#zip-unzip">Zip, unzip</a></li>
<li class="toctree-l2"><a class="reference internal" href="paths.html#copy-files">Copy files</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="email.html">Email</a><ul>
@ -118,9 +125,17 @@
<li class="toctree-l2"><a class="reference internal" href="application.html#iter-docs">Iter docs</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#count">Count</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#get-by-name">Get by name</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#if-contain">If contain</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#new">New</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#open">Open</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#save">Save</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#close">Close</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#to-pdf">To PDF</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#export">Export</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#fonst">Fonst</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#filters">Filters</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#call-dispatch">Call dispatch</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html#properties">Properties</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="calc.html">Calc</a><ul>

View File

@ -39,11 +39,99 @@
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">easymacro</span> <span class="k">as</span> <span class="nn">app</span>
</pre></div>
</div>
<p><strong>IMPORTANT:</strong> Always save your config the more security way possible.</p>
<section id="send-email">
<h2>Send email<a class="headerlink" href="#send-email" title="Permalink to this headline"></a></h2>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">OS</span><span class="p">)</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">conf</span> <span class="kn">import</span> <span class="n">PASSWORD</span>
<span class="n">SERVER</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
<span class="n">server</span> <span class="o">=</span> <span class="s1">&#39;mail.server.net&#39;</span> <span class="p">,</span>
<span class="n">port</span> <span class="o">=</span> <span class="mi">495</span><span class="p">,</span>
<span class="n">ssl</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span>
<span class="n">user</span> <span class="o">=</span> <span class="s1">&#39;no-responder@noexiste.mx&#39;</span><span class="p">,</span>
<span class="n">password</span> <span class="o">=</span> <span class="n">PASSWORD</span><span class="p">,</span>
<span class="p">)</span>
<span class="n">body</span> <span class="o">=</span> <span class="s2">&quot;Hello Ingrid</span><span class="se">\n\n</span><span class="s2">Who are you?</span><span class="se">\n\n</span><span class="s2">Best regards&quot;</span>
<span class="n">message</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
<span class="n">to</span> <span class="o">=</span> <span class="s1">&#39;ingrid.bergman@love.you&#39;</span><span class="p">,</span>
<span class="n">subject</span> <span class="o">=</span> <span class="s1">&#39;I love you&#39;</span><span class="p">,</span>
<span class="n">body</span> <span class="o">=</span> <span class="n">body</span><span class="p">,</span>
<span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">send_email</span><span class="p">(</span><span class="n">SERVER</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>We can use fields <cite>cc</cite>, <cite>bcc</cite> too and send to more than one address emails.</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">to</span> <span class="o">=</span> <span class="s1">&#39;mail1@correo.com,mail2@correo.com,mail3@correo.com&#39;</span>
<span class="n">cc</span> <span class="o">=</span> <span class="s1">&#39;other@correo.com&#39;</span>
<span class="n">bcc</span> <span class="o">=</span> <span class="s1">&#39;hidden@correo.com&#39;</span>
</pre></div>
</div>
<ul class="simple">
<li><p>We can send too more than one message.</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">message1</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
<span class="n">to</span> <span class="o">=</span> <span class="s1">&#39;ingrid.bergman@email.net&#39;</span><span class="p">,</span>
<span class="n">subject</span> <span class="o">=</span> <span class="s1">&#39;I love you&#39;</span><span class="p">,</span>
<span class="n">body</span> <span class="o">=</span> <span class="s2">&quot;Hello Ingrid</span><span class="se">\n\n</span><span class="s2">Who are you?</span><span class="se">\n\n</span><span class="s2">Best regards&quot;</span><span class="p">,</span>
<span class="p">)</span>
<span class="n">message2</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
<span class="n">to</span> <span class="o">=</span> <span class="s1">&#39;sophia.loren@email.net&#39;</span><span class="p">,</span>
<span class="n">subject</span> <span class="o">=</span> <span class="s1">&#39;I love you&#39;</span><span class="p">,</span>
<span class="n">body</span> <span class="o">=</span> <span class="s2">&quot;Hello Sophia</span><span class="se">\n\n</span><span class="s2">Who are you?</span><span class="se">\n\n</span><span class="s2">Best regards&quot;</span><span class="p">,</span>
<span class="p">)</span>
<span class="n">messages</span> <span class="o">=</span> <span class="p">(</span><span class="n">message1</span><span class="p">,</span> <span class="n">message2</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">send_email</span><span class="p">(</span><span class="n">SERVER</span><span class="p">,</span> <span class="n">messages</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="m">30</span>/06/2021 <span class="m">13</span>:43:23 - DEBUG - Connect to: mail.gandi.net
<span class="m">30</span>/06/2021 <span class="m">13</span>:43:24 - DEBUG - Email sent...
<span class="m">30</span>/06/2021 <span class="m">13</span>:43:26 - DEBUG - Email sent...
<span class="m">30</span>/06/2021 <span class="m">13</span>:43:26 - DEBUG - Close connection...
</pre></div>
</div>
<ul class="simple">
<li><p>Send with attachment</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">files</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/file.epub&#39;</span>
<span class="n">message</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
<span class="n">to</span> <span class="o">=</span> <span class="s1">&#39;ingrid.bergman@email.net&#39;</span><span class="p">,</span>
<span class="n">subject</span> <span class="o">=</span> <span class="s1">&#39;I love you&#39;</span><span class="p">,</span>
<span class="n">body</span> <span class="o">=</span> <span class="s2">&quot;Hello Ingrid</span><span class="se">\n\n</span><span class="s2">Who are you?</span><span class="se">\n\n</span><span class="s2">Best regards&quot;</span><span class="p">,</span>
<span class="n">files</span> <span class="o">=</span> <span class="n">files</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>Send more than one file.</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">files</span> <span class="o">=</span> <span class="p">(</span>
<span class="s1">&#39;/home/mau/file1.epub&#39;</span><span class="p">,</span>
<span class="s1">&#39;/home/mau/file2.epub&#39;</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>If your client email used <cite>mbox</cite> format, we can save in any path into your email client configuration.</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path_save</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/.thunderbird/7iznrbyw.default/Mail/Local Folders/LibreOffice&#39;</span>
<span class="n">message</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
<span class="n">to</span> <span class="o">=</span> <span class="s1">&#39;ingrid.bergman@email.net&#39;</span><span class="p">,</span>
<span class="n">subject</span> <span class="o">=</span> <span class="s1">&#39;I love you&#39;</span><span class="p">,</span>
<span class="n">body</span> <span class="o">=</span> <span class="s2">&quot;Hello Ingrid</span><span class="se">\n\n</span><span class="s2">Who are you?</span><span class="se">\n\n</span><span class="s2">Best regards&quot;</span><span class="p">,</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">path_save</span>
<span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">send_email</span><span class="p">(</span><span class="n">SERVER</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>All emails always send in other thread.</p></li>
</ul>
</section>
</section>

View File

@ -420,8 +420,8 @@
</pre></div>
</div>
</section>
<section id="get-install-path-from-id-extension">
<h2>Get install path from id extension<a class="headerlink" href="#get-install-path-from-id-extension" title="Permalink to this headline"></a></h2>
<section id="get-install-path-extension-from-id">
<h2>Get install path extension from id<a class="headerlink" href="#get-install-path-extension-from-id" title="Permalink to this headline"></a></h2>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">id_ext</span> <span class="o">=</span> <span class="s1">&#39;net.elmau.zaz.EasyMacro&#39;</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">from_id</span><span class="p">(</span><span class="n">id_ext</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
@ -431,6 +431,154 @@
</pre></div>
</div>
</section>
<section id="verify-if-application-exists">
<h2>Verify if application exists<a class="headerlink" href="#verify-if-application-exists" title="Permalink to this headline"></a></h2>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">app_name</span> <span class="o">=</span> <span class="s1">&#39;nosoffice&#39;</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">exists_app</span><span class="p">(</span><span class="n">app_name</span><span class="p">))</span>
<span class="n">app_name</span> <span class="o">=</span> <span class="s1">&#39;soffice&#39;</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">exists_app</span><span class="p">(</span><span class="n">app_name</span><span class="p">))</span>
</pre></div>
</div>
</section>
<section id="open-any-type-file">
<h2>Open any type file<a class="headerlink" href="#open-any-type-file" title="Permalink to this headline"></a></h2>
<p>Open with default application in OS.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/Downloads/file.pdf&#39;</span>
<span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
<span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/Projects/libre_office/zaz/doc/build/index.html&#39;</span>
<span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="save-and-read-json">
<h2>Save and read json<a class="headerlink" href="#save-and-read-json" title="Permalink to this headline"></a></h2>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/data.json&#39;</span>
<span class="n">data</span> <span class="o">=</span> <span class="p">{</span>
<span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="s1">&#39;calc&#39;</span><span class="p">,</span>
<span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;myfile.ods&#39;</span><span class="p">,</span>
<span class="p">}</span>
<span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">to_json</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">from_json</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="save-and-read-csv">
<h2>Save and read csv<a class="headerlink" href="#save-and-read-csv" title="Permalink to this headline"></a></h2>
<p>You can used the same way that <a class="reference external" href="https://docs.python.org/3.7/library/csv.html">python csv</a></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/data.csv&#39;</span>
<span class="n">data</span> <span class="o">=</span> <span class="p">(</span>
<span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;one&#39;</span><span class="p">,</span> <span class="n">app</span><span class="o">.</span><span class="n">now</span><span class="p">()),</span>
<span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;two&#39;</span><span class="p">,</span> <span class="n">app</span><span class="o">.</span><span class="n">now</span><span class="p">()),</span>
<span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;three&#39;</span><span class="p">,</span> <span class="n">app</span><span class="o">.</span><span class="n">now</span><span class="p">()),</span>
<span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">to_csv</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">from_csv</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="zip-unzip">
<h2>Zip, unzip<a class="headerlink" href="#zip-unzip" title="Permalink to this headline"></a></h2>
<p>For default, save in the same directory with the same name + <cite>.zip</cite></p>
<ul class="simple">
<li><p>Zip file</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">source</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/logo.svg&#39;</span>
<span class="n">path_zip</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">zip</span><span class="p">(</span><span class="n">source</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">path_zip</span><span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>Zip directory</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">source</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/test&#39;</span>
<span class="n">path_zip</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">zip</span><span class="p">(</span><span class="n">source</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">path_zip</span><span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>Set target</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">source</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/logo.svg&#39;</span>
<span class="n">target</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/myfile.zip&#39;</span>
<span class="n">path_zip</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">zip</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">target</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">path_zip</span><span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>Read content of zip</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path_zip</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/test.zip&#39;</span>
<span class="n">names</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">zip_content</span><span class="p">(</span><span class="n">path_zip</span><span class="p">)</span>
<span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
<span class="n">app</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>Unzip in the same directory</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path_zip</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/test.zip&#39;</span>
<span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">unzip</span><span class="p">(</span><span class="n">path_zip</span><span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>Unzip in other directory</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path_zip</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/test.zip&#39;</span>
<span class="n">target</span> <span class="o">=</span> <span class="s1">&#39;/srv/mau&#39;</span>
<span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">unzip</span><span class="p">(</span><span class="n">path_zip</span><span class="p">,</span> <span class="n">target</span><span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>Extract one or more files</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path_zip</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/test.zip&#39;</span>
<span class="n">members</span> <span class="o">=</span> <span class="s1">&#39;calc.ods&#39;</span>
<span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">unzip</span><span class="p">(</span><span class="n">path_zip</span><span class="p">,</span> <span class="n">members</span><span class="o">=</span><span class="n">members</span><span class="p">)</span>
<span class="c1"># or</span>
<span class="n">members</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;calc.ods&#39;</span><span class="p">,</span> <span class="s1">&#39;subdir/file.md&#39;</span><span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>Merge zips</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">zips</span> <span class="o">=</span> <span class="p">(</span>
<span class="s1">&#39;/home/mau/test.zip&#39;</span><span class="p">,</span>
<span class="s1">&#39;/home/mau/pictures.zip&#39;</span><span class="p">,</span>
<span class="p">)</span>
<span class="n">target</span> <span class="o">=</span> <span class="s1">&#39;/srv/mau/file.zip&#39;</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">merge_zip</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">zips</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="copy-files">
<h2>Copy files<a class="headerlink" href="#copy-files" title="Permalink to this headline"></a></h2>
<p>Copy with the same name</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/image.png&#39;</span>
<span class="n">target</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/Pictures&#39;</span>
<span class="n">path_new</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">target</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">path_new</span><span class="p">)</span>
</pre></div>
</div>
<p>Copy with other name</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/image.png&#39;</span>
<span class="n">target</span> <span class="o">=</span> <span class="s1">&#39;/home/mau/Pictures&#39;</span>
<span class="n">new_name</span> <span class="o">=</span> <span class="s1">&#39;other_name.png&#39;</span>
<span class="n">path_new</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">paths</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">path_new</span><span class="p">)</span>
</pre></div>
</div>
</section>
</section>

View File

@ -482,6 +482,23 @@ drwxr-xr-x <span class="m">2</span> mau mau <span class="m">4</span>.0K Jun <sp
</div>
<p>For more complex case, you can used <a class="reference external" href="https://docs.python-requests.org">requests</a> or <a class="reference external" href="https://www.python-httpx.org/">httpx</a></p>
</section>
<section id="color">
<h2>Color<a class="headerlink" href="#color" title="Permalink to this headline"></a></h2>
<p>Look colors that you can used in <a class="reference external" href="https://en.wikipedia.org/wiki/Web_colors">web colors</a></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">color_name</span> <span class="o">=</span> <span class="s1">&#39;darkblue&#39;</span>
<span class="n">color</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">get_color</span><span class="p">(</span><span class="n">color_name</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
<span class="n">color_rgb</span> <span class="o">=</span> <span class="p">(</span><span class="mi">125</span><span class="p">,</span> <span class="mi">200</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="n">color</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">get_color</span><span class="p">(</span><span class="n">color_rgb</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
<span class="n">color_html</span> <span class="o">=</span> <span class="s1">&#39;#008080&#39;</span>
<span class="n">color</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">get_color</span><span class="p">(</span><span class="n">color_html</span><span class="p">)</span>
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
</pre></div>
</div>
</section>
</section>

BIN
doc/build/objects.inv vendored

Binary file not shown.

View File

@ -88,6 +88,7 @@
<li class="toctree-l1"><a class="reference internal" href="main/config.html">Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="main/easymacro.html">Library easymacro.py</a></li>
<li class="toctree-l1"><a class="reference internal" href="main/examples.html">Examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="main/apendixes.html">Apendixes</a></li>
</ul>
<div class="relations">

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,3 @@
#!/bin/bash
rsync -ravz build/ elmau.net:/opt/www/doc/zaz/
rsync -ravz --delete build/ elmau.net:/opt/www/doc/zaz/

View File

@ -14,6 +14,7 @@ Welcome to ZAZ's documentation!
main/config
main/easymacro
main/examples
main/apendixes
Indices and tables

View File

@ -0,0 +1,46 @@
Apendixes
---------
Remember, always import library.
.. code-block:: python
import easymacro as app
Get all filters in Calc sheet
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* Fields in filter
.. code-block:: python
'Finalized': False,
'UIName': 'EPS - Encapsulated PostScript',
'UserData': <ByteSequence instance 'b'''>,
'TemplateName': '',
'Enabled': True,
'Mandatory': False,
'Name': 'impress_eps_Export',
'FilterService': '',
'Type': 'eps_Encapsulated_PostScript',
'UIComponent': 'com.sun.star.svtools.SvFilterOptionsDialog',
'Flags': 1090,
'FileFormatVersion': 0,
'DocumentService': 'com.sun.star.presentation.PresentationDocument',
'UINames': {
'en-US': 'EPS - Encapsulated PostScript',
'es': 'EPS - PostScript encapsulado'}
.. code-block:: python
filters = app.get_filters()
headers = (('DocumentService', 'UIName', 'Name', 'Type'),)
data = [(f['DocumentService'], f['UIName'], f['Name'], f['Type'])
for f in filters]
doc = app.docs.new()
doc[0]['A1'].data = headers
doc[0]['A2'].data = data

View File

@ -75,6 +75,16 @@ Get by name
app.msgbox(doc.title)
If contain
^^^^^^^^^^
.. code-block:: python
result = 'myfile.ods' in app.docs
app.msgbox(result)
New
^^^
@ -142,6 +152,114 @@ With arguments.
doc = app.docs.open(path, args)
Save
^^^^
.. code-block:: python
path = '/home/mau/myfile.ods'
doc = app.docs.new()
doc.save(path)
* If previously open and modify any file.
.. code-block:: python
doc.save()
* Open exists file and save with other name.
.. code-block:: python
path = '/home/mau/myfile.ods'
doc = app.docs.open(path)
new_path = '/srv/mau/other_name.ods'
doc.save(new_path)
Close
^^^^^
.. code-block:: python
doc = app.docs.new()
app.msgbox(doc.title)
doc.close()
To PDF
^^^^^^
* Save in path
.. code-block:: python
doc = app.active
path = '/home/mau/test.pdf'
doc.to_pdf(path)
* Save in memory
.. code-block:: python
doc = app.active
pdf = doc.to_pdf()
Export
^^^^^^
* Export common formats
.. code-block:: python
doc = app.docs.new()
path = '/home/mau/myfile.xlsx'
filter_name = 'xlsx'
doc.export(path, filter_name)
path = '/home/mau/myfile.xls'
filter_name = 'xls'
doc.export(path, filter_name)
doc = app.docs.new('writer')
path = '/home/mau/myfile.docx'
filter_name = 'docx'
doc.export(path, filter_name)
path = '/home/mau/myfile.doc'
filter_name = 'doc'
doc.export(path, filter_name)
* For all support formats look `Apendix`_
Fonst
^^^^^
* Get all fonts
.. code-block:: python
fonts = app.get_fonts()
for f in fonts:
print(f'Name: {f.Name} - StyleName: {f.StyleName}')
Filters
^^^^^^^
* Get all `support filters`_
.. code-block:: python
filters = app.get_filters()
ds = []
for f in filters:
data = f"UI Name: {f['UIName']} - Name: {f['Name']} - Type: {f['Type']}"
app.debug(data)
Call dispatch
^^^^^^^^^^^^^
@ -154,5 +272,18 @@ You can call any `dispatch command`_ used only if property or method no exists i
app.call_dispatch(doc, command)
Properties
^^^^^^^^^^
Title
~~~~~
.. code-block:: python
doc = app.active
app.msgbox(doc.title)
.. _dispatch command: https://wiki.documentfoundation.org/Development/DispatchCommands
.. _support filters: https://help.libreoffice.org/latest/en-US/text/shared/guide/convertfilters.html
.. _Apendix: apendix

View File

@ -9,12 +9,103 @@ Remember, always import library.
import easymacro as app
**IMPORTANT:** Always save your config the more security way possible.
Send email
^^^^^^^^^^
.. code-block:: python
app.msgbox(app.OS)
from conf import PASSWORD
SERVER = dict(
server = 'mail.server.net' ,
port = 495,
ssl = True,
user = 'no-responder@noexiste.mx',
password = PASSWORD,
)
body = "Hello Ingrid\n\nWho are you?\n\nBest regards"
message = dict(
to = 'ingrid.bergman@love.you',
subject = 'I love you',
body = body,
)
app.send_email(SERVER, message)
* We can use fields `cc`, `bcc` too and send to more than one address emails.
.. code-block:: python
to = 'mail1@correo.com,mail2@correo.com,mail3@correo.com'
cc = 'other@correo.com'
bcc = 'hidden@correo.com'
* We can send too more than one message.
.. code-block:: python
message1 = dict(
to = 'ingrid.bergman@email.net',
subject = 'I love you',
body = "Hello Ingrid\n\nWho are you?\n\nBest regards",
)
message2 = dict(
to = 'sophia.loren@email.net',
subject = 'I love you',
body = "Hello Sophia\n\nWho are you?\n\nBest regards",
)
messages = (message1, message2)
app.send_email(SERVER, messages)
.. code-block:: bash
30/06/2021 13:43:23 - DEBUG - Connect to: mail.gandi.net
30/06/2021 13:43:24 - DEBUG - Email sent...
30/06/2021 13:43:26 - DEBUG - Email sent...
30/06/2021 13:43:26 - DEBUG - Close connection...
* Send with attachment
.. code-block:: python
files = '/home/mau/file.epub'
message = dict(
to = 'ingrid.bergman@email.net',
subject = 'I love you',
body = "Hello Ingrid\n\nWho are you?\n\nBest regards",
files = files,
)
* Send more than one file.
.. code-block:: python
files = (
'/home/mau/file1.epub',
'/home/mau/file2.epub',
)
* If your client email used `mbox` format, we can save in any path into your email client configuration.
.. code-block:: python
path_save = '/home/mau/.thunderbird/7iznrbyw.default/Mail/Local Folders/LibreOffice'
message = dict(
to = 'ingrid.bergman@email.net',
subject = 'I love you',
body = "Hello Ingrid\n\nWho are you?\n\nBest regards",
path = path_save
)
app.send_email(SERVER, message)
* All emails always send in other thread.
.. _cryptography: https://github.com/pyca/cryptography

View File

@ -446,4 +446,169 @@ Get install path extension from id
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
Verify if application exists
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
app_name = 'nosoffice'
app.msgbox(app.paths.exists_app(app_name))
app_name = 'soffice'
app.msgbox(app.paths.exists_app(app_name))
Open any type file
^^^^^^^^^^^^^^^^^^
Open with default application in OS.
.. code-block:: python
path = '/home/mau/Downloads/file.pdf'
app.paths.open(path)
path = '/home/mau/Projects/libre_office/zaz/doc/build/index.html'
app.paths.open(path)
Save and read json
^^^^^^^^^^^^^^^^^^
.. code-block:: python
path = '/home/mau/data.json'
data = {
'type': 'calc',
'name': 'myfile.ods',
}
app.paths.to_json(path, data)
data = app.paths.from_json(path)
app.msgbox(data)
Save and read csv
^^^^^^^^^^^^^^^^^
You can used the same way that `python csv`_
.. code-block:: python
path = '/home/mau/data.csv'
data = (
(1, 'one', app.now()),
(2, 'two', app.now()),
(3, 'three', app.now()),
)
app.paths.to_csv(path, data)
data = app.paths.from_csv(path)
app.msgbox(data)
Zip, unzip
^^^^^^^^^^
For default, save in the same directory with the same name + `.zip`
* Zip file
.. code-block:: python
source = '/home/mau/logo.svg'
path_zip = app.paths.zip(source)
app.debug(path_zip)
* Zip directory
.. code-block:: python
source = '/home/mau/test'
path_zip = app.paths.zip(source)
app.debug(path_zip)
* Set target
.. code-block:: python
source = '/home/mau/logo.svg'
target = '/home/mau/myfile.zip'
path_zip = app.paths.zip(source, target)
app.debug(path_zip)
* Read content of zip
.. code-block:: python
path_zip = '/home/mau/test.zip'
names = app.paths.zip_content(path_zip)
for n in names:
app.debug(n)
* Unzip in the same directory
.. code-block:: python
path_zip = '/home/mau/test.zip'
app.paths.unzip(path_zip)
* Unzip in other directory
.. code-block:: python
path_zip = '/home/mau/test.zip'
target = '/srv/mau'
app.paths.unzip(path_zip, target)
* Extract one or more files
.. code-block:: python
path_zip = '/home/mau/test.zip'
members = 'calc.ods'
app.paths.unzip(path_zip, members=members)
# or
members = ('calc.ods', 'subdir/file.md')
* Merge zips
.. code-block:: python
zips = (
'/home/mau/test.zip',
'/home/mau/pictures.zip',
)
target = '/srv/mau/file.zip'
result = app.paths.merge_zip(target, zips)
app.msgbox(result)
Copy files
^^^^^^^^^^
Copy with the same name
.. code-block:: python
path = '/home/mau/image.png'
target = '/home/mau/Pictures'
path_new = app.paths.copy(path, target)
app.msgbox(path_new)
Copy with other name
.. code-block:: python
path = '/home/mau/image.png'
target = '/home/mau/Pictures'
new_name = 'other_name.png'
path_new = app.paths.copy(path, target, name)
app.msgbox(path_new)
.. _API XPathSettings: http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1util_1_1XPathSettings.html
.. _python csv: https://docs.python.org/3.7/library/csv.html

View File

@ -505,7 +505,28 @@ Simple url open
For more complex case, you can used `requests`_ or `httpx`_
Color
^^^^^
Look colors that you can used in `web colors`_
.. code-block:: python
color_name = 'darkblue'
color = app.get_color(color_name)
app.msgbox(color)
color_rgb = (125, 200, 10)
color = app.get_color(color_rgb)
app.msgbox(color)
color_html = '#008080'
color = app.get_color(color_html)
app.msgbox(color)
.. _epoch time: https://en.wikipedia.org/wiki/Unix_time
.. _cryptography: https://github.com/pyca/cryptography
.. _requests: https://docs.python-requests.org
.. _httpx: https://www.python-httpx.org/
.. _web colors: https://en.wikipedia.org/wiki/Web_colors

View File

@ -26,6 +26,7 @@ import datetime
import getpass
import gettext
import hashlib
import io
import json
import logging
import os
@ -100,6 +101,8 @@ from com.sun.star.awt.grid import XGridDataListener
from com.sun.star.awt.grid import XGridSelectionListener
from com.sun.star.script import ScriptEventDescriptor
from com.sun.star.io import IOException, XOutputStream
# ~ https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1awt_1_1FontUnderline.html
from com.sun.star.awt import FontUnderline
from com.sun.star.style.VerticalAlignment import TOP, MIDDLE, BOTTOM
@ -889,11 +892,11 @@ class SmtpServer(object):
return False
def _body(self, msg):
body = msg.replace('\\n', '<BR>')
body = msg.replace('\n', '<BR>')
return body
def send(self, message):
file_name = 'attachment; filename={}'
# ~ file_name = 'attachment; filename={}'
email = MIMEMultipart()
email['From'] = self._sender
email['To'] = message['to']
@ -904,12 +907,16 @@ class SmtpServer(object):
email['Disposition-Notification-To'] = email['From']
email.attach(MIMEText(self._body(message['body']), 'html'))
for path in message.get('files', ()):
paths = message.get('files', ())
if isinstance(paths, str):
paths = (paths,)
for path in paths:
fn = _P(path).file_name
print('NAME', fn)
part = MIMEBase('application', 'octet-stream')
part.set_payload(_P.read_bin(path))
encoders.encode_base64(part)
part.add_header('Content-Disposition', f'attachment; filename={fn}')
part.add_header('Content-Disposition', f'attachment; filename="{fn}"')
email.attach(part)
receivers = (
@ -1051,10 +1058,6 @@ class LOBaseObject(object):
class LODocument(object):
FILTERS = {
'doc': 'MS Word 97',
'docx': 'MS Word 2007 XML',
}
def __init__(self, obj):
self._obj = obj
@ -1200,26 +1203,40 @@ class LODocument(object):
"""
https://wiki.documentfoundation.org/Macros/Python_Guide/PDF_export_filter_data
"""
path_pdf = path
stream = None
path_pdf = 'private:stream'
if path:
path_pdf = _P.to_url(path)
filter_name = '{}_pdf_Export'.format(self.type)
filter_data = dict_to_property(args, True)
args = {
'FilterName': filter_name,
'FilterData': filter_data,
}
if not path:
stream = IOStream.output()
args['OutputStream'] = stream
opt = dict_to_property(args)
try:
self.obj.storeToURL(_P.to_url(path), opt)
self.obj.storeToURL(path_pdf, opt)
except Exception as e:
error(e)
path_pdf = ''
return _P.exists(path_pdf)
if not stream is None:
stream = stream.buffer
def export(self, path: str, ext: str='', args: dict={}):
if not ext:
ext = _P(path).ext
filter_name = self.FILTERS[ext]
return stream
def export(self, path: str, filter_name: str, args: dict={}):
FILTERS = {
'xlsx': 'Calc MS Excel 2007 XML',
'xls': 'MS Excel 97',
'docx': 'MS Word 2007 XML',
'doc': 'MS Word 97',
}
filter_name = FILTERS.get(filter_name, filter_name)
filter_data = dict_to_property(args, True)
args = {
'FilterName': filter_name,
@ -1231,6 +1248,7 @@ class LODocument(object):
except Exception as e:
error(e)
path = ''
return _P.exists(path)
def save(self, path: str='', args: dict={}) -> bool:
@ -2198,7 +2216,6 @@ class LOCalcSheet(object):
@property
def draw_page(self):
return LODrawPage(self.obj.DrawPage)
@property
def dp(self):
return self.draw_page
@ -2828,7 +2845,8 @@ class LOCalcRange(object):
call_dispatch(self.doc.frame, url, args)
return self.sheet.shapes[-1]
def insert_image(self, path, args={}):
def insert_image(self, path, options={}):
args = options.copy()
ps = self.possize
args['Width'] = args.get('Width', ps['Width'])
args['Height'] = args.get('Height', ps['Height'])
@ -3350,6 +3368,13 @@ class LOShape(LOBaseObject):
def shape_type(self):
return self.obj.ShapeType
@property
def properties(self):
return {}
@properties.setter
def properties(self, values):
_set_properties(self.obj, values)
@property
def is_image(self):
return self.shape_type == self.IMAGE
@ -3527,19 +3552,21 @@ class LODrawPage(LOBaseObject):
def create_instance(self, name):
return self.doc.createInstance(name)
def add(self, type_shape, args={}):
def add(self, type_shape, options={}):
args = options.copy()
"""Insert a shape in page, type shapes:
Line
Rectangle
Ellipse
Text
Connector
"""
index = self.count
w = args.get('Width', 3000)
h = args.get('Height', 3000)
x = args.get('X', 1000)
y = args.get('Y', 1000)
name = args.get('Name', f'{type_shape.lower()}{index}')
w = args.pop('Width', 3000)
h = args.pop('Height', 3000)
x = args.pop('X', 1000)
y = args.pop('Y', 1000)
name = args.pop('Name', f'{type_shape.lower()}{index}')
service = f'com.sun.star.drawing.{type_shape}Shape'
shape = self.create_instance(service)
@ -3547,6 +3574,10 @@ class LODrawPage(LOBaseObject):
shape.Position = Point(x, y)
shape.Name = name
self.obj.add(shape)
if args:
_set_properties(shape, args)
return LOShape(self.obj[index], index)
def remove(self, shape):
@ -3559,7 +3590,8 @@ class LODrawPage(LOBaseObject):
self.obj.remove(self.obj[0])
return
def insert_image(self, path, args={}):
def insert_image(self, path, options={}):
args = options.copy()
index = self.count
w = args.get('Width', 3000)
h = args.get('Height', 3000)
@ -3568,11 +3600,17 @@ class LODrawPage(LOBaseObject):
name = args.get('Name', f'image{index}')
image = self.create_instance('com.sun.star.drawing.GraphicObjectShape')
image.GraphicURL = _P.to_url(path)
if isinstance(path, str):
image.GraphicURL = _P.to_url(path)
else:
gp = create_instance('com.sun.star.graphic.GraphicProvider')
properties = dict_to_property({'InputStream': path})
image.Graphic = gp.queryGraphic(properties)
self.obj.add(image)
image.Size = Size(w, h)
image.Position = Point(x, y)
image.Name = name
self.obj.add(image)
return LOShape(self.obj[index], index)
@ -6100,7 +6138,7 @@ class LODBServer(object):
def __init__(self):
self._conn = None
self._error = ''
self._error = 'Not connected'
self._type = ''
def __str__(self):
@ -6114,7 +6152,7 @@ class LODBServer(object):
@property
def is_connected(self):
return not bool(self._error)
return not self._conn is None
@property
def error(self):
@ -6531,7 +6569,7 @@ class Paths(object):
return
@classmethod
def zip(cls, source, target='', pwd=''):
def zip(cls, source, target=''):
path_zip = target
if not isinstance(source, (tuple, list)):
path, _, name, _ = _P(source).info
@ -6550,7 +6588,7 @@ class Paths(object):
with zipfile.ZipFile(path_zip, 'w', compression=compression) as z:
for f in files:
z.write(f[0], f[1])
return
return path_zip
@classmethod
def zip_content(cls, path):
@ -6569,7 +6607,7 @@ class Paths(object):
if isinstance(members, str):
members = (members,)
z.extractall(path, members=members, pwd=pwd)
return True
return
@classmethod
def merge_zip(cls, target, zips):
@ -6587,10 +6625,14 @@ class Paths(object):
@classmethod
def image(cls, path):
# ~ sfa = create_instance('com.sun.star.ucb.SimpleFileAccess')
# ~ stream = sfa.openFileRead(cls.to_url(path))
gp = create_instance('com.sun.star.graphic.GraphicProvider')
image = gp.queryGraphic((
PropertyValue(Name='URL', Value=cls.to_url(path)),
))
if isinstance(path, str):
properties = (PropertyValue(Name='URL', Value=cls.to_url(path)),)
else:
properties = (PropertyValue(Name='InputStream', Value=path),)
image = gp.queryGraphic(properties)
return image
@classmethod
@ -6598,6 +6640,7 @@ class Paths(object):
p, f, n, e = _P(source).info
if target:
p = target
e = f'.{e}'
if name:
e = ''
n = name
@ -6615,6 +6658,57 @@ class Dates(object):
return d
class OutputStream(unohelper.Base, XOutputStream):
def __init__(self):
self._buffer = b''
self.closed = 0
@property
def buffer(self):
return self._buffer
def closeOutput(self):
self.closed = 1
def writeBytes(self, seq):
if seq.value:
self._buffer = seq.value
def flush(self):
pass
class IOStream(object):
@classmethod
def buffer(cls):
return io.BytesIO()
@classmethod
def input(cls, buffer):
instance = 'com.sun.star.io.SequenceInputStream'
stream = create_instance(instance, True)
stream.initialize((uno.ByteSequence(buffer.getvalue()),))
return stream
@classmethod
def output(cls):
return OutputStream()
@classmethod
def qr(cls, data, **kwargs):
import segno
kwargs['kind'] = kwargs.get('kind', 'svg')
kwargs['scale'] = kwargs.get('scale', 8)
kwargs['border'] = kwargs.get('border', 2)
buffer = cls.buffer()
segno.make(data).save(buffer, **kwargs)
stream = cls.input(buffer)
return stream
class SpellChecker(object):
def __init__(self):
@ -6680,6 +6774,8 @@ def __getattr__(name):
return ClipBoard
if name == 'dates':
return Dates
if name == 'ios':
return IOStream()
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
@ -6766,6 +6862,18 @@ def get_fonts():
return device.FontDescriptors
def get_filters():
"""
Get all support filters
https://help.libreoffice.org/latest/en-US/text/shared/guide/convertfilters.html
"""
factory = create_instance('com.sun.star.document.FilterFactory')
rows = [data_to_dict(factory[name]) for name in factory]
for row in rows:
row['UINames'] = data_to_dict(row['UINames'])
return rows
# ~ https://en.wikipedia.org/wiki/Web_colors
def get_color(value):
COLORS = {

File diff suppressed because it is too large Load Diff