https://github.com/cvaniak/textuallistviewunofficial
Unofficial Textual List View for Widgets that supports scrolling. Short and dirty hack to use while waiting for official ListView.
https://github.com/cvaniak/textuallistviewunofficial
listview rich scroll scrollable textual widgets
Last synced: 4 months ago
JSON representation
Unofficial Textual List View for Widgets that supports scrolling. Short and dirty hack to use while waiting for official ListView.
- Host: GitHub
- URL: https://github.com/cvaniak/textuallistviewunofficial
- Owner: Cvaniak
- License: mit
- Created: 2022-02-20T08:28:33.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-02-22T15:39:47.000Z (over 3 years ago)
- Last Synced: 2023-03-10T19:35:58.832Z (over 2 years ago)
- Topics: listview, rich, scroll, scrollable, textual, widgets
- Language: Python
- Homepage:
- Size: 5.25 MB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Unofficial [Textual](https://github.com/Textualize) List View (Scrollable list of widgets)
While waiting for [ticket](https://github.com/Textualize/textual/projects/1#card-66941810) (also mentioned [here](https://github.com/Textualize/textual/discussions/196)) and official `ListView`, you can use this dirty version that allows you to scroll thrue list of widgets.
## Demo

## Installation
This is not pip package but you can install this with pip:
```bash
pip3 install git+https://github.com/Cvaniak/TextualListViewUnofficial.git
```
## Usage
Then in code you can use it this way:
```python
from ck_widgets_lv import ListViewUo
class TestListView(App):
async def on_mount(self, event: events.Mount) -> None:
await self.view.dock(ListViewUo([Placeholder(height=10) for _ in range(20)]))
if __name__ == "__main__":
TestListView.run()
```
or more complex example (from gif demo above):
```python3
from textual.widgets import Placeholder
from textual.widget import Widget
from textual.events import Message
from textual.app import App
from textual import events
from ck_widgets_lv import ListViewUo
if __name__ == "__main__":
from textual.widgets import Footer
class DeleteStatus(Message):
def __init__(self, sender: Widget):
super().__init__(sender)
self.to_delete = sender
class DeletablePlaceholder(Placeholder):
async def on_click(self, event: events.Click) -> None:
await self.emit(DeleteStatus(self))
class TestListView(App):
async def action_add(self) -> None:
await self.list_view.add_widget(DeletablePlaceholder(height=10))
self.refresh()
async def action_add_index_2(self) -> None:
await self.list_view.add_widget(DeletablePlaceholder(height=10), index=2)
self.refresh()
async def action_remove(self) -> None:
await self.list_view.remove_widget_by_index()
self.refresh()
async def action_remove_index_2(self) -> None:
await self.list_view.remove_widget_by_index(index=2)
self.refresh()
async def on_load(self, _: events.Load) -> None:
await self.bind("a", "add()", "Add Widget")
await self.bind("s", "add_index_2()", "Add Widget in index 2")
await self.bind("r", "remove()", "Remove Widget")
await self.bind("e", "remove_index_2()", "Remove Widget in index 2")
await self.bind("Click Widget", "_()", "To delete it")
async def on_mount(self, event: events.Mount) -> None:
self.list_view = ListViewUo(
[DeletablePlaceholder(height=10) for _ in range(7)]
)
await self.view.dock(Footer(), edge="bottom")
await self.view.dock(self.list_view)
async def handle_delete_status(self, message: DeleteStatus):
await self.list_view.remove_widget(message.to_delete)
TestListView.run()
```