(Python, Libre Office) When I create a dialog using dlg.execute(), I am able to listen and find, if user clicked a close icon (the cross button in the right upper corner of window). I do it this way: I add Dialog Listener (with actionPerformed, itemstateChanged, textChanged) and WindowCloseListener (with windowClosing, disposing, windowResized, windowMoved, windowShown, windowHidden). I listen and I can catch:
1) when OK button is clicked (actionPerformed)
2) when button Cancel is clicked (actionPerformed)
3) when the window is closed using .endExecute() (under windowHidden)
If window was closed but not using OK or cancel button, we know, it was using the cross (close) icon! That works. I did not find any other way to detect clicking on cross icon. (windowClosing is never catched)
Now, I have a different situation. I have a simple window with progress bar running. When the user clicks on the cross icon, nothing happens. The window can not be closed, the progress bar continues. The window is loaded from xdl (dlg:closeable="true"). My listeners can not catch when cross icon is clicked. The only thing I can catch is disposing in my WindowCloseListener but only after all the progress bar is done and the window closes itself. To show the window I use dlg.setVisible(True) and for closing dlg.dispose().
How can I let the user close the window any time and do some action (like stopping the program)? If needed, I can show parts of my code.
EDIT: I added cmdCancel button, still can not catch it using listener. actionEvent.Source.Model.Name - nothing.
[Solved] Progress Bar Dialog - Close Icon Listener, Close Window
[Solved] Progress Bar Dialog - Close Icon Listener, Close Window
Last edited by MrProgrammer on Tue Sep 12, 2023 7:06 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
LibreOffice 7.5.5.2 on Linux Mint 21
Re: Progress Bar Dialog - Close Icon Listener, Close Window
If you don't find a solution an alternative would be to create your own progress bar - all it is is a visual representation of progress. One label can suffice - a label with a solid background color being resized or else a label which progresses from * to ** to *** etc or whatever character of your choice.
Last edited by JeJe on Mon Sep 04, 2023 11:26 am, edited 1 time in total.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Progress Bar Dialog - Close Icon Listener, Close Window
So far, I found that listeners mostly do not work if window is displayed using dlg.setVisible(True). Only windowMoved listener works. Different situation is when dialog is displayed using dlg.execute() where all listeners works as intended. But dlg.execute() is not usable for progress bar because it basically stops the program if I understand it correctly.
Yes, we could draw anything, I even tried tkinter (not available in Mac/Windows) and PyQT6 (crashes LO when any dialog window closes).
Yes, we could draw anything, I even tried tkinter (not available in Mac/Windows) and PyQT6 (crashes LO when any dialog window closes).
LibreOffice 7.5.5.2 on Linux Mint 21
Re: Progress Bar Dialog - Close Icon Listener, Close Window
If you want some code to run after dlg.execute but before endexecute then: when your dialog is shown one of the controls will recieve the keyboard focus - make that or a similar event kick off your code.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Progress Bar Dialog - Close Icon Listener, Close Window
To run a non-modal dialog, I recommend to use
and, indeed not to use Execute().
The 1st statement disconnects the dialog from any window in the background.
I never found a mean either to capture a click on the top-right closing cross, or to hide it. An explicit Close button is necessary.
BTW ScriptForge proposes a simple progress bar. Read about the ShowProgressBar() method in :
https://help.libreoffice.org/latest/en- ... ystem=UNIX
Similarly the SetStatusBar() allows to run a progress bar in the status bar (same page).
Regards.
Code: Select all
dlgModel.DesktopAsParent = True
dlgView.setVisible(True)
The 1st statement disconnects the dialog from any window in the background.
I never found a mean either to capture a click on the top-right closing cross, or to hide it. An explicit Close button is necessary.
BTW ScriptForge proposes a simple progress bar. Read about the ShowProgressBar() method in :
https://help.libreoffice.org/latest/en- ... ystem=UNIX
Similarly the SetStatusBar() allows to run a progress bar in the status bar (same page).
Regards.
Kubuntu 22.04 / LibO 24.2
Access2Base (LibO).
BaseDocumenter extension (LibO)
ScriptForge (LibO)
Documentation on https://help.libreoffice.org/latest/en- ... bPAR=BASIC
Access2Base (LibO).
BaseDocumenter extension (LibO)
ScriptForge (LibO)
Documentation on https://help.libreoffice.org/latest/en- ... bPAR=BASIC
Re: Progress Bar Dialog - Close Icon Listener, Close Window
Very interesting notes, thank you! But when I add an explicit Close button, I am not able to listen and catch something from it...what works with execute() does not work with setVisible()...
LibreOffice 7.5.5.2 on Linux Mint 21
Re: Progress Bar Dialog - Close Icon Listener, Close Window
The Close button must activate a script that
- removes the pending listeners, if any
- disposes the dialog view.
The dialog window will vanish.
- removes the pending listeners, if any
- disposes the dialog view.
The dialog window will vanish.
Kubuntu 22.04 / LibO 24.2
Access2Base (LibO).
BaseDocumenter extension (LibO)
ScriptForge (LibO)
Documentation on https://help.libreoffice.org/latest/en- ... bPAR=BASIC
Access2Base (LibO).
BaseDocumenter extension (LibO)
ScriptForge (LibO)
Documentation on https://help.libreoffice.org/latest/en- ... bPAR=BASIC
Re: Progress Bar Dialog - Close Icon Listener, Close Window
"The Close button must activate a script" - how do you make this? Because I am not able to listen when Close button is pressed. Is there any other way?
LibreOffice 7.5.5.2 on Linux Mint 21
- MrProgrammer
- Moderator
- Posts: 5373
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: Progress Bar Dialog - Close Icon Listener, Close Window
After selecting the button, if I use the Control icon of the Form Controls toolbar to display the button's properties, then I can assign a macro to the Execute action. The Macro button shown may want to assign a Basic macro but you should be able to supply a Python macro by providing its path in the Properties dialog. I suspect, with a bit of searching, you can find an example on the forum of a pushbutton control which calls a Python macro.
If this solved your problem please go to your first post use the Edit ☐ button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).