Update easymacro

This commit is contained in:
Mauricio Baeza 2020-11-18 22:35:13 -06:00
parent 54b2ed7913
commit 2e7a390a13
1 changed files with 29 additions and 50 deletions

View File

@ -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)