mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge branch 'main' into strip-optimization
This commit is contained in:
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
- Added textual.strip.Strip primitive
|
||||
- Added textual._cache.FIFOCache
|
||||
- Added an option to clear columns in DataTable.clear() https://github.com/Textualize/textual/pull/1427
|
||||
|
||||
## [0.8.2] - 2022-12-28
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ The Textual repository comes with a number of example apps. To try out the examp
|
||||
```
|
||||
|
||||
|
||||
With the repository cloned, navigate to the `/examples/` directory where you fill find a number of Python files you can run from the command line:
|
||||
With the repository cloned, navigate to the `/examples/` directory where you will find a number of Python files you can run from the command line:
|
||||
|
||||
```bash
|
||||
cd textual/examples/
|
||||
|
||||
@@ -314,7 +314,7 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
|
||||
cell_region = Region(x, y, width, height)
|
||||
return cell_region
|
||||
|
||||
def clear(self) -> None:
|
||||
def clear(self, columns: bool = False) -> None:
|
||||
"""Clear the table.
|
||||
|
||||
Args:
|
||||
@@ -325,6 +325,8 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
|
||||
self._y_offsets.clear()
|
||||
self.data.clear()
|
||||
self.rows.clear()
|
||||
if columns:
|
||||
self.columns.clear()
|
||||
self._line_no = 0
|
||||
self._require_update_dimensions = True
|
||||
self.refresh()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import asyncio
|
||||
|
||||
from rich.text import Text
|
||||
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import DataTable
|
||||
|
||||
@@ -18,13 +20,32 @@ async def test_table_clear() -> None:
|
||||
table.add_columns("foo", "bar")
|
||||
assert table.row_count == 0
|
||||
table.add_row("Hello", "World!")
|
||||
assert [col.label for col in table.columns] == [Text("foo"), Text("bar")]
|
||||
assert table.data == {0: ["Hello", "World!"]}
|
||||
assert table.row_count == 1
|
||||
table.clear()
|
||||
assert [col.label for col in table.columns] == [Text("foo"), Text("bar")]
|
||||
assert table.data == {}
|
||||
assert table.row_count == 0
|
||||
|
||||
|
||||
async def test_table_clear_with_columns() -> None:
|
||||
"""Check DataTable.clear(columns=True)"""
|
||||
|
||||
app = TableApp()
|
||||
async with app.run_test() as pilot:
|
||||
table = app.query_one(DataTable)
|
||||
table.add_columns("foo", "bar")
|
||||
assert table.row_count == 0
|
||||
table.add_row("Hello", "World!")
|
||||
assert [col.label for col in table.columns] == [Text("foo"), Text("bar")]
|
||||
assert table.data == {0: ["Hello", "World!"]}
|
||||
assert table.row_count == 1
|
||||
table.clear(columns=True)
|
||||
assert [col.label for col in table.columns] == []
|
||||
assert table.data == {}
|
||||
assert table.row_count == 0
|
||||
|
||||
async def test_table_add_row() -> None:
|
||||
|
||||
app = TableApp()
|
||||
|
||||
Reference in New Issue
Block a user