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/.
10 from com
.sun
.star
.document
import XDocumentEventListener
12 print("pyuno not found: try to set PYTHONPATH and URE_BOOTSTRAP variables")
13 print("PYTHONPATH=/installation/opt/program")
14 print("URE_BOOTSTRAP=file:///installation/opt/program/fundamentalrc")
17 class EventListener(XDocumentEventListener
,unohelper
.Base
):
19 def __init__(self
, xContext
, eventNames
, **kwargs
):
20 self
.xGEB
= xContext
.ServiceManager
.createInstanceWithContext(
21 "com.sun.star.frame.GlobalEventBroadcaster", xContext
)
22 self
.xContext
= xContext
24 self
.eventExecuted
= []
25 self
.printEvents
= kwargs
.get('printNames', False)
26 if isinstance(eventNames
, str):
27 self
.eventNames
= [eventNames
]
28 elif isinstance(eventNames
, list):
29 self
.eventNames
= eventNames
32 self
.xGEB
.addDocumentEventListener(self
)
35 def __exit__(self
, type, value
, traceback
):
36 self
.xGEB
.removeDocumentEventListener(self
)
38 def documentEventOccured(self
, event
):
39 if self
.printEvents
is True:
40 print(event
.EventName
)
42 if event
.EventName
in self
.eventNames
:
44 self
.eventExecuted
.append(event
.EventName
)
46 print(self
.eventNames
)
47 print(event
.EventName
)
49 def hasExecuted(self
, eventName
):
50 return eventName
in self
.eventExecuted
55 # vim: set shiftwidth=4 softtabstop=4 expandtab: