Add custom shapes

This commit is contained in:
El Mau 2024-01-02 19:46:51 -06:00
parent 12c6c5deaf
commit d337678d4e
8 changed files with 92 additions and 7 deletions

View File

@ -20,6 +20,7 @@
from .easymain import * from .easymain import *
from .easydialog import * from .easydialog import *
from .easytools import * from .easytools import *
from .constants import *
from .easydocs import LODocuments from .easydocs import LODocuments
from .easydrawpage import LOGalleries from .easydrawpage import LOGalleries

View File

@ -5,6 +5,17 @@
from com.sun.star.sheet import CellFlags from com.sun.star.sheet import CellFlags
from .easyuno import BitmapMode, FillStyle, LineStyle
__all__ = [
'ALL',
'ONLY_DATA',
'BitmapMode',
'FillStyle',
'LineStyle',
]
ONLY_DATA = 31 ONLY_DATA = 31
ALL = 1023 ALL = 1023

View File

@ -6,6 +6,7 @@ from .easymain import (log,
dict_to_property, create_instance dict_to_property, create_instance
) )
from .easyuno import IOStream from .easyuno import IOStream
from .easyshape import LOShapes, LOShape
class LOLayoutManager(BaseObject): class LOLayoutManager(BaseObject):
@ -339,3 +340,13 @@ class LODrawImpress(LODocument):
def __init__(self, obj): def __init__(self, obj):
super().__init__(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

View File

@ -15,6 +15,9 @@ from .easydoc import IOStream
DEFAULT_WH = 3000 DEFAULT_WH = 3000
DEFAULT_XY = 1000 DEFAULT_XY = 1000
TYPE_SHAPES = ('Line', 'Measure', 'Rectangle', 'Ellipse', 'Text', 'Connector',
'ClosedBezier', 'OpenBezier', 'PolyLine', 'PolyPolygon', 'ClosedFreeHand',
'OpenFreeHand')
# ~ class LOShapeBK(BaseObject): # ~ class LOShapeBK(BaseObject):
@ -194,10 +197,17 @@ class LODrawPage(BaseObject):
properties = options.copy() properties = options.copy()
"""Insert a shape in page, type shapes: """Insert a shape in page, type shapes:
Line Line
Measure
Rectangle Rectangle
Ellipse Ellipse
Text Text
Connector Connector
ClosedBezier
OpenBezier
PolyLine
PolyPolygon
ClosedFreeHand
OpenFreeHand
""" """
index = self.count index = self.count
default_height = DEFAULT_WH default_height = DEFAULT_WH
@ -209,13 +219,19 @@ class LODrawPage(BaseObject):
y = properties.pop('Y', DEFAULT_XY) y = properties.pop('Y', DEFAULT_XY)
name = properties.pop('Name', f'{type_shape.lower()}{index}') 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 = self._create_instance(service)
shape.Size = Size(w, h) shape.Size = Size(w, h)
shape.Position = Point(x, y) shape.Position = Point(x, y)
shape.Name = name shape.Name = name
self.obj.add(shape) self.obj.add(shape)
if not type_shape in TYPE_SHAPES:
shape.CustomShapeGeometry = dict_to_property({'Type': type_shape})
if properties: if properties:
set_properties(shape, properties) set_properties(shape, properties)

View File

@ -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.datatransfer import XTransferable, DataFlavor
from com.sun.star.ui.dialogs import TemplateDescription from com.sun.star.ui.dialogs import TemplateDescription
from .constants import ALL # ~ from .constants import ALL
from .messages import MESSAGES from .messages import MESSAGES
__all__ = [ __all__ = [
'ALL',
'DESKTOP', 'DESKTOP',
'INFO_DEBUG', 'INFO_DEBUG',
'IS_APPIMAGE', 'IS_APPIMAGE',

View File

@ -7,7 +7,10 @@ from .easymain import (
BaseObject, Paths, BaseObject, Paths,
create_instance, dict_to_property, set_properties, get_properties 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' IMAGE = 'com.sun.star.drawing.GraphicObjectShape'
@ -102,7 +105,15 @@ class LOShape(BaseObjectProperties):
return self.obj.ShapeType return self.obj.ShapeType
@property @property
def type(self): 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 @property
def name(self): def name(self):
@ -229,10 +240,14 @@ class LOShape(BaseObjectProperties):
return self.url return self.url
@property @property
def url(self): def url(self):
url = ''
if self.is_image: if self.is_image:
url = Paths.to_system(self.obj.GraphicURL.OriginURL) url = Paths.to_system(self.obj.GraphicURL.OriginURL)
else:
url = self.obj.FillBitmapName
return url return url
@url.setter
def url(self, value):
self.obj.FillBitmapURL = Paths.to_url(value)
@property @property
def visible(self): def visible(self):

View File

@ -3,7 +3,7 @@
import uno import uno
import unohelper import unohelper
from com.sun.star.io import IOException, XOutputStream from com.sun.star.io import IOException, XOutputStream
from .easymain import create_instance from .easymain import Paths, create_instance
# UNO Enum # UNO Enum
@ -16,6 +16,18 @@ class MessageBoxType():
import MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX 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): class IOStream(object):
"""Classe for input/output stream""" """Classe for input/output stream"""
@ -86,6 +98,8 @@ class BaseObjectProperties():
super().__setattr__(name, value) super().__setattr__(name, value)
else: else:
if name in self: if name in self:
if name == 'FillBitmapURL':
value = Paths.to_url(value)
setattr(self.obj, name, value) setattr(self.obj, name, value)
else: else:
object.__setattr__(self, name, value) object.__setattr__(self, name, value)

View File

@ -1,5 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from typing import Any
from .easymain import log, BaseObject from .easymain import log, BaseObject
from .easydoc import LODocument from .easydoc import LODocument
from .easydrawpage import LODrawPage from .easydrawpage import LODrawPage
@ -169,3 +171,19 @@ class LOWriter(LODocument):
@property @property
def shapes(self): def shapes(self):
return self.draw_page 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