End document for docs
This commit is contained in:
parent
298fceb1e2
commit
f9b2b7679a
Binary file not shown.
Binary file not shown.
|
@ -231,8 +231,20 @@ Export
|
|||
filter_name = 'doc'
|
||||
doc.export(path, filter_name)
|
||||
|
||||
path = '/home/mau/myfile.rtf'
|
||||
filter_name = 'rtf'
|
||||
doc.export(path, filter_name)
|
||||
|
||||
* For all support formats look `Apendix`_
|
||||
|
||||
* Export in memory.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.docs.new()
|
||||
filter_name = 'xlsx'
|
||||
excel_doc = doc.export(filter_name=filter_name)
|
||||
|
||||
|
||||
Fonst
|
||||
^^^^^
|
||||
|
@ -294,12 +306,14 @@ title
|
|||
|
||||
doc = app.active
|
||||
app.msgbox(doc.title)
|
||||
doc.title = 'New title'
|
||||
app.msgbox(doc.title)
|
||||
|
||||
|
||||
type
|
||||
~~~~
|
||||
|
||||
* Get type document: calc, writer, etc.
|
||||
* Get type document: calc, writer, etc. (read only)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -310,7 +324,7 @@ type
|
|||
uid
|
||||
~~~
|
||||
|
||||
* Get internal RuntimeUID form document.
|
||||
* Get internal RuntimeUID form document. (read only)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -321,7 +335,7 @@ uid
|
|||
is_saved
|
||||
~~~~~~~~
|
||||
|
||||
* If document is saved in this or not
|
||||
* If document is saved in this or not (read only)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -332,7 +346,7 @@ is_saved
|
|||
is_modified
|
||||
~~~~~~~~~~~
|
||||
|
||||
* If document has been modified
|
||||
* If document has been modified (read only)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -352,7 +366,7 @@ is_read_only
|
|||
path
|
||||
~~~~
|
||||
|
||||
* Get path of document.
|
||||
* Get path of document. (read only)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -361,9 +375,9 @@ path
|
|||
|
||||
|
||||
dir
|
||||
~~~~
|
||||
~~~
|
||||
|
||||
* Get only directory from path saved
|
||||
* Get only directory from path saved (read only)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -371,7 +385,124 @@ dir
|
|||
app.msgbox(doc.dir)
|
||||
|
||||
|
||||
file_name
|
||||
~~~~~~~~~
|
||||
|
||||
* Get only file name from path saved (read only)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.active
|
||||
app.msgbox(doc.file_name)
|
||||
|
||||
|
||||
name
|
||||
~~~~
|
||||
|
||||
* Get only name without extension (read only)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.active
|
||||
app.msgbox(doc.file_name)
|
||||
|
||||
|
||||
visible
|
||||
~~~~~~~
|
||||
|
||||
* Hide or show document.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.active
|
||||
doc.visible = False
|
||||
app.msgbox(doc.visible)
|
||||
doc.visible = True
|
||||
|
||||
|
||||
zoom
|
||||
~~~~
|
||||
|
||||
* Get or set zoom value.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.active
|
||||
zoom = doc.zoom
|
||||
app.msgbox(zoom)
|
||||
doc.zoom = zoom * 2
|
||||
app.msgbox(doc.zoom)
|
||||
doc.zoom = zoom
|
||||
|
||||
|
||||
selection
|
||||
~~~~~~~~~
|
||||
|
||||
* **CAUTION**: Selection can be many things.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.active
|
||||
selection = doc.selection
|
||||
app.msgbox(selection)
|
||||
|
||||
|
||||
status_bar
|
||||
~~~~~~~~~~
|
||||
|
||||
* Get status bar, always control in other thread.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@app.run_in_thread
|
||||
def update_status_bar(sb, text, limit):
|
||||
sb.start(text, limit)
|
||||
for i in range(limit):
|
||||
sb.setValue(i)
|
||||
app.sleep(1)
|
||||
# ~ Is important free status bar
|
||||
sb.end()
|
||||
return
|
||||
|
||||
def main():
|
||||
doc = app.active
|
||||
update_status_bar(doc.status_bar, 'Line', 10)
|
||||
return
|
||||
|
||||
|
||||
Methods
|
||||
^^^^^^^
|
||||
|
||||
set_focus
|
||||
~~~~~~~~~
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
name = 'MyDoc.ods'
|
||||
if name in app.docs:
|
||||
doc = app.docs[name]
|
||||
doc.set_focus()
|
||||
|
||||
copy
|
||||
~~~~
|
||||
|
||||
* Copy current selection
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.active
|
||||
doc.copy()
|
||||
|
||||
|
||||
paste
|
||||
~~~~~
|
||||
|
||||
* Paste any content in clipboard
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.active
|
||||
doc.paste()
|
||||
|
||||
|
||||
.. _dispatch command: https://wiki.documentfoundation.org/Development/DispatchCommands
|
||||
|
|
|
@ -220,11 +220,21 @@
|
|||
<span class="n">path</span> <span class="o">=</span> <span class="s1">'/home/mau/myfile.doc'</span>
|
||||
<span class="n">filter_name</span> <span class="o">=</span> <span class="s1">'doc'</span>
|
||||
<span class="n">doc</span><span class="o">.</span><span class="n">export</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">filter_name</span><span class="p">)</span>
|
||||
|
||||
<span class="n">path</span> <span class="o">=</span> <span class="s1">'/home/mau/myfile.rtf'</span>
|
||||
<span class="n">filter_name</span> <span class="o">=</span> <span class="s1">'rtf'</span>
|
||||
<span class="n">doc</span><span class="o">.</span><span class="n">export</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">filter_name</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>For all support formats look <a class="reference external" href="apendixes.html">Apendix</a></p></li>
|
||||
<li><p>Export 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">docs</span><span class="o">.</span><span class="n">new</span><span class="p">()</span>
|
||||
<span class="n">filter_name</span> <span class="o">=</span> <span class="s1">'xlsx'</span>
|
||||
<span class="n">excel_doc</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">export</span><span class="p">(</span><span class="n">filter_name</span><span class="o">=</span><span class="n">filter_name</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="fonst">
|
||||
<h2>Fonst<a class="headerlink" href="#fonst" title="Permalink to this headline">¶</a></h2>
|
||||
|
@ -276,13 +286,15 @@
|
|||
<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>
|
||||
<span class="n">doc</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="s1">'New title'</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 id="type">
|
||||
<h3>type<a class="headerlink" href="#type" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Get type document: calc, writer, etc.</p></li>
|
||||
<li><p>Get type document: calc, writer, etc. (read only)</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">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">type</span><span class="p">)</span>
|
||||
|
@ -292,7 +304,7 @@
|
|||
<section id="uid">
|
||||
<h3>uid<a class="headerlink" href="#uid" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Get internal RuntimeUID form document.</p></li>
|
||||
<li><p>Get internal RuntimeUID form document. (read only)</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">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">uid</span><span class="p">)</span>
|
||||
|
@ -302,7 +314,7 @@
|
|||
<section id="is-saved">
|
||||
<h3>is_saved<a class="headerlink" href="#is-saved" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>If document is saved in this or not</p></li>
|
||||
<li><p>If document is saved in this or not (read only)</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">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">is_saved</span><span class="p">)</span>
|
||||
|
@ -312,7 +324,7 @@
|
|||
<section id="is-modified">
|
||||
<h3>is_modified<a class="headerlink" href="#is-modified" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>If document has been modified</p></li>
|
||||
<li><p>If document has been modified (read only)</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">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">is_modified</span><span class="p">)</span>
|
||||
|
@ -329,7 +341,7 @@
|
|||
<section id="path">
|
||||
<h3>path<a class="headerlink" href="#path" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Get path of document.</p></li>
|
||||
<li><p>Get path of document. (read only)</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">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">path</span><span class="p">)</span>
|
||||
|
@ -339,13 +351,124 @@
|
|||
<section id="dir">
|
||||
<h3>dir<a class="headerlink" href="#dir" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Get only directory from path saved</p></li>
|
||||
<li><p>Get only directory from path saved (read only)</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">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">dir</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="file-name">
|
||||
<h3>file_name<a class="headerlink" href="#file-name" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Get only file name from path saved (read only)</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">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">file_name</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="name">
|
||||
<h3>name<a class="headerlink" href="#name" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Get only name without extension (read only)</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">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">file_name</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="visible">
|
||||
<h3>visible<a class="headerlink" href="#visible" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Hide or show document.</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">doc</span><span class="o">.</span><span class="n">visible</span> <span class="o">=</span> <span class="kc">False</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">visible</span><span class="p">)</span>
|
||||
<span class="n">doc</span><span class="o">.</span><span class="n">visible</span> <span class="o">=</span> <span class="kc">True</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="zoom">
|
||||
<h3>zoom<a class="headerlink" href="#zoom" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Get or set zoom value.</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">zoom</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">zoom</span>
|
||||
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">zoom</span><span class="p">)</span>
|
||||
<span class="n">doc</span><span class="o">.</span><span class="n">zoom</span> <span class="o">=</span> <span class="n">zoom</span> <span class="o">*</span> <span class="mi">2</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">zoom</span><span class="p">)</span>
|
||||
<span class="n">doc</span><span class="o">.</span><span class="n">zoom</span> <span class="o">=</span> <span class="n">zoom</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="selection">
|
||||
<h3>selection<a class="headerlink" href="#selection" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p><strong>CAUTION</strong>: Selection can be many things.</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">selection</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">selection</span>
|
||||
<span class="n">app</span><span class="o">.</span><span class="n">msgbox</span><span class="p">(</span><span class="n">selection</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="status-bar">
|
||||
<h3>status_bar<a class="headerlink" href="#status-bar" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Get status bar, always control in other thread.</p></li>
|
||||
</ul>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">run_in_thread</span>
|
||||
<span class="k">def</span> <span class="nf">update_status_bar</span><span class="p">(</span><span class="n">sb</span><span class="p">,</span> <span class="n">text</span><span class="p">,</span> <span class="n">limit</span><span class="p">):</span>
|
||||
<span class="n">sb</span><span class="o">.</span><span class="n">start</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="n">limit</span><span class="p">)</span>
|
||||
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">limit</span><span class="p">):</span>
|
||||
<span class="n">sb</span><span class="o">.</span><span class="n">setValue</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
|
||||
<span class="n">app</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
|
||||
<span class="c1"># ~ Is important free status bar</span>
|
||||
<span class="n">sb</span><span class="o">.</span><span class="n">end</span><span class="p">()</span>
|
||||
<span class="k">return</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">main</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">active</span>
|
||||
<span class="n">update_status_bar</span><span class="p">(</span><span class="n">doc</span><span class="o">.</span><span class="n">status_bar</span><span class="p">,</span> <span class="s1">'Line'</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
|
||||
<span class="k">return</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
<section id="methods">
|
||||
<h2>Methods<a class="headerlink" href="#methods" title="Permalink to this headline">¶</a></h2>
|
||||
<section id="set-focus">
|
||||
<h3>set_focus<a class="headerlink" href="#set-focus" title="Permalink to this headline">¶</a></h3>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">name</span> <span class="o">=</span> <span class="s1">'MyDoc.ods'</span>
|
||||
<span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">app</span><span class="o">.</span><span class="n">docs</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="p">[</span><span class="n">name</span><span class="p">]</span>
|
||||
<span class="n">doc</span><span class="o">.</span><span class="n">set_focus</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="copy">
|
||||
<h3>copy<a class="headerlink" href="#copy" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Copy current selection</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">doc</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="paste">
|
||||
<h3>paste<a class="headerlink" href="#paste" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Paste any content in clipboard</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">doc</span><span class="o">.</span><span class="n">paste</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
|
|
@ -136,6 +136,7 @@
|
|||
<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>
|
||||
<li class="toctree-l2"><a class="reference internal" href="application.html#methods">Methods</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="calc.html">Calc</a><ul>
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -231,8 +231,20 @@ Export
|
|||
filter_name = 'doc'
|
||||
doc.export(path, filter_name)
|
||||
|
||||
path = '/home/mau/myfile.rtf'
|
||||
filter_name = 'rtf'
|
||||
doc.export(path, filter_name)
|
||||
|
||||
* For all support formats look `Apendix`_
|
||||
|
||||
* Export in memory.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.docs.new()
|
||||
filter_name = 'xlsx'
|
||||
excel_doc = doc.export(filter_name=filter_name)
|
||||
|
||||
|
||||
Fonst
|
||||
^^^^^
|
||||
|
@ -395,7 +407,102 @@ name
|
|||
app.msgbox(doc.file_name)
|
||||
|
||||
|
||||
visible
|
||||
~~~~~~~
|
||||
|
||||
* Hide or show document.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.active
|
||||
doc.visible = False
|
||||
app.msgbox(doc.visible)
|
||||
doc.visible = True
|
||||
|
||||
|
||||
zoom
|
||||
~~~~
|
||||
|
||||
* Get or set zoom value.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.active
|
||||
zoom = doc.zoom
|
||||
app.msgbox(zoom)
|
||||
doc.zoom = zoom * 2
|
||||
app.msgbox(doc.zoom)
|
||||
doc.zoom = zoom
|
||||
|
||||
|
||||
selection
|
||||
~~~~~~~~~
|
||||
|
||||
* **CAUTION**: Selection can be many things.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.active
|
||||
selection = doc.selection
|
||||
app.msgbox(selection)
|
||||
|
||||
|
||||
status_bar
|
||||
~~~~~~~~~~
|
||||
|
||||
* Get status bar, always control in other thread.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@app.run_in_thread
|
||||
def update_status_bar(sb, text, limit):
|
||||
sb.start(text, limit)
|
||||
for i in range(limit):
|
||||
sb.setValue(i)
|
||||
app.sleep(1)
|
||||
# ~ Is important free status bar
|
||||
sb.end()
|
||||
return
|
||||
|
||||
def main():
|
||||
doc = app.active
|
||||
update_status_bar(doc.status_bar, 'Line', 10)
|
||||
return
|
||||
|
||||
|
||||
Methods
|
||||
^^^^^^^
|
||||
|
||||
set_focus
|
||||
~~~~~~~~~
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
name = 'MyDoc.ods'
|
||||
if name in app.docs:
|
||||
doc = app.docs[name]
|
||||
doc.set_focus()
|
||||
|
||||
copy
|
||||
~~~~
|
||||
|
||||
* Copy current selection
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.active
|
||||
doc.copy()
|
||||
|
||||
|
||||
paste
|
||||
~~~~~
|
||||
|
||||
* Paste any content in clipboard
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
doc = app.active
|
||||
doc.paste()
|
||||
|
||||
|
||||
.. _dispatch command: https://wiki.documentfoundation.org/Development/DispatchCommands
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Calc
|
||||
----
|
||||
|
||||
Remember, always import library.
|
||||
Remember, always import library.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -18,8 +18,11 @@ Current doc
|
|||
app.msgbox(doc.type)
|
||||
|
||||
|
||||
Sheets
|
||||
^^^^^^
|
||||
|
||||
Active sheet
|
||||
^^^^^^^^^^^^
|
||||
~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
|
|
@ -1121,10 +1121,6 @@ class LODocument(object):
|
|||
def name(self):
|
||||
return _P(self.path).name
|
||||
|
||||
@property
|
||||
def status_bar(self):
|
||||
return self._cc.getStatusIndicator()
|
||||
|
||||
@property
|
||||
def visible(self):
|
||||
w = self.frame.ContainerWindow
|
||||
|
@ -1163,7 +1159,6 @@ class LODocument(object):
|
|||
@property
|
||||
def selection(self):
|
||||
sel = self.obj.CurrentSelection
|
||||
# ~ return _get_class_uno(sel)
|
||||
return sel
|
||||
|
||||
@property
|
||||
|
@ -1171,6 +1166,11 @@ class LODocument(object):
|
|||
taf = create_instance('com.sun.star.sheet.TableAutoFormats')
|
||||
return taf.ElementNames
|
||||
|
||||
@property
|
||||
def status_bar(self):
|
||||
bar = self._cc.getStatusIndicator()
|
||||
return bar
|
||||
|
||||
def create_instance(self, name):
|
||||
obj = self.obj.createInstance(name)
|
||||
return obj
|
||||
|
@ -1199,10 +1199,11 @@ class LODocument(object):
|
|||
self._cc.select(obj)
|
||||
return
|
||||
|
||||
def to_pdf(self, path: str='', args: dict={}):
|
||||
def to_pdf(self, path: str='', options: dict={}):
|
||||
"""
|
||||
https://wiki.documentfoundation.org/Macros/Python_Guide/PDF_export_filter_data
|
||||
"""
|
||||
args = options.copy()
|
||||
stream = None
|
||||
path_pdf = 'private:stream'
|
||||
if path:
|
||||
|
@ -1229,40 +1230,56 @@ class LODocument(object):
|
|||
|
||||
return stream
|
||||
|
||||
def export(self, path: str, filter_name: str, args: dict={}):
|
||||
def export(self, path: str='', filter_name: str='', options: dict={}):
|
||||
FILTERS = {
|
||||
'xlsx': 'Calc MS Excel 2007 XML',
|
||||
'xls': 'MS Excel 97',
|
||||
'docx': 'MS Word 2007 XML',
|
||||
'doc': 'MS Word 97',
|
||||
'rtf': 'Rich Text Format',
|
||||
}
|
||||
args = options.copy()
|
||||
stream = None
|
||||
path_target = 'private:stream'
|
||||
if path:
|
||||
path_target = _P.to_url(path)
|
||||
|
||||
filter_name = FILTERS.get(filter_name, filter_name)
|
||||
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_target, opt)
|
||||
except Exception as e:
|
||||
error(e)
|
||||
path = ''
|
||||
|
||||
return _P.exists(path)
|
||||
if not stream is None:
|
||||
stream = stream.buffer
|
||||
|
||||
def save(self, path: str='', args: dict={}) -> bool:
|
||||
result = True
|
||||
opt = dict_to_property(args)
|
||||
if path:
|
||||
try:
|
||||
self.obj.storeAsURL(_P.to_url(path), opt)
|
||||
except Exception as e:
|
||||
error(e)
|
||||
result = False
|
||||
else:
|
||||
return stream
|
||||
|
||||
def save(self, path: str='', options: dict={}):
|
||||
if not path:
|
||||
self.obj.store()
|
||||
return result
|
||||
return
|
||||
|
||||
args = options.copy()
|
||||
path_target = _P.to_url(path)
|
||||
|
||||
opt = dict_to_property(args)
|
||||
try:
|
||||
self.obj.storeAsURL(path_target, opt)
|
||||
except Exception as e:
|
||||
error(e)
|
||||
|
||||
return
|
||||
|
||||
def close(self):
|
||||
self.obj.close(True)
|
||||
|
@ -6140,6 +6157,7 @@ class LODBServer(object):
|
|||
self._conn = None
|
||||
self._error = 'Not connected'
|
||||
self._type = ''
|
||||
self._drivers = []
|
||||
|
||||
def __str__(self):
|
||||
return f'DB type {self._type}'
|
||||
|
@ -6158,13 +6176,19 @@ class LODBServer(object):
|
|||
def error(self):
|
||||
return self._error
|
||||
|
||||
@property
|
||||
def drivers(self):
|
||||
return self._drivers
|
||||
|
||||
def disconnet(self):
|
||||
if not self._conn is None:
|
||||
if not self._conn.isClosed():
|
||||
self._conn.close()
|
||||
self._conn.dispose()
|
||||
return
|
||||
|
||||
def connect(self, args):
|
||||
def connect(self, options={}):
|
||||
args = options.copy()
|
||||
self._error = ''
|
||||
self._type = args.get('type', 'postgres')
|
||||
driver = self.DRIVERS[self._type]
|
||||
|
@ -6175,9 +6199,14 @@ class LODBServer(object):
|
|||
password = args['password']
|
||||
|
||||
data = {'user': user, 'password': password}
|
||||
# ~ 'JavaDriverClass': 'org.mariadb.jdbc.Driver'}
|
||||
url = f'sdbc:{driver}://{server}:{port}/{dbname}'
|
||||
# ~ https://downloads.mariadb.com/Connectors/java/
|
||||
# ~ url = f'jdbc:mysql://{server}:{port}/{dbname}'
|
||||
|
||||
args = dict_to_property(data)
|
||||
manager = create_instance('com.sun.star.sdbc.DriverManager')
|
||||
self._drivers = [d.ImplementationName for d in manager]
|
||||
|
||||
try:
|
||||
self._conn = manager.getConnectionWithInfo(url, args)
|
||||
|
@ -6187,6 +6216,18 @@ class LODBServer(object):
|
|||
|
||||
return self
|
||||
|
||||
def execute(self, sql):
|
||||
query = self._conn.createStatement()
|
||||
try:
|
||||
query.execute(sql)
|
||||
result = True
|
||||
except Exception as e:
|
||||
error(e)
|
||||
self._error = str(e)
|
||||
result = False
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def create_window(args):
|
||||
return LOWindow(args)
|
||||
|
|
Loading…
Reference in New Issue