Page 1 of 1
[Solved] [Python] Improve MsgBox aspect
Posted: Mon May 10, 2021 8:36 am
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
Re: [Python]-Improve MsgBox aspect
Posted: Mon May 10, 2021 9:59 am
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.
Re: [Python]-Improve MsgBox aspect
Posted: Mon May 10, 2021 12:23 pm
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.
Re: [Python]-Improve MsgBox aspect
Posted: Mon May 10, 2021 1:41 pm
by El Catala
with all my apologies, I did not specify that the script was launched from Libre Office.
TKinter is therefore not usable.
Re: [Python]-Improve MsgBox aspect
Posted: Tue May 11, 2021 9:23 pm
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.
Re: [Python]-Improve MsgBox aspect
Posted: Tue May 11, 2021 11:50 pm
by JeJe
Villeroy - setpossize is always in pixels.
Re: [Python] Improve MsgBox aspect
Posted: Wed May 12, 2021 7:32 am
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
Re: [Solved]-[Python] Improve MsgBox aspect
Posted: Thu May 13, 2021 2:46 pm
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.