Describing UNO API objects

I’m trying to create a tool to describe UNO API objects. The way it works now will probably do for me for the time being, but I’ve got questions and maybe you can help me make it better.

I tried to inspect a view cursor. According to the documentation (and the output confirms it) it implements (is that the term? includes?) the com.sun.star.text.TextViewCursor service, which implements the com.sun.star.text.TextLayoutCursor service, which in its turn implements the com.sun.star.text.TextCursor service. The last one implements the com.sun.star.beans.XMultiPropertyStates interface. But in practice a view cursor doesn’t implement the interface. Shouldn’t it?

Objects that implement (include?) services supposedly implement com.sun.star.lang.XServiceInfo. Which objects doesn’t implement it?

doc = m_uno.get_desktop().CurrentComponent
vc = doc.CurrentController.ViewCursor
print(m_debug.inspect(vc))
print('---')
m_debug.print_obj_info(m_debug.get_obj_info(vc))

src\lib\libre\debug.py:

import uno
from com.sun.star.beans.PropertyConcept import ALL as PROPERTY_CONCEPT_ALL
from com.sun.star.beans.MethodConcept import ALL as METHOD_CONCEPT_ALL

import libre.uno as m_uno

def print_obj_info(i):
    print_svc_tree(i['services'])
    for n, ms in i['methods'].items():
        printl(f'm {n}: ' + ', '.join(ms))
    for n, fs in i['fields'].items():
        printl(f'f {n}: ' + ', '.join(fs))
    print('only-in-definition: ' + ', '.join(i['only-in-definition']))
    print('only-in-implementation: ' + ', '.join(i['only-in-implementation']))

def print_svc_tree(t, l=0):
    for s in t:
        printl(('[oS] ' if s['optional'] else '[S] ') + s['name'], l)
        for i, ms in s['methods'].items():
            printl(f'm {i}: ' + ', '.join(ms), l+1)
        for i, ms in s['optional-methods'].items():
            printl(f'om {i}: ' + ', '.join(ms), l+1)
        for i, fs in s['fields'].items():
            printl(f'f {i}: ' + ', '.join(fs), l+1)
        for i, fs in s['optional-fields'].items():
            printl(f'of {i}: ' + ', '.join(fs), l+1)
        for p in s['properties']:
            printl('p ' + p, l+1)
        print_svc_tree(s['services'], l+1)
        print_svc_tree(s['optional-services'], l+1)

def get_obj_info(o):
    tdm = m_uno.get_ctx().getValueByName('/singletons/com.sun.star.reflection.theTypeDescriptionManager')
    r = {'services': []}
    for i, n in enumerate(o.SupportedServiceNames):
        r['services'].append(get_svc_info(tdm, n))
    top_svc = [s['name'] for s in r['services']]

    r['methods'] = {}
    for t in o.Types:
        for i, ms in get_all_methods_by_interface(t.typeName).items():
            safe_dict_update(r['methods'], i, ms)

    r['fields'] = {}
    for t in o.Types:
        for i, fs in get_all_fields_by_interface(t.typeName).items():
            if fs:
                safe_dict_update(r['fields'], i, fs)

    def filter_nested(s):
        rs = s | {
            'services': [filter_nested(s2) for s2 in s['services']
                         if s2['name'] not in top_svc],
            'optional-services': [filter_nested(s2) for s2 in s['optional-services']
                                  if s2['name'] not in top_svc],
            # 'interfaces': [i for i in s['interfaces'] if i not in r['methods']],
            # 'optional-interfaces': [i for i in s['optional-interfaces'] if i not in r['methods']],
        }

        rs['methods'] = {}
        for i in rs['interfaces']:
            if i not in r['methods']:
                for i2, ms in get_all_methods_by_interface(i).items():
                    if i2 not in r['methods']:
                        safe_dict_update(rs['methods'], i2, ms)

        rs['optional-methods'] = {}
        for i in rs['optional-interfaces']:
            if i not in r['methods']:
                for i2, ms in get_all_methods_by_interface(i).items():
                    if i2 not in r['methods']:
                        safe_dict_update(rs['optional-methods'], i2, ms)

        rs['fields'] = {}
        for i in s['interfaces']:
            if i not in r['fields']:
                for i2, fs in get_all_fields_by_interface(i).items():
                    if i2 not in r['fields'] and fs:
                        safe_dict_update(rs['fields'], i2, fs)

        rs['optional-fields'] = {}
        for i in s['optional-interfaces']:
            if i not in r['fields']:
                for i2, fs in get_all_fields_by_interface(i).items():
                    if i2 not in r['fields'] and fs:
                        safe_dict_update(rs['optional-fields'], i2, fs)

        return rs
    r['services'] = [filter_nested(s) for s in r['services']]
    assert {m for i, ms in r['methods'].items() for m in ms} == set(get_obj_desc(o)['methods'])
    s1 = {p for s in r['services'] for p in s['properties']}
    s2 = set(get_obj_desc(o)['properties'])
    r['only-in-definition'] = s1 - s2
    r['only-in-implementation'] = s2 - s1
    return r

def get_svc_info(tdm, n, **kwargs):
    td = tdm.getByHierarchicalName(n)
    assert td.Name == n
    assert td.TypeClass.value == 'SERVICE'
    r = {
        'name': n,
        'optional': kwargs.get('optional'),
        'interfaces': [i.Name for i in td.MandatoryInterfaces],
        'optional-interfaces': [i.Name for i in td.OptionalInterfaces],
        'services': [get_svc_info(tdm, s.Name) for s in td.MandatoryServices],
        'optional-services': [get_svc_info(tdm, s.Name, optional=True) for s in td.OptionalServices],
        'properties': [p.Name for p in td.Properties],
    }
    return r

def get_all_fields_by_interface(o, **kwargs):
    return get_all_methods_by_interface(o, fields=True)

def get_all_methods_by_interface(o, **kwargs):
    r = {}
    smgr = m_uno.get_ctx().ServiceManager
    cr = smgr.createInstance('com.sun.star.reflection.CoreReflection')
    for t in [o] if isinstance(o, str) else o.Types:
        c = cr.forName(t if isinstance(o, str) else t.typeName)
        ms = get_methods_by_interface(c, **{k: v for k, v in kwargs.items() if k == 'fields'})
        for n in ms:
            safe_dict_update(r, n, ms[n])
    return r

def get_methods_by_interface(c, **kwargs):
    r = {c.Name: get_own_methods(c, **{k: v for k, v in kwargs.items() if k == 'fields'})}
    for sc in c.Superclasses:
        sr = get_methods_by_interface(sc, **{k: v for k, v in kwargs.items() if k == 'fields'})
        assert r.keys().isdisjoint(sr)
        r |= sr
    return r

def get_own_methods(c, **kwargs):
    r = {m.Name for m
         in (c.Fields if kwargs.get('fields') else c.Methods)}
    for sc in c.Superclasses:
        r -= {m.Name for m
              in (sc.Fields if kwargs.get('fields') else sc.Methods)}
    return list(r)

def inspect(o):
    r = []
    for k, v in get_obj_desc(o).items():
        r += [f'{k}:']
        for el in v:
            r += [f'  {el}']
    return '\n'.join(r)

def get_obj_desc(o):
    r = {}
    if o.queryInterface(uno.getTypeByName('com.sun.star.lang.XServiceInfo')):
        r['services'] = o.SupportedServiceNames
    r['interfaces'] = [t.typeName for t in o.Types]

    smgr = m_uno.get_ctx().ServiceManager
    introspection = smgr.createInstance('com.sun.star.beans.Introspection')
    iaccess = introspection.inspect(o)

    r['properties'] = [p.Name for p in iaccess.getProperties(PROPERTY_CONCEPT_ALL)]
    r['methods'] = [m.Name for m in iaccess.getMethods(METHOD_CONCEPT_ALL)]
    return r

def safe_dict_update(d, k, v):
    if k in d:
        assert d[k] == v
    else:
        d[k] = v

def printl(v, l=0):
    print(' ' * 4 * l + str(v))

Output:

services:
  com.sun.star.text.TextViewCursor
  com.sun.star.style.CharacterProperties
  com.sun.star.style.CharacterPropertiesAsian
  com.sun.star.style.CharacterPropertiesComplex
  com.sun.star.style.ParagraphProperties
  com.sun.star.style.ParagraphPropertiesAsian
  com.sun.star.style.ParagraphPropertiesComplex
interfaces:
  com.sun.star.text.XTextViewCursor
  com.sun.star.lang.XServiceInfo
  com.sun.star.text.XPageCursor
  com.sun.star.view.XScreenCursor
  com.sun.star.view.XViewCursor
  com.sun.star.view.XLineCursor
  com.sun.star.beans.XPropertyState
  com.sun.star.lang.XTypeProvider
  com.sun.star.beans.XPropertySet
  com.sun.star.lang.XTypeProvider
  com.sun.star.uno.XWeak
properties:
  BorderDistance
  BottomBorder
  BottomBorderComplexColor
  BottomBorderDistance
  BreakType
  Cell
  CharAutoEscapement
  CharAutoKerning
  CharAutoStyleName
  CharBackColor
  CharBackTransparent
  CharBackgroundComplexColor
  CharBorderDistance
  CharBottomBorder
  CharBottomBorderComplexColor
  CharBottomBorderDistance
  CharCaseMap
  CharColor
  CharColorTheme
  CharColorTintOrShade
  CharCombineIsOn
  CharCombinePrefix
  CharCombineSuffix
  CharComplexColor
  CharContoured
  CharCrossedOut
  CharEmphasis
  CharEscapement
  CharEscapementHeight
  CharFlash
  CharFontCharSet
  CharFontCharSetAsian
  CharFontCharSetComplex
  CharFontFamily
  CharFontFamilyAsian
  CharFontFamilyComplex
  CharFontName
  CharFontNameAsian
  CharFontNameComplex
  CharFontPitch
  CharFontPitchAsian
  CharFontPitchComplex
  CharFontStyleName
  CharFontStyleNameAsian
  CharFontStyleNameComplex
  CharFontVariations
  CharHeight
  CharHeightAsian
  CharHeightComplex
  CharHidden
  CharHighlight
  CharInteropGrabBag
  CharKerning
  CharLeftBorder
  CharLeftBorderComplexColor
  CharLeftBorderDistance
  CharLocale
  CharLocaleAsian
  CharLocaleComplex
  CharNoHyphenation
  CharOpticalSizing
  CharOverline
  CharOverlineColor
  CharOverlineComplexColor
  CharOverlineHasColor
  CharPosture
  CharPostureAsian
  CharPostureComplex
  CharRelief
  CharRightBorder
  CharRightBorderComplexColor
  CharRightBorderDistance
  CharRotation
  CharRotationIsFitToLine
  CharScaleWidth
  CharScriptHint
  CharShadingValue
  CharShadowFormat
  CharShadowed
  CharStrikeout
  CharStyleName
  CharStyleNames
  CharTopBorder
  CharTopBorderComplexColor
  CharTopBorderDistance
  CharTransparence
  CharUnderline
  CharUnderlineColor
  CharUnderlineComplexColor
  CharUnderlineHasColor
  CharWeight
  CharWeightAsian
  CharWeightComplex
  CharWordMode
  ContinueingPreviousSubTree
  DocumentIndex
  DocumentIndexMark
  DropCapCharStyleName
  DropCapFormat
  DropCapWholeWord
  Endnote
  Footnote
  HyperLinkEvents
  HyperLinkName
  HyperLinkTarget
  HyperLinkURL
  LeftBorder
  LeftBorderComplexColor
  LeftBorderDistance
  ListAutoFormat
  ListId
  ListLabelString
  NestedTextContent
  NumberingIsNumber
  NumberingLevel
  NumberingRules
  NumberingStartValue
  NumberingStyleName
  OutlineContentVisible
  OutlineLevel
  PageDescName
  PageNumberOffset
  PageStyleName
  ParRsid
  ParaAdjust
  ParaAutoStyleName
  ParaBackColor
  ParaBackGraphic
  ParaBackGraphicFilter
  ParaBackGraphicLocation
  ParaBackGraphicURL
  ParaBackTransparent
  ParaBackgroundComplexColor
  ParaBottomMargin
  ParaChapterNumberingLevel
  ParaComposer
  ParaConditionalStyleName
  ParaContextMargin
  ParaExpandSingleWord
  ParaFirstLineIndent
  ParaFirstLineIndentUnit
  ParaHyphenationCompoundMinLeadingChars
  ParaHyphenationCompoundMinTrailingChars
  ParaHyphenationKeep
  ParaHyphenationKeepLine
  ParaHyphenationKeepType
  ParaHyphenationMaxHyphens
  ParaHyphenationMaxLeadingChars
  ParaHyphenationMaxTrailingChars
  ParaHyphenationMinWordLength
  ParaHyphenationNoCaps
  ParaHyphenationNoLastWord
  ParaHyphenationZone
  ParaHyphenationZoneAlways
  ParaHyphenationZoneColumn
  ParaHyphenationZonePage
  ParaHyphenationZoneSpread
  ParaInteropGrabBag
  ParaIsAutoFirstLineIndent
  ParaIsCharacterDistance
  ParaIsConnectBorder
  ParaIsForbiddenRules
  ParaIsHangingPunctuation
  ParaIsHyphenation
  ParaIsNumberingRestart
  ParaKeepTogether
  ParaLastLineAdjust
  ParaLeftMargin
  ParaLeftMarginUnit
  ParaLetterSpacingMaximum
  ParaLetterSpacingMinimum
  ParaLineNumberCount
  ParaLineNumberStartValue
  ParaLineSpacing
  ParaOrphans
  ParaRegisterModeActive
  ParaRightMargin
  ParaRightMarginUnit
  ParaScaleWidthMaximum
  ParaScaleWidthMinimum
  ParaShadowFormat
  ParaSplit
  ParaStyleName
  ParaTabStops
  ParaTopMargin
  ParaUserDefinedAttributes
  ParaVertAlignment
  ParaWidows
  ParaWordSpacing
  ParaWordSpacingMaximum
  ParaWordSpacingMinimum
  ReferenceMark
  RightBorder
  RightBorderComplexColor
  RightBorderDistance
  Rsid
  RubyAdjust
  RubyCharStyleName
  RubyIsAbove
  RubyPosition
  RubyText
  SnapToGrid
  SortedTextId
  TextField
  TextFrame
  TextParagraph
  TextSection
  TextTable
  TextUserDefinedAttributes
  TopBorder
  TopBorderComplexColor
  TopBorderDistance
  UnvisitedCharStyleName
  VisitedCharStyleName
  WritingMode
  WritingModeAutomatic
  Text
  Start
  End
  String
  Position
  Visible
  ImplementationName
  SupportedServiceNames
  Page
  PropertyToDefault
  Types
  ImplementationId
  PropertySetInfo
methods:
  queryInterface
  acquire
  release
  getText
  getStart
  getEnd
  getString
  setString
  collapseToStart
  collapseToEnd
  isCollapsed
  goLeft
  goRight
  gotoStart
  gotoEnd
  gotoRange
  isVisible
  setVisible
  getPosition
  getImplementationName
  supportsService
  getSupportedServiceNames
  jumpToFirstPage
  jumpToLastPage
  jumpToPage
  getPage
  jumpToNextPage
  jumpToPreviousPage
  jumpToEndOfPage
  jumpToStartOfPage
  screenDown
  screenUp
  goDown
  goUp
  goLeft
  goRight
  isAtStartOfLine
  isAtEndOfLine
  gotoEndOfLine
  gotoStartOfLine
  getPropertyState
  getPropertyStates
  setPropertyToDefault
  getPropertyDefault
  getTypes
  getImplementationId
  getPropertySetInfo
  setPropertyValue
  getPropertyValue
  addPropertyChangeListener
  removePropertyChangeListener
  addVetoableChangeListener
  removeVetoableChangeListener
  queryAdapter
---
[S] com.sun.star.text.TextViewCursor
    [S] com.sun.star.text.TextLayoutCursor
        [S] com.sun.star.text.TextCursor
            m com.sun.star.beans.XMultiPropertyStates: getPropertyStates, getPropertyDefaults, setAllPropertiesToDefault, setPropertiesToDefault
            om com.sun.star.text.XWordCursor: gotoNextWord, gotoStartOfWord, gotoPreviousWord, isEndOfWord, isStartOfWord, gotoEndOfWord
            om com.sun.star.text.XSentenceCursor: isEndOfSentence, gotoStartOfSentence, gotoNextSentence, isStartOfSentence, gotoPreviousSentence, gotoEndOfSentence
            om com.sun.star.text.XParagraphCursor: gotoPreviousParagraph, gotoNextParagraph, gotoEndOfParagraph, gotoStartOfParagraph, isStartOfParagraph, isEndOfParagraph
            om com.sun.star.document.XDocumentInsertable: insertDocumentFromURL
            om com.sun.star.util.XSortable: createSortDescriptor, sort
            [S] com.sun.star.text.TextRange
                om com.sun.star.container.XContentEnumerationAccess: getAvailableServiceNames, createContentEnumeration
[S] com.sun.star.style.CharacterProperties
    p CharFontName
    p CharFontStyleName
    p CharFontFamily
    p CharFontCharSet
    p CharFontPitch
    p CharColor
    p CharEscapement
    p CharHeight
    p CharUnderline
    p CharWeight
    p CharPosture
    p CharAutoKerning
    p CharBackColor
    p CharShadingValue
    p CharBackTransparent
    p CharCaseMap
    p CharCrossedOut
    p CharFlash
    p CharStrikeout
    p CharWordMode
    p CharKerning
    p CharLocale
    p CharKeepTogether
    p CharNoLineBreak
    p CharShadowed
    p CharFontType
    p CharStyleName
    p CharContoured
    p CharCombineIsOn
    p CharCombinePrefix
    p CharCombineSuffix
    p CharEmphasis
    p CharRelief
    p RubyText
    p RubyAdjust
    p RubyCharStyleName
    p RubyIsAbove
    p CharRotation
    p CharRotationIsFitToLine
    p CharScaleWidth
    p HyperLinkURL
    p HyperLinkTarget
    p HyperLinkName
    p VisitedCharStyleName
    p UnvisitedCharStyleName
    p CharEscapementHeight
    p CharNoHyphenation
    p CharUnderlineColor
    p CharUnderlineHasColor
    p CharStyleNames
    p CharHidden
    p TextUserDefinedAttributes
    p CharLeftBorder
    p CharRightBorder
    p CharTopBorder
    p CharBottomBorder
    p CharBorderDistance
    p CharLeftBorderDistance
    p CharRightBorderDistance
    p CharTopBorderDistance
    p CharBottomBorderDistance
    p CharShadowFormat
    p CharHighlight
    p CharInteropGrabBag
    p RubyPosition
    p CharTransparence
    p CharColorTheme
    p CharColorTintOrShade
    p CharScriptHint
[S] com.sun.star.style.CharacterPropertiesAsian
    p CharHeightAsian
    p CharWeightAsian
    p CharFontNameAsian
    p CharFontStyleNameAsian
    p CharFontFamilyAsian
    p CharFontCharSetAsian
    p CharFontPitchAsian
    p CharPostureAsian
    p CharLocaleAsian
[S] com.sun.star.style.CharacterPropertiesComplex
    p CharHeightComplex
    p CharWeightComplex
    p CharFontNameComplex
    p CharFontStyleNameComplex
    p CharFontFamilyComplex
    p CharFontCharSetComplex
    p CharFontPitchComplex
    p CharPostureComplex
    p CharLocaleComplex
[S] com.sun.star.style.ParagraphProperties
    p ParaAdjust
    p ParaLineSpacing
    p ParaBackColor
    p ParaBackTransparent
    p ParaBackGraphicURL
    p ParaBackGraphicFilter
    p ParaBackGraphicLocation
    p ParaLastLineAdjust
    p ParaExpandSingleWord
    p ParaLeftMargin
    p ParaRightMargin
    p ParaTopMargin
    p ParaBottomMargin
    p ParaContextMargin
    p ParaInteropGrabBag
    p ParaLineNumberCount
    p ParaLineNumberStartValue
    p PageDescName
    p PageNumberOffset
    p ParaRegisterModeActive
    p ParaTabStops
    p ParaStyleName
    p PageStyleName
    p DropCapFormat
    p DropCapWholeWord
    p ParaKeepTogether
    p ParaSplit
    p NumberingLevel
    p NumberingRules
    p NumberingStartValue
    p ParaIsNumberingRestart
    p NumberingStyleName
    p ParaOrphans
    p ParaWidows
    p ParaShadowFormat
    p LeftBorder
    p RightBorder
    p TopBorder
    p BottomBorder
    p BorderDistance
    p LeftBorderDistance
    p RightBorderDistance
    p TopBorderDistance
    p BottomBorderDistance
    p BreakType
    p DropCapCharStyleName
    p ParaFirstLineIndent
    p ParaIsAutoFirstLineIndent
    p ParaIsHyphenation
    p ParaHyphenationMaxHyphens
    p ParaHyphenationMaxLeadingChars
    p ParaHyphenationMaxTrailingChars
    p ParaVertAlignment
    p ParaUserDefinedAttributes
    p NumberingIsNumber
    p ParaIsConnectBorder
    p ListId
    p OutlineLevel
    p ParaBackGraphic
    p ContinueingPreviousSubTree
    p ListLabelString
    p ParaHyphenationNoCaps
    p ParaHyphenationNoLastWord
    p ParaHyphenationMinWordLength
    p ParaHyphenationZone
    p SortedTextId
    p ParaHyphenationKeep
    p ParaHyphenationKeepType
    p ParaHyphenationCompoundMinLeadingChars
    p ParaHyphenationKeepLine
    p ParaHyphenationZoneAlways
    p ParaHyphenationZoneColumn
    p ParaHyphenationZonePage
    p ParaHyphenationZoneSpread
    p ParaWordSpacing
    p ParaWordSpacingMinimum
    p ParaWordSpacingMaximum
    p ParaLetterSpacingMinimum
    p ParaLetterSpacingMaximum
    p ParaScaleWidthMinimum
    p ParaScaleWidthMaximum
    p ParaHyphenationCompoundMinTrailingChars
    p ParaComposer
[S] com.sun.star.style.ParagraphPropertiesAsian
    p ParaIsHangingPunctuation
    p ParaIsCharacterDistance
    p ParaIsForbiddenRules
[S] com.sun.star.style.ParagraphPropertiesComplex
    p WritingMode
m com.sun.star.text.XTextViewCursor: isVisible, getPosition, setVisible
m com.sun.star.text.XTextCursor: gotoRange, gotoEnd, gotoStart, isCollapsed, collapseToEnd, goRight, collapseToStart, goLeft
m com.sun.star.text.XTextRange: getEnd, getString, getStart, setString, getText
m com.sun.star.uno.XInterface: release, acquire, queryInterface
m com.sun.star.lang.XServiceInfo: getSupportedServiceNames, supportsService, getImplementationName
m com.sun.star.text.XPageCursor: jumpToLastPage, getPage, jumpToEndOfPage, jumpToPage, jumpToNextPage, jumpToStartOfPage, jumpToPreviousPage, jumpToFirstPage
m com.sun.star.view.XScreenCursor: screenDown, screenUp
m com.sun.star.view.XViewCursor: goLeft, goRight, goDown, goUp
m com.sun.star.view.XLineCursor: isAtStartOfLine, isAtEndOfLine, gotoEndOfLine, gotoStartOfLine
m com.sun.star.beans.XPropertyState: getPropertyStates, setPropertyToDefault, getPropertyDefault, getPropertyState
m com.sun.star.lang.XTypeProvider: getTypes, getImplementationId
m com.sun.star.beans.XPropertySet: removePropertyChangeListener, getPropertyValue, addVetoableChangeListener, addPropertyChangeListener, getPropertySetInfo, removeVetoableChangeListener, setPropertyValue
m com.sun.star.uno.XWeak: queryAdapter
only-in-definition: CharNoLineBreak, CharFontType, CharKeepTogether
only-in-implementation: CharComplexColor, TextFrame, DocumentIndex, ParaChapterNumberingLevel, LeftBorderComplexColor, CharOverline, CharOverlineHasColor, DocumentIndexMark, TextParagraph, Endnote, End, PropertyToDefault, TextSection, Start, Position, ParaConditionalStyleName, WritingModeAutomatic, Page, ParRsid, CharOpticalSizing, ParaFirstLineIndentUnit, ParaAutoStyleName, ParaBackgroundComplexColor, CharBackgroundComplexColor, CharFontVariations, Cell, ImplementationId, ReferenceMark, Footnote, HyperLinkEvents, NestedTextContent, PropertySetInfo, Text, CharAutoEscapement, CharTopBorderComplexColor, SnapToGrid, ParaLeftMarginUnit, CharOverlineColor, ParaRightMarginUnit, CharBottomBorderComplexColor, CharLeftBorderComplexColor, Rsid, ListAutoFormat, BottomBorderComplexColor, CharRightBorderComplexColor, String, Types, TopBorderComplexColor, TextField, SupportedServiceNames, TextTable, Visible, ImplementationName, RightBorderComplexColor, CharAutoStyleName, OutlineContentVisible, CharOverlineComplexColor, CharUnderlineComplexColor

… are you sure you are not reinventing the wheel? Maybe MRI or Xray can help How can I reach dialog elements from python macro - #5 by ms777

Thanks for bringing them up.

One issue with MRI and Xray is that I always forget how to use them and whether they’re installed. So let me share what I was able to figure out just now, while I’m at it:

  • MRI is an extension. They’re installed by executing an extension package. For MRI you can find it at Releases · hanya/MRI · GitHub (https://github.com/hanya/MRI/releases/download/v1.3.5/MRI-1.3.5.oxt is the latest version at the moment). The extensions are installed to ~\AppData\Roaming\LibreOffice\4\user\uno_packages\cache\uno_packages under Windows (most of the files). It adds the following menu items: Tools > Add-Ons > MRI and Tools > Add-Ons > MRI <- selection. You can find installed extensions in the Extensions dialog (Tools > Extensions or Ctrl-Alt-E).

  • Xray is a Basic library. To install it open https://web.archive.org/web/20231002132402/https://berma.pagesperso-orange.fr/Files_en/XrayTool60_en.odt and click Install Xray on page 5 (Suppress Xray to uninstall). It’s installed to ~\AppData\Roaming\LibreOffice\4\user\basic. Once installed you can find it under My Macros in the Organizing Basic Macros dialog (Tools > Macros > Organize Macros > Basic...).

  • To use them (check if they work) create e.g. ~\AppData\Roaming\LibreOffice\4\user\scripts\python\a.py:

    def m():
        doc = XSCRIPTCONTEXT.getDesktop().CurrentComponent
        vc = doc.CurrentController.ViewCursor
        xray(vc)
        # xray(XSCRIPTCONTEXT.getComponentContext())
        # xray(XSCRIPTCONTEXT)
        # mri(vc)
        # mri(XSCRIPTCONTEXT.getComponentContext())
        # mri(XSCRIPTCONTEXT)
    
    def xray(o):
        ctx = XSCRIPTCONTEXT.getComponentContext()
        mspf = ctx.ServiceManager.createInstanceWithContext('com.sun.star.script.provider.MasterScriptProviderFactory', ctx)
        mspf.createScriptProvider('') \
            .getScript('vnd.sun.star.script:XRayTool._Main.Xray?language=Basic&location=application') \
            .invoke((o,), (), ())
    
    def mri(o):
        ctx = XSCRIPTCONTEXT.getComponentContext()
        mri = ctx.ServiceManager.createInstanceWithContext('mytools.Mri', ctx)
        mri.inspect(o)
    

    Then open the Run Macro dialog (Tools > Macros > Run Macro...), choose My Macros > a and double-click the m() macro.

  • Alternatively install the apso extension (Releases · Jean-Marc Zambon / apso · GitLab or https://gitlab.com/jmzambon/apso/-/raw/v1.5.3/apso.oxt). Then you can do (MRI and Xray still need to be installed):

    from apso_utils import xray, mri
    
    def m():
        doc = XSCRIPTCONTEXT.getDesktop().CurrentComponent
        vc = doc.CurrentController.ViewCursor
        xray(vc)
        # xray(XSCRIPTCONTEXT.getComponentContext())
        # xray(XSCRIPTCONTEXT)
        # mri(vc)
        # mri(XSCRIPTCONTEXT.getComponentContext())
        # mri(XSCRIPTCONTEXT)
    

    The trick is to open the Organize python scripts dialog (Tools > Macros > Organize python scripts or Alt-Shift-F11) before running m() (basically to use apso_utils use apso to run macros), otherwise it won’t find apso_utils.

  • Xray has a menu: Tools > Macros > Run Macro..., select My Macros > XrayTool > Xutils and execute the XrayMenu macro.

Other issues are:

  • Are they supported? Xray was last modified in 2012, MRI in 2025, before that in 2018.
  • Are they well documented? MRI has a wiki. Xray is documented in the document that is used to install it.
  • The UIX is not very intuitive or not all the features work? E.g. I fail to make MRI or Xray open the documentation for what is under the cursor. If that doesn’t work, how do I find the documentation for a property or method? For that I need to know which interface or service they belong to.
  • I prefer to work from the console. And mostly run external python scripts which connect to LibreOffice via a socket.
  • Can I trust them? MRI say that text view cursor (doc.CurrentController.ViewCursor) implements com.sun.star.beans.XMultiPropertyStates, Xray says that it doesn’t. Xray says it implements com.sun.star.text.TextCursor, com.sun.star.text.TextLayoutCursor, com.sun.star.text.TextRange, MRI says that it doesn’t.

So to answer your question, indeed I do reinvent the wheel. But I do so because I tried them and they apparently weren’t helpful enough. Probably because they don’t show which property/method belong to which interface/service. I don’t really remember. But reinventing the wheel most likely allowed me to better understand how to find the documentation. And my wheel may be more or less ready, at least for my purposes. But maybe it makes sense to give MRI and Xray another try. Also, Tools > Development Tools might also come in handy in some cases.