Ask Your Question
0

Dialog problem when using Python

asked 2017-07-11 00:22:44 +0200

Ratslinger gravatar image

updated 2017-07-13 20:25:49 +0200

When running a dialog from a Python script, I am having an impossible time letting the user know that processing is taking place and to wait. This is not a problem when running a Basic macro.

The attached sample demonstrates each process

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) 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.

One more point. The Progress Bar control has not been available for over 20 months now due to a regression around the release of v5.0.x - see Bug #95173. Even if it was, based on this problem, not sure how to update it. You can place the control but it is not visible!

Further testing shows the Progress Bar is working in Basic. It is not visible when placed on dialog but progress displays. In Python, however, again there are no updated steps displayed. Only the final 100% display.

Have tried numerous things in past week but all fail. Only one I haven't tried (because of not being sure how) is addPaintListener but not really sure this is an answer.

Sample: DialogProblem.ods (used Calc document since involves my project)

Just the Code: DialogCode.odt

Any direction appreciated!

EDIT: Please note, this has now been cross posted in AOO forum here.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-07-14 18:17:04 +0200

Ratslinger gravatar image

This question has been resolved in the AOO Forum by sasa (link presented in Question). Here is the method provided:

# ...
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
# ...

I have tested this with both text messaging and the Progress Bar and both work.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-07-11 00:22:44 +0200

Seen: 425 times

Last updated: Jul 14 '17