Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix setting total by attribute #4316

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Fixed a crash in `TextArea` when undoing an edit to a selection the selection was made backwards https://github.com/Textualize/textual/issues/4301
- Fix progress bar ETA not updating when setting `total` reactive https://github.com/Textualize/textual/pull/4316
- ProgressBar won't show ETA until there is at least one second of samples https://github.com/Textualize/textual/pull/4316

## [0.53.1] - 2023-03-18

Expand Down
3 changes: 3 additions & 0 deletions src/textual/eta.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def speed(self) -> float | None:
progress_start_time, progress1 = self._get_progress_at(
recent_sample_time - self.estimation_period
)
if recent_sample_time - progress_start_time < 1:
# Require at least a second span to calculate speed.
return None
time_delta = recent_sample_time - progress_start_time
distance = progress2 - progress1
speed = distance / time_delta if time_delta else 0
Expand Down
4 changes: 4 additions & 0 deletions src/textual/widgets/_progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ def _watch_progress(self, progress: float) -> None:
"""Perform update when progress is modified."""
self.update(progress=progress)

def _watch_total(self, total: float) -> None:
"""Update when the total is modified."""
self.update(total=total)

def advance(self, advance: float = 1) -> None:
"""Advance the progress of the progress bar by the given amount.

Expand Down
Loading