2022-08-18 22:42:32 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2023-12-17 23:57:30 -06:00
|
|
|
from .easymain import log, BaseObject
|
2022-08-18 22:42:32 -05:00
|
|
|
from .easydoc import LODocument
|
|
|
|
|
|
|
|
|
2023-12-17 23:57:30 -06:00
|
|
|
class LOWriterTextPortion(BaseObject):
|
|
|
|
|
|
|
|
def __init__(self, obj):
|
|
|
|
super().__init__(obj)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'Writer: TextPortion'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def string(self):
|
|
|
|
return self.obj.String
|
|
|
|
|
|
|
|
|
|
|
|
class LOWriterParagraph(BaseObject):
|
|
|
|
TEXT_PORTION = 'SwXTextPortion'
|
|
|
|
|
|
|
|
def __init__(self, obj):
|
|
|
|
super().__init__(obj)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'Writer: Paragraph'
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
self._iter = iter(self.obj)
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __next__(self):
|
|
|
|
obj = next(self._iter)
|
|
|
|
type_obj = obj.ImplementationName
|
|
|
|
if type_obj == self.TEXT_PORTION:
|
|
|
|
obj = LOWriterTextPortion(obj)
|
|
|
|
return obj
|
|
|
|
|
|
|
|
@property
|
|
|
|
def string(self):
|
|
|
|
return self.obj.String
|
|
|
|
|
|
|
|
@property
|
|
|
|
def cursor(self):
|
|
|
|
return self.obj.Text.createTextCursorByRange(self.obj)
|
|
|
|
|
|
|
|
|
|
|
|
class LOWriterTextRange(BaseObject):
|
|
|
|
PARAGRAPH = 'SwXParagraph'
|
|
|
|
|
|
|
|
def __init__(self, obj):
|
|
|
|
super().__init__(obj)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'Writer: TextRange'
|
|
|
|
|
|
|
|
def __getitem__(self, index):
|
|
|
|
for i, v in enumerate(self):
|
|
|
|
if index == i:
|
|
|
|
return v
|
|
|
|
if index > i:
|
|
|
|
raise IndexError
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
self._enum = self.obj.createEnumeration()
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __next__(self):
|
|
|
|
if self._enum.hasMoreElements():
|
|
|
|
obj = self._enum.nextElement()
|
|
|
|
type_obj = obj.ImplementationName
|
|
|
|
if type_obj == self.PARAGRAPH:
|
|
|
|
obj = LOWriterParagraph(obj)
|
|
|
|
else:
|
|
|
|
raise StopIteration
|
|
|
|
return obj
|
|
|
|
|
|
|
|
@property
|
|
|
|
def string(self):
|
|
|
|
return self.obj.String
|
|
|
|
|
|
|
|
@property
|
|
|
|
def cursor(self):
|
|
|
|
return self.obj.Text.createTextCursorByRange(self.obj)
|
|
|
|
|
|
|
|
|
|
|
|
class LOWriterTextRanges(BaseObject):
|
|
|
|
|
|
|
|
def __init__(self, obj):
|
|
|
|
super().__init__(obj)
|
|
|
|
# ~ self._doc = doc
|
|
|
|
# ~ self._paragraphs = [LOWriterTextRange(p, doc) for p in obj]
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'Writer: TextRanges'
|
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
return self.obj.Count
|
|
|
|
|
|
|
|
def __getitem__(self, index):
|
|
|
|
return LOWriterTextRange(self.obj[index])
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
self._index = 0
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __next__(self):
|
|
|
|
try:
|
|
|
|
obj = LOWriterTextRange(self.obj[self._index])
|
|
|
|
except IndexError:
|
|
|
|
raise StopIteration
|
|
|
|
|
|
|
|
self._index += 1
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
2022-08-18 22:42:32 -05:00
|
|
|
class LOWriter(LODocument):
|
|
|
|
TEXT_RANGES = 'SwXTextRanges'
|
2023-12-17 23:57:30 -06:00
|
|
|
_type = 'writer'
|
2022-08-18 22:42:32 -05:00
|
|
|
|
|
|
|
def __init__(self, obj):
|
|
|
|
super().__init__(obj)
|
|
|
|
self._view_settings = self._cc.ViewSettings
|
|
|
|
|
|
|
|
@property
|
|
|
|
def zoom(self):
|
|
|
|
return self._view_settings.ZoomValue
|
|
|
|
@zoom.setter
|
|
|
|
def zoom(self, value):
|
|
|
|
self._view_settings.ZoomValue = value
|
2023-12-17 23:57:30 -06:00
|
|
|
|
|
|
|
@property
|
|
|
|
def selection(self):
|
|
|
|
"""Get current seleccion"""
|
|
|
|
sel = None
|
|
|
|
selection = self.obj.CurrentSelection
|
|
|
|
type_obj = selection.ImplementationName
|
|
|
|
|
|
|
|
if type_obj == self.TEXT_RANGES:
|
|
|
|
sel = LOWriterTextRanges(selection)
|
|
|
|
if len(sel) == 1:
|
|
|
|
sel = sel[0]
|
|
|
|
else:
|
|
|
|
log.debug(type_obj)
|
|
|
|
log.debug(selection)
|
|
|
|
sel = selection
|
|
|
|
|
|
|
|
return sel
|
|
|
|
|
|
|
|
@property
|
|
|
|
def string(self):
|
|
|
|
return self._obj.Text.String
|