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/.
13 from libreoffice
.util
import printing
15 class ItemSetPrinter(object):
16 '''Prints SfxItemSets'''
18 def __init__(self
, typename
, value
):
19 self
.typename
= typename
23 whichranges
= self
.which_ranges()
24 return "SfxItemSet of pool %s with parent %s and Which ranges: %s" \
25 % (self
.value
['m_pPool'], self
.value
['m_pParent'], whichranges
)
27 def which_ranges(self
):
28 whichranges
= self
.value
['m_pWhichRanges']['m_pairs']
29 whichranges_cnt
= self
.value
['m_pWhichRanges']['m_size']
31 for index
in range(whichranges_cnt
):
32 whiches
.append((int(whichranges
[index
]['first']), int(whichranges
[index
]['second'])))
36 whichranges
= self
.which_ranges()
39 for (whichfrom
, whichto
) in whichranges
:
40 size
+= whichto
- whichfrom
+ 1
41 whichids
+= [which
for which
in range(whichfrom
, whichto
+1)]
42 return self
._iterator
(self
.value
['m_ppItems'], size
, whichids
)
44 class _iterator(six
.Iterator
):
46 def __init__(self
, data
, count
, whichids
):
48 self
.whichids
= whichids
51 self
._check
_invariant
()
57 if self
.pos
== self
.count
:
60 which
= self
.whichids
[self
.pos
]
61 elem
= self
.data
[self
.pos
]
62 self
.pos
= self
.pos
+ 1
64 self
._check
_invariant
()
68 # let's try how well that works...
69 elem
= elem
.cast(elem
.dynamic_type
).dereference()
70 return (str(which
), elem
)
72 def _check_invariant(self
):
73 assert self
.count
>= 0
76 assert self
.pos
<= self
.count
77 assert len(self
.whichids
) == self
.count
81 def build_pretty_printers():
84 printer
= printing
.Printer("libreoffice/svl")
86 printer
.add('SfxItemSet', ItemSetPrinter
)
88 def register_pretty_printers(obj
):
89 printing
.register_pretty_printer(printer
, obj
)
91 build_pretty_printers()
93 # vim:set shiftwidth=4 softtabstop=4 expandtab: