MessageBox in Python in OO4 different from OOo3. help!

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
xargsOOo
Posts: 24
Joined: Fri Oct 18, 2013 11:17 am

MessageBox in Python in OO4 different from OOo3. help!

Post by xargsOOo »

Hi to all!

In a python macro in OO3 i use this snippet of code to run a message box, i've took that from this blog http://universolibre.org/node/27

It simply pop up a message box.

Code: Select all

def MostrarMensaje( Mensaje ):  
	# El documento desde donde se llama esta macro
	oDoc = XSCRIPTCONTEXT.getDocument()
	# El manejador de servicios
	oSM = uno.getComponentContext().getServiceManager()
	# Creamos una instancia del servicio Toolkit
	oToolkit = oSM.createInstance( "com.sun.star.awt.Toolkit" )
	# Creamos una estructura Rectangulo
	rec = uno.createUnoStruct("com.sun.star.awt.Rectangle")
	# El tipo de cuadro de mensaje, solo informativo
	sTipo = "infobox"
	# El Título del cuadro de mensaje
	sTitulo = "Mensaje"
	# Mostraremos solo el botón Aceptar
	botones = 1
	# Referencia a la ventana contenedora
	oParentWin = oDoc.getCurrentController().getFrame().getContainerWindow()
	# Creamos el cuadro de mensaje con los parámetros necesarios
	oMsgBox = oToolkit.createMessageBox( oParentWin, rec, sTipo, botones, sTitulo, Mensaje )
	# Mostramos el cuadro de mensaje
	oMsgBox.execute()
	return None	

If i run that in OO4 with the 2.7 python it pop up an error
Image

It says that the number of the parameter is not correct on the line
oMsgBox = oToolkit.createMessageBox( oParentWin, rec, sTipo, botones, sTitulo, Mensaje )


How can i solve that?

I use OO4 with the bult in OO4 python on win7.

Thanks!
Last edited by RoryOF on Fri Oct 18, 2013 11:56 am, edited 1 time in total.
Reason: Added code tags (RoryOF, Moderator)
OpenOffice 4.01 on Windows 7
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: MessageBox in Python in OO4 different from OOo3. help!

Post by B Marcelly »

Hi,
Your code seems valid for LibreOffice.
In Apache OpenOffice 4 the second argument (rec) of createMessageBox does not exist.
So this would probably work:

Code: Select all

oMsgBox = oToolkit.createMessageBox( oParentWin, sTipo, botones, sTitulo, Mensaje )
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
xargsOOo
Posts: 24
Joined: Fri Oct 18, 2013 11:17 am

Re: MessageBox in Python in OO4 different from OOo3. help!

Post by xargsOOo »

Thanks, now it works.
But i can confirm that my first code works without any warnings in OOo3.4
:)

Where can i find the developer documentation guide for python in OO?
OpenOffice 4.01 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31349
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: MessageBox in Python in OO4 different from OOo3. help!

Post by Villeroy »

Where can i find the developer documentation guide for python in OO?
Yes, they removed one useless (?) "Rectangle" argument to createMessageBox. This has nothing to do with Python. Any changes to UNO apply to Basic, Java, C++ and all the other languages as well.
The Python-UNO bridge is documented here: http://www.openoffice.org/udk/python/python-bridge.html and in the self-documenting modules uno and unohelper.
The UNO thing is documented on the internet and in the self-documenting UNO services accessible through the MRI extension.
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
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: MessageBox in Python in OO4 different from OOo3. help!

Post by B Marcelly »

For your information :
Hanya documented the change in API changes on 4.0 since 3.4, chapter MessageBox
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
Post Reply