Ask Your Question
0

msgbox python

asked 2019-12-12 13:33:54 +0200

mrkalvin gravatar image

updated 2019-12-13 11:42:24 +0200

Could someone show me an example of msgbox for python macro in CALC

I tried this example, but it didn't work: https://help.libreoffice.org/6.3/en-U...

Complement2: Doubt resolved I will leave here a simple example code as a reference for other user searches

MSG_BUTTONS https://api.libreoffice.org/docs/idl/...

type_msg: https://api.libreoffice.org/docs/idl/...

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import uno
from com.sun.star.awt import MessageBoxButtons as MSG_BUTTONS

def msgbox(message, title='LibreOffice', buttons=MSG_BUTTONS.BUTTONS_OK, type_msg='infobox'):
    """ Create message box
        MSG_BUTTONS => BUTTONS_OK = 1, BUTTONS_OK_CANCEL = 2, BUTTONS_YES_NO = 3, BUTTONS_YES_NO_CANCEL = 4, BUTTONS_RETRY_CANCEL = 5, BUTTONS_ABORT_IGNORE_RETRY = 6
        https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1awt_1_1MessageBoxButtons.html

        type_msg => MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
        https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1awt.html#ad249d76933bdf54c35f4eaf51a5b7965
    """
    CTX = XSCRIPTCONTEXT.getComponentContext()
    toolkit = CTX.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
    parent = toolkit.getDesktopWindow()
    mb = toolkit.createMessageBox(parent, type_msg, buttons, title, str(message))
    return mb.execute()

def test(*args):
    result = msgbox('Hiiiiiiii', 'my Title', 3, 'QUERYBOX')
    print(result)

    if result == 2:
        print('Hello!')
    else:
        print('World!')
edit retag flag offensive close merge delete

Comments

You can read:

The Alternative Python Script Organizer (APSO) extension offers a msgbox() function out of its apso_utils module.

You need install it, and maybe copy the module.

mauricio gravatar imagemauricio ( 2019-12-12 18:05:03 +0200 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2019-12-12 18:05:59 +0200

mauricio gravatar image

I you only need a simple msgbox, look:

https://wiki.documentfoundation.org/M...

edit flag offensive delete link more

Comments

Thank you so much, that's what you needed.

mrkalvin gravatar imagemrkalvin ( 2019-12-13 01:30:58 +0200 )edit
0

answered 2020-01-08 15:14:44 +0200

Hi

Input/Output to Screen with Python provides extra examples.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-12-12 13:33:54 +0200

Seen: 376 times

Last updated: Jan 08