-
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.
- Loading branch information
1 parent
618a450
commit a85edb7
Showing
1 changed file
with
58 additions
and
0 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,58 @@ | ||
from time import time | ||
|
||
from textual.app import App, ComposeResult, RenderableType | ||
from textual.containers import Container | ||
from textual.renderables.gradient import LinearGradient | ||
from textual.widgets import Static | ||
|
||
COLORS = [ | ||
"#881177", | ||
"#aa3355", | ||
"#cc6666", | ||
"#ee9944", | ||
"#eedd00", | ||
"#99dd55", | ||
"#44dd88", | ||
"#22ccbb", | ||
"#00bbcc", | ||
"#0099cc", | ||
"#3366bb", | ||
"#663399", | ||
] | ||
STOPS = [(i / (len(COLORS) - 1), color) for i, color in enumerate(COLORS)] | ||
|
||
|
||
class Splash(Container): | ||
"""Custom widget that extends Container.""" | ||
|
||
DEFAULT_CSS = """ | ||
Splash { | ||
align: center middle; | ||
} | ||
Static { | ||
width: 40; | ||
padding: 2 4; | ||
} | ||
""" | ||
|
||
def on_mount(self) -> None: | ||
self.auto_refresh = 1 / 30 | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Static("Making a splash with Textual!") | ||
|
||
def render(self) -> RenderableType: | ||
return LinearGradient(time() * 90, STOPS) | ||
|
||
|
||
class SplashApp(App): | ||
"""Simple app to show our custom widget.""" | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Splash() | ||
|
||
|
||
if __name__ == "__main__": | ||
app = SplashApp() | ||
app.run() | ||
print("https://textual.textualize.io/how-to/render-and-compose/") |