-
Notifications
You must be signed in to change notification settings - Fork 840
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add loading reactive * loading indicator example * Apply suggestions from code review Co-authored-by: Rodrigo Girão Serrão <[email protected]> * into * changelog --------- Co-authored-by: Rodrigo Girão Serrão <[email protected]>
- Loading branch information
1 parent
5cf0e1a
commit 47af5e0
Showing
6 changed files
with
191 additions
and
4 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
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,54 @@ | ||
from asyncio import sleep | ||
from random import randint | ||
|
||
from textual import work | ||
from textual.app import App, ComposeResult | ||
from textual.widgets import DataTable | ||
|
||
ROWS = [ | ||
("lane", "swimmer", "country", "time"), | ||
(4, "Joseph Schooling", "Singapore", 50.39), | ||
(2, "Michael Phelps", "United States", 51.14), | ||
(5, "Chad le Clos", "South Africa", 51.14), | ||
(6, "László Cseh", "Hungary", 51.14), | ||
(3, "Li Zhuhao", "China", 51.26), | ||
(8, "Mehdy Metella", "France", 51.58), | ||
(7, "Tom Shields", "United States", 51.73), | ||
(1, "Aleksandr Sadovnikov", "Russia", 51.84), | ||
(10, "Darren Burns", "Scotland", 51.84), | ||
] | ||
|
||
|
||
class DataApp(App): | ||
CSS = """ | ||
Screen { | ||
layout: grid; | ||
grid-size: 2; | ||
} | ||
DataTable { | ||
height: 1fr; | ||
} | ||
""" | ||
|
||
def compose(self) -> ComposeResult: | ||
yield DataTable() | ||
yield DataTable() | ||
yield DataTable() | ||
yield DataTable() | ||
|
||
def on_mount(self) -> None: | ||
for data_table in self.query(DataTable): | ||
data_table.loading = True # (1)! | ||
self.load_data(data_table) | ||
|
||
@work | ||
async def load_data(self, data_table: DataTable) -> None: | ||
await sleep(randint(2, 10)) # (2)! | ||
data_table.add_columns(*ROWS[0]) | ||
data_table.add_rows(ROWS[1:]) | ||
data_table.loading = False # (3)! | ||
|
||
|
||
if __name__ == "__main__": | ||
app = DataApp() | ||
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
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