LibreOffice SymbolLibreOffice Symbol

¡Necesitamos su ayuda!

Módulo msgbox

Para acceder a esta orden…

Abra el menú Herramientas - Macros - Organizar macros.


Descripción

MsgBox class methods in msgbox Python module simplify the creation of message boxes using Abstract Windowing Toolkit API facilities. MsgBox constructor creates an empty dialog to be completed with buttons and texts.

Icono de aviso

This module is not part of supported UNO API. Output to screen with msgbox module is to be limited to development or test situations.


Icono de consejo

Performing input/output to screen with Python can the achieved using LibreOfficeDev UNO API, resorting to ScriptForge.Basic service routines or using Python to Basic inter-language calls as described on wiki.


Propiedades

Nombre

De solo lectura

Tipo

Descripción

numberOfLines

No

Boolean

Optionally overrides dialog rendered height.


Métodos

List of Methods in MsgBox class

addButton

renderFromBoxSize

renderFromButtonSize

show


addButton

Add a button to a MsgBox() object.

Sintaxis:

addButton(caption: str)

Parámetros:

caption: Button caption.

Ejemplo:

Vea a continuación un ejemplo detallado.

renderFromBoxSize

Defines MsgBox dialog dimensions as well as size of buttons according to a specified size.

Sintaxis:

renderFromBoxSize(size=150)

Parámetros:

size: Dialog size.
Width: ( 2 * size ) / ( 3 * numberOfbuttons + 1 )
Height is set according the number of Newline separators in dialog text.

Ejemplo:

Vea a continuación un ejemplo detallado.

renderFromButtonSize

Accommodates MsgBox dialog dimensions according to a specified size for buttons.

Sintaxis:

renderFromButtonSize(size=50)

Parámetros:

size: Size for buttons.
Width: ( numberOfButtons * 1.5 + 0.5) * size
Height is set according the number of Newline separators in dialog text.

Ejemplo:

Vea a continuación un ejemplo detallado.

show

Displays MsgBox variations, such as information box, warning box and so on.

Sintaxis:

show(message: str, decoration, title: str): str

Parámetros:

message: Dialog prompted text that may contain Newline separators.

decoration: n/a.

title: Dialog caption.

Ejemplo:

Vea a continuación un ejemplo detallado.

Ejemplo detallado


import uno
from msgbox import MsgBox

if uno: _CTX = uno.getComponentContext()

def my_script():
    response = msgBox('Do you want to continue?',('Yes', 'No', 'Cancel'),'A message from Python')
    infoBox(button=response)

def msgBox(prompt='', buttons=('Ok',), title='') -> str:
    dlg = MsgBox(_CTX)  # uno.getComponentContext()
    for btn in buttons:
        dlg.addButton(btn)
    dlg.renderFromButtonSize()
    dlg.numberOfLines = 15
    return dlg.show(prompt,0,title)
  
def infoBox(prompt='adapted from msgbox.MsgBox', button='Howdy', title='msgbox module'):
    dlg = MsgBox(_CTX)  # uno.getComponentContext()
    dlg.addButton(button)
    dlg.renderFromBoxSize(345)
    dlg.show(prompt,0,title)

g_exportedScripts = (my_script,)  # LibreOffice entry points
  
if __name__ == "__main__":  # entry point for IDEs
    from officehelper import SessionManager
    with SessionManager() as ctx:  # Python remote context
      _CTX = ctx
      my_script()
Icono de consejo

El servicio ScriptForge.Basic brinda alternativas a MsgBox e InputBox cuyas firmas se asemejan a las de las funciones de BASIC.