gpt4 book ai didi

python - 从 Python 在 LibreOffice 中创建复选框

转载 作者:行者123 更新时间:2023-12-01 09:33:40 29 4
gpt4 key购买 nike

我正在开发一个 LibreOffice 扩展,其中“选项”对话框必须具有以编程方式创建的复选框列表,因为它们取决于用户安装的额外数据文件( spelling/grammar checker 的自定义设置)。

在宏管理器中手动添加一些复选框非常容易 dialog editor我可以导出到 .xdl 文件并从 Python 加载,但我还没有找到任何可以添加复选框的“容器”,以便我可以自动定位和滚动。

我可以使用

以编程方式将条目添加到我在dialog.xdl 中创建的列表框
boxC = windowC.getControl("toggleIds")
boxM = boxC.getModel()
entries = ("some", "checkbox", "entries")
uno.invoke(boxM, "setPropertyValue", ("StringItemList", uno.Any("[]string", entries)))

但是列表框中的多选需要按住 Ctrl 键单击,这不是很直观。

我可以使用以下方式以编程方式将单个复选框添加到对话框窗口(扩展程序选项选项卡的“主要部分”)

windowM = windowC.getModel()
ctx = uno.getComponentContext()
cb1 = ctx.ServiceManager.createInstanceWithContext("com.sun.star.form.component.CheckBox", ctx)
cb1.Label = "some label"
cb1.State = 1;
windowM.insertByName("mycb1", cb1)

将它放在最顶部,但似乎我必须手动执行所有滚动代码、定位等。如果我在这里多次执行 insertByName ,它会将它们全部添加在同一位置,我还没有弄清楚如何将它们添加到另一个下面。

我看到有 C++ 代码使用 SvxCheckListBox ,例如optcomp.cxx ,但这似乎是一个较新的开发,至少我在旧的 Java AWT docs 中找不到任何引用它的内容。 。

<小时/>

TL;DR:是否有一种简单的方法可以通过编程方式创建从 Python 扩展到 LibreOffice 的复选框列表?

最佳答案

SvxCheckListBox 由 LibreOffice 用于对话框,例如工具 -> 选项 -> LibreOffice -> 字体中的替换表。但是,它没有由 API 公开,因此您无法使用它。

为了证明这一点,以下是 API 公开的所有接口(interface)和服务,其中包含单词“Box”,来自 offapi/type_reference/offapi.idl

com::sun::star::awt::UnoControlCheckBox
com::sun::star::awt::UnoControlCheckBoxModel
com::sun::star::awt::UnoControlComboBox
com::sun::star::awt::UnoControlComboBoxModel
com::sun::star::awt::UnoControlGroupBox
com::sun::star::awt::UnoControlGroupBoxModel
com::sun::star::awt::UnoControlListBox
com::sun::star::awt::UnoControlListBoxModel
com::sun::star::awt::XCheckBox
com::sun::star::awt::XComboBox
com::sun::star::awt::XMessageBox
com::sun::star::awt::XMessageBoxFactory
com::sun::star::form::component::CheckBox
com::sun::star::form::component::ComboBox
com::sun::star::form::component::ListBox

所以唯一的办法就是......

manually do all the scrolling-code, positioning etc.

我的建议是创建一个名为“CheckListBox”的新通用 Python 类来处理滚动和定位,然后派生或实例化它以制作选项的特定复选框。

关于python - 从 Python 在 LibreOffice 中创建复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49732534/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com