I am creating a for component command button by scripting in python. I fallowed the next tutorial https://help.libreoffice.org/latest/en-GB/text/sbasic/python/python_listener.html except that "com.sun.star.drawing.controlShape doesn't have the method addActionListener but AddEventListener
oMRI.inspect(target )
def addingform():
from com.sun.star.awt import Point
from com.sun.star.awt import Size
oDoc = XSCRIPTCONTEXT.getDocument()
ctx = uno.getComponentContext()
sm = ctx.getServiceManager()
desktop = sm.createInstanceWithContext("com.sun.star.frame.Desktop",ctx)
doc = desktop.getCurrentComponent()
doc.getCurrentController().setFormDesignMode(True)
oSheet = doc.getSheets().getByName("Sheet1")
oDrawPage = oSheet.getDrawPage()
oForm = oDoc.createInstance("com.sun.star.form.component.Form")
oForm.Name = "Form2"
oForms = oDrawPage.getForms()
oForms.insertByIndex(0,oForm)
oButton = doc.createInstance("com.sun.star.form.component.CommandButton")
oButton.BackgroundColor = 15650253
oButton.Name = "_MY_BUTTON"
oButton.Label = "_MY_LABEL"
#oButton.Enabled = True
oForm.insertByName("_MY_BUTTON",oButton)
oShape = doc.createInstance("com.sun.star.drawing.ControlShape")
oShape.Control = oButton
oDrawPage.add(oShape)
oShape.Position = Point(1000,2000)
oShape.Size = Size(7560,4000)
act = ActionListener()
oShape.addEventListener(act)
doc.getCurrentController().setFormDesignMode(False)
import uno, unohelper
from com.sun.star.awt import XActionListener
from com.sun.star.lang import EventObject
from com.sun.star.awt import ActionEvent
class ActionListener(unohelper.Base, XActionListener):
def __init__(self):
self.count = 0
def actionPerformed(self, ActionEvent):
msgbox("click")
def disposing(self, eventObject):
pass
~
~
I put an msgbox in __init__Self() and disposing and they work I want to click the command button and trigger msgbox