Difference between revisions of "PythonDialogBox"
From Apache OpenOffice Wiki
(Registro de instrucciones.) |
(Added information to the analysis of the snippet.) |
||
Line 1: | Line 1: | ||
− | Originally created by Paolo Mantovani for the [Code Snippet Project]. The snippet explains how to generate a MsgBox within the Python-Uno environment. | + | Originally created by Paolo Mantovani for the [http://codesnippets.services.openoffice.org/ Code Snippet Project]. The snippet explains how to generate a '''MsgBox''' within the Python-Uno environment. |
<source lang=Python> | <source lang=Python> | ||
Line 52: | Line 52: | ||
===Analysis=== | ===Analysis=== | ||
Analyzing the script we can consider the following: | Analyzing the script we can consider the following: | ||
− | + | * Studying the series of UNO components for the UNO widgets | |
− | + | * Difference between TextMessageBox() and MessageBox() | |
− | + | * Dialog object properties | |
====UNO component composition==== | ====UNO component composition==== | ||
First thing we notice is the amount of widgets imported from the [http://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/module-ix.html awt module]. The [http://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/WindowDescriptor.html WindowDescriptor struct] | First thing we notice is the amount of widgets imported from the [http://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/module-ix.html awt module]. The [http://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/WindowDescriptor.html WindowDescriptor struct] | ||
+ | |||
+ | === Anatomy of the snippet === | ||
+ | The snippet have two different classes the one in charge of creating the message box called '''MessageBox()''' which design the specs of the dialog and the '''TestMessageBox()''' which pass the arguments to the dialog. The MessageBox() set the following properties: | ||
+ | * [http://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/WindowDescriptor.html#Type Type] - specifies the type of window. | ||
+ | * [http://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/WindowDescriptor.html#WindowServiceName WindowServiceName] - specifies the name of the component service. | ||
+ | * [http://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/WindowDescriptor.html#Parent ParentIndex] - specifies the index of the parent window, if available. | ||
+ | * [http://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/WindowDescriptor.html#Bounds Bounds] - specifies the position and size of the window. | ||
+ | * [http://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/WindowDescriptor.html#WindowAttributes WindowAttributes] - specifies the window attributes. | ||
+ | The following properties can be find on the WindowDescriptor struct on the API documentation. |
Revision as of 14:49, 19 August 2013
Originally created by Paolo Mantovani for the Code Snippet Project. The snippet explains how to generate a MsgBox within the Python-Uno environment.
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") # Show a message box with the UNO based toolkit def MessageBox(ParentWin, MsgText, MsgTitle, MsgType="messbox", MsgButtons=OK): MsgType = MsgType.lower() #available msg types MsgTypes = ("messbox", "infobox", "errorbox", "warningbox", "querybox") if not ( MsgType in MsgTypes ): MsgType = "messbox" #describe window properties. aDescriptor = WindowDescriptor() aDescriptor.Type = MODALTOP aDescriptor.WindowServiceName = MsgType aDescriptor.ParentIndex = -1 aDescriptor.Parent = ParentWin #aDescriptor.Bounds = Rectangle() aDescriptor.WindowAttributes = MsgButtons tk = ParentWin.getToolkit() msgbox = tk.createWindow(aDescriptor) msgbox.setMessageText(MsgText) if MsgTitle : msgbox.setCaptionText(MsgTitle) return msgbox.execute() g_exportedScripts = TestMessageBox,
Analysis
Analyzing the script we can consider the following:
- Studying the series of UNO components for the UNO widgets
- Difference between TextMessageBox() and MessageBox()
- Dialog object properties
UNO component composition
First thing we notice is the amount of widgets imported from the awt module. The WindowDescriptor struct
Anatomy of the snippet
The snippet have two different classes the one in charge of creating the message box called MessageBox() which design the specs of the dialog and the TestMessageBox() which pass the arguments to the dialog. The MessageBox() set the following properties:
- Type - specifies the type of window.
- WindowServiceName - specifies the name of the component service.
- ParentIndex - specifies the index of the parent window, if available.
- Bounds - specifies the position and size of the window.
- WindowAttributes - specifies the window attributes.
The following properties can be find on the WindowDescriptor struct on the API documentation.