[Solved] [Python] Improve MsgBox aspect

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
El Catala
Posts: 22
Joined: Mon Dec 07, 2020 6:29 pm

[Solved] [Python] Improve MsgBox aspect

Post by El Catala »

Hello,


I have the function below which allows me to display a message.

Code: Select all

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
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Python]-Improve MsgBox aspect

Post by RoryOF »

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.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Python]-Improve MsgBox aspect

Post by JeJe »

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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
El Catala
Posts: 22
Joined: Mon Dec 07, 2020 6:29 pm

Re: [Python]-Improve MsgBox aspect

Post by El Catala »

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
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Python]-Improve MsgBox aspect

Post by Villeroy »

With a dialog MyMacros.Standard.Dialog1 in the Basic IDE

Code: Select all

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
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Python]-Improve MsgBox aspect

Post by JeJe »

Villeroy - setpossize is always in pixels.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
El Catala
Posts: 22
Joined: Mon Dec 07, 2020 6:29 pm

Re: [Python] Improve MsgBox aspect

Post by El Catala »

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
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post by Villeroy »

[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
Post Reply