Pyuno IllegalArgumentException

I am writing a python macro that runs inside of libreoffice (as opposed to externally via the pyuno bridge). The code calls insertByIndex on an XIndexContainer, created by createSettings on an XUIConfigurationManager, which I am trying to use to define a custom toolbar and toolbar items in writer. According to this source a Sequence maps to a tuple in python. However, when I pass a tuple of PropertyValues, I instead get an IllegalArgumentException which says that I need to pass a css::uno::Sequence< css::beans::PropertyValue >. However, I am passing a tuple filled with PropertyValues, which should meet that definition. What data structure do I need to pass to the insertByIndex function, or how can I accomplish something similar in python? I am following listing 5.109 from Andrew Pitonyak’s English Macros document, and am trying to convert it to python.

Here is the code which causes said error (I run the createToolbar function with “test” as the only input):

https://raw.githubusercontent.com/otisdog8/open-debate/master/api/0001-toolbars.py

https://raw.githubusercontent.com/otisdog8/open-debate/master/src/test.py

Here is the error that happens when I run the code:

com.sun.star.lang.IllegalArgumentException: Type must be css::uno::Sequence< css::beans::PropertyValue > (Error during invoking function test2 in module file:///home/otis/.config/libreoffice/4/user/Scripts/python/debate.py (<class ‘uno.com.sun.star.lang.IllegalArgumentException’>: Type must be css::uno::Sequence< css::beans::PropertyValue >
File “/usr/lib/libreoffice/program/pythonscript.py”, line 921, in invoke
ret = self.func( *args )
File “/home/otis/.config/libreoffice/4/user/Scripts/python/debate.py”, line 29, in test2
createToolbar(“test”)
File “/home/otis/.config/libreoffice/4/user/Scripts/python/debate.py”, line 181, in createToolbar
settings.insertByIndex(0, item)
))

System Details:
Python 3.8, in libreoffice 6.4.4.2
Arch linux, kernel 5.7.2

Please comment if you need any more info, I would be happy to provide.

Error during invoking function test2 in module file:///home/otis/.config/libreoffice/4/user/Scripts/python/debate.py

You seem to forget to include the code of the actually failing module

I updated the post.

I don’t know if that helps, but please check that XIndexContainer::insertByIndex expects the second parameter to be css::uno::Any, and it extracts the sequence from that Any. You pass the sequence there directly - does that work?

I know that it expects the parameter to be an Any, how do I pass the Sequence as an Any?

Maybe @LibreOfficiant can advise?

Normally tuples work, but this call requires special syntax to pass the exact type.

uno.invoke(
    settings, "insertByIndex",
    (0, uno.Any("[]com.sun.star.beans.PropertyValue", item)))

Note that the return statement of createToolbarItem can be simplified.

return tuple(item)