[英]How to check paragraph adjustment using pyUNO library in Libre/Open Office?
The com.sun.star.style.ParagraphProperties
service supports the property ParaAdjust
, that supports 5 values from com.sun.star.style.ParagraphAdjust
( ParagraphProperties , ParagraphAdjust ). com.sun.star.style.ParagraphProperties
服务支持属性ParaAdjust
,它支持来自com.sun.star.style.ParagraphAdjust
( ParagraphProperties , ParagraphAdjust )的5个值。
To set the value, one of the two methods could be used: 要设置该值,可以使用以下两种方法之一:
cursor.ParaAdjust = com.sun.star.style.ParagraphAdjust.RIGHT
cursor.setPropertyValue('ParaAdjust', com.sun.star.style.ParagraphAdjust.RIGHT)
To check the value the first try was: 要检查值,第一次尝试是:
if cursor.ParaAdjust == com.sun.star.style.ParagraphAdjust.RIGHT:
...
but didn't work. 但没有奏效。
Inspecting: 检查:
type(cursor.ParaAdjust)
----> <class 'int'>
type(com.sun.star.style.ParagraphAdjust.RIGHT)
----> <class 'uno.Enum'>
right, I've assumed that these were constants (see Note below), my fault. 是的,我认为这些是常数(见下面的注释),我的错。
Now, the uno.Enum
class has two properties typeName
and value
, so I've tried: 现在,
uno.Enum
类有两个属性typeName
和value
,所以我尝试过:
if cursor.ParaAdjust == com.sun.star.style.ParagraphAdjust.RIGHT.value:
...
but didn't work, too! 但也没有用!
Inspecting: 检查:
type(com.sun.star.style.ParagraphAdjust.RIGHT.value)
----> <class 'string'>
print(com.sun.star.style.ParagraphAdjust.RIGHT.value)
----> 'RIGHT'
Setting the ParaAdjust
property and then print its actual value, I get: 设置
ParaAdjust
属性,然后打印其实际值,我得到:
LEFT = 0
RIGHT = 1
BLOCK = 2
CENTER = 3
STRETCH = 0
(note that STRETCH is considered as LEFT,
a bug or something not implemented?)
So: 所以:
Note : 注意 :
In LibreOffice 4.0 (maybe in older versions too), you could get this values with: 在LibreOffice 4.0中(也许在旧版本中),您可以通过以下方式获取此值:
uno.getConstantByName('com.sun.star.style.ParagraphAdjust.RIGHT')
from version 4.1 that doesn't work anymore (rightly, not being a constant). 从版本4.1不再起作用(正确,不是一个常数)。
Thanks to " hanya " from the OpenOffice Forum ( link ), here's some python code for mapping the values of ParagraphAdjust
: 感谢OpenOffice论坛中的“ hanya ”( 链接 ),这里有一些用于映射
ParagraphAdjust
值的python代码:
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())}
In python 2.6, that doesn't support the comprehension syntax for dictionaries, the dict() function can be used instead. 在python 2.6中,它不支持字典的理解语法,可以使用dict()函数代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.