1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 from libreoffice
.util
import printing
13 from libreoffice
.util
.uno
import TypeClass
, make_uno_type
, uno_cast
15 class UnoAnyPrinter(object):
18 def __init__(self
, typename
, value
):
20 self
.typename
= typename
.replace('com::sun::star::', '')
23 type_desc
= self
.value
['pType']
25 type = make_uno_type(type_desc
.dereference())
27 if type_desc
.dereference()['eTypeClass'] == TypeClass
.VOID
:
28 return ('%s(%s)' % (self
.typename
, type.tag
))
30 ptr
= self
.value
['pData']
32 return ('%s(%s: %s)' % (self
.typename
, type.tag
, str(uno_cast(type, ptr
).dereference())))
34 class UnoReferencePrinter(object):
35 '''Prints reference to a UNO interface'''
37 def __init__(self
, typename
, value
):
39 self
.typename
= typename
.replace('com::sun::star::', '')
42 iface
= self
.value
['_pInterface']
45 return '%s to (%s) %s' % (self
.typename
, str(iface
.dynamic_type
), str(iface
))
47 # fallback for potential problem:
48 # base class 'com::sun::star::uno::XInterface' is ambiguous
49 return '%s to (XInterface) %s' % (self
.typename
, str(iface
))
52 return "empty %s" % self
.typename
54 class UnoSequencePrinter(object):
55 '''Prints UNO Sequence'''
57 class iterator(six
.Iterator
):
58 '''Sequence iterator'''
60 def __init__(self
, first
, size
):
69 if self
.count
== self
.size
:
72 self
.count
= self
.count
+ 1
73 elem
= self
.item
.dereference()
74 self
.item
= self
.item
+ 1
75 return ('[%d]' % count
, elem
)
78 def __init__(self
, typename
, value
):
80 self
.typename
= typename
.replace('com::sun::star::', '')
83 pimpl
= self
.value
['_pSequence']
85 impl
= pimpl
.dereference()
86 elems
= impl
['nElements']
88 return "empty %s" % self
.typename
90 return "%s of length %d" % (self
.typename
, elems
)
92 return "uninitialized %s" % self
.typename
95 pimpl
= self
.value
['_pSequence']
97 impl
= pimpl
.dereference()
98 elemtype
= self
.value
.type.template_argument(0)
99 elements
= impl
['elements'].cast(elemtype
.pointer())
100 return self
.iterator(elements
, int(impl
['nElements']))
102 # TODO is that the best thing to do here?
105 def display_hint(self
):
106 if self
.value
['_pSequence']:
111 class UnoTypePrinter(object):
112 '''Prints UNO Type'''
114 def __init__(self
, typename
, value
):
116 self
.typename
= typename
.replace('com::sun::star::', '')
119 uno
= make_uno_type(self
.value
)
121 return "%s %s" % (self
.typename
, uno
.tag
)
122 # return "%s %s" % (self.typename, uno.typename)
124 return "invalid %s" % self
.typename
126 class CppuThreadpoolThreadPoolPrinter(object):
127 '''Prints cppu_threadpool::ThreadPool objects (a hack to avoid infinite recursion through sal.RtlReferencePrinter when printing an rtl::Reference<cppu_threadpool::ThreadPool> whose std::list<cppu_threadpool::WaitingThread*> m_lstThreads member, via rtl::Reference<cppu_threadpool::ORequestThread> thread member, via rtl::Reference<cppu_threadpool::ThreadPool> m_aThreadPool member, has a circular reference back)'''
129 def __init__(self
, typename
, value
):
130 self
.typename
= typename
134 return '%s@%s' % (self
.typename
, self
.value
.address
)
138 def build_pretty_printers():
141 printer
= printing
.Printer("libreoffice/cppu")
144 printer
.add('_uno_Any', UnoAnyPrinter
)
145 printer
.add('com::sun::star::uno::Any', UnoAnyPrinter
)
146 printer
.add('com::sun::star::uno::Reference', UnoReferencePrinter
)
147 printer
.add('com::sun::star::uno::Sequence', UnoSequencePrinter
)
148 printer
.add('com::sun::star::uno::Type', UnoTypePrinter
)
149 printer
.add('cppu_threadpool::ThreadPool', CppuThreadpoolThreadPoolPrinter
)
151 def register_pretty_printers(obj
):
152 printing
.register_pretty_printer(printer
, obj
)
154 build_pretty_printers()
156 # vim:set shiftwidth=4 softtabstop=4 expandtab: