1 I open one stored document, store it, call MsgBox, close de document. 2 I open a new document and call MsgBox again and get object has no attribute getCurrentController
I thought that after closing the first document MsgBox was attached to the first document so I changed "_default" for "_blank' then I thought that it was a matter of time so I put a 3 second delay. This is my code:
import uno,os,time
from com.sun.star.beans import PropertyValue
def MsgBox(message):
ctx = uno.getComponentContext()
sm = ctx.getServiceManager()
desktop = sm.createInstanceWithContext('com.sun.star.frame.Desktop', ctx)
oDoc = desktop.getCurrentComponent().getCurrentController()
oToolkit = sm.createInstance('com.sun.star.awt.Toolkit')
msgbox = oToolkit.createMessageBox(oDoc.getFrame().getContainerWindow(),"infobox",1,"LibreOffice",str(message))
msgbox.execute()
msgbox.dispose()
return
def documento_1():
ctx = uno.getComponentContext()
sm = ctx.getServiceManager()
desktop = sm.createInstanceWithContext('com.sun.star.frame.Desktop',ctx)
opciones =[]
opcion = PropertyValue()
opcion.Name = 'As Template'
opcion.Value = False
opciones.append(opcion)
opcion.Name ='Password'
opcion.Value = 'letmein'
opciones.append(opcion)
ruta = uno.systemPathToFileUrl('/home/jaguar/Documentos/Untitled 1.odt')
#first document
doc = desktop.loadComponentFromURL(ruta,'_blank',0,tuple(opciones))
MsgBox(doc.hasLocation())
doc.store()
doc.close(True)
time.sleep(3)
#second new document
doc1 = desktop.loadComponentFromURL('private:factory/swriter','_blank',0,())
time.sleep(3)
#Here is the problem
MsgBox(doc1.hasLocation())
doc1.close(True)
return
Get the controller from the new document if it's active. Here is an example based on code I use.