From 2e7a390a139b92bd451a3c1bed82041e5f9d1931 Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Wed, 18 Nov 2020 22:35:13 -0600 Subject: [PATCH] Update easymacro --- easymacro.py | 79 +++++++++++++++++++--------------------------------- 1 file changed, 29 insertions(+), 50 deletions(-) diff --git a/easymacro.py b/easymacro.py index 6ddace0..17d1253 100644 --- a/easymacro.py +++ b/easymacro.py @@ -184,7 +184,6 @@ DIR = { 'images': 'images', 'locales': 'locales', } -DEFAULT_MIME_TYPE = 'png' KEY = { 'enter': 1280, @@ -219,6 +218,7 @@ MENUS = { 'show': '.uno:SlideShowMenu', } +DEFAULT_MIME_TYPE = 'png' MIME_TYPE = { 'png': 'image/png', 'jpg': 'image/jpeg', @@ -917,54 +917,6 @@ class LOBaseObject(object): return self._obj -class LOImage(object): - TYPE = { - 'png': 'image/png', - 'jpg': 'image/jpeg', - } - - def __init__(self, obj): - self._obj = obj - - @property - def obj(self): - return self._obj - - @property - def name(self): - return self.obj.Name or 'img' - - @property - def mimetype(self): - return self.obj.Bitmap.MimeType - - def save(self, path, mimetype=DEFAULT_MIME_TYPE): - p = _P(path) - if _P.is_dir(path): - name = self.name - else: - path = p.path - name = p.name - - path = _P.join(path, f'{name}.{mimetype.lower()}') - args = dict( - URL = _P.to_url(path), - MimeType = self.TYPE[mimetype], - ) - if not _export_image(self.obj, args): - path = '' - - # ~ size = len(self.obj.Bitmap.DIB) - # ~ data = self.obj.GraphicStream.readBytes((), size) - # ~ data = data[-1].value - - # ~ data = self.obj.Bitmap.DIB.value - # ~ data = self.obj.Graphic.DIB.value - - # ~ _P.save_bin(path, data) - return path - - class LODocument(object): FILTERS = { 'doc': 'MS Word 97', @@ -2422,6 +2374,33 @@ class LOShape(LOBaseObject): self.obj.Parent.remove(self.obj) return + def save(self, path: str, mimetype=DEFAULT_MIME_TYPE): + if _P.is_dir(path): + name = self.name + ext = mimetype.lower() + else: + p = _P(path) + path = p.path + name = p.name + ext = p.ext.lower() + + path = _P.join(path, f'{name}.{ext}') + args = dict( + URL = _P.to_url(path), + MimeType = MIME_TYPE[ext], + ) + if not _export_image(self.obj, args): + path = '' + return path + + # ~ def save2(self, path: str): + # ~ size = len(self.obj.Bitmap.DIB) + # ~ data = self.obj.GraphicStream.readBytes((), size) + # ~ data = data[-1].value + # ~ path = _P.join(path, f'{self.name}.png') + # ~ _P.save_bin(path, b'') + # ~ return + class LODrawPage(LOBaseObject): @@ -2533,7 +2512,7 @@ class LODrawImpress(LODocument): def paste(self): call_dispatch(self.frame, '.uno:Paste') - return self.selection + return self.current_page[-1] def add(self, type_shape, args={}): return self.current_page.add(type_shape, args)