A possible answer. But I think it’s a workaround, not the real answer.
When I click on the form icon and the form opens, I have found that a listener is indeed triggered, but not on the form itself:
doc = Base.open_doc('test_db.odb', loader)
GUI.set_visible(is_visible=True, odoc=doc)
class DocEventListener(unohelper.Base, XDocumentEventListener):
def documentEventOccured(self, event):
print_out_element(event, 'doc event')
doc.addDocumentEventListener(DocEventListener())
… one possible hypothesis is thus that the “property” “When loading” which you can use to attach a macro to the event of a form being opened is in fact a sort of pseudo-property: this event is actually attached to the object at the top of the hierarchy, which I shall refer to as the “ODB document”, with the following spec: implementationName=com.sun.star.comp.dba.ODatabaseDocument, supportedServices={com.sun.star.sdb.OfficeDatabaseDocument,com.sun.star.document.OfficeDocument}
Interestingly, before a form is opened, although it implements the interface XComponent
, actually getComponent()
returns None
. After a form is opened, however, this returns an object, which is essentially a Writer document, since Base forms are obviously modelled on Writer documents. This might explain why form objects implement XCloseListener
, but (apparently) nothing to listen in on the event of opening.
I tentatively call it a “pseudo property”, because the user who edits the form, and attaches a macro to this event, is no doubt tempted to think that they are configuring an event of the form itself. Which then begs the question, are all these form events pseudo properties, or just this one: for example, what about the event “After record change”, which I also need to configure?
A bit later: I now don’t think this is right. Clearly the Writer document which is used to make the component when a form is loaded must be stored somewhere inside the .odb file. Having examined the component after opening, this has a method getEvents
, one of which is OnLoad
(however, there is nothing there which corresponds to the form’s “After record change” event: maybe this can be found from the form’s data provider objects …).
So the question is: how to obtain a reference to this Writer document, before the form is loaded? It must be present in some storage location.