1

I'm working on a LibreOffice extension where the Options dialog has to have a list of checkboxes that are created programmatically, since they depend on what extra data files (custom settings for a spelling/grammar checker) the user has installed.

It's easy enough to add some checkboxes manually in the macro organizer dialog editor that I can export to a .xdl file and load from Python, but I haven't found any sort of "container" that I can add checkboxes to so I can get automatic positioning and scrolling.

I can add entries programmatically to a ListBox that I've made in a dialog.xdl using

boxC = windowC.getControl("toggleIds")
boxM = boxC.getModel()
entries = ("some", "checkbox", "entries")
uno.invoke(boxM, "setPropertyValue", ("StringItemList", uno.Any("[]string", entries)))

but multiselection in a listbox requires ctrl-clicking, which is not very intuitive.

I can programmatically add a single checkbox to the dialog window (the "main part" of the extension's Options tab) using

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)

which puts it at the very top, but then it seems I'd have to manually do all the scrolling-code, positioning etc. If I do insertByName multiple times here, it adds them all at the same position, I haven't yet figured out how to add them below one another.

I see there is C++ code which uses SvxCheckListBox, e.g. optcomp.cxx, but this seems like a newer development, at least I can't find anything referring to it in the old Java AWT docs.


TL;DR: Is there a simple way to programmatically make a list of checkboxes from Python extensions to LibreOffice?

1 Answer 1

1

SvxCheckListBox is used by LibreOffice for dialogs such as the replacement table in Tools -> Options -> LibreOffice -> Fonts. However, it is not exposed by the API, so you cannot use it.

To prove this, here are all of the interfaces and services exposed by the API that have the word "Box" in it, from 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

So the only way is to...

manually do all the scrolling-code, positioning etc.

My suggestion is to create a new general Python class called "CheckListBox" to handle scrolling and positioning, and then derive or instantiate it to make the specific checkboxes for the options.

Sign up to request clarification or add additional context in comments.

1 Comment

Another possibility is to do something fancy with a Tree Control, such as creating graphics that look like checkboxes and checking them when the element is clicked. However, I do not think this would work as well as what my answer describes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.