 | OO-Snippets: MessageBox with the UNO based toolkitCommons| Keywords | com.sun.star.awt.WindowDescriptor, WindowServiceName, messbox, infobox, querybox, warningbox, errorbox |
|---|
| Language | Python |
|---|
| Application | Office |
|---|
| Authors | Paolo Mantovani (initial)
|
|---|
| Supported Versions | 1.0.x 1.1.x 2.0.x |
|---|
| Supported OS | All |
|---|
| Question | How do I display a message box from a PyUno component / script ?
I'm wondering if it is possible to display message boxes (similar to those displayed by Basic's MsgBox function) using the OpenOffice.org API
|
|---|
| Answer | You can use the following function as a replacement for the Msgbox StarBasic function: |
|---|
from com.sun.star.awt import Rectangle
from com.sun.star.awt import WindowDescriptor
from com.sun.star.awt.WindowClass import MODALTOP
from com.sun.star.awt.VclWindowPeerAttribute import OK, OK_CANCEL, YES_NO, YES_NO_CANCEL, RETRY_CANCEL, DEF_OK, DEF_CANCEL, DEF_RETRY, DEF_YES, DEF_NO
def TestMessageBox():
doc = XSCRIPTCONTEXT.getDocument()
parentwin = doc.CurrentController.Frame.ContainerWindow
s = "This is a test"
t = "Test"
res = MessageBox(parentwin, s, t, "querybox", YES_NO_CANCEL + DEF_NO)
s = res
MessageBox(parentwin, s, t, "infobox")
def MessageBox(ParentWin, MsgText, MsgTitle, MsgType="messbox", MsgButtons=OK):
MsgType = MsgType.lower()
MsgTypes = ("messbox", "infobox", "errorbox", "warningbox", "querybox")
if not ( MsgType in MsgTypes ):
MsgType = "messbox"
aDescriptor = WindowDescriptor()
aDescriptor.Type = MODALTOP
aDescriptor.WindowServiceName = MsgType
aDescriptor.ParentIndex = -1
aDescriptor.Parent = ParentWin
aDescriptor.WindowAttributes = MsgButtons
tk = ParentWin.getToolkit()
msgbox = tk.createWindow(aDescriptor)
msgbox.setMessageText(MsgText)
if MsgTitle :
msgbox.setCaptionText(MsgTitle)
return msgbox.execute()
g_exportedScripts = TestMessageBox,
|
Changelog| Date | User | Modification |
|---|
| 2006-07-04 | paolomantovani | Initial version |
|