end of file

This commit is contained in:
Will McGugan
2021-08-31 17:34:19 +01:00
parent 0696468a1c
commit 3f28a36028
6 changed files with 96 additions and 10 deletions

22
.github/workflows/comment.yml vendored Normal file
View File

@@ -0,0 +1,22 @@
name: issues
on:
issues:
types: [closed]
jobs:
add-comment:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Did I solve your problem?
uses: peter-evans/create-or-update-comment@a35cf36e5301d70b76f316e867e7788a55a31dae
with:
issue-number: ${{ github.event.issue.number }}
body: |
Did I solve your problem?
Consider [sponsoring my work](https://github.com/sponsors/willmcgugan) on Textual with a monthly donation.
Or buy me a [coffee](https://ko-fi.com/willmcgugan) to say thanks.
– [Will McGugan](https://twitter.com/willmcgugan)

36
examples/big_table.py Normal file
View File

@@ -0,0 +1,36 @@
from rich.table import Table
from rich.measure import Measurement
from textual import events
from textual.app import App
from textual.widgets import Header, Footer, ScrollView
class MyApp(App):
"""An example of a very simple Textual App"""
async def on_load(self, event: events.Load) -> None:
await self.bind("q", "quit", "Quit")
async def on_mount(self, event: events.Mount) -> None:
self.body = body = ScrollView()
#body.virtual_size.width = 300
await self.view.dock(body)
async def add_content():
table = Table(title="Demo", width=1000)
for i in range(40):
table.add_column(f'Col {i + 1}', style='magenta')
for i in range(200):
table.add_row(*[f'cell {i},{j}' for j in range(40)])
await body.update(table)
await self.call_later(add_content)
MyApp.run(title="Simple App", log="textual.log")

View File

@@ -74,7 +74,7 @@ class Size(NamedTuple):
height: int
def __bool__(self) -> bool:
"""A Size is Falsey if it has area 0"""
"""A Size is Falsey if it has area 0."""
return self.width * self.height != 0
@property

View File

@@ -36,8 +36,6 @@ class VerticalLayout(Layout):
gutter_height, gutter_width = self.gutter
render_width = width - gutter_width * 2
render_width = 1000 + gutter_width * 2
x = gutter_width
y = gutter_height
map: LayoutMap = LayoutMap(size)

View File

@@ -9,9 +9,9 @@ from rich.style import Style
from . import events
from . import log
from . import messages
from .layout import Layout, NoWidget
from .geometry import Size, Offset, Region
from .messages import Update, Layout
from .reactive import Reactive, watch
from .widget import Widget, Widget
@@ -86,10 +86,7 @@ class View(Widget):
def get_offset(self, widget: Widget) -> Offset:
return self.layout.get_offset(widget)
# def check_layout(self) -> bool:
# return super().check_layout() or self.layout.check_update()
async def handle_update(self, message: Update) -> None:
async def handle_update(self, message: messages.Update) -> None:
if self.is_root_view:
message.stop()
widget = message.widget
@@ -99,7 +96,7 @@ class View(Widget):
if display_update is not None:
self.app.display(display_update)
async def handle_layout(self, message: Layout) -> None:
async def handle_layout(self, message: messages.Layout) -> None:
if self.is_root_view:
message.stop()
await self.refresh_layout()
@@ -245,4 +242,4 @@ class View(Widget):
async def action_toggle(self, name: str) -> None:
widget = self.named_widgets[name]
widget.visible = not widget.visible
await self.post_message(Layout(self))
await self.post_message(messages.Layout(self))

View File

@@ -60,6 +60,7 @@ def test_clamp():
assert clamp(11, 0, 10) == 10
assert clamp(0, 0, 10) == 0
assert clamp(10, 0, 10) == 10
assert clamp(5, 10, 0) == 5
def test_point_is_origin():
@@ -185,3 +186,35 @@ def test_region_intersection():
def test_region_union():
assert Region(5, 5, 10, 10).union(Region(20, 30, 10, 5)) == Region(5, 5, 25, 30)
def test_size_add():
assert Size(5, 10) + Size(2, 3) == Size(7, 13)
def test_size_sub():
assert Size(5, 10) - Size(2, 3) == Size(3, 7)
def test_region_x_extents():
assert Region(5, 10, 20, 30).x_extents == (5, 25)
def test_region_y_extents():
assert Region(5, 10, 20, 30).y_extents == (10, 40)
def test_region_x_max():
assert Region(5, 10, 20, 30).x_max == 25
def test_region_y_max():
assert Region(5, 10, 20, 30).y_max == 40
def test_region_x_range():
assert Region(5, 10, 20, 30).x_range == range(5, 25)
def test_region_y_range():
assert Region(5, 10, 20, 30).y_range == range(10, 40)