1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 from com
.sun
.star
.document
import XDocumentEventListener
14 print("pyuno not found: try to set PYTHONPATH and URE_BOOTSTRAP variables")
15 print("PYTHONPATH=/installation/opt/program")
16 print("URE_BOOTSTRAP=file:///installation/opt/program/fundamentalrc")
19 class EventListener(XDocumentEventListener
,unohelper
.Base
):
21 def __init__(self
, xContext
, eventNames
, **kwargs
):
22 self
.xGEB
= xContext
.ServiceManager
.createInstanceWithContext(
23 "com.sun.star.frame.GlobalEventBroadcaster", xContext
)
24 self
.xContext
= xContext
26 self
.eventExecuted
= []
27 self
.printEvents
= kwargs
.get('printNames', False)
28 if isinstance(eventNames
, str):
29 self
.eventNames
= [eventNames
]
30 elif isinstance(eventNames
, list):
31 self
.eventNames
= eventNames
34 self
.xGEB
.addDocumentEventListener(self
)
37 def __exit__(self
, type, value
, traceback
):
38 self
.xGEB
.removeDocumentEventListener(self
)
40 def documentEventOccured(self
, event
):
41 if self
.printEvents
is True:
42 print(event
.EventName
)
44 if event
.EventName
in self
.eventNames
:
46 self
.eventExecuted
.append(event
.EventName
)
48 def hasExecuted(self
, eventName
):
49 return eventName
in self
.eventExecuted
54 # vim: set shiftwidth=4 softtabstop=4 expandtab: