Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: add disabled param to mo.status.progress_bar (#2235)

eugene0b7acca260d0
diff --git a/marimo/_plugins/stateless/status/_progress.py b/marimo/_plugins/stateless/status/_progress.py
index 7cff23d1e8..41f5a6817a 100644
--- a/marimo/_plugins/stateless/status/_progress.py
+++ b/marimo/_plugins/stateless/status/_progress.py
@@ -176,7 +176,11 @@ class ProgressBar(_Progress):
class Spinner(_Progress):
"""A spinner output representing a loading state"""
- def __init__(self, title: str | None, subtitle: str | None) -> None:
+ def __init__(
+ self,
+ title: str | None,
+ subtitle: str | None,
+ ) -> None:
super().__init__(
title=title,
subtitle=subtitle,
@@ -317,10 +321,12 @@ class progress_bar:
show_rate: bool = True,
show_eta: bool = True,
remove_on_exit: bool = False,
+ disabled: bool = False,
):
self.completion_title = completion_title
self.completion_subtitle = completion_subtitle
self.remove_on_exit = remove_on_exit
+ self.disabled = disabled
if collection is not None:
self.collection = collection
@@ -348,12 +354,14 @@ class progress_bar:
show_rate=show_rate,
show_eta=show_eta,
)
- output.append(self.progress)
+ if not disabled:
+ output.append(self.progress)
def __iter__(self) -> Iterable[S | int]:
for item in self.collection:
yield item
- self.progress.update(increment=self.step)
+ if not self.disabled:
+ self.progress.update(increment=self.step)
self._finish()
def __enter__(self) -> ProgressBar:
diff --git a/marimo/_smoke_tests/status.py b/marimo/_smoke_tests/status.py
index 1be5b5824c..0c3e6eafe5 100644
--- a/marimo/_smoke_tests/status.py
+++ b/marimo/_smoke_tests/status.py
@@ -2,7 +2,7 @@
import marimo
-__generated_with = "0.6.0"
+__generated_with = "0.8.11"
app = marimo.App()
@@ -15,7 +15,9 @@ def __():
@app.cell
def __(mo):
- sleep_time_radio = mo.ui.radio([".01", ".1", "1"], label="Sleep time", value=".01")
+ sleep_time_radio = mo.ui.radio(
+ [".01", ".1", "1"], label="Sleep time", value=".01"
+ )
sleep_time_radio
return sleep_time_radio,
@@ -27,30 +29,46 @@ def __(sleep_time_radio):
@app.cell
-def __(mo, sleep_time, time):
+def __(mo):
+ disabled_switch = mo.ui.switch(label="Disable progress bar")
+ disabled_switch
+ return disabled_switch,
+
+
+def __(disabled_switch, mo, sleep_time, time):
for _ in mo.status.progress_bar(
- range(10), title="Loading", subtitle="Please wait"
+ range(10),
+ title="Loading",
+ subtitle="Please wait",
+ disabled=disabled_switch.value,
):
time.sleep(sleep_time)
return
@app.cell
-def __(mo, sleep_time, time):
+def __(disabled_switch, mo, sleep_time, time):
for _ in mo.status.progress_bar(
range(10),
title="Loading",
subtitle="Please wait",
show_eta=True,
show_rate=True,
+ disabled=disabled_switch.value,
):
time.sleep(sleep_time)
return
@app.cell
-def __(mo, sleep_time, time):
- with mo.status.progress_bar(title='Loading', subtitle='Please wait', total=10) as bar:
+def __(disabled_switch, mo, sleep_time, time):
+ with mo.status.progress_bar(
+ title="Loading",
+ subtitle="Please wait",
+ total=10,
+ disabled=disabled_switch.value,
+ ) as bar:
for _ in range(10):
time.sleep(sleep_time)
bar.update()
@@ -60,7 +78,7 @@ def __(mo, sleep_time, time):
@app.cell
def __(mo, sleep_time, time):
with mo.status.spinner(title="Loading...", remove_on_exit=True) as _spinner:
- time.sleep(.1)
+ time.sleep(0.1)
_spinner.update("Almost done")
time.sleep(sleep_time)
return
@@ -77,10 +95,13 @@ def __(mo, sleep_time, time):
@app.cell
-def __(mo, sleep_time, time):
+def __(disabled_switch, mo, sleep_time, time):
# Fast updates should be debounced for performance
- for i in mo.status.progress_bar(range(1000)):
- time.sleep(sleep_time/10)
+ for i in mo.status.progress_bar(
+ range(1000),
+ disabled=disabled_switch.value,
+ ):
+ time.sleep(sleep_time / 10)
return i,