Skip to content

Commit 559cf35

Browse files
committed
style: intégration de rich.progress pour un affichage de progression console moderne et propre
1 parent ad77e8e commit 559cf35

1 file changed

Lines changed: 37 additions & 14 deletions

File tree

Plugins_SDK/GeneralContext/Dialog.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,47 @@ def progress(
150150
"""Create and return a ProgressDialog from Core.dialogs.
151151
152152
Uses Core.dialogs.ProgressDialog when GUI is available,
153-
otherwise returns a console-based fallback.
153+
otherwise returns a Rich-based console fallback.
154154
"""
155155
from PySide6.QtWidgets import QApplication
156156
if QApplication.instance() is None:
157-
# Fallback for headless/sandbox mode
157+
# Fallback for headless/sandbox mode using Rich
158+
from rich.progress import Progress, SpinnerColumn, TextColumn, BarColumn, TaskProgressColumn, TimeElapsedColumn
159+
158160
class ConsoleProgress:
159-
def __init__(self, title):
160-
self.title = title
161-
self._canceled = False
162-
def show(self): print(f"[PROGRESS:START] {self.title}")
163-
def set_message(self, msg): print(f"[PROGRESS:MSG] {msg}")
164-
def set_status(self, msg): print(f"[PROGRESS:STATUS] {msg}")
165-
def set_progress(self, val, total=None):
166-
if total: print(f"[PROGRESS:VALUE] {val}/{total}")
167-
else: print(f"[PROGRESS:VALUE] {val}%")
168-
def close(self): print(f"[PROGRESS:END] {self.title}")
169-
def is_canceled(self): return False
161+
def __init__(self, title_str, console_obj):
162+
self.progress = Progress(
163+
SpinnerColumn(),
164+
TextColumn("[progress.description]{task.description}"),
165+
BarColumn(),
166+
TaskProgressColumn(),
167+
TimeElapsedColumn(),
168+
console=console_obj,
169+
transient=True # Disappear when finished
170+
)
171+
self.task_id = self.progress.add_task(description=title_str, total=None)
172+
173+
def show(self):
174+
self.progress.start()
175+
176+
def set_message(self, msg):
177+
self.progress.update(self.task_id, description=msg)
178+
179+
def set_status(self, msg):
180+
self.set_message(msg)
181+
182+
def set_progress(self, val, total=None):
183+
kwargs = {"completed": val}
184+
if total is not None:
185+
kwargs["total"] = total
186+
self.progress.update(self.task_id, **kwargs)
187+
188+
def close(self):
189+
self.progress.stop()
190+
191+
def is_canceled(self):
192+
return False
170193

171-
return ConsoleProgress(title) # type: ignore
194+
return ConsoleProgress(title, self.console) # type: ignore
172195

173196
return ProgressDialog(title=title, cancelable=cancelable)

0 commit comments

Comments
 (0)