Add insert image from stream
This commit is contained in:
parent
80691ad797
commit
467280fca3
|
@ -26,6 +26,7 @@ import datetime
|
||||||
import getpass
|
import getpass
|
||||||
import gettext
|
import gettext
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import io
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -2198,7 +2199,6 @@ class LOCalcSheet(object):
|
||||||
@property
|
@property
|
||||||
def draw_page(self):
|
def draw_page(self):
|
||||||
return LODrawPage(self.obj.DrawPage)
|
return LODrawPage(self.obj.DrawPage)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def dp(self):
|
def dp(self):
|
||||||
return self.draw_page
|
return self.draw_page
|
||||||
|
@ -2828,7 +2828,8 @@ class LOCalcRange(object):
|
||||||
call_dispatch(self.doc.frame, url, args)
|
call_dispatch(self.doc.frame, url, args)
|
||||||
return self.sheet.shapes[-1]
|
return self.sheet.shapes[-1]
|
||||||
|
|
||||||
def insert_image(self, path, args={}):
|
def insert_image(self, path, options={}):
|
||||||
|
args = options.copy()
|
||||||
ps = self.possize
|
ps = self.possize
|
||||||
args['Width'] = args.get('Width', ps['Width'])
|
args['Width'] = args.get('Width', ps['Width'])
|
||||||
args['Height'] = args.get('Height', ps['Height'])
|
args['Height'] = args.get('Height', ps['Height'])
|
||||||
|
@ -3572,7 +3573,8 @@ class LODrawPage(LOBaseObject):
|
||||||
self.obj.remove(self.obj[0])
|
self.obj.remove(self.obj[0])
|
||||||
return
|
return
|
||||||
|
|
||||||
def insert_image(self, path, args={}):
|
def insert_image(self, path, options={}):
|
||||||
|
args = options.copy()
|
||||||
index = self.count
|
index = self.count
|
||||||
w = args.get('Width', 3000)
|
w = args.get('Width', 3000)
|
||||||
h = args.get('Height', 3000)
|
h = args.get('Height', 3000)
|
||||||
|
@ -3581,11 +3583,17 @@ class LODrawPage(LOBaseObject):
|
||||||
name = args.get('Name', f'image{index}')
|
name = args.get('Name', f'image{index}')
|
||||||
|
|
||||||
image = self.create_instance('com.sun.star.drawing.GraphicObjectShape')
|
image = self.create_instance('com.sun.star.drawing.GraphicObjectShape')
|
||||||
image.GraphicURL = _P.to_url(path)
|
if isinstance(path, str):
|
||||||
|
image.GraphicURL = _P.to_url(path)
|
||||||
|
else:
|
||||||
|
gp = create_instance('com.sun.star.graphic.GraphicProvider')
|
||||||
|
properties = dict_to_property({'InputStream': path})
|
||||||
|
image.Graphic = gp.queryGraphic(properties)
|
||||||
|
|
||||||
|
self.obj.add(image)
|
||||||
image.Size = Size(w, h)
|
image.Size = Size(w, h)
|
||||||
image.Position = Point(x, y)
|
image.Position = Point(x, y)
|
||||||
image.Name = name
|
image.Name = name
|
||||||
self.obj.add(image)
|
|
||||||
return LOShape(self.obj[index], index)
|
return LOShape(self.obj[index], index)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3957,6 +3965,7 @@ class LOBasic(LODocument):
|
||||||
|
|
||||||
class LODocs(object):
|
class LODocs(object):
|
||||||
_desktop = None
|
_desktop = None
|
||||||
|
# ~ 'private:stream'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._desktop = get_desktop()
|
self._desktop = get_desktop()
|
||||||
|
@ -6602,13 +6611,12 @@ class Paths(object):
|
||||||
def image(cls, path):
|
def image(cls, path):
|
||||||
# ~ sfa = create_instance('com.sun.star.ucb.SimpleFileAccess')
|
# ~ sfa = create_instance('com.sun.star.ucb.SimpleFileAccess')
|
||||||
# ~ stream = sfa.openFileRead(cls.to_url(path))
|
# ~ stream = sfa.openFileRead(cls.to_url(path))
|
||||||
# ~ debug(type(stream), stream)
|
|
||||||
# ~ Name = "InputStream"
|
|
||||||
# ~ Value = stream
|
|
||||||
gp = create_instance('com.sun.star.graphic.GraphicProvider')
|
gp = create_instance('com.sun.star.graphic.GraphicProvider')
|
||||||
image = gp.queryGraphic((
|
if isinstance(path, str):
|
||||||
PropertyValue(Name='URL', Value=cls.to_url(path)),
|
properties = (PropertyValue(Name='URL', Value=cls.to_url(path)),)
|
||||||
))
|
else:
|
||||||
|
properties = (PropertyValue(Name='InputStream', Value=path),)
|
||||||
|
image = gp.queryGraphic(properties)
|
||||||
return image
|
return image
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -6634,6 +6642,32 @@ class Dates(object):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
class IOStream(object):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def buffer(cls):
|
||||||
|
return io.BytesIO()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def input(cls, buffer):
|
||||||
|
instance = 'com.sun.star.io.SequenceInputStream'
|
||||||
|
stream = create_instance(instance, True)
|
||||||
|
stream.initialize((uno.ByteSequence(buffer.getvalue()),))
|
||||||
|
return stream
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def qr(cls, data, **kwargs):
|
||||||
|
import segno
|
||||||
|
|
||||||
|
kwargs['kind'] = kwargs.get('kind', 'svg')
|
||||||
|
kwargs['scale'] = kwargs.get('scale', 8)
|
||||||
|
kwargs['border'] = kwargs.get('border', 2)
|
||||||
|
buffer = cls.buffer()
|
||||||
|
segno.make(data).save(buffer, **kwargs)
|
||||||
|
stream = cls.input(buffer)
|
||||||
|
return stream
|
||||||
|
|
||||||
|
|
||||||
class SpellChecker(object):
|
class SpellChecker(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -6699,6 +6733,8 @@ def __getattr__(name):
|
||||||
return ClipBoard
|
return ClipBoard
|
||||||
if name == 'dates':
|
if name == 'dates':
|
||||||
return Dates
|
return Dates
|
||||||
|
if name == 'ios':
|
||||||
|
return IOStream()
|
||||||
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue