[Solved] [Python] Improve MsgBox aspect

Creating a macro - Writing a Script - Using the API

[Solved] [Python] Improve MsgBox aspect

Postby El Catala » Mon May 10, 2021 8:36 am

Hello,


I have the function below which allows me to display a message.
Code: Select all   Expand viewCollapse view
def MessageBox( box_type: int, buttons: int, title: str, message: str) -> int:
    ctx = uno.getComponentContext()
    smgr = ctx.getServiceManager()
    DESK = 'com.sun.star.frame.Desktop'
    desktop = smgr.createInstanceWithContext(DESK , ctx)
    frame = desktop.getCurrentFrame()
    window = frame.getContainerWindow()
    toolkit = window.getToolkit()
    messagebox = toolkit.createMessageBox(window, box_type, buttons, title, message)
    return messagebox.execute()


I would like to improve its appearance by playing on its position and the dimensions of the font.

Is it possible ?


cordially
Last edited by El Catala on Wed May 12, 2021 7:32 am, edited 1 time in total.
LibreOffice 7.0.4 Xubuntu 20.4
El Catala
 
Posts: 17
Joined: Mon Dec 07, 2020 6:29 pm

Re: [Python]-Improve MsgBox aspect

Postby RoryOF » Mon May 10, 2021 9:59 am

One can do almost anything in Python; you may need to explore Tkinter (sometimes tkinter, depending on python version in use). This permits a very complete customisation of input and output displays in python.
Apache OpenOffice 4.1.10 on Xubuntu 20.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 33052
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Python]-Improve MsgBox aspect

Postby JeJe » Mon May 10, 2021 12:23 pm

Make your own dialog. All a message box is is a very simple dialog with a message and a choice of a small number of buttons... you can re-create that yourself easily and change it however.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1704
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Python]-Improve MsgBox aspect

Postby El Catala » Mon May 10, 2021 1:41 pm

with all my apologies, I did not specify that the script was launched from Libre Office.
TKinter is therefore not usable.
LibreOffice 7.0.4 Xubuntu 20.4
El Catala
 
Posts: 17
Joined: Mon Dec 07, 2020 6:29 pm

Re: [Python]-Improve MsgBox aspect

Postby Villeroy » Tue May 11, 2021 9:23 pm

With a dialog MyMacros.Standard.Dialog1 in the Basic IDE
Code: Select all   Expand viewCollapse view
g_URL = "vnd.sun.star.script:Standard.Dialog1?location=application"
def Test_Dialog1_modal(**args):
    smgr = uno.getComponentContext().getServiceManager()
    dp = smgr.createInstance('com.sun.star.awt.DialogProvider')
    dlg = dp.createDialog(g_URL)
    dlg.setPosSize(100,100, 500, 400, 15)
    x = dlg.execute()

this shows the dialog near the top-left corner of the screen (x=100, y=100), 500 units wide, 400 units high (don't know which units right now).
x == 1 when the OK button has been clicked (button type = OK), x == 0 otherwise.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 30288
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Python]-Improve MsgBox aspect

Postby JeJe » Tue May 11, 2021 11:50 pm

Villeroy - setpossize is always in pixels.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1704
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Python] Improve MsgBox aspect

Postby El Catala » Wed May 12, 2021 7:32 am

Hello,

It is therefore confirmed that MsgBox cannot be positioned according to the user.
Thank you for your help and will therefore direct me to a dialog box.

Good luck and thank you
LibreOffice 7.0.4 Xubuntu 20.4
El Catala
 
Posts: 17
Joined: Mon Dec 07, 2020 6:29 pm

Re: [Solved]-[Python] Improve MsgBox aspect

Postby Villeroy » Thu May 13, 2021 2:46 pm

[BASIC] Resizable dialog
I would replace
ThisComponent.getCurrentController().getFrame()
with
StarDesktop.getCurrentFrame()
so the code can be tested from the IDE without needing any document window.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 30288
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 9 guests