From f597411d3e65b9db601b81c9742d32a6ca35891d Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Sun, 29 Aug 2021 15:43:37 -0500 Subject: [PATCH] Add writer cursor move --- CHANGELOG | 4 +++ README.md | 2 +- VERSION | 2 +- doc/published.sh | 2 +- source/easymacro.py | 67 +++++++++++++++++++++++++++++++++++++++++---- source/zaz.py | 5 ++-- 6 files changed, 72 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5b936b8..604f826 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +v 0.18.0 [29-aug-2021] + - Writer. Move cursor: start, end, left, right + + v 0.17.0 [10-jul-2021] - Add insert math in writer diff --git a/README.md b/README.md index 0f3164d..a8d2f48 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,9 @@ IBAN: BE60 9671 0556 5870 SWIFT / BIC: TRWIBEB1XXX ``` +* BCH: `qztd3l00xle5tffdqvh2snvadkuau2ml0uqm4n875d` * FairCoin: `fJ7emvtyGfvcMuxk1nHSnS7gmeScdcZXL5` * Monero: `43H43TpQKYdYcw2ZCnn2nbjDh3imNQg8RGYS4oP4p7Z8aeBHg6VpeaFfBoMzDTUUDdQBiGkiQUSydJB96m6MqiEuEeyoopQ` -* BCH: `qztd3l00xle5tffdqvh2snvadkuau2ml0uqm4n875d` * ETH: `0x61a4f614a30ff686445751ed8328b82b77ecfc69` * XRP: `rLSn6Z3T8uCxbcd1oxwfGQN1Fdn5CyGujK` Tag: `6643162` diff --git a/VERSION b/VERSION index 04a373e..6633391 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.16.0 +0.18.0 diff --git a/doc/published.sh b/doc/published.sh index 6277a25..5bd5669 100755 --- a/doc/published.sh +++ b/doc/published.sh @@ -1,3 +1,3 @@ #!/bin/bash -rsync -ravz --delete build/ elmau.net:/opt/www/doc/zaz/ +rsync -ravz --delete build/ 152.89.107.109:/opt/doc.cuates.net/zaz/ diff --git a/source/easymacro.py b/source/easymacro.py index b125752..3d3ebaf 100644 --- a/source/easymacro.py +++ b/source/easymacro.py @@ -3223,6 +3223,7 @@ class LOWriterTextRange(object): self._is_paragraph = self.obj.ImplementationName == 'SwXParagraph' self._is_table = self.obj.ImplementationName == 'SwXTextTable' self._is_text = self.obj.ImplementationName == 'SwXTextPortion' + self._is_section = not self.obj.TextSection is None self._parts = [] if self._is_paragraph: self._parts = [LOWriterTextRange(p, doc) for p in obj] @@ -3288,6 +3289,10 @@ class LOWriterTextRange(object): def is_text(self): return self._is_text + @property + def is_section(self): + return self._is_section + @property def text(self): return self.obj.Text @@ -3296,15 +3301,63 @@ class LOWriterTextRange(object): def cursor(self): return self.text.createTextCursorByRange(self.obj) + @property + def text_cursor(self): + return self.text.createTextCursor() + @property def dp(self): return self._doc.dp - def delete(self): + @property + def paragraph(self): cursor = self.cursor cursor.gotoStartOfParagraph(False) cursor.gotoNextParagraph(True) - cursor.String = '' + return LOWriterTextRange(cursor, self._doc) + + def goto_start(self): + if self.is_section: + rango = self.obj.TextSection.Anchor.Start + else: + rango = self.obj.Start + return LOWriterTextRange(rango, self._doc) + + def goto_end(self): + if self.is_section: + rango = self.obj.TextSection.Anchor.End + else: + rango = self.obj.End + return LOWriterTextRange(rango, self._doc) + + def goto_previous(self, expand=True): + cursor = self.cursor + cursor.gotoPreviousParagraph(expand) + return LOWriterTextRange(cursor, self._doc) + + def goto_next(self, expand=True): + cursor = self.cursor + cursor.gotoNextParagraph(expand) + return LOWriterTextRange(cursor, self._doc) + + def go_left(self, from_self=True, count=1, expand=False): + cursor = self.cursor + if not from_self: + cursor = self.text_cursor + cursor.gotoRange(self.obj, False) + cursor.goLeft(count, expand) + return LOWriterTextRange(cursor, self._doc) + + def go_right(self, from_self=True, count=1, expand=False): + cursor = self.cursor + if not from_self: + cursor = self.text_cursor + cursor.gotoRange(self.obj, False) + cursor.goRight(count, expand) + return LOWriterTextRange(cursor, self._doc) + + def delete(self): + self.value = '' return def offset(self): @@ -3332,7 +3385,7 @@ class LOWriterTextRange(object): cursor = self.cursor for i in range(count): self.text.insertControlCharacter(cursor, PARAGRAPH_BREAK, False) - return self._doc.selection + return LOWriterTextRange(cursor, self._doc) def insert_table(self, data): table = self._doc.create_instance(SERVICES['TEXT_TABLE']) @@ -6707,8 +6760,12 @@ class Paths(object): return result @classmethod - def read(cls, path, encoding='utf-8'): - data = Path(path).read_text(encoding=encoding) + def read(cls, path, get_lines=False, encoding='utf-8'): + if get_lines: + with Path(path).open(encoding=encoding) as f: + data = f.readlines() + else: + data = Path(path).read_text(encoding=encoding) return data @classmethod diff --git a/source/zaz.py b/source/zaz.py index 83e6058..4846605 100755 --- a/source/zaz.py +++ b/source/zaz.py @@ -793,8 +793,8 @@ def main(args): def _process_command_line_arguments(): - parser = argparse.ArgumentParser( - description='Make LibreOffice extensions') + parser = argparse.ArgumentParser(description='Make LibreOffice extensions') + parser.add_argument('-new', '--new', dest='new', action='store_true', default=False, required=False) parser.add_argument('-t', '--target', dest='target', default='') @@ -813,6 +813,7 @@ def _process_command_line_arguments(): default=False, required=False) parser.add_argument('-oc', '--only_compress', dest='only_compress', action='store_true', default=False, required=False) + return parser.parse_args()