How to display a dialog in Python that does not block code execution?

How to display a dialog in Python that does not block code execution?

I am attempting to create a dialog in python that is display for a long running process to let the user have feedback. In my case I don’t know how long the process will run. So I am thinking start in a seperate thread and then stop the thread with the process is done.

I am testing this in a python marco by simulating some time passing. I can’t get the dialog to display when the thread starts. It pops up for a split second after the time has elapsed time.sleep(10).

How do I get show a dialog window that does not block python and acutally displays.

from __future__ import annotations
import time
from lo_pip.dialog.infinite_progress import InfiniteProgress

def show_some_progress(*args) -> None:
    # InfiniteProgress is a threading.Thread class.
    my_progress = InfiniteProgress(XSCRIPTCONTEXT.getComponentContext())
    my_progress.start()
    time.sleep(10)
    my_progress.stop()

g_exportedScripts = (show_some_progress,)

This is the thread class that starts the dialog.

import threading

class InfiniteProgress(threading.Thread):
    """
    Infinite progress thread.
    """

    def __init__(self, ctx: Any, title: str = "Infinite Progress", msg: str = "Please wait"):
        super().__init__()
        self._ctx = ctx
        self._title = title
        self._msg = msg
        self._ellipsis = 0
        self._stop_event = threading.Event()

    def run(self):
        in_progress = InfiniteProgressDialog(self._ctx, self._title)

        while not self._stop_event.is_set():
            # possibly sleep and update a label to show progress
            self._ellipsis += 1
            in_progress.dialog.setVisible(True)
            in_progress.update(f"{self._msg}{'.' * self._ellipsis}")
            if self._ellipsis > 10:
                self._ellipsis = 1
            time.sleep(1)
        in_progress.dialog.dispose()

    def stop(self):
        self._stop_event.set()

See my infinite_progress.py code for more details on the entire code.

Hi

Did you have a look at SetStatusBar() and ShowProgressBar methods of ScriptForge.UI service?