[Libreoffice] python - msgbox fragment ...

Timo timo at iera.de
Mon Apr 11 12:26:21 PDT 2011

Hi Michael,

MessageBoxButtons as well as XSCRIPTCONTEXT do not exist for me. Python
doesn´t find them and they are documented as “not published” [1]. I
think it would be nice to use createMessageBox() and to have a dynamic
size and a nice error icon. But with the use of Laurent´s implementation
I could solve the task. [2]

With the modified mailmerge.py I get the expected pythonerror in a
messagebox after closing the MsgBox. [3] In fact all pythonerrors are
reported like this on my computer. What does it look like on nonfree
platforms? In fact it is better to display only one error message.

Not all python errors are reported in a message by default. If there are
syntax errors at the beginning of the file, office remains silent. This
is problem. 

When there is a MsgBox that works for everybody I suggest to implement
it into pythonscript.py so that it is being used for all exceptions. 




[2] see mailmerge.py and MsgBox.py from the attachments

[3] see screenshot Bildschirmfoto.png

Am Montag, den 11.04.2011, 17:01 +0100 schrieb Michael Meeks:
> Hi Timo,
> On Sat, 2011-04-09 at 02:22 +0200, Timo wrote:
> > Is there a way to test the pythonfile within office? At the moment each
> > time i kill soffice, restart writer and click
> 	So - after a bit more digging; I got to here:
> class MessageBox:
>     def __init__(self, XParentWindow):
>         try:
>             if XParentWindow is None:
>                 frame = XSCRIPTCONTEXT.getDesktop().getCurrentFrame()
>                 XParentWindow = frame.getContainerWindow()
>             self.Parent = XParentWindow
>             self.Toolkit = XParentWindow.getToolkit()
>         except:
>             raise AttributeError, 'Did not get a valid parent window'
>     def msgbox(self, message='', flag=0, title=''):
>         '''Wrapper for com.sun.star.awt.XMessageBoxFactory.'''
>         rect = uno.createUnoStruct('com.sun.star.awt.Rectangle')
>         dlg = self.Toolkit.createMessageBox(self.Parent, rect, "errorbox", 1, title, message)
>         dlg.execute()
> 	Which at least works for me, though I couldn't see why the
> com.sun.star.awt.MessageBoxButtons set of constants wouldn't work nicely
> for me.
> 	When I whack that into my system's TableSample.py and add:
>     box = MessageBox(None)
>     box.msgbox ("What is this ?")
> 	to createTable() - I get a nice message-box first :-) I bound running
> that macro to F4 to make it quicker to loop iterate / check the code
> 	The UNO API is pretty fearsome to use, it can help to read the
> interface comments in offapi/ but it is not for the faint hearted,
> clearly :-)
> 	I guess, seeing how broken the C++ side is - with helpful comments
> like:
>     if(!bIsLoggedIn)
>     {
>         OSL_FAIL("create error message");
>         return;
>     }
> 	that simply don't create an error message, or do anything useful -
> perhaps a chunk of the work needed is on the C++ side anyway.
> 	HTH,
> 		Michael.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bildschirmfoto.png
Type: image/png
Size: 231003 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20110411/077e35a4/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mailmerge.py
Type: text/x-python
Size: 15815 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20110411/077e35a4/attachment-0002.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MsgBox.py
Type: text/x-python
Size: 10113 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20110411/077e35a4/attachment-0003.py>

More information about the LibreOffice mailing list