New class for shapes
This commit is contained in:
parent
01dab4e416
commit
925adfa982
|
@ -23,6 +23,7 @@
|
|||
import datetime
|
||||
import getpass
|
||||
import gettext
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
|
@ -546,6 +547,17 @@ def _export_image(obj, args):
|
|||
return _P.exists(path)
|
||||
|
||||
|
||||
def sha256(data):
|
||||
result = hashlib.sha256(data.encode()).hexdigest()
|
||||
return result
|
||||
|
||||
def sha512(data):
|
||||
result = hashlib.sha512(data.encode()).hexdigest()
|
||||
return result
|
||||
|
||||
|
||||
# ~ Classes
|
||||
|
||||
class LOBaseObject(object):
|
||||
|
||||
def __init__(self, obj):
|
||||
|
@ -553,7 +565,7 @@ class LOBaseObject(object):
|
|||
|
||||
def __setattr__(self, name, value):
|
||||
exists = hasattr(self, name)
|
||||
if not exists and name != '_obj':
|
||||
if not exists and not name in ('_obj', '_index'):
|
||||
setattr(self._obj, name, value)
|
||||
else:
|
||||
super().__setattr__(name, value)
|
||||
|
@ -1060,6 +1072,15 @@ class LOCalcRange(object):
|
|||
def rows(self):
|
||||
return self.obj.Rows.Count
|
||||
|
||||
@property
|
||||
def row(self):
|
||||
r1 = self.address.Row
|
||||
r2 = r1 + 1
|
||||
ra = self.current_region.range_address
|
||||
c1 = ra.StartColumn
|
||||
c2 = ra.EndColumn + 1
|
||||
return LOCalcRange(self.sheet[r1:r2, c1:c2].obj)
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
return self.obj.Type
|
||||
|
@ -1204,11 +1225,74 @@ class LOWriter(LODocument):
|
|||
self._type = WRITER
|
||||
|
||||
|
||||
class LOShape(LOBaseObject):
|
||||
|
||||
def __init__(self, obj, index):
|
||||
self._index = index
|
||||
super().__init__(obj)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.obj.Name or f'shape{self.index}'
|
||||
|
||||
@property
|
||||
def index(self):
|
||||
return self._index
|
||||
|
||||
@property
|
||||
def string(self):
|
||||
return self.obj.String
|
||||
@string.setter
|
||||
def string(self, value):
|
||||
self.obj.String = value
|
||||
|
||||
|
||||
class LODrawPage(LOBaseObject):
|
||||
|
||||
def __init__(self, obj):
|
||||
super().__init__(obj)
|
||||
|
||||
def __getitem__(self, index):
|
||||
if isinstance(index, int):
|
||||
shape = LOShape(self.obj[index], index)
|
||||
else:
|
||||
for i, o in enumerate(self.obj):
|
||||
shape = self.obj[i]
|
||||
name = shape.Name or f'shape{i}'
|
||||
if name == index:
|
||||
shape = LOShape(shape, i)
|
||||
break
|
||||
return shape
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.obj.Name
|
||||
|
||||
@property
|
||||
def width(self):
|
||||
return self.obj.Width
|
||||
|
||||
@property
|
||||
def height(self):
|
||||
return self.obj.Height
|
||||
|
||||
@property
|
||||
def count(self):
|
||||
return self.obj.Count
|
||||
|
||||
|
||||
class LODrawImpress(LODocument):
|
||||
|
||||
def __init__(self, obj):
|
||||
super().__init__(obj)
|
||||
|
||||
def __getitem__(self, index):
|
||||
if isinstance(index, int):
|
||||
page = self.obj.DrawPages[index]
|
||||
else:
|
||||
page = self.obj.DrawPages.getByName(index)
|
||||
return LODrawPage(page)
|
||||
|
||||
@property
|
||||
def selection(self):
|
||||
sel = self.obj.CurrentSelection[0]
|
||||
|
@ -2550,6 +2634,8 @@ class classproperty:
|
|||
class Paths(object):
|
||||
|
||||
def __init__(self, path=''):
|
||||
if path.startswith('file://'):
|
||||
path = str(Path(uno.fileUrlToSystemPath(path)).resolve())
|
||||
self._path = Path(path)
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue