【问题标题】:Creating a checklistbox in LibreOffice from Python从 Python 在 LibreOffice 中创建一个复选框
【发布时间】:2018-09-18 19:52:11
【问题描述】:

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

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

我可以使用

以编程方式将条目添加到我在 dialog.xdl 中创建的 ListBox
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,它会将它们全部添加到同一个位置,我还没有弄清楚如何将它们相互添加。

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


TL;DR:有没有一种简单的方法可以以编程方式制作从 Python 扩展到 LibreOffice 的复选框列表?

【问题讨论】:

    标签: python user-interface awt libreoffice uno


    【解决方案1】:

    SvxCheckListBox 被 LibreOffice 用于对话框,例如 工具 -> 选项 -> LibreOffice -> 字体 中的替换表。但是,它没有被 API 公开,所以你不能使用它。

    为了证明这一点,以下是 API 公开的所有接口和服务,其中包含“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
    

    所以唯一的办法就是……

    手动完成所有的滚动代码、定位等

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

    【讨论】:

    • 另一种可能性是使用Tree Control 做一些花哨的事情,例如创建看起来像复选框的图形并在单击元素时检查它们。但是,我认为这不会像我的回答所描述的那样有效。
    猜你喜欢
    • 1970-01-01
    • 2021-09-20
    • 1970-01-01
    • 2021-06-24
    • 2013-04-03
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 2012-10-23
    相关资源
    最近更新 更多