[Solved] Dialog problem - Updating using Python

Creating a macro - Writing a Script - Using the API

[Solved] Dialog problem - Updating using Python

Postby Ratslinger » Thu Jul 13, 2017 8:16 pm

When running a dialog from a Python script, I have not found a method to let the user know that processing is taking place and to wait. This is not a problem when running from a Basic macro.

Note: This is cross posted on ask.LibreOffice: https://ask.libreoffice.org/en/question/110001/dialog-problem-when-using-python/. Trying here as other post has had no response.

Originally developed using LO v5.3.4.2 but same results on AOO v4.0.1.

As background, here is why I chose this method. The use is in Calc. The process inserts graphic information tied to selected cells. The dialog allows a variety of settings. Once selected, the user clicks a button to insert the info. If the result is not acceptable, the user can clear, adjust setting(s) and re-run. The Dialog is non-modal so the user can then select new cells or a different sheet & apply there.

The attached sample demonstrates the problem.

Click the `Run Dialog from Basic` button to open the dialog. Click the `Execute Process` button and the message will change every second (only 4) leaving the last on the dialog.

Next the `Run Dialog from Python` button. Click the `Execute Process` button (wait about 5 seconds after clicking). It only displays the final message. The Python script completes but never displays the individual messages. There is no ability to update dialog information while the script is running. Therefore, the user doesn't know what is happening.

The `Run Python Dialog with Progress Bar` basically operates the same as the previous Python button. It uses an IDE dialog & the progress bar update only displays when code 100% completed. The individual stepping is never seen. The progress bar is present, just not visible in display or IDE (been like this for some time).

Have tried numerous things in past week but all fail.

DialogProblem.ods
Sample using Calc doc
(14.42 KiB) Downloaded 121 times

DialogCode.odt
Just the code used
(15 KiB) Downloaded 116 times


Any direction appreciated!
Last edited by Ratslinger on Fri Jul 14, 2017 6:06 pm, edited 1 time in total.
LibreOffice 6.1.3
OpenOffice 4.0.1
Ubuntu Mate 18.04
Mint 18.3
Ratslinger
 
Posts: 19
Joined: Sun Mar 01, 2015 3:34 am

Re: Dialog problem - Updating using Python

Postby sasa » Fri Jul 14, 2017 5:01 pm

I feel your pain. Dirty copy/paste Progres Bar example with button, worker and engine - just for idea.

Code: Select all   Expand viewCollapse view
# ...
from threading import Thread
# ...
# -----------------------------------------------------------
#               Action event
# -----------------------------------------------------------
def btnCirToLat_OnClick(self):
    self.t = Thread(target=self.workerCirToLat)  # , args = (doc,))
    self.t.start()
# -----------------------------------------------------------
#               Worker
# -----------------------------------------------------------
def workerCirToLat(self):
    self.translitWriterAll(language_code='sr', reversed=True)
    # or write engine code here
# -----------------------------------------------------------
#               Engine
# -----------------------------------------------------------
def translitWriterAll(self, language_code='sr', reversed=True):
    # ...
    # set progressbar values
    self.pbProgress.ProgressValue = 0
    self.pbProgress.ProgressValueMin = 0
    self.pbProgress.ProgressValueMax = 100
    # ...
    n = 0
    for word, translation in words_dict.items():
        # ...
        n += 1
        self.pbProgress.ProgressValue = n
# ...


HTH
LibreOffice 5.2 on Xubuntu 16.04
sasa
 
Posts: 6
Joined: Wed Feb 08, 2017 12:54 am

Re: [Solved]Dialog problem - Updating using Python

Postby Ratslinger » Fri Jul 14, 2017 6:11 pm

sasa Thank you for your answer. Have tested both Progress Bar & text message updating and both work as needed.

Your answer has saved me from going back to basic code for this and/or spending numerous hours searching for this solution.

Much appreciated!
LibreOffice 6.1.3
OpenOffice 4.0.1
Ubuntu Mate 18.04
Mint 18.3
Ratslinger
 
Posts: 19
Joined: Sun Mar 01, 2015 3:34 am

Re: [Solved] Dialog problem - Updating using Python

Postby klkmva » Wed May 15, 2019 4:39 pm

I do not have a lot of python experience and I have the same problem but the information given here does not allow me to solve it.
Could you provide additional details by providing, for example, a complete sample file?
The CommandButton1 button performs the DialogTest.py $ fake_process (document, Python) action. I can not find the DialogTest.py file.
Thank you

LibreOffice 5.4.6.2
Windows 7 Professionnel
klkmva
LibreOffice 5.4.6.2
Windows 7
klkmva
 
Posts: 2
Joined: Wed Mar 25, 2015 3:30 pm

Re: [Solved] Dialog problem - Updating using Python

Postby Villeroy » Wed May 15, 2019 6:16 pm

It is embedded in the ODF document. ODF documents are zip files.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26868
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Dialog problem - Updating using Python

Postby kiloran » Tue May 28, 2019 9:25 pm

--kiloran
LibreOffice 4.2.3.3 on Windows 7
kiloran
 
Posts: 26
Joined: Sun Oct 14, 2012 2:06 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests