class KeyHandler(unohelper.Base, XKeyHandler):
def disposing(self, ev):
pass
def keyPressed(self, ev):
if ev.KeyCode == PAUSE:
# here I need o access the current document to manipulate text
else:
return False
return True
def keyReleased(self, ev):
return False
By instrospecting 'ev' I get a 'source' but I can't see how to reach my current document.
and what kind of animal is Source? Does it have an ImplementationName or something?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
The source is the Window which receives the key event... you could use the accessible context to go up the chain of accessible parent windows until you get the titledbordertext for the frame and then enumerate all the frames to find the document.
But as this should be the same as ThisComponent why not use that?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Then I can work on the current component (called here 'mission) using a property. I'm pretty sure it's not the best solution. It should be possible to get the current component straight from the KeyEvent (which was my initial question).
title= source.gettoolkit.getactivetopwindow.accessiblecontext.titledbordertext
frames = stardesktop.getframes
for i = 0 to frames.count -1
if frames(i).title = title then
component =frames(i).getcontroller.model
exit for
end if
next
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
If the calling object is a window object, you have attached the listener to that object. Is there any controller availlable? A controller also has XKeyHandler and from there you get the document via obj.getModel()
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice