I am trying to generate a ToolbarItem in calc. The Basic code (just copied the relevant lines) works without problem. The python code throws an "Type must be com::sun::uno::Sequence< com::sun::beans::PropertyValue >" exception. Can somebody help?
Cheers ms777
The Basic code
Code: Select all
Sub Main
toolbarResourceUrl = "private:resource/toolbar/custom_ms777"
itemCommandUrl = "itemCommandUrl"
itemService = "itemService"
itemLabel = "itemLabel"
'register the itemService at the Toolbarfactory
oo = createUnoService("com.sun.star.frame.ToolbarControllerFactory")
if oo.hasController( itemCommandUrl, "") then oo.deregisterController( itemCommandUrl, "")
oo.registerController( itemCommandUrl, "", itemService)
'delete toolbar if existing
oLM = ThisComponent.CurrentController.Frame.Layoutmanager
if not IsNull(oLM.getElement(toolbarResourceUrl)) then oLM.destroyElement(toolbarResourceUrl)
'create toolbar
oLM.createElement(toolbarResourceUrl)
'insert one component into toolbar and set the UIName
oEL = oLM.getElement(toolbarResourceUrl)
oToolbarSettings = oEL.getSettings(true)
Dim aItem(1) as new com.sun.star.beans.PropertyValue
aItem(0).Name = "CommandURL"
aItem(0).Value = itemCommandUrl
aItem(1).Name = "Label"
aItem(1).Value = itemLabel
oToolbarSettings.insertByIndex( 0, aItem )
End Sub
Code: Select all
import uno
from com.sun.star.beans import PropertyValue # type:ignore
doc = XSCRIPTCONTEXT.getDocument() # type: ignore
ctx = XSCRIPTCONTEXT.getComponentContext() # type: ignore
smgr = ctx.ServiceManager
def InsertToolbar():
toolbarResourceUrl = "private:resource/toolbar/custom_ms777"
itemCommandUrl = "itemCommandUrl"
itemService = "itemService"
itemLabel = "itemLabel"
oo = smgr.createInstanceWithContext("com.sun.star.frame.ToolbarControllerFactory", ctx)
if oo.hasController( itemCommandUrl, ""):
oo.deregisterController( itemCommandUrl, "")
oo.registerController( itemCommandUrl, "", itemService)
# delete toolbar if existing
oLM = doc.CurrentController.Frame.LayoutManager
if oLM.getElement(toolbarResourceUrl) is None:
oLM.destroyElement(toolbarResourceUrl)
# create toolbar
oLM.createElement(toolbarResourceUrl)
# insert one component into toolbar and set the UIName
oEL = oLM.getElement(toolbarResourceUrl)
oToolbarSettings = oEL.getSettings(True)
prop1 = PropertyValue()
prop1.Name = "CommandURL"
prop1.Value = itemCommandUrl
prop2 = PropertyValue()
prop2.Name = "Label"
prop2.Value = itemLabel
aprop = (prop1, prop2,)
oToolbarSettings.insertByIndex( 0, aprop)
#I get this error: Type must be com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >