99 lines
2.3 KiB
Python
99 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import uno
|
|
import unohelper
|
|
from com.sun.star.io import IOException, XOutputStream
|
|
from .easymain import create_instance
|
|
|
|
|
|
# UNO Enum
|
|
class MessageBoxType():
|
|
"""Class for import enum
|
|
|
|
`See Api MessageBoxType <https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1awt.html#ad249d76933bdf54c35f4eaf51a5b7965>`_
|
|
"""
|
|
from com.sun.star.awt.MessageBoxType \
|
|
import MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
|
|
|
|
|
|
class IOStream(object):
|
|
"""Classe for input/output stream"""
|
|
|
|
class OutputStream(unohelper.Base, XOutputStream):
|
|
|
|
def __init__(self):
|
|
self._buffer = b''
|
|
self.closed = 0
|
|
|
|
@property
|
|
def buffer(self):
|
|
return self._buffer
|
|
|
|
def closeOutput(self):
|
|
self.closed = 1
|
|
|
|
def writeBytes(self, seq):
|
|
if seq.value:
|
|
self._buffer = seq.value
|
|
|
|
def flush(self):
|
|
pass
|
|
|
|
@classmethod
|
|
def buffer(cls):
|
|
return io.BytesIO()
|
|
|
|
@classmethod
|
|
def input(cls, buffer):
|
|
service = 'com.sun.star.io.SequenceInputStream'
|
|
stream = create_instance(service, True)
|
|
stream.initialize((uno.ByteSequence(buffer.getvalue()),))
|
|
return stream
|
|
|
|
@classmethod
|
|
def output(cls):
|
|
return cls.OutputStream()
|
|
|
|
@classmethod
|
|
def to_bin(cls, stream):
|
|
buffer = cls.OutputStream()
|
|
_, data = stream.readBytes(buffer, stream.available())
|
|
return data.value
|
|
|
|
|
|
def get_input_stream(data):
|
|
stream = create_instance('com.sun.star.io.SequenceInputStream', True)
|
|
stream.initialize((data,))
|
|
return stream
|
|
|
|
|
|
class BaseObjectProperties():
|
|
|
|
def __init__(self, obj):
|
|
self._obj = obj
|
|
|
|
def __enter__(self):
|
|
return self
|
|
|
|
def __exit__(self, exc_type, exc_value, traceback):
|
|
pass
|
|
|
|
def __contains__(self, item):
|
|
return hasattr(self.obj, item)
|
|
|
|
def __setattr__(self, name, value):
|
|
if name == '_obj':
|
|
super().__setattr__(name, value)
|
|
else:
|
|
if name in self:
|
|
setattr(self.obj, name, value)
|
|
else:
|
|
object.__setattr__(self, name, value)
|
|
|
|
def __getattr__(self, name):
|
|
return self.obj.getPropertyValue(name)
|
|
|
|
@property
|
|
def obj(self):
|
|
return self._obj
|