Skip to content

Commit

Permalink
fix: add disabled param to mo.status.progress_bar (#2235)
Browse files Browse the repository at this point in the history
* fix: add disabled param to mo.status.progress_bar

* append the progress bar to the output if not disabled

* remove unused disabled params
  • Loading branch information
metaboulie authored Sep 5, 2024
1 parent 70c6110 commit 0b7acca
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
14 changes: 11 additions & 3 deletions marimo/_plugins/stateless/status/_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ def update(
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,
Expand Down Expand Up @@ -317,10 +321,12 @@ def __init__(
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
Expand Down Expand Up @@ -348,12 +354,14 @@ def __init__(
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:
Expand Down
43 changes: 32 additions & 11 deletions marimo/_smoke_tests/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import marimo

__generated_with = "0.6.0"
__generated_with = "0.8.11"
app = marimo.App()


Expand All @@ -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,

Expand All @@ -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,


@app.cell
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()
Expand All @@ -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
Expand All @@ -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,


Expand Down

0 comments on commit 0b7acca

Please sign in to comment.