You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if I could get some tips on styling the bar component of a ProgressBar that is inside a widget? For testing purposes, I'm aiming for a small bar that is red:
I've consulted the Progress Bar docs, and can achieve the desired style by declaring the CSS globally inside the app's main CSS attribute:
fromtextual.appimportApp, ComposeResultfromtextual.containersimportCenter, Middlefromtextual.timerimportTimerfromtextual.widgetsimportFooter, ProgressBarclassStyledProgressBar(ProgressBar):
defcompose(self) ->ComposeResult:
yieldProgressBar()
classStyledProgressBarApp(App[None]):
BINDINGS= [("s", "start", "Start")]
CSS=""" Bar { width: 10; } Bar > .bar--bar { color: red; background: yellow 50%; } """progress_timer: Timer"""Timer to simulate progress happening."""defcompose(self) ->ComposeResult:
withCenter():
withMiddle():
yieldStyledProgressBar()
yieldFooter()
defon_mount(self) ->None:
"""Set up a timer to simulate progress happening."""self.progress_timer=self.set_interval(1/10, self.make_progress, pause=True)
defmake_progress(self) ->None:
"""Called automatically to advance the progress bar."""self.query_one(StyledProgressBar).query_one(ProgressBar).advance(1)
defaction_start(self) ->None:
"""Start the progress tracking."""self.query_one(StyledProgressBar).query_one(ProgressBar).update(total=100)
self.progress_timer.resume()
if__name__=="__main__":
StyledProgressBarApp().run()
But I can't figure out how to achieve this customization locally in the widget, without setting a global style. This is what I was hoping would work, but I just get whatever the default/global style is instead:
classStyledProgressBar(ProgressBar):
DEFAULT_CSS=""" Bar { width: 10; } Bar > .bar--bar { color: red; background: yellow 50%; } """defcompose(self) ->ComposeResult:
yieldProgressBar()
Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered:
Hah, I figured it out. Sometimes you just need to say something "out loud" 😆. This is how the widget DEFAULT_CSS needs to be defined. I don't yet understand why this CSS works, but it does!
I was wondering if I could get some tips on styling the bar component of a
ProgressBar
that is inside a widget? For testing purposes, I'm aiming for a small bar that is red:I've consulted the Progress Bar docs, and can achieve the desired style by declaring the CSS globally inside the app's main
CSS
attribute:But I can't figure out how to achieve this customization locally in the widget, without setting a global style. This is what I was hoping would work, but I just get whatever the default/global style is instead:
Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: