Add custom shapes
This commit is contained in:
parent
12c6c5deaf
commit
d337678d4e
|
@ -20,6 +20,7 @@
|
|||
from .easymain import *
|
||||
from .easydialog import *
|
||||
from .easytools import *
|
||||
from .constants import *
|
||||
from .easydocs import LODocuments
|
||||
|
||||
from .easydrawpage import LOGalleries
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue