3

com.sun.star.style.ParagraphProperties服务支持属性 ParaAdjust,它支持来自com.sun.star.style.ParagraphAdjustParagraphPropertiesParagraphAdjust)的 5 个值。

要设置该值,可以使用以下两种方法之一:

cursor.ParaAdjust = com.sun.star.style.ParagraphAdjust.RIGHT
cursor.setPropertyValue('ParaAdjust', com.sun.star.style.ParagraphAdjust.RIGHT)

要检查值,第一次尝试是:

if cursor.ParaAdjust == com.sun.star.style.ParagraphAdjust.RIGHT:
    ...

但没有用。

检查:

type(cursor.ParaAdjust)
----> <class 'int'>
type(com.sun.star.style.ParagraphAdjust.RIGHT)
----> <class 'uno.Enum'>

对,我假设这些是常数(见下面的注释),我的错。

现在,uno.Enum该类有两个属性typeNamevalue,所以我尝试过:

if cursor.ParaAdjust == com.sun.star.style.ParagraphAdjust.RIGHT.value:
    ...

但也没有用!

检查:

type(com.sun.star.style.ParagraphAdjust.RIGHT.value)
----> <class 'string'>
print(com.sun.star.style.ParagraphAdjust.RIGHT.value)
----> 'RIGHT'

设置ParaAdjust属性然后打印它的实际值,我得到:

LEFT    = 0
RIGHT   = 1
BLOCK   = 2
CENTER  = 3
STRETCH = 0
(note that STRETCH is considered as LEFT,
 a bug or something not implemented?)

所以:

  • 这些值在哪里定义?
  • 如何使用 UNO API 获取这些值?
  • 我是否遗漏了官方文档中的某些内容?

注意

在 LibreOffice 4.0(也可能是旧版本)中,您可以通过以下方式获取此值:

uno.getConstantByName('com.sun.star.style.ParagraphAdjust.RIGHT')

从 4.1 版开始,它不再起作用(正确地,不是一个常数)。

4

1 回答 1

2

感谢来自 OpenOffice 论坛(链接)的“ hanya ” ,这里有一些用于映射以下值的 python 代码:ParagraphAdjust

def get_paragraph_adjust_values():
    ctx = uno.getComponentContext()
    tdm = ctx.getByName(
            "/singletons/com.sun.star.reflection.theTypeDescriptionManager")
    v = tdm.getByHierarchicalName("com.sun.star.style.ParagraphAdjust")
    return {name : value
            for name, value
            in zip(v.getEnumNames(), v.getEnumValues())}

在不支持字典的理解语法的 python 2.6 中,可以使用dict()函数代替。

于 2015-03-15T10:54:39.380 回答