Repository navigation
Replies: 1 comment
|
Since you can change the function, an optional progress callback is the cleanest bridge. Report structured progress from the work itself, and let the terminal and GUI decide how to display it: from rich.progress import Progress
def process(n=50, on_progress=None, terminal=True):
with Progress(disable=not terminal) as progress:
task_id = progress.add_task("Processing...", total=n)
for index in range(n):
do_one_item(index)
progress.advance(task_id)
task = progress.tasks[0]
if on_progress is not None:
on_progress({
"completed": task.completed,
"total": task.total,
"description": task.description,
"remaining_seconds": task.time_remaining,
})For the GUI, the callback should emit a Qt signal from the worker. Connect that signal to a slot on the main-window object, using a queued connection; update For example, a
|
Uh oh!
There was an error while loading. Please reload this page.
First, I obviously realize that rich is intended to be used in a terminal, not a GUI. That said, I have a CLI application that is built using rich and works great. Now, in a separate project, I'm trying to use the main function of that CLI (which uses a rich progress bar) in a GUI. Essentially I'm adding a GUI wrapper around the CLI. What I'd like to do is capture the progress bar to update the GUI. Below is a simplified example of what I'd like to do.
In the
runmethod below I can callfunction_from_another_modulejust fine, which, of course, outputs to the terminal and doesn't update the GUI progress bar. I need a way to get the progress from this function --- is there a way to add a callback or something to the rich progress bar? I didn't see a way in the documentation.I'd be great to also get all information from the progress bar, not only the % complete. For example, description, estimated time remaining, etc. That way I could add that stuff to the GUI as well.
All reactions