diff --git a/source/easymacro/__init__.py b/source/easymacro/__init__.py index ac54c2e..9cb1f89 100644 --- a/source/easymacro/__init__.py +++ b/source/easymacro/__init__.py @@ -20,6 +20,7 @@ from .easymain import * from .easydialog import * from .easytools import * +from .constants import * from .easydocs import LODocuments from .easydrawpage import LOGalleries diff --git a/source/easymacro/constants.py b/source/easymacro/constants.py index bef7b98..c81473a 100644 --- a/source/easymacro/constants.py +++ b/source/easymacro/constants.py @@ -5,6 +5,17 @@ from com.sun.star.sheet import CellFlags +from .easyuno import BitmapMode, FillStyle, LineStyle + + +__all__ = [ + 'ALL', + 'ONLY_DATA', + 'BitmapMode', + 'FillStyle', + 'LineStyle', +] + ONLY_DATA = 31 ALL = 1023 diff --git a/source/easymacro/easydoc.py b/source/easymacro/easydoc.py index a0d5fa3..a16ded0 100644 --- a/source/easymacro/easydoc.py +++ b/source/easymacro/easydoc.py @@ -6,6 +6,7 @@ from .easymain import (log, dict_to_property, create_instance ) from .easyuno import IOStream +from .easyshape import LOShapes, LOShape class LOLayoutManager(BaseObject): @@ -339,3 +340,13 @@ class LODrawImpress(LODocument): def __init__(self, obj): super().__init__(obj) + + @property + def selection(self): + """Get current selecction""" + sel = self.obj.CurrentSelection + if sel.Count == 1: + sel = LOShape(sel[0]) + else: + sel = LOShapes(sel) + return sel \ No newline at end of file diff --git a/source/easymacro/easydrawpage.py b/source/easymacro/easydrawpage.py index 05502ce..e30c16f 100644 --- a/source/easymacro/easydrawpage.py +++ b/source/easymacro/easydrawpage.py @@ -15,6 +15,9 @@ from .easydoc import IOStream DEFAULT_WH = 3000 DEFAULT_XY = 1000 +TYPE_SHAPES = ('Line', 'Measure', 'Rectangle', 'Ellipse', 'Text', 'Connector', + 'ClosedBezier', 'OpenBezier', 'PolyLine', 'PolyPolygon', 'ClosedFreeHand', + 'OpenFreeHand') # ~ class LOShapeBK(BaseObject): @@ -194,10 +197,17 @@ class LODrawPage(BaseObject): properties = options.copy() """Insert a shape in page, type shapes: Line + Measure Rectangle Ellipse Text Connector + ClosedBezier + OpenBezier + PolyLine + PolyPolygon + ClosedFreeHand + OpenFreeHand """ index = self.count default_height = DEFAULT_WH @@ -209,13 +219,19 @@ class LODrawPage(BaseObject): y = properties.pop('Y', DEFAULT_XY) name = properties.pop('Name', f'{type_shape.lower()}{index}') - service = f'com.sun.star.drawing.{type_shape}Shape' + if type_shape in TYPE_SHAPES: + service = f'com.sun.star.drawing.{type_shape}Shape' + else: + service = 'com.sun.star.drawing.CustomShape' shape = self._create_instance(service) shape.Size = Size(w, h) shape.Position = Point(x, y) shape.Name = name self.obj.add(shape) + if not type_shape in TYPE_SHAPES: + shape.CustomShapeGeometry = dict_to_property({'Type': type_shape}) + if properties: set_properties(shape, properties) diff --git a/source/easymacro/easymain.py b/source/easymacro/easymain.py index fbacd0b..3a10334 100644 --- a/source/easymacro/easymain.py +++ b/source/easymacro/easymain.py @@ -24,12 +24,11 @@ from com.sun.star.beans import PropertyValue, NamedValue, StringPair from com.sun.star.datatransfer import XTransferable, DataFlavor from com.sun.star.ui.dialogs import TemplateDescription -from .constants import ALL +# ~ from .constants import ALL from .messages import MESSAGES __all__ = [ - 'ALL', 'DESKTOP', 'INFO_DEBUG', 'IS_APPIMAGE', diff --git a/source/easymacro/easyshape.py b/source/easymacro/easyshape.py index d3085a6..f3c93fe 100644 --- a/source/easymacro/easyshape.py +++ b/source/easymacro/easyshape.py @@ -7,7 +7,10 @@ from .easymain import ( BaseObject, Paths, create_instance, dict_to_property, set_properties, get_properties ) -from .easyuno import BaseObjectProperties, IOStream, get_input_stream +from .easyuno import ( + BaseObjectProperties, + IOStream, + get_input_stream) IMAGE = 'com.sun.star.drawing.GraphicObjectShape' @@ -102,7 +105,15 @@ class LOShape(BaseObjectProperties): return self.obj.ShapeType @property def type(self): - return self.shape_type + value = '' + if hasattr(self.obj, 'CustomShapeGeometry'): + for p in self.obj.CustomShapeGeometry: + if p.Name == 'Type': + value = p.Value + break + else: + value = self.shape_type + return value @property def name(self): @@ -229,10 +240,14 @@ class LOShape(BaseObjectProperties): return self.url @property def url(self): - url = '' if self.is_image: url = Paths.to_system(self.obj.GraphicURL.OriginURL) + else: + url = self.obj.FillBitmapName return url + @url.setter + def url(self, value): + self.obj.FillBitmapURL = Paths.to_url(value) @property def visible(self): diff --git a/source/easymacro/easyuno.py b/source/easymacro/easyuno.py index a00d197..d4dce6f 100644 --- a/source/easymacro/easyuno.py +++ b/source/easymacro/easyuno.py @@ -3,7 +3,7 @@ import uno import unohelper from com.sun.star.io import IOException, XOutputStream -from .easymain import create_instance +from .easymain import Paths, create_instance # UNO Enum @@ -16,6 +16,18 @@ class MessageBoxType(): import MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX +class LineStyle(): + from com.sun.star.drawing.LineStyle import NONE, SOLID, DASH + + +class FillStyle(): + from com.sun.star.drawing.FillStyle import NONE, SOLID, GRADIENT, HATCH, BITMAP + + +class BitmapMode(): + from com.sun.star.drawing.BitmapMode import REPEAT, STRETCH, NO_REPEAT + + class IOStream(object): """Classe for input/output stream""" @@ -86,6 +98,8 @@ class BaseObjectProperties(): super().__setattr__(name, value) else: if name in self: + if name == 'FillBitmapURL': + value = Paths.to_url(value) setattr(self.obj, name, value) else: object.__setattr__(self, name, value) diff --git a/source/easymacro/easywriter.py b/source/easymacro/easywriter.py index 04afb1b..a07dcf3 100644 --- a/source/easymacro/easywriter.py +++ b/source/easymacro/easywriter.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +from typing import Any + from .easymain import log, BaseObject from .easydoc import LODocument from .easydrawpage import LODrawPage @@ -169,3 +171,19 @@ class LOWriter(LODocument): @property def shapes(self): return self.draw_page + + @property + def cursor(self): + return self.obj.Text.createTextCursor() + + @property + def view_cursor(self): + return self._cc.ViewCursor + + def select(self, rango: Any): + """""" + obj = rango + if hasattr(rango, 'obj'): + obj = rango.obj + self._cc.select(obj) + return