Skip to content

Commit

Permalink
end of file
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Aug 31, 2021
1 parent 0696468 commit 3f28a36
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 10 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/comment.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 36 additions & 0 deletions examples/big_table.py
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion src/textual/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/textual/layouts/vertical.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ def generate_map(
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)
Expand Down
11 changes: 4 additions & 7 deletions src/textual/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

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
Expand Down Expand Up @@ -86,10 +86,7 @@ def render(self) -> RenderableType:
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
Expand All @@ -99,7 +96,7 @@ async def handle_update(self, message: Update) -> None:
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()
Expand Down Expand Up @@ -245,4 +242,4 @@ async def forward_event(self, event: events.Event) -> None:
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))
33 changes: 33 additions & 0 deletions tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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)

0 comments on commit 3f28a36

Please sign in to comment.