diff --git a/doc/source/main/application.rst b/doc/source/main/application.rst new file mode 100644 index 0000000..88ce71d --- /dev/null +++ b/doc/source/main/application.rst @@ -0,0 +1,85 @@ + +Application +----------- + +Remember, always import library. + +.. code-block:: python + + import easymacro as app + + +Current doc +^^^^^^^^^^^ + +.. code-block:: python + + doc = app.active + app.msgbox(doc.title) + + +Iter docs +^^^^^^^^^ + +.. code-block:: python + + for doc in app.docs: + app.msgbox(doc.title) + + +Count +^^^^^ + +.. code-block:: python + + count = len(app.docs) + app.msgbox(count) + + +Get by name +^^^^^^^^^^^ + +.. code-block:: python + + name = 'MyDoc.ods' + if name in app.docs: + doc = app.docs[name] + app.msgbox(doc.title) + + +New +^^^ + +For default create new Calc document. + +.. code-block:: python + + doc = app.docs.new() + app.msgbox(doc.type) + +For new Writer document. + +.. code-block:: python + + doc = app.docs.new('writer') + app.msgbox(doc.type) + +Other documents. + +.. code-block:: python + + doc = app.docs.new('draw') + app.msgbox(doc.type) + + doc = app.docs.new('impress') + app.msgbox(doc.type) + + +Open +^^^^ + +.. code-block:: python + + path = '/home/mau/MyDoc.ods' + doc = app.docs.open(path) + diff --git a/doc/source/main/easymacro.rst b/doc/source/main/easymacro.rst index 7133449..e597ef1 100644 --- a/doc/source/main/easymacro.rst +++ b/doc/source/main/easymacro.rst @@ -2,7 +2,18 @@ Library easymacro.py ==================== -.. include:: 01_tools.rst -.. include:: 02_tools.rst +**easymacro.py** it's a library for easily develop macros en LibreOffice con Python. It is an abstraction layer between the extensive and complex LibreOffice API UNO and your code. +Probably, your will be more happy if used it. :) +You can used **easymacro.py** with any extension or directly in your macros. + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + tools_for_debug.rst + tools.rst + application.rst + calc.rst + writer.rst diff --git a/doc/source/main/02_tools.rst b/doc/source/main/tools.rst similarity index 99% rename from doc/source/main/02_tools.rst rename to doc/source/main/tools.rst index 946128f..2cefda5 100644 --- a/doc/source/main/02_tools.rst +++ b/doc/source/main/tools.rst @@ -1,6 +1,6 @@ -1.2) Tools -^^^^^^^^^^ +Tools +----- Remember, always import library. diff --git a/doc/source/main/01_tools.rst b/doc/source/main/tools_for_debug.rst similarity index 86% rename from doc/source/main/01_tools.rst rename to doc/source/main/tools_for_debug.rst index 3879da2..322055c 100644 --- a/doc/source/main/01_tools.rst +++ b/doc/source/main/tools_for_debug.rst @@ -1,18 +1,6 @@ -**easymacro.py** it's a library for easily develop macros en LibreOffice con -Python. It is an abstraction layer between the extensive and complex LibreOffice -API UNO and your code. - -Probably, your will be more happy if used it. :) - -You can used **easymacro.py** with any extension or directly in your macros. - - -1) Tools --------- - -1.1) For debug -^^^^^^^^^^^^^^ +Tools for debug +--------------- **INFO_DEBUG** ^^^^^^^^^^^^^^ diff --git a/source/easymacro.py b/source/easymacro.py index b8db956..3a8193c 100644 --- a/source/easymacro.py +++ b/source/easymacro.py @@ -2882,6 +2882,9 @@ class LOCalcRange(object): return def _cast(self, t, v): + if not t: + return v + if t == datetime.date: nv = datetime.date.fromordinal(int(v) + DATE_OFFSET) else: @@ -3958,6 +3961,7 @@ class LODocs(object): return doc def __len__(self): + # ~ len(self._desktop.Components) for i, _ in enumerate(self._desktop.Components): pass return i + 1 @@ -6659,48 +6663,6 @@ def get_fonts(): return device.FontDescriptors -# ~ From request -# ~ https://github.com/psf/requests/blob/master/requests/structures.py#L15 -class CaseInsensitiveDict(MutableMapping): - - def __init__(self, data=None, **kwargs): - self._store = OrderedDict() - if data is None: - data = {} - self.update(data, **kwargs) - - def __setitem__(self, key, value): - # Use the lowercased key for lookups, but store the actual - # key alongside the value. - self._store[key.lower()] = (key, value) - - def __getitem__(self, key): - return self._store[key.lower()][1] - - def __delitem__(self, key): - del self._store[key.lower()] - - def __iter__(self): - return (casedkey for casedkey, mappedvalue in self._store.values()) - - def __len__(self): - return len(self._store) - - def lower_items(self): - """Like iteritems(), but with all lowercase keys.""" - values = ( - (lowerkey, keyval[1]) for (lowerkey, keyval) in self._store.items() - ) - return values - - # Copy is required - def copy(self): - return CaseInsensitiveDict(self._store.values()) - - def __repr__(self): - return str(dict(self.items())) - - # ~ https://en.wikipedia.org/wiki/Web_colors def get_color(value): COLORS = {