libreoffice 宏 - 在文本字段上切换启用可见

libreoffice macro - toggle enablevisible on a textfield

我正在使用 python 宏来处理 libreoffice 编写器文件。我想要切换 TextField 的 EnableVisible 标志的可能性。

这意味着,双击该字段时,切换您可以使用的小标志,使其可见或不可见。

到目前为止,我在我的代码中得到了这个:

import uno

def toggle_field(field_title):
    document = XSCRIPTCONTEXT.getDocument()
    textfields = document.getTextFields()
    enum = textfields.createEnumeration()
    while enum.hasMoreElements():
        tf = enum.nextElement()
        if tf.VariableName == field_title:
            visibility = tf.getPropertyValue('EnableVisible') #wrong
            tf.EnableVisible = not visibility                 #wrong
            tf.update()                                       #maybe right

这个给我那个

com.sun.star.beans.UnknownPropertyException: Unknown property: Enabled (Error during invoking function toggle_field in module (...)file.py (: Unknown property: EnableVisible

此外,如果我评论第一个错误行,第二个错误行给我

com.sun.star.beans.UnknownPropertyException: Unknown property: Enabled (Error during invoking function toggle_field in module (...)file.py (: EnableVisible


更新:

tf.IsFieldDisplayed = False

tf.setPropertyValue('IsFieldDisplayed', False)

不再是未知数 属性,但我收到此错误消息:

com.sun.star.beans.UnknownPropertyException: IntrospectionAccessStatic_Impl::setPropertyValueByIndex(), property at index 13 is readonly (Error during invoking function toggle_field in module (...)file.py (: IntrospectionAccessStatic_Impl::setPropertyValueByIndex(), property at index 13 is readonly

什么看起来不公平,因为它在文档中不是只读的,BASIC 可以修改它(https://wiki.documentfoundation.org/images/b/b0/BH5009-Macros.pdf 第 19 页)

经过共同研究,结果 属性 被称为 IsVisible:

 tf.IsVisible = not tf.IsVisible