Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for footer #670

Merged
merged 10 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sandbox/will/add_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class AddRemoveApp(App):
CSS = """
#buttons {
dock: top;
height: auto;
height: auto;
}
Button {
#buttons Button {
width: 1fr;
}
#items {
Expand All @@ -26,8 +26,8 @@ class AddRemoveApp(App):
Thing {
height: 5;
background: $panel;
border: wide $primary;
margin: 0 1;
border: tall $primary;
margin: 1 1;
content-align: center middle;
}
"""
Expand Down
18 changes: 7 additions & 11 deletions sandbox/will/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ App > Screen {

background: $surface;
color: $text-surface;
layers: sidebar;
layers: base sidebar;

color: $text-background;
background: $background;
layout: vertical;

overflow: hidden;

}

Expand All @@ -47,14 +49,15 @@ DataTable {
/* opacity: 50%; */
padding: 1;
margin: 1 2;
height: 12;
height: 24;
}

#sidebar {
color: $text-panel;
background: $panel;
dock: left;
width: 30;
margin-bottom: 1;
offset-x: -100%;

transition: offset 500ms in_out_cubic;
Expand Down Expand Up @@ -88,14 +91,7 @@ DataTable {
content-align: center middle;
}

#header {
color: $text-secondary-background;
background: $secondary-background;
height: 1;
content-align: center middle;

dock: top;
}



Tweet {
Expand All @@ -120,7 +116,7 @@ Tweet {
overflow-x: auto;
overflow-y: scroll;
margin: 1 2;
height: 20;
height: 24;
align-horizontal: center;
layout: vertical;
}
Expand Down
45 changes: 32 additions & 13 deletions sandbox/will/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from textual.app import App, ComposeResult
from textual.reactive import Reactive
from textual.widget import Widget
from textual.widgets import Static, DataTable, DirectoryTree
from textual.layout import Vertical
from textual.widgets import Static, DataTable, DirectoryTree, Header, Footer
from textual.layout import Container

CODE = '''
from __future__ import annotations
Expand Down Expand Up @@ -109,19 +109,18 @@ class BasicApp(App, css_path="basic.css"):

def on_load(self):
"""Bind keys here."""
self.bind("s", "toggle_class('#sidebar', '-active')")
self.bind("s", "toggle_class('#sidebar', '-active')", description="Sidebar")
self.bind("d", "toggle_dark", description="Dark mode")
self.bind("q", "quit", description="Quit")
self.bind("f", "query_test", description="Query test")

def compose(self):
yield Header()

def compose(self) -> ComposeResult:
table = DataTable()
self.scroll_to_target = Tweet(TweetBody())

yield Static(
Text.from_markup(
"[b]This is a [u]Textual[/u] app, running in the terminal"
),
id="header",
)
yield from (
yield Container(
Tweet(TweetBody()),
Widget(
Static(
Expand All @@ -143,7 +142,6 @@ def compose(self) -> ComposeResult:
Tweet(TweetBody(), classes="scroll-horizontal"),
Tweet(TweetBody(), classes="scroll-horizontal"),
)
yield Widget(id="footer")
yield Widget(
Widget(classes="title"),
Widget(classes="user"),
Expand All @@ -153,6 +151,7 @@ def compose(self) -> ComposeResult:
Widget(classes="content"),
id="sidebar",
)
yield Footer()

table.add_column("Foo", width=20)
table.add_column("Bar", width=20)
Expand All @@ -164,12 +163,32 @@ def compose(self) -> ComposeResult:
for n in range(100):
table.add_row(*[f"Cell ([b]{n}[/b], {col})" for col in range(6)])

def on_mount(self):
self.sub_title = "Widget demo"

async def on_key(self, event) -> None:
await self.dispatch_key(event)

def key_d(self):
def action_toggle_dark(self):
self.dark = not self.dark

def action_query_test(self):
query = self.query("Tweet")
self.log(query)
self.log(query.nodes)
self.log(query)
self.log(query.nodes)

query.set_styles("outline: outer red;")

query = query.exclude(".scroll-horizontal")
self.log(query)
self.log(query.nodes)

# query = query.filter(".rubbish")
# self.log(query)
# self.log(query.first())

async def key_q(self):
await self.shutdown()

Expand Down
8 changes: 8 additions & 0 deletions sandbox/will/fill.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
App Static {
border: heavy white;
background: blue;
color: white;
height: 100%;

box-sizing: border-box;
}
10 changes: 10 additions & 0 deletions sandbox/will/fill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from textual.app import App, ComposeResult
from textual.widgets import Static


class FillApp(App):
def compose(self) -> ComposeResult:
yield Static("Hello")


app = FillApp(css_path="fill.css")
17 changes: 17 additions & 0 deletions sandbox/will/footer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from textual.app import App
from textual.widgets import Header, Footer


class FooterApp(App):
def on_mount(self):
self.sub_title = "Header and footer example"
self.bind("b", "app.bell", description="Play the Bell")
self.bind("d", "dark", description="Toggle dark")
self.bind("f1", "app.bell", description="Hello World")

def action_dark(self):
self.dark = not self.dark

def compose(self):
yield Header()
yield Footer()
3 changes: 2 additions & 1 deletion src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,6 @@ async def broker_event(
Returns:
bool: True if an action was processed.
"""
event.stop()
try:
style = getattr(event, "style")
except AttributeError:
Expand All @@ -1091,6 +1090,8 @@ async def broker_event(
modifiers, action = extract_handler_actions(event_name, style.meta)
except NoHandler:
return False
else:
event.stop()
if isinstance(action, str):
await self.action(
action, default_namespace=default_namespace, modifiers=modifiers
Expand Down
10 changes: 6 additions & 4 deletions src/textual/box_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ def get_box_model(
)
else:
# An explicit width
content_width = styles.width.resolve_dimension(
styles_width = styles.width
content_width = styles_width.resolve_dimension(
sizing_container - styles.margin.totals, viewport, fraction_unit
)
if is_border_box:
if is_border_box and styles_width.excludes_border:
content_width -= gutter.width

if styles.min_width is not None:
Expand Down Expand Up @@ -92,11 +93,12 @@ def get_box_model(
get_content_height(content_container, viewport, int(content_width))
)
else:
styles_height = styles.height
# Explicit height set
content_height = styles.height.resolve_dimension(
content_height = styles_height.resolve_dimension(
sizing_container - styles.margin.totals, viewport, fraction_unit
)
if is_border_box:
if is_border_box and styles_height.excludes_border:
content_height -= gutter.height

if styles.min_height is not None:
Expand Down
3 changes: 3 additions & 0 deletions src/textual/css/_help_renderables.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def __init__(self, summary: str, *, bullets: Iterable[Bullet] = None) -> None:
self.summary = summary
self.bullets = bullets or []

def __str__(self) -> str:
return self.summary

def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:
Expand Down
4 changes: 2 additions & 2 deletions src/textual/css/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@


class DeclarationError(Exception):
def __init__(self, name: str, token: Token, message: str) -> None:
def __init__(self, name: str, token: Token, message: str | HelpText) -> None:
self.name = name
self.token = token
self.message = message
super().__init__(message)
super().__init__(str(message))


class StyleTypeError(TypeError):
Expand Down
4 changes: 4 additions & 0 deletions src/textual/css/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def __post_init__(self) -> None:
for selector, next_selector in zip(self.selectors, self.selectors[1:]):
selector.advance = int(next_selector.combinator != SAME)

@property
def css(self) -> str:
return RuleSet._selector_to_css(self.selectors)

def __rich_repr__(self) -> rich.repr.Result:
selectors = RuleSet._selector_to_css(self.selectors)
yield selectors
Expand Down
Loading