-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new color scheme and thickness to progress bar
- Rainbow scheme will update bar color based on percentage starting from .bar--bar.color up to .bar--complete.color in counterclockwise direction. - Bar thickness can have 3 styles: thin, normal or thick.
- Loading branch information
Peter Talaber
authored and
Peter Talaber
committed
Oct 9, 2023
1 parent
5fac8b2
commit bcc686b
Showing
11 changed files
with
1,204 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Bar > .bar--indeterminate { | ||
color: $primary; | ||
background: $secondary; | ||
} | ||
|
||
Bar > .bar--bar { | ||
color: blue; | ||
background: $primary 30%; | ||
} | ||
|
||
Bar > .bar--complete { | ||
color: red; | ||
} | ||
|
||
PercentageStatus { | ||
text-style: reverse; | ||
color: $secondary; | ||
} | ||
|
||
ETAStatus { | ||
text-style: underline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.containers import Center, Middle | ||
from textual.timer import Timer | ||
from textual.widgets import Footer, ProgressBar | ||
|
||
|
||
class StyledExtProgressBar(App[None]): | ||
BINDINGS = [ | ||
("s", "start", "Start"), | ||
] | ||
CSS_PATH = "progress_bar_styled_rainbow.css" | ||
|
||
progress_timer: Timer | ||
"""Timer to simulate progress happening.""" | ||
|
||
def compose(self) -> ComposeResult: | ||
with Center(): | ||
with Middle(): | ||
yield ProgressBar(color_scheme="rainbow") | ||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
"""Set up a timer to simulate progess happening.""" | ||
self.progress_timer = self.set_interval(1 / 10, self.make_progress, pause=True) | ||
|
||
def make_progress(self) -> None: | ||
"""Called automatically to advance the progress bar.""" | ||
self.query_one(ProgressBar).advance(1) | ||
|
||
def action_start(self) -> None: | ||
"""Start the progress tracking.""" | ||
self.query_one(ProgressBar).update(total=100) | ||
self.progress_timer.resume() | ||
|
||
|
||
if __name__ == "__main__": | ||
app = StyledExtProgressBar() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.containers import Center, Middle | ||
from textual.timer import Timer | ||
from textual.widgets import Footer, ProgressBar | ||
|
||
|
||
class StyledExtProgressBar(App[None]): | ||
BINDINGS = [ | ||
("s", "start", "Start"), | ||
] | ||
CSS_PATH = "progress_bar_styled_rainbow.css" | ||
|
||
progress_timer: Timer | ||
"""Timer to simulate progress happening.""" | ||
|
||
def compose(self) -> ComposeResult: | ||
with Center(): | ||
with Middle(): | ||
yield ProgressBar(color_scheme="rainbow") | ||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
"""Set up a timer to simulate progess happening.""" | ||
self.progress_timer = self.set_interval(1 / 10, self.make_progress, pause=True) | ||
|
||
def make_progress(self) -> None: | ||
"""Called automatically to advance the progress bar.""" | ||
self.query_one(ProgressBar).advance(1) | ||
|
||
def action_start(self) -> None: | ||
"""Start the progress tracking.""" | ||
self.query_one(ProgressBar).update(total=100) | ||
self.progress_timer.resume() | ||
|
||
def key_1(self) -> None: | ||
self._action_common_keypress(10) | ||
|
||
def key_5(self) -> None: | ||
self._action_common_keypress(50) | ||
|
||
def key_9(self) -> None: | ||
self._action_common_keypress(90) | ||
|
||
def _action_common_keypress(self, progress: int) -> None: | ||
# Freeze time for the indeterminate progress bar. | ||
self.query_one(ProgressBar).query_one("#eta")._get_elapsed_time = lambda: 0 | ||
self.query_one(ProgressBar).update(total=100, progress=progress) | ||
self.progress_timer.pause() | ||
|
||
if __name__ == "__main__": | ||
app = StyledExtProgressBar() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.containers import Center, Middle | ||
from textual.timer import Timer | ||
from textual.widgets import Footer, ProgressBar | ||
|
||
|
||
class StyledExtProgressBar(App[None]): | ||
BINDINGS = [ | ||
("s", "start", "Start"), | ||
] | ||
CSS_PATH = "progress_bar_styled.css" | ||
|
||
progress_timer: Timer | ||
"""Timer to simulate progress happening.""" | ||
|
||
def compose(self) -> ComposeResult: | ||
with Center(): | ||
with Middle(): | ||
yield ProgressBar(thickness=2) | ||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
"""Set up a timer to simulate progess happening.""" | ||
self.progress_timer = self.set_interval(1 / 10, self.make_progress, pause=True) | ||
|
||
def make_progress(self) -> None: | ||
"""Called automatically to advance the progress bar.""" | ||
self.query_one(ProgressBar).advance(1) | ||
|
||
def action_start(self) -> None: | ||
"""Start the progress tracking.""" | ||
self.query_one(ProgressBar).update(total=100) | ||
self.progress_timer.resume() | ||
|
||
|
||
if __name__ == "__main__": | ||
app = StyledExtProgressBar() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.containers import Center, Middle | ||
from textual.timer import Timer | ||
from textual.widgets import Footer, ProgressBar | ||
|
||
|
||
class StyledExtProgressBar(App[None]): | ||
BINDINGS = [ | ||
("s", "start", "Start"), | ||
] | ||
CSS_PATH = "progress_bar_styled.css" | ||
|
||
progress_timer: Timer | ||
"""Timer to simulate progress happening.""" | ||
|
||
def compose(self) -> ComposeResult: | ||
with Center(): | ||
with Middle(): | ||
yield ProgressBar() | ||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
"""Set up a timer to simulate progess happening.""" | ||
self.progress_timer = self.set_interval(1 / 10, self.make_progress, pause=True) | ||
|
||
def make_progress(self) -> None: | ||
"""Called automatically to advance the progress bar.""" | ||
self.query_one(ProgressBar).advance(1) | ||
|
||
def action_start(self) -> None: | ||
"""Start the progress tracking.""" | ||
self.query_one(ProgressBar).update(total=100) | ||
self.progress_timer.resume() | ||
|
||
def key_0(self) -> None: | ||
self._action_common_keypress(0) | ||
|
||
def key_1(self) -> None: | ||
self._action_common_keypress(1) | ||
|
||
def key_2(self) -> None: | ||
self._action_common_keypress(2) | ||
|
||
def _action_common_keypress(self, thickness: int) -> None: | ||
# Freeze time for the indeterminate progress bar. | ||
self.query_one(ProgressBar).query_one("#eta")._get_elapsed_time = lambda: 0 | ||
self.query_one(ProgressBar).query_one("#bar").thickness = thickness | ||
self.query_one(ProgressBar).update(total=100, progress=50) | ||
self.progress_timer.pause() | ||
|
||
if __name__ == "__main__": | ||
app = StyledExtProgressBar() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.