29_component_context = pyuno.getComponentContext()
33 """Returns the UNO component context used to initialize the Python runtime."""
35 return _component_context
39 """Returns the current context.
41 See http://udk.openoffice.org/common/man/concept/uno_contexts.html
42 for an explanation on the current context concept.
45 return pyuno.getCurrentContext()
49 """Sets newContext as new UNO context.
51 The newContext must implement the XCurrentContext interface. The
52 implementation should handle the desired properties and delegate
53 unknown properties to the old context. Ensure that the old one
54 is reset when you leave your stack, see
55 http://udk.openoffice.org/common/man/concept/uno_contexts.html
58 return pyuno.setCurrentContext(newContext)
62 """Looks up the value of an IDL constant by giving its explicit name."""
64 return pyuno.getConstantByName(constant)
68 """Returns a `uno.Type` instance of the type given by typeName.
70 If the type does not exist, a `com.sun.star.uno.RuntimeException`
is raised.
73 return pyuno.getTypeByName(typeName)
77 """Creates a UNO struct or exception given by typeName.
81 1) No additional argument.
82 In this case, you get a default constructed UNO structure.
84 2) Exactly one additional argument that
is an instance of typeName.
85 In this case, a copy constructed instance of typeName
is returned
87 3) As many additional arguments
as the number of elements within typeName
88 (e.g. `
createUnoStruct(
"com.sun.star.uno.Exception",
"foo error" , self)`).
89 4) Keyword arguments to give values
for each element of the struct by name.
90 5) A mix of 3)
and 4), such that each struct element
is given a value exactly once,
91 either by a positional argument
or by a keyword argument.
93 The additional
and/
or keyword arguments must match the type of each struct element,
94 otherwise an exception
is thrown.
97 return getClass(typeName)(*args, **kwargs)
101 """Returns the class of a concrete UNO exception, struct, or interface."""
107 """Returns True, when obj is a class of a UNO interface."""
109 return pyuno.isInterface(obj)
113 """Returns a 16 byte sequence containing a newly generated uuid or guid.
115 For more information, see rtl/uuid.h.
118 return pyuno.generateUuid()
122 """Returns a file URL for the given system path."""
124 return pyuno.systemPathToFileUrl(systemPath)
128 """Returns a system path.
130 This path is determined by the system that the Python interpreter
is running on.
133 return pyuno.fileUrlToSystemPath(url)
137 """Returns an absolute file url from the given urls."""
139 return pyuno.absolutize(path, relativeUrl)
143 """Represents a UNO enum.
145 Use an instance of this class to explicitly pass an enum to UNO.
147 :param typeName: The name of the enum
as a string.
148 :param value: The actual value of this enum
as a string.
154 pyuno.checkEnum(self)
157 return "<Enum instance %s (%r)>" % (self.
typeName, self.
value)
160 if not isinstance(that, Enum):
163 return (self.
typeName == that.typeName)
and (self.
value == that.value)
166 return not self.
__eq__(other)
170 """Represents a UNO type.
172 Use an instance of this class to explicitly pass a type to UNO.
174 :param typeName: Name of the UNO type
175 :param typeClass: Python Enum of TypeClass, see com/sun/star/uno/TypeClass.idl
181 pyuno.checkType(self)
187 if not isinstance(that, Type):
193 return not self.
__eq__(other)
200 """Represents a UNO boolean.
202 Use an instance of this class to explicitly pass a boolean to UNO.
204 Note: This
class is deprecated. Use Python
's True and False directly instead.
208 message =
"The Bool class is deprecated. Use Python's True and False directly instead."
209 warnings.warn(message, DeprecationWarning)
211 if isinstance(value, str)
and value ==
"true":
214 if isinstance(value, str)
and value ==
"false":
224 """Represents a UNO char.
226 Use an instance of this class to explicitly pass a char to UNO.
228 For Python 3, this
class only works with
unicode (str) objects. Creating
229 a Char instance
with a bytes object
or comparing a Char instance
230 to a bytes object will
raise an AssertionError.
232 :param value: A Unicode string
with length 1
236 assert isinstance(value, str),
"Expected str object, got %s instead." % type(value)
238 assert len(value) == 1,
"Char value must have length of 1."
239 assert ord(value[0]) <= 0xFFFF,
"Char value must be UTF-16 code unit"
244 return "<Char instance %s>" % (self.
value,)
247 if isinstance(that, str):
251 return self.
value == that[0]
253 if isinstance(that, Char):
254 return self.
value == that.value
259 return not self.
__eq__(other)
263 """Represents a UNO ByteSequence value.
265 Use an instance of this class to explicitly pass a byte sequence to UNO.
267 :param value: A string
or bytesequence
271 if isinstance(value, bytes):
274 elif isinstance(value, ByteSequence):
275 self.
value = value.value
278 raise TypeError(
"Expected bytes object or ByteSequence, got %s instead." % type(value))
281 return "<ByteSequence instance '%s'>" % (self.
value,)
284 if isinstance(that, bytes):
285 return self.
value == that
287 if isinstance(that, ByteSequence):
288 return self.
value == that.value
293 return len(self.
value)
296 return self.
value[index]
302 if isinstance(b, bytes):
305 elif isinstance(b, ByteSequence):
309 raise TypeError(
"Can't add ByteString and %s." % type(b))
312 return self.
value.hash()
316 """Represents a UNO Any value.
318 Use only in connection
with uno.invoke() to
pass an explicit typed Any.
322 if isinstance(type, Type):
331 """Use this function to pass exactly typed Anys to the callee (using uno.Any)."""
333 return pyuno.invoke(object, methodname, argTuple)
339_builtin_import = __import__
343 """Overrides built-in import to allow directly importing LibreOffice classes."""
347 except ImportError
as e:
349 globals, locals, fromlist = list(optargs)[:3] + [kwargs.get(
'globals', {}), kwargs.get(
'locals', {}),
350 kwargs.get(
'fromlist', [])][len(optargs):]
353 if not fromlist
or hasattr(e,
'_uno_import_failed'):
362 for module
in name.split(
"."):
367 mod = pyuno.__class__(module)
373 RuntimeException =
pyuno.getClass(
"com.sun.star.uno.RuntimeException")
375 for class_name
in fromlist:
376 if class_name
not in d:
382 except RuntimeException:
385 d[class_name] =
Enum(name, class_name)
386 except RuntimeException:
390 except RuntimeException:
419 uno_import_exc = ImportError(
"%s (or '%s.%s' is unknown)" %
420 (py_import_exc, name, class_name))
422 uno_import_exc = uno_import_exc.with_traceback(py_import_exc.__traceback__)
424 uno_import_exc._uno_import_failed =
True
433 import builtins
as __builtin__
436__builtin__.__dict__[
'__import__'] = _uno_import
440 """Represents a group of UNOIDL constants."""
442 __slots__ = [
'_constants']
454 raise AttributeError(
"The constant '%s' could not be found." % name)
458 """Gets UNOIDL constant group by name."""
460 constants =
Enum(
'com.sun.star.uno.TypeClass',
'CONSTANTS')
461 one =
Enum(
'com.sun.star.reflection.TypeDescriptionSearchDepth',
'ONE')
462 type_desc_mgr = _component_context.getValueByName(
'/singletons/com.sun.star.reflection.theTypeDescriptionManager')
463 type_descs = type_desc_mgr.createTypeDescriptionEnumeration(module, (constants,), one)
464 qualified_name = module +
'.' + group
466 for type_desc
in type_descs:
467 if type_desc.Name == qualified_name:
469 (c.Name.split(
'.')[-1], c.ConstantValue)
470 for c
in type_desc.Constants))
472 raise ValueError(
"The constant group '%s' could not be found." % qualified_name)
476 """Initializes a UNO struct.
478 Referenced from the pyuno shared library.
480 This function can be called
with either an already constructed UNO struct, which it
481 will then just reference without copying,
or with arguments to create a new UNO struct.
485 if len(kwargs) == 0
and len(args) == 1
and getattr(args[0],
"__class__",
None) == self.__class__:
486 self.__dict__[
'value'] = args[0]
488 struct, used = pyuno._createUnoStructHelper(self.__class__.__pyunostruct__, args, **kwargs)
490 for kwarg
in kwargs.keys():
491 if not used.get(kwarg):
492 RuntimeException =
pyuno.getClass(
"com.sun.star.uno.RuntimeException")
493 raise RuntimeException(
"_uno_struct__init__: unused keyword argument '%s'." % kwarg,
None)
495 self.__dict__[
"value"] = struct
499 """Gets attribute from UNO struct.
501 Referenced from the pyuno shared library.
504 return getattr(self.__dict__[
"value"], name)
508 """Sets attribute on UNO struct.
510 Referenced from the pyuno shared library.
513 return setattr(self.__dict__[
"value"], name, value)
517 """Converts a UNO struct to a printable string.
519 Referenced from the pyuno shared library.
522 return repr(self.__dict__[
"value"])
526 """Converts a UNO struct to a string."""
528 return str(self.__dict__[
"value"])
531 return not self.__eq__(other)
534 """Compares two UNO structs.
536 Referenced from the pyuno shared library.
539 if hasattr(that,
"value"):
540 return self.__dict__[
"value"] == that.__dict__[
"value"]
546 """Extracts a printable stacktrace.
548 Referenced from pyuno shared lib
and pythonscript.py.
551 return ''.join(traceback.format_tb(trace))
def __getitem__(self, index)
def __init__(self, value)
def __init__(self, value)
def __init__(self, typeName, value)
def __init__(self, typeName, typeClass)
def __init__(self, constants)
def __getattr__(self, name)
PyRef getClass(const OUString &name, const Runtime &runtime)
def absolutize(path, relativeUrl)
def _uno_struct__repr__(self)
def _uno_struct__str__(self)
def _uno_struct__ne__(self, other)
def invoke(object, methodname, argTuple)
def _uno_import(name, *optargs, **kwargs)
def _uno_extract_printable_stacktrace(trace)
def getComponentContext()
def _uno_struct__setattr__(self, name, value)
def createUnoStruct(typeName, *args, **kwargs)
def fileUrlToSystemPath(url)
def getConstantByName(constant)
def systemPathToFileUrl(systemPath)
def _impl_getConstantGroupByName(module, group)
def getTypeByName(typeName)
def _uno_struct__getattr__(self, name)
def setCurrentContext(newContext)
def _uno_struct__init__(self, *args, **kwargs)
def _uno_struct__eq__(self, that)